1+ import { Flex , Text } from '@chakra-ui/react' ;
12import ERC20Artifact from '@openzeppelin/contracts/build/contracts/ERC20.json' ;
23import NftArtifact from '@openzeppelin/contracts/build/contracts/ERC721.json' ;
34import { useCallback } from 'react' ;
45import { waitForTransactionReceipt } from 'viem/actions' ;
56import { useAccount , useWriteContract , useSwitchChain } from 'wagmi' ;
67
8+ import type { EssentialDappsChainConfig } from 'types/client/marketplace' ;
79import type { AllowanceType } from 'types/client/revoke' ;
810
911import useRewardsActivity from 'lib/hooks/useRewardsActivity' ;
1012import * as mixpanel from 'lib/mixpanel/index' ;
1113import { toaster } from 'toolkit/chakra/toaster' ;
14+ import TxEntity from 'ui/shared/entities/tx/TxEntity' ;
1215
1316import 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