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

853: Clicking "Back" during pending transaction should reset #886

Merged
1 commit merged into from
Mar 27, 2024
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
21 changes: 17 additions & 4 deletions src/components/@reviewScreens/ApproveReview/ApproveReview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
} from "./ApproveReview.styles";

interface ApproveReviewProps {
hasEditButton?: boolean;
isLoading: boolean;
amount: string;
amountPlusFee?: string;
Expand All @@ -35,17 +36,17 @@ interface ApproveReviewProps {
readableAllowance: string;
token: TokenInfo | null;
wrappedNativeToken: TokenInfo | null;
onEditButtonClick: () => void;
onEditButtonClick?: () => void;
onRestartButtonClick?: () => void;
onSignButtonClick: () => void;
className?: string;
}

const ApproveReview: FC<ApproveReviewProps> = ({
hasEditButton,
isLoading,
amount,
amountPlusFee,
backButtonText,
errors = [],
readableAllowance,
token,
Expand Down Expand Up @@ -78,6 +79,16 @@ const ApproveReview: FC<ApproveReviewProps> = ({
return toRoundedNumberString(amountPlusFee, justifiedToken?.decimals);
}, [amountPlusFee, justifiedToken]);

const handleEditOrBackButtonClick = () => {
if (!isLoading && hasEditButton && onEditButtonClick) {
onEditButtonClick();
}

if (onRestartButtonClick) {
onRestartButtonClick();
}
};

return (
<Container className={className}>
<StyledWidgetHeader>
Expand Down Expand Up @@ -133,8 +144,10 @@ const ApproveReview: FC<ApproveReviewProps> = ({

<StyledActionButtons
isLoading={isLoading}
backButtonText={backButtonText || t("common.back")}
onEditButtonClick={onEditButtonClick}
backButtonText={
hasEditButton && !isLoading ? t("common.edit") : t("common.back")
}
onEditButtonClick={handleEditOrBackButtonClick}
onSignButtonClick={onSignButtonClick}
/>

Expand Down
22 changes: 17 additions & 5 deletions src/components/@reviewScreens/WrapReview/WrapReview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,24 @@ import {
} from "./WrapReview.styles";

interface WrapReviewProps {
hasEditButton?: boolean;
isLoading: boolean;
amount: string;
amountPlusFee?: string;
backButtonText?: string;
errors?: AppError[];
wrappedNativeToken: TokenInfo | null;
shouldDepositNativeTokenAmount: string;
onEditButtonClick: () => void;
onEditButtonClick?: () => void;
onRestartButtonClick?: () => void;
onSignButtonClick: () => void;
className?: string;
}

const ApproveReview: FC<WrapReviewProps> = ({
hasEditButton,
isLoading,
amount,
amountPlusFee,
backButtonText,
errors = [],
shouldDepositNativeTokenAmount,
wrappedNativeToken,
Expand Down Expand Up @@ -80,6 +80,16 @@ const ApproveReview: FC<WrapReviewProps> = ({
return toRoundedNumberString(amountPlusFee, wrappedNativeToken?.decimals);
}, [amountPlusFee, wrappedNativeToken]);

const handleEditOrBackButtonClick = () => {
if (!isLoading && hasEditButton && onEditButtonClick) {
onEditButtonClick();
}

if (onRestartButtonClick) {
onRestartButtonClick();
}
};

return (
<Container className={className}>
<StyledWidgetHeader>
Expand Down Expand Up @@ -137,8 +147,10 @@ const ApproveReview: FC<WrapReviewProps> = ({

<StyledActionButtons
isLoading={isLoading}
backButtonText={backButtonText || t("common.back")}
onEditButtonClick={onEditButtonClick}
backButtonText={
hasEditButton && !isLoading ? t("common.edit") : t("common.back")
}
onEditButtonClick={handleEditOrBackButtonClick}
onSignButtonClick={onSignButtonClick}
/>

Expand Down
16 changes: 11 additions & 5 deletions src/components/@widgets/MakeWidget/MakeWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,11 @@ const MakeWidget: FC = () => {
setState(MakeWidgetState.list);
};

const restart = () => {
setState(MakeWidgetState.list);
dispatch(reset());
};

const handleActionButtonClick = (action: ButtonActions) => {
if (action === ButtonActions.connectWallet) {
setShowWalletList(true);
Expand All @@ -352,13 +357,13 @@ const MakeWidget: FC = () => {
}

if (action === ButtonActions.restart) {
dispatch(reset());
restart();
}
};

const handleBackButtonClick = (action: ButtonActions) => {
if (action === ButtonActions.restart) {
dispatch(reset());
restart();
}

if (action === ButtonActions.goBack) {
Expand All @@ -385,13 +390,14 @@ const MakeWidget: FC = () => {
return (
<Container>
<WrapReview
hasEditButton
isLoading={hasDepositPending}
amount={makerAmount}
amountPlusFee={makerAmountPlusFee}
backButtonText={t("common.edit")}
shouldDepositNativeTokenAmount={shouldDepositNativeTokenAmount}
wrappedNativeToken={wrappedNativeToken}
onEditButtonClick={handleEditButtonClick}
onRestartButtonClick={restart}
onSignButtonClick={depositNativeToken}
/>
</Container>
Expand All @@ -402,14 +408,15 @@ const MakeWidget: FC = () => {
return (
<Container>
<ApproveReview
hasEditButton
isLoading={hasApprovalPending}
amount={makerAmount}
amountPlusFee={makerAmountPlusFee}
backButtonText={t("common.edit")}
readableAllowance={readableAllowance}
token={makerTokenInfo}
wrappedNativeToken={wrappedNativeToken}
onEditButtonClick={handleEditButtonClick}
onRestartButtonClick={restart}
onSignButtonClick={approveToken}
/>
</Container>
Expand Down Expand Up @@ -509,7 +516,6 @@ const MakeWidget: FC = () => {
hasMissingMakerToken={!makerTokenInfo}
hasMissingTakerAmount={hasMissingTakerAmount}
hasMissingTakerToken={!takerTokenInfo}
isLoading={hasApprovalPending || hasDepositPending}
isNetworkUnsupported={
!!web3Error && web3Error instanceof UnsupportedChainIdError
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ type ActionButtonsProps = {
hasMissingMakerToken: boolean;
hasMissingTakerAmount: boolean;
hasMissingTakerToken: boolean;
isLoading: boolean;
isNetworkUnsupported: boolean;
shouldDepositNativeToken: boolean;
walletIsNotConnected: boolean;
Expand All @@ -40,7 +39,6 @@ const ActionButtons: FC<ActionButtonsProps> = ({
hasMissingMakerToken,
hasMissingTakerAmount,
hasMissingTakerToken,
isLoading,
isNetworkUnsupported,
shouldDepositNativeToken,
walletIsNotConnected,
Expand Down Expand Up @@ -97,7 +95,6 @@ const ActionButtons: FC<ActionButtonsProps> = ({
<SignButton
disabled={isDisabled}
intent="primary"
loading={isLoading}
onClick={handleSignButtonClick}
>
{buttonText}
Expand Down
10 changes: 4 additions & 6 deletions src/components/@widgets/OrderDetailWidget/OrderDetailWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ const OrderDetailWidget: FC<OrderDetailWidgetProps> = ({ order }) => {
dispatch(reset());
};

const handleEditButtonClick = () => {
const backToOverview = () => {
setState(OrderDetailWidgetState.overview);
};

Expand Down Expand Up @@ -298,8 +298,7 @@ const OrderDetailWidget: FC<OrderDetailWidgetProps> = ({ order }) => {
errors={errors}
shouldDepositNativeTokenAmount={shouldDepositNativeTokenAmount}
wrappedNativeToken={wrappedNativeToken}
onEditButtonClick={handleEditButtonClick}
onRestartButtonClick={restart}
onRestartButtonClick={backToOverview}
onSignButtonClick={depositNativeToken}
/>
</Container>
Expand All @@ -316,8 +315,7 @@ const OrderDetailWidget: FC<OrderDetailWidgetProps> = ({ order }) => {
readableAllowance={"0"}
token={senderToken}
wrappedNativeToken={wrappedNativeToken}
onEditButtonClick={handleEditButtonClick}
onRestartButtonClick={restart}
onRestartButtonClick={backToOverview}
onSignButtonClick={approveToken}
/>
</Container>
Expand All @@ -335,7 +333,7 @@ const OrderDetailWidget: FC<OrderDetailWidgetProps> = ({ order }) => {
signerAmount={signerAmount || "0"}
signerToken={signerToken}
wrappedNativeToken={wrappedNativeToken}
onEditButtonClick={handleEditButtonClick}
onEditButtonClick={backToOverview}
onRestartButtonClick={restart}
onSignButtonClick={takeOrder}
/>
Expand Down
23 changes: 8 additions & 15 deletions src/components/@widgets/SwapWidget/SwapWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,10 @@ const SwapWidget: FC = () => {
dispatch(setCustomServerUrl(null));
};

const backToOverview = () => {
handleActionButtonClick(ButtonActions.restart);
};

if (ordersStatus === "signing") {
return (
<Container>
Expand All @@ -795,9 +799,7 @@ const SwapWidget: FC = () => {
token={baseTokenInfo}
wrappedNativeToken={wrappedNativeTokenInfo}
onEditButtonClick={handleEditButtonClick}
onRestartButtonClick={() =>
handleActionButtonClick(ButtonActions.restart)
}
onRestartButtonClick={backToOverview}
onSignButtonClick={approveToken}
/>
</Container>
Expand Down Expand Up @@ -890,9 +892,7 @@ const SwapWidget: FC = () => {
needsApproval={!!baseToken && shouldApprove}
pairUnavailable={pairUnavailable}
onButtonClicked={(action) => handleActionButtonClick(action)}
isLoading={
isConnecting || isRequestingQuotes || hasApprovalPending
}
isLoading={isConnecting || isRequestingQuotes}
transactionsTabOpen={transactionsTabIsOpen}
/>
)}
Expand All @@ -919,17 +919,10 @@ const SwapWidget: FC = () => {
<Overlay
title={t("validatorErrors.unableSwap")}
subTitle={t("validatorErrors.swapFail")}
onCloseButtonClick={() =>
handleActionButtonClick(ButtonActions.restart)
}
onCloseButtonClick={backToOverview}
isHidden={!ordersErrors.length}
>
<ErrorList
errors={ordersErrors}
onBackButtonClick={() =>
handleActionButtonClick(ButtonActions.restart)
}
/>
<ErrorList errors={ordersErrors} onBackButtonClick={backToOverview} />
</Overlay>
<Overlay
title={t("information.gasFreeSwaps.title")}
Expand Down
Loading