Skip to content

Commit

Permalink
fix: WC bug: retry on failed notification to dApp
Browse files Browse the repository at this point in the history
  • Loading branch information
dianasavvatina committed Feb 4, 2025
1 parent 284ab75 commit cf27736
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 19 deletions.
71 changes: 55 additions & 16 deletions apps/web/src/components/SendFlow/SuccessStep.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
Button,
Card,
Center,
Heading,
Icon,
Expand All @@ -13,37 +14,75 @@ import { useDynamicModalContext } from "@umami/components";
import { useSelectedNetwork } from "@umami/state";
import { useNavigate } from "react-router-dom";

import { CheckCircleIcon, ExternalLinkIcon } from "../../assets/icons";
import { AlertTriangleIcon, CheckCircleIcon, ExternalLinkIcon } from "../../assets/icons";
import { useColor } from "../../styles/useColor";
import { ModalCloseButton } from "../CloseButton";

export const SuccessStep = ({ hash }: { hash: string }) => {
export const SuccessStep = ({
hash,
dAppNotificationError,
}: {
hash: string;
dAppNotificationError?: string;
}) => {
const network = useSelectedNetwork();
const tzktUrl = `${network.tzktExplorerUrl}/${hash}`;
const { onClose } = useDynamicModalContext();
const navigate = useNavigate();
const color = useColor();

type StepData = [React.ElementType, string, string];

const getIconAndHeader = (): StepData => {
if (dAppNotificationError) {
return [AlertTriangleIcon, color("orange"), "Operation Submitted but dApp Not Notified"];
}

return [CheckCircleIcon, color("green"), "Operation Submitted"];
};

const Message = () => {
const successText =
"You can follow this operation's progress in the Operations section. It may take up to 30 seconds to appear.";

if (dAppNotificationError) {
return (
<>
<Text size="md">
Transaction was performed successfully and stored on the blockchain. However, the dApp
was not notified.
</Text>
<Text marginTop="12px" size="md">
<strong>Do not retry this operation</strong> — it has already been completed. You may
need to reload the dApp page to see the updated status.
</Text>
<Text marginTop="12px" size="md">
<strong>Error on dApp notification:</strong> {dAppNotificationError}
</Text>
<Text marginTop="12px" size="md">
{successText}
</Text>
</>
);
} else {
return <Text size="md">successText</Text>;
}
};

const [icon, iconColor, heading] = getIconAndHeader();

return (
<ModalContent paddingY="20px">
<ModalHeader textAlign="center">
<ModalCloseButton />
<Center flexDirection="column">
<Icon as={CheckCircleIcon} boxSize="24px" marginBottom="18px" color={color("green")} />
<Heading marginBottom="12px" size="xl">
Operation Submitted
<Icon as={icon} boxSize="24px" marginBottom="18px" color={iconColor} />
<Heading marginTop="24px" marginBottom="24px" size="xl">
{heading}
</Heading>
<Text
maxWidth="340px"
color={color("700")}
fontWeight="400"
whiteSpace="break-spaces"
size="md"
>
{
"You can follow this operation's progress\n in the Operations section. It may take up to 30 seconds to appear."
}
</Text>
<Card maxWidth="340px" color={color("700")} fontWeight="400" whiteSpace="pre-line">
<Message />
</Card>
</Center>
</ModalHeader>
<ModalBody gap="24px">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { type TezosToolkit } from "@taquito/taquito";
import { useDynamicModalContext } from "@umami/components";
import { executeOperations, totalFee } from "@umami/core";
import { useAsyncActionHandler, walletKit } from "@umami/state";
import { getErrorContext } from "@umami/utils";
import { formatJsonRpcResult } from "@walletconnect/jsonrpc-utils";
import { useForm } from "react-hook-form";

Expand Down Expand Up @@ -35,12 +36,24 @@ export const useSignWithWalletConnect = ({
tezosToolkit
);

const response = formatJsonRpcResult(requestId.id, { hash: opHash, operationHash: opHash });
await walletKit.respondSessionRequest({ topic: requestId.topic, response });
try {
const response = formatJsonRpcResult(requestId.id, {
hash: opHash,
operationHash: opHash,
});
await walletKit.respondSessionRequest({ topic: requestId.topic, response });
} catch (error: any) {
const errorContext = getErrorContext(error);
await openWith(
<SuccessStep dAppNotificationError={errorContext.description} hash={opHash} />
);
error.processed = true; // no toast for this error
throw error;
}
return openWith(<SuccessStep hash={opHash} />);
},
(error: { message: any }) => ({
description: `Failed to confirm WalletConnect operation: ${error.message}`,
description: `Failed to perform WalletConnect operation: ${error.message}`,
})
);

Expand Down

1 comment on commit cf27736

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Title Lines Statements Branches Functions
apps/desktop Coverage: 83%
83.74% (1788/2135) 79.43% (850/1070) 78.27% (454/580)
apps/web Coverage: 83%
83.74% (1788/2135) 79.43% (850/1070) 78.27% (454/580)
packages/components Coverage: 97%
97.51% (196/201) 95.91% (94/98) 88.13% (52/59)
packages/core Coverage: 81%
82.37% (215/261) 72.51% (95/131) 81.66% (49/60)
packages/crypto Coverage: 100%
100% (43/43) 90.9% (10/11) 100% (7/7)
packages/data-polling Coverage: 96%
94.66% (142/150) 87.5% (21/24) 92.85% (39/42)
packages/multisig Coverage: 98%
98.47% (129/131) 85.71% (18/21) 100% (36/36)
packages/social-auth Coverage: 95%
95.45% (21/22) 91.66% (11/12) 100% (3/3)
packages/state Coverage: 83%
83.21% (833/1001) 79.58% (191/240) 76.7% (303/395)
packages/tezos Coverage: 89%
88.72% (118/133) 94.59% (35/37) 86.84% (33/38)
packages/tzkt Coverage: 89%
87.32% (62/71) 87.5% (14/16) 80.48% (33/41)

Please sign in to comment.