Skip to content

Commit 4cc3368

Browse files
authored
Improve toast messages in the Revoke dapp (#3344)
1 parent ee922ef commit 4cc3368

3 files changed

Lines changed: 32 additions & 12 deletions

File tree

ui/marketplace/essentialDapps/revoke/components/ApprovalsListItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ export default function ApprovalsListItem({
3838

3939
const handleRevoke = useCallback(async() => {
4040
setIsPending(true);
41-
const success = await revoke(approval, Number(selectedChain?.id));
41+
const success = await revoke(approval, selectedChain);
4242
if (success) {
4343
hideApproval(approval);
4444
}
4545
setIsPending(false);
46-
}, [ revoke, hideApproval, approval, selectedChain?.id ]);
46+
}, [ revoke, hideApproval, approval, selectedChain ]);
4747

4848
return (
4949
<ListItemMobileGrid.Container

ui/marketplace/essentialDapps/revoke/components/ApprovalsTableItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ export default function ApprovalsTableItem({
3737

3838
const handleRevoke = useCallback(async() => {
3939
setIsPending(true);
40-
const success = await revoke(approval, Number(selectedChain?.id));
40+
const success = await revoke(approval, selectedChain);
4141
if (success) {
4242
hideApproval(approval);
4343
}
4444
setIsPending(false);
45-
}, [ revoke, hideApproval, approval, selectedChain?.id ]);
45+
}, [ revoke, hideApproval, approval, selectedChain ]);
4646

4747
return (
4848
<TableRow fontWeight="500">

ui/marketplace/essentialDapps/revoke/hooks/useRevoke.tsx

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1+
import { Flex, Text } from '@chakra-ui/react';
12
import ERC20Artifact from '@openzeppelin/contracts/build/contracts/ERC20.json';
23
import NftArtifact from '@openzeppelin/contracts/build/contracts/ERC721.json';
34
import { useCallback } from 'react';
45
import { waitForTransactionReceipt } from 'viem/actions';
56
import { useAccount, useWriteContract, useSwitchChain } from 'wagmi';
67

8+
import type { EssentialDappsChainConfig } from 'types/client/marketplace';
79
import type { AllowanceType } from 'types/client/revoke';
810

911
import useRewardsActivity from 'lib/hooks/useRewardsActivity';
1012
import * as mixpanel from 'lib/mixpanel/index';
1113
import { toaster } from 'toolkit/chakra/toaster';
14+
import TxEntity from 'ui/shared/entities/tx/TxEntity';
1215

1316
import createPublicClient from '../lib/createPublicClient';
1417

@@ -18,13 +21,13 @@ export default function useRevoke() {
1821
const { writeContractAsync } = useWriteContract();
1922
const { trackTransaction, trackTransactionConfirm } = useRewardsActivity();
2023

21-
return useCallback(async(approval: AllowanceType, chainId: number) => {
24+
return useCallback(async(approval: AllowanceType, chain?: EssentialDappsChainConfig) => {
2225
try {
2326
if (!userAddress) return;
2427

25-
await switchChainAsync({ chainId });
28+
await switchChainAsync({ chainId: Number(chain?.id) });
2629

27-
const activityResponse = await trackTransaction(userAddress, approval.address, String(chainId));
30+
const activityResponse = await trackTransaction(userAddress, approval.address, chain?.id);
2831

2932
const isErc20 = approval.type === 'ERC-20';
3033

@@ -34,22 +37,22 @@ export default function useRevoke() {
3437
abi: isErc20 ? ERC20Artifact.abi : NftArtifact.abi,
3538
functionName: isErc20 ? 'approve' : 'setApprovalForAll',
3639
args: [ approval.spender, isErc20 ? 0 : false ],
37-
chainId,
40+
chainId: Number(chain?.id),
3841
});
3942

4043
mixpanel.logEvent(mixpanel.EventTypes.WALLET_ACTION, {
4144
Action: 'Send Transaction',
4245
Address: userAddress,
4346
AppId: 'revoke',
4447
Source: 'Essential dapps',
45-
ChainId: String(chainId),
48+
ChainId: chain?.id,
4649
});
4750

4851
if (activityResponse?.token) {
4952
await trackTransactionConfirm(hash, activityResponse.token);
5053
}
5154

52-
const publicClient = createPublicClient(String(chainId));
55+
const publicClient = createPublicClient(chain?.id);
5356
if (!publicClient) {
5457
throw new Error('Public client not found');
5558
}
@@ -62,15 +65,32 @@ export default function useRevoke() {
6265

6366
toaster.success({
6467
title: 'Success',
65-
description: 'Approval revoked successfully.',
68+
meta: {
69+
renderDescription: () => (
70+
<Flex direction="column">
71+
<Text>Approval revoked successfully.</Text>
72+
<TxEntity
73+
hash={ hash }
74+
text="View transaction"
75+
link={{ external: true }}
76+
noCopy
77+
noIcon
78+
chain={ chain }
79+
/>
80+
</Flex>
81+
),
82+
},
6683
});
6784

6885
return true;
6986

7087
} catch (error) {
7188
toaster.error({
7289
title: 'Error',
73-
description: (error as Error)?.message || 'Something went wrong. Try again later.',
90+
description:
91+
(error as { shortMessage?: string })?.shortMessage ||
92+
(error as Error)?.message ||
93+
'Something went wrong. Try again later.',
7494
});
7595

7696
return false;

0 commit comments

Comments
 (0)