Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: tx modal success stage for multisig #15

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions features/home/stake-form/stake-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ export const StakeForm: FC = memo(() => {
providerWeb3,
stethContractWeb3,
openTxModal,
closeTxModal,
setTxStage,
setTxHash,
setTxModalFailedText,
Expand All @@ -113,7 +112,6 @@ export const StakeForm: FC = memo(() => {
providerWeb3,
stethContractWeb3,
openTxModal,
closeTxModal,
stethBalance.update,
chainId,
router?.query?.ref,
Expand Down
6 changes: 2 additions & 4 deletions features/home/stake-form/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ type StakeProcessingProps = (
providerWeb3: Web3Provider | undefined,
stethContractWeb3: StethAbi | null,
openTxModal: () => void,
closeTxModal: () => void,
setTxStage: (value: TX_STAGE) => void,
setTxHash: (value: string | undefined) => void,
setTxModalFailedText: (value: string) => void,
Expand Down Expand Up @@ -68,7 +67,6 @@ export const stakeProcessing: StakeProcessingProps = async (
providerWeb3,
stethContractWeb3,
openTxModal,
closeTxModal,
setTxStage,
setTxHash,
setTxModalFailedText,
Expand Down Expand Up @@ -148,12 +146,13 @@ export const stakeProcessing: StakeProcessingProps = async (
);

const handleEnding = () => {
openTxModal();
resetForm();
stethBalanceUpdate();
};

if (isMultisig) {
closeTxModal();
setTxStage(TX_STAGE.SUCCESS_MULTISIG);
handleEnding();
return;
}
Expand All @@ -168,7 +167,6 @@ export const stakeProcessing: StakeProcessingProps = async (
}

setTxStage(TX_STAGE.SUCCESS);
openTxModal();
handleEnding();
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
} catch (error: any) {
Expand Down
3 changes: 3 additions & 0 deletions features/withdrawals/claim/tx-modal/tx-claim-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
TxStageModal,
TxStagePending,
TxStageSuccess,
TxStageSuccessMultisig,
TxStageSign,
TxStageFail,
TX_STAGE,
Expand Down Expand Up @@ -65,6 +66,8 @@ export const TxClaimModal = () => {
}
/>
);
case TX_STAGE.SUCCESS_MULTISIG:
return <TxStageSuccessMultisig />;
case TX_STAGE.FAIL:
return (
<TxStageFail
Expand Down
9 changes: 9 additions & 0 deletions features/withdrawals/contexts/transaction-modal-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ type TransactionModalAction =
}
| {
type: 'success';
}
| {
type: 'success_multisig';
Jeday marked this conversation as resolved.
Show resolved Hide resolved
};

const TransactionModalContext =
Expand Down Expand Up @@ -149,6 +152,12 @@ const TransactionModalReducer = (
isModalOpen: true,
txStage: TX_STAGE.SUCCESS,
};
case 'success_multisig':
return {
...state,
isModalOpen: true,
txStage: TX_STAGE.SUCCESS_MULTISIG,
};
case 'error':
return {
...state,
Expand Down
4 changes: 3 additions & 1 deletion features/withdrawals/hooks/contract/useClaim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ export const useClaim = () => {
);
}
await update();
dispatchModalState({ type: isMultisig ? 'reset' : 'success' });
dispatchModalState({
type: isMultisig ? 'success_multisig' : 'success',
});
} catch (error) {
const errorMessage = getErrorMessage(error);
dispatchModalState({ type: 'error', errorText: errorMessage });
Expand Down
7 changes: 3 additions & 4 deletions features/withdrawals/hooks/contract/useRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,6 @@ export const useWithdrawalRequest = ({
});
if (!bunkerDialogResult) return { success: false };
}
// we can't know if tx was successful or even wait for it with multisig
// so we exit flow gracefully and reset UI
const shouldSkipSuccess = isMultisig;
// get right method
const method = getRequestMethod(isApprovalFlow, token);
// start flow
Expand Down Expand Up @@ -383,7 +380,9 @@ export const useWithdrawalRequest = ({
await method({ signature, requests });
}
// end flow
dispatchModalState({ type: shouldSkipSuccess ? 'reset' : 'success' });
dispatchModalState({
type: isMultisig ? 'success_multisig' : 'success',
});
return { success: true };
} catch (error) {
const errorMessage = getErrorMessage(error);
Expand Down
3 changes: 3 additions & 0 deletions features/withdrawals/request/tx-modal/tx-request-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
TxStagePermit,
TxStageFail,
TxStageBunker,
TxStageSuccessMultisig,
TX_STAGE,
} from 'features/withdrawals/shared/tx-stage-modal';
import { useTransactionModal } from 'features/withdrawals/contexts/transaction-modal-context';
Expand Down Expand Up @@ -67,6 +68,8 @@ export const TxRequestModal = () => {
amountAsString={amountAsString}
/>
);
case TX_STAGE.SUCCESS_MULTISIG:
return <TxStageSuccessMultisig />;
case TX_STAGE.FAIL:
return (
<TxStageFail
Expand Down
10 changes: 10 additions & 0 deletions features/withdrawals/shared/tx-stage-modal/stages/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export const iconsDict = {
<LedgerSuccess fill="transparent" />
</LedgerIconWrapper>
),
[TX_STAGE.SUCCESS_MULTISIG]: (
<LedgerIconWrapper>
<LedgerSuccess fill="transparent" />
</LedgerIconWrapper>
),
[TX_STAGE.SIGN]: (
<LedgerIconWrapper>
<LedgerConfirm fill="transparent" />
Expand Down Expand Up @@ -54,6 +59,11 @@ export const iconsDict = {
<SuccessIcon />
</IconWrapper>
),
[TX_STAGE.SUCCESS_MULTISIG]: (
<IconWrapper>
<SuccessIcon />
</IconWrapper>
),
[TX_STAGE.FAIL]: (
<IconWrapper>
<FailIcon />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './tx-stage-pending';
export * from './tx-stage-success';
export * from './tx-stage-success-multisig';
export * from './tx-stage-sign';
export * from './tx-stage-permit';
export * from './tx-stage-fail';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useConnectorInfo } from 'reef-knot/web3-react';

import { TxStageModalContent } from 'shared/components/tx-stage-modal-content';
import { getStageIcon } from './icons';
import { TX_STAGE } from '../types';

export const TxStageSuccessMultisig = () => {
const { isLedger } = useConnectorInfo();
return (
<TxStageModalContent
icon={getStageIcon(isLedger, TX_STAGE.SUCCESS_MULTISIG)}
title="Success"
description="Your transaction has been successfully created in the multisig wallet and awaits approval from other participants"
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ export const TxStageModal: FC<TxStageModalProps> = (props) => {
() =>
isLedger &&
txStage &&
![TX_STAGE.SUCCESS, TX_STAGE.FAIL].includes(txStage),
![TX_STAGE.SUCCESS, TX_STAGE.SUCCESS_MULTISIG, TX_STAGE.FAIL].includes(
txStage,
),
[isLedger, txStage],
);

Expand Down
1 change: 1 addition & 0 deletions features/withdrawals/shared/tx-stage-modal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum TX_STAGE {
SIGN,
BLOCK,
SUCCESS,
SUCCESS_MULTISIG,
FAIL,
BUNKER,
}
2 changes: 0 additions & 2 deletions features/wrap/features/unwrap-form/unwrap-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export const UnwrapForm: FC = memo(() => {
providerWeb3,
wstethContractWeb3,
openTxModal,
closeTxModal,
setTxStage,
setTxHash,
setTxModalFailedText,
Expand All @@ -97,7 +96,6 @@ export const UnwrapForm: FC = memo(() => {
providerWeb3,
wstethContractWeb3,
openTxModal,
closeTxModal,
wstethBalance.update,
stethBalance.update,
chainId,
Expand Down
4 changes: 0 additions & 4 deletions features/wrap/features/wrap-form/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ type FromProps = {
setTxOperation: (value: TX_OPERATION) => void;
setInputValue: (value: string) => void;
openTxModal: () => void;
closeTxModal: () => void;
setTxStage: (value: TX_STAGE) => void;
setTxHash: (value?: string) => void;
setTxModalFailedText: (value: string) => void;
Expand All @@ -67,7 +66,6 @@ export const Form: FC<FromProps> = (props) => {
setWrappingAmountValue,
setTxOperation,
openTxModal,
closeTxModal,
setTxStage,
setTxHash,
setTxModalFailedText,
Expand Down Expand Up @@ -108,7 +106,6 @@ export const Form: FC<FromProps> = (props) => {
providerWeb3,
wstethContractWeb3,
openTxModal,
closeTxModal,
setTxStage,
setTxHash,
setTxModalFailedText,
Expand All @@ -134,7 +131,6 @@ export const Form: FC<FromProps> = (props) => {
chainId,
wstethContractWeb3,
openTxModal,
closeTxModal,
setTxStage,
setTxHash,
setTxModalFailedText,
Expand Down
7 changes: 3 additions & 4 deletions features/wrap/features/wrap-form/wrap-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ export const WrapForm: FC = memo(() => {
);

if (isMultisig) {
setTxStage(TX_STAGE.IDLE);
closeTxModal();
setTxStage(TX_STAGE.SUCCESS_MULTISIG);
openTxModal();
return;
}

Expand All @@ -130,7 +130,7 @@ export const WrapForm: FC = memo(() => {
openTxModal();
}
},
[openTxModal, closeTxModal, isMultisig],
[openTxModal, isMultisig],
);

const {
Expand Down Expand Up @@ -167,7 +167,6 @@ export const WrapForm: FC = memo(() => {
setTxOperation={setTxOperation}
setInputValue={setInputValue}
openTxModal={openTxModal}
closeTxModal={closeTxModal}
setTxStage={setTxStage}
setTxHash={setTxHash}
setTxModalFailedText={setTxModalFailedText}
Expand Down
21 changes: 8 additions & 13 deletions features/wrap/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ type UnwrapProcessingProps = (
providerWeb3: Web3Provider | undefined,
stethContractWeb3: WstethAbi | null,
openTxModal: () => void,
closeTxModal: () => void,
setTxStage: (value: TX_STAGE) => void,
setTxHash: (value: string | undefined) => void,
setTxModalFailedText: (value: string) => void,
Expand All @@ -30,7 +29,6 @@ export const unwrapProcessing: UnwrapProcessingProps = async (
providerWeb3,
wstethContractWeb3,
openTxModal,
closeTxModal,
setTxStage,
setTxHash,
setTxModalFailedText,
Expand Down Expand Up @@ -76,14 +74,15 @@ export const unwrapProcessing: UnwrapProcessingProps = async (
);

const handleEnding = () => {
openTxModal();
resetForm();
stethBalanceUpdate();
wstethBalanceUpdate();
};

if (isMultisig) {
setTxStage(TX_STAGE.SUCCESS_MULTISIG);
handleEnding();
closeTxModal();
return;
}

Expand All @@ -96,9 +95,8 @@ export const unwrapProcessing: UnwrapProcessingProps = async (
);
}

handleEnding();
setTxStage(TX_STAGE.SUCCESS);
openTxModal();
handleEnding();
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
} catch (error: any) {
// errors are sometimes nested :(
Expand All @@ -114,7 +112,6 @@ type WrapProcessingWithApproveProps = (
providerWeb3: Web3Provider | undefined,
stethContractWeb3: WstethAbi | null,
openTxModal: () => void,
closeTxModal: () => void,
setTxStage: (value: TX_STAGE) => void,
setTxHash: (value: string | undefined) => void,
setTxModalFailedText: (value: string) => void,
Expand All @@ -133,7 +130,6 @@ export const wrapProcessingWithApprove: WrapProcessingWithApproveProps = async (
providerWeb3,
wstethContractWeb3,
openTxModal,
closeTxModal,
setTxStage,
setTxHash,
setTxModalFailedText,
Expand All @@ -155,6 +151,7 @@ export const wrapProcessingWithApprove: WrapProcessingWithApproveProps = async (
const wstethTokenAddress = getTokenAddress(chainId, TOKENS.WSTETH);

const handleEnding = () => {
openTxModal();
resetForm();
ethBalanceUpdate();
stethBalanceUpdate();
Expand Down Expand Up @@ -198,7 +195,7 @@ export const wrapProcessingWithApprove: WrapProcessingWithApproveProps = async (
);

if (isMultisig) {
closeTxModal();
setTxStage(TX_STAGE.SUCCESS_MULTISIG);
handleEnding();
return;
}
Expand All @@ -212,9 +209,8 @@ export const wrapProcessingWithApprove: WrapProcessingWithApproveProps = async (
);
}

handleEnding();
setTxStage(TX_STAGE.SUCCESS);
openTxModal();
handleEnding();
} else if (selectedToken === TOKENS.STETH) {
if (needsApprove) {
approve();
Expand Down Expand Up @@ -242,7 +238,7 @@ export const wrapProcessingWithApprove: WrapProcessingWithApproveProps = async (
);

if (isMultisig) {
closeTxModal();
setTxStage(TX_STAGE.SUCCESS_MULTISIG);
handleEnding();
return;
}
Expand All @@ -256,9 +252,8 @@ export const wrapProcessingWithApprove: WrapProcessingWithApproveProps = async (
);
}

handleEnding();
setTxStage(TX_STAGE.SUCCESS);
openTxModal();
handleEnding();
}
}
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
Expand Down
Loading