From 796862165f606c594c0f5dbcad1cacae8de0ad35 Mon Sep 17 00:00:00 2001 From: Logan Nguyen Date: Fri, 22 Sep 2023 19:19:47 -0500 Subject: [PATCH] dapp-feat: added remove transaction records feature to main activity page (#419) * dapp-update: added transactionResultStorageKey to the TransactionResult type Signed-off-by: Logan Nguyen * dapp-feat: added delete individual transaction feature in /activity Signed-off-by: Logan Nguyen * dapp-feat: remove all cached transactions feature complete Signed-off-by: Logan Nguyen --------- Signed-off-by: Logan Nguyen --- .../src/api/hedera/index.ts | 1 + .../erc/erc-20/methods/mint/index.tsx | 4 +- .../erc-20/methods/token-permission/index.tsx | 2 + .../erc-20/methods/token-transfer/index.tsx | 2 + .../erc/erc-721/methods/approve/index.tsx | 3 + .../erc/erc-721/methods/mint/index.tsx | 2 + .../methods/operator-approve/index.tsx | 2 + .../erc-721/methods/token-transfer/index.tsx | 2 + .../exchange-rate/methods/index.tsx | 2 + .../hts/shared/methods/handleAPIErrors.tsx | 5 +- .../methods/AssociateHederaToken.tsx | 2 + .../methods/FungibleTokenCreate.tsx | 2 + .../methods/GrantTokenKYC.tsx | 2 + .../methods/MintHederaToken.tsx | 2 + .../methods/NonFungibleTokenCreate.tsx | 2 + .../methods/manageTokenDelete/index.tsx | 2 + .../methods/manageTokenInfo/index.tsx | 2 + .../methods/manageTokenPermission/index.tsx | 2 + .../methods/manageTokenRelation/index.tsx | 2 + .../methods/manageTokenStatus/index.tsx | 2 + .../manageTokenSupplyReduction/index.tsx | 2 + .../methods/querySpecificToken/index.tsx | 2 + .../methods/queryTokenGeneralInfo/index.tsx | 2 + .../methods/queryTokenPermission/index.tsx | 2 + .../methods/queryTokenStatus/index.tsx | 2 + .../methods/queryTokenValidity/index.tsx | 2 + .../method/transferCrypto/index.tsx | 2 + .../method/transferMultipleTokens/index.tsx | 2 + .../method/transferSingleToken/index.tsx | 2 + .../ihrc/methods/index.tsx | 2 + .../prng/methods/index.tsx | 2 + .../src/sections/activity/index.tsx | 143 +++++++++++++++--- .../contract-interactions/HTS/index.d.ts | 1 + 33 files changed, 190 insertions(+), 21 deletions(-) diff --git a/system-contract-dapp-playground/src/api/hedera/index.ts b/system-contract-dapp-playground/src/api/hedera/index.ts index f9349c780..3e17dc8cc 100644 --- a/system-contract-dapp-playground/src/api/hedera/index.ts +++ b/system-contract-dapp-playground/src/api/hedera/index.ts @@ -77,6 +77,7 @@ export const deploySmartContract = async ( if (txReceipt) { const createTransactionResult: TransactionResult = { status: 'success', + transactionResultStorageKey, transactionTimeStamp: Date.now(), txHash: txReceipt.hash as string, transactionType: 'CONTRACT-CREATE', diff --git a/system-contract-dapp-playground/src/components/contract-interaction/erc/erc-20/methods/mint/index.tsx b/system-contract-dapp-playground/src/components/contract-interaction/erc/erc-20/methods/mint/index.tsx index c99747e7e..18b5679d1 100644 --- a/system-contract-dapp-playground/src/components/contract-interaction/erc/erc-20/methods/mint/index.tsx +++ b/system-contract-dapp-playground/src/components/contract-interaction/erc/erc-20/methods/mint/index.tsx @@ -71,10 +71,11 @@ const Mint = ({ baseContract }: PageProps) => { if (mintErr || !mintRes) { handleAPIErrors({ - err: mintErr, toaster, + err: mintErr, setTransactionResults, transactionHash: txHash, + transactionResultStorageKey, transactionType: 'ERC20-MINT', sessionedContractAddress: currentContractAddress, }); @@ -86,6 +87,7 @@ const Mint = ({ baseContract }: PageProps) => { { status: 'success', txHash: txHash as string, + transactionResultStorageKey, transactionType: 'ERC20-MINT', transactionTimeStamp: Date.now(), sessionedContractAddress: currentContractAddress, diff --git a/system-contract-dapp-playground/src/components/contract-interaction/erc/erc-20/methods/token-permission/index.tsx b/system-contract-dapp-playground/src/components/contract-interaction/erc/erc-20/methods/token-permission/index.tsx index 4cd89352a..c195ccc9a 100644 --- a/system-contract-dapp-playground/src/components/contract-interaction/erc/erc-20/methods/token-permission/index.tsx +++ b/system-contract-dapp-playground/src/components/contract-interaction/erc/erc-20/methods/token-permission/index.tsx @@ -213,6 +213,7 @@ const TokenPermission = ({ baseContract }: PageProps) => { handleAPIErrors({ toaster, setTransactionResults, + transactionResultStorageKey, err: tokenPermissionRes.err, transactionHash: tokenPermissionRes.txHash, sessionedContractAddress: currentContractAddress, @@ -265,6 +266,7 @@ const TokenPermission = ({ baseContract }: PageProps) => { ...prev, { status: 'success', + transactionResultStorageKey, transactionTimeStamp: Date.now(), txHash: tokenPermissionRes.txHash as string, sessionedContractAddress: currentContractAddress, diff --git a/system-contract-dapp-playground/src/components/contract-interaction/erc/erc-20/methods/token-transfer/index.tsx b/system-contract-dapp-playground/src/components/contract-interaction/erc/erc-20/methods/token-transfer/index.tsx index 2b962bb79..987284875 100644 --- a/system-contract-dapp-playground/src/components/contract-interaction/erc/erc-20/methods/token-transfer/index.tsx +++ b/system-contract-dapp-playground/src/components/contract-interaction/erc/erc-20/methods/token-transfer/index.tsx @@ -129,6 +129,7 @@ const Transfer = ({ baseContract }: PageProps) => { toaster, setTransactionResults, err: tokenTransferRes.err, + transactionResultStorageKey, transactionHash: tokenTransferRes.txHash, sessionedContractAddress: currentContractAddress, transactionType: `ERC20-${convertCalmelCaseFunctionName(method).replace(' ', '-')}`, @@ -143,6 +144,7 @@ const Transfer = ({ baseContract }: PageProps) => { ...prev, { status: 'success', + transactionResultStorageKey, transactionTimeStamp: Date.now(), txHash: tokenTransferRes.txHash as string, sessionedContractAddress: currentContractAddress, diff --git a/system-contract-dapp-playground/src/components/contract-interaction/erc/erc-721/methods/approve/index.tsx b/system-contract-dapp-playground/src/components/contract-interaction/erc/erc-721/methods/approve/index.tsx index c777f0cb2..124281c8c 100644 --- a/system-contract-dapp-playground/src/components/contract-interaction/erc/erc-721/methods/approve/index.tsx +++ b/system-contract-dapp-playground/src/components/contract-interaction/erc/erc-721/methods/approve/index.tsx @@ -123,6 +123,7 @@ const ERC721Approve = ({ baseContract }: PageProps) => { handleAPIErrors({ toaster, setTransactionResults, + transactionResultStorageKey, err: erc721ApproveResult.err, transactionType: 'ERC721-APPROVE', transactionHash: erc721ApproveResult.txHash, @@ -136,6 +137,7 @@ const ERC721Approve = ({ baseContract }: PageProps) => { ...prev, { status: 'success', + transactionResultStorageKey, transactionTimeStamp: Date.now(), transactionType: 'ERC721-APPROVE', txHash: erc721ApproveResult.txHash as string, @@ -162,6 +164,7 @@ const ERC721Approve = ({ baseContract }: PageProps) => { getApproveTokenId, approveParams.tokenId, currentContractAddress, + transactionResultStorageKey, approveParams.spenderAddress, ] ); diff --git a/system-contract-dapp-playground/src/components/contract-interaction/erc/erc-721/methods/mint/index.tsx b/system-contract-dapp-playground/src/components/contract-interaction/erc/erc-721/methods/mint/index.tsx index 2f2801763..3105ef8b4 100644 --- a/system-contract-dapp-playground/src/components/contract-interaction/erc/erc-721/methods/mint/index.tsx +++ b/system-contract-dapp-playground/src/components/contract-interaction/erc/erc-721/methods/mint/index.tsx @@ -75,6 +75,7 @@ const Mint = ({ baseContract }: PageProps) => { toaster, setTransactionResults, transactionHash: txHash, + transactionResultStorageKey, transactionType: 'ERC721-MINT', sessionedContractAddress: currentContractAddress, }); @@ -86,6 +87,7 @@ const Mint = ({ baseContract }: PageProps) => { { status: 'success', txHash: txHash as string, + transactionResultStorageKey, transactionType: 'ERC721-MINT', transactionTimeStamp: Date.now(), sessionedContractAddress: currentContractAddress, diff --git a/system-contract-dapp-playground/src/components/contract-interaction/erc/erc-721/methods/operator-approve/index.tsx b/system-contract-dapp-playground/src/components/contract-interaction/erc/erc-721/methods/operator-approve/index.tsx index 749e2a736..770577446 100644 --- a/system-contract-dapp-playground/src/components/contract-interaction/erc/erc-721/methods/operator-approve/index.tsx +++ b/system-contract-dapp-playground/src/components/contract-interaction/erc/erc-721/methods/operator-approve/index.tsx @@ -170,6 +170,7 @@ const ERC721OperatorApproval = ({ baseContract }: PageProps) => { toaster, setTransactionResults, err: tokenApprovalRes.err, + transactionResultStorageKey, transactionType: 'ERC721-SET-APPROVAL', transactionHash: tokenApprovalRes.txHash, sessionedContractAddress: currentContractAddress, @@ -182,6 +183,7 @@ const ERC721OperatorApproval = ({ baseContract }: PageProps) => { ...prev, { status: 'success', + transactionResultStorageKey, transactionTimeStamp: Date.now(), transactionType: 'ERC721-SET-APPROVAL', txHash: tokenApprovalRes.txHash as string, diff --git a/system-contract-dapp-playground/src/components/contract-interaction/erc/erc-721/methods/token-transfer/index.tsx b/system-contract-dapp-playground/src/components/contract-interaction/erc/erc-721/methods/token-transfer/index.tsx index 782a9a3ae..e7b63a950 100644 --- a/system-contract-dapp-playground/src/components/contract-interaction/erc/erc-721/methods/token-transfer/index.tsx +++ b/system-contract-dapp-playground/src/components/contract-interaction/erc/erc-721/methods/token-transfer/index.tsx @@ -121,6 +121,7 @@ const ERC721Transfer = ({ baseContract }: PageProps) => { toaster, setTransactionResults, err: tokenTransferRes.err, + transactionResultStorageKey, transactionHash: tokenTransferRes.txHash, sessionedContractAddress: currentContractAddress, transactionType: `ERC721-${convertCalmelCaseFunctionName(method).replace(' ', '-')}`, @@ -134,6 +135,7 @@ const ERC721Transfer = ({ baseContract }: PageProps) => { ...prev, { status: 'success', + transactionResultStorageKey, transactionTimeStamp: Date.now(), txHash: tokenTransferRes.txHash as string, sessionedContractAddress: currentContractAddress, diff --git a/system-contract-dapp-playground/src/components/contract-interaction/exchange-rate/methods/index.tsx b/system-contract-dapp-playground/src/components/contract-interaction/exchange-rate/methods/index.tsx index 8f5903e56..7e1bae6f7 100644 --- a/system-contract-dapp-playground/src/components/contract-interaction/exchange-rate/methods/index.tsx +++ b/system-contract-dapp-playground/src/components/contract-interaction/exchange-rate/methods/index.tsx @@ -124,6 +124,7 @@ const HederaExchangeRateMethods = ({ baseContract }: PageProps) => { transactionHash, transactionType: API, setTransactionResults, + transactionResultStorageKey, initialAmount: paramValues.amountToConvert, sessionedContractAddress: currentContractAddress, }); @@ -136,6 +137,7 @@ const HederaExchangeRateMethods = ({ baseContract }: PageProps) => { status: 'success', APICalled: API, transactionType: API, + transactionResultStorageKey, transactionTimeStamp: Date.now(), txHash: transactionHash as string, initialAmount: paramValues.amountToConvert, diff --git a/system-contract-dapp-playground/src/components/contract-interaction/hts/shared/methods/handleAPIErrors.tsx b/system-contract-dapp-playground/src/components/contract-interaction/hts/shared/methods/handleAPIErrors.tsx index 2260f9afc..0bc89930b 100644 --- a/system-contract-dapp-playground/src/components/contract-interaction/hts/shared/methods/handleAPIErrors.tsx +++ b/system-contract-dapp-playground/src/components/contract-interaction/hts/shared/methods/handleAPIErrors.tsx @@ -38,6 +38,7 @@ export const handleAPIErrors = ({ receiverAddress, setTransactionResults, sessionedContractAddress, + transactionResultStorageKey, }: { err: any; toaster: any; @@ -49,6 +50,7 @@ export const handleAPIErrors = ({ receiverAddress?: string; tokenAddresses?: string[]; sessionedContractAddress: string; + transactionResultStorageKey: string; transactionHash: string | undefined; keyTypeCalled?: IHederaTokenServiceKeyType; setTransactionResults: Dispatch>; @@ -87,12 +89,13 @@ export const handleAPIErrors = ({ transactionType, txHash: transactionHash, sessionedContractAddress, + transactionResultStorageKey, + transactionTimeStamp: Date.now(), tokenAddress: tokenAddress ? tokenAddress : '', initialAmount: initialAmount ? initialAmount : '', accountAddress: accountAddress ? accountAddress : '', tokenAddresses: tokenAddresses ? tokenAddresses : [''], receiverAddress: receiverAddress ? receiverAddress : '', - transactionTimeStamp: Date.now(), }, ]); diff --git a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-create-custom/methods/AssociateHederaToken.tsx b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-create-custom/methods/AssociateHederaToken.tsx index a7874ca9f..7fc54d027 100644 --- a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-create-custom/methods/AssociateHederaToken.tsx +++ b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-create-custom/methods/AssociateHederaToken.tsx @@ -152,6 +152,7 @@ const AssociateHederaToken = ({ baseContract }: PageProps) => { tokenAddresses, transactionHash, setTransactionResults, + transactionResultStorageKey, accountAddress: associatingAddress, transactionType: 'HTS-TOKEN-ASSOCIATE', sessionedContractAddress: currentContractAddress, @@ -164,6 +165,7 @@ const AssociateHederaToken = ({ baseContract }: PageProps) => { { tokenAddresses, status: 'success', + transactionResultStorageKey, transactionTimeStamp: Date.now(), txHash: transactionHash as string, accountAddress: associatingAddress, diff --git a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-create-custom/methods/FungibleTokenCreate.tsx b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-create-custom/methods/FungibleTokenCreate.tsx index 2adee1cc3..d020d7afc 100644 --- a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-create-custom/methods/FungibleTokenCreate.tsx +++ b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-create-custom/methods/FungibleTokenCreate.tsx @@ -181,6 +181,7 @@ const FungibleTokenCreate = ({ baseContract }: PageProps) => { toaster, transactionHash, setTransactionResults, + transactionResultStorageKey, transactionType: 'HTS-TOKEN-CREATE', sessionedContractAddress: currentContractAddress, }); @@ -192,6 +193,7 @@ const FungibleTokenCreate = ({ baseContract }: PageProps) => { { tokenAddress, status: 'success', + transactionResultStorageKey, transactionTimeStamp: Date.now(), txHash: transactionHash as string, transactionType: 'HTS-TOKEN-CREATE', diff --git a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-create-custom/methods/GrantTokenKYC.tsx b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-create-custom/methods/GrantTokenKYC.tsx index 33392ac5f..c7ea29ca9 100644 --- a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-create-custom/methods/GrantTokenKYC.tsx +++ b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-create-custom/methods/GrantTokenKYC.tsx @@ -119,6 +119,7 @@ const GrantTokenKYC = ({ baseContract }: PageProps) => { toaster, transactionHash, setTransactionResults, + transactionResultStorageKey, tokenAddress: hederaTokenAddress, transactionType: 'HTS-GRANT-KYC', accountAddress: grantingKYCAccountAddress, @@ -131,6 +132,7 @@ const GrantTokenKYC = ({ baseContract }: PageProps) => { ...prev, { status: 'success', + transactionResultStorageKey, transactionType: 'HTS-GRANT-KYC', transactionTimeStamp: Date.now(), tokenAddress: hederaTokenAddress, diff --git a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-create-custom/methods/MintHederaToken.tsx b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-create-custom/methods/MintHederaToken.tsx index a6d89e446..b8f31a8a1 100644 --- a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-create-custom/methods/MintHederaToken.tsx +++ b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-create-custom/methods/MintHederaToken.tsx @@ -190,6 +190,7 @@ const MintHederaToken = ({ baseContract }: PageProps) => { toaster, err: txRes.err, setTransactionResults, + transactionResultStorageKey, tokenAddress: tokenAddressToMint, transactionHash: txRes.transactionHash, sessionedContractAddress: currentContractAddress, @@ -202,6 +203,7 @@ const MintHederaToken = ({ baseContract }: PageProps) => { ...prev, { status: 'success', + transactionResultStorageKey, accountAddress: recipientAddress, transactionTimeStamp: Date.now(), txHash: txRes.transactionHash as string, diff --git a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-create-custom/methods/NonFungibleTokenCreate.tsx b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-create-custom/methods/NonFungibleTokenCreate.tsx index b325039e1..774fb3bb0 100644 --- a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-create-custom/methods/NonFungibleTokenCreate.tsx +++ b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-create-custom/methods/NonFungibleTokenCreate.tsx @@ -159,6 +159,7 @@ const NonFungibleTokenCreate = ({ baseContract }: PageProps) => { toaster, transactionHash, setTransactionResults, + transactionResultStorageKey, transactionType: 'HTS-NFT-CREATE', sessionedContractAddress: currentContractAddress, }); @@ -170,6 +171,7 @@ const NonFungibleTokenCreate = ({ baseContract }: PageProps) => { { tokenAddress, status: 'success', + transactionResultStorageKey, transactionTimeStamp: Date.now(), transactionType: 'HTS-NFT-CREATE', txHash: transactionHash as string, diff --git a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-management-contract/methods/manageTokenDelete/index.tsx b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-management-contract/methods/manageTokenDelete/index.tsx index b702fb5a6..ab6e0bac4 100644 --- a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-management-contract/methods/manageTokenDelete/index.tsx +++ b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-management-contract/methods/manageTokenDelete/index.tsx @@ -120,6 +120,7 @@ const ManageTokenDelete = ({ baseContract }: PageProps) => { toaster, transactionHash, setTransactionResults, + transactionResultStorageKey, tokenAddress: hederaTokenAddress, transactionType: 'HTS-TOKEN-DELETE', sessionedContractAddress: currentContractAddress, @@ -131,6 +132,7 @@ const ManageTokenDelete = ({ baseContract }: PageProps) => { ...prev, { status: 'success', + transactionResultStorageKey, tokenAddress: hederaTokenAddress, transactionTimeStamp: Date.now(), txHash: transactionHash as string, diff --git a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-management-contract/methods/manageTokenInfo/index.tsx b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-management-contract/methods/manageTokenInfo/index.tsx index 3587a648c..fa02c13af 100644 --- a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-management-contract/methods/manageTokenInfo/index.tsx +++ b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-management-contract/methods/manageTokenInfo/index.tsx @@ -262,6 +262,7 @@ const ManageTokenInfo = ({ baseContract }: PageProps) => { toaster, transactionHash, setTransactionResults, + transactionResultStorageKey, tokenAddress: hederaTokenAddress, sessionedContractAddress: currentContractAddress, transactionType: `HTS-${APIMethods.replace('_', '-')}`, @@ -273,6 +274,7 @@ const ManageTokenInfo = ({ baseContract }: PageProps) => { ...prev, { status: 'success', + transactionResultStorageKey, tokenAddress: hederaTokenAddress, transactionTimeStamp: Date.now(), txHash: transactionHash as string, diff --git a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-management-contract/methods/manageTokenPermission/index.tsx b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-management-contract/methods/manageTokenPermission/index.tsx index f30375ab4..995f549aa 100644 --- a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-management-contract/methods/manageTokenPermission/index.tsx +++ b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-management-contract/methods/manageTokenPermission/index.tsx @@ -167,6 +167,7 @@ const ManageTokenPermission = ({ baseContract }: PageProps) => { toaster, transactionHash, setTransactionResults, + transactionResultStorageKey, tokenAddress: hederaTokenAddress, transactionType: transactionTypeMap[API], sessionedContractAddress: currentContractAddress, @@ -178,6 +179,7 @@ const ManageTokenPermission = ({ baseContract }: PageProps) => { ...prev, { status: 'success', + transactionResultStorageKey, tokenAddress: hederaTokenAddress, transactionTimeStamp: Date.now(), txHash: transactionHash as string, diff --git a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-management-contract/methods/manageTokenRelation/index.tsx b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-management-contract/methods/manageTokenRelation/index.tsx index 7fb1a8c91..d5b9d551d 100644 --- a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-management-contract/methods/manageTokenRelation/index.tsx +++ b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-management-contract/methods/manageTokenRelation/index.tsx @@ -218,6 +218,7 @@ const ManageTokenRelation = ({ baseContract }: PageProps) => { toaster, transactionHash, setTransactionResults, + transactionResultStorageKey, tokenAddress: paramValues.hederaTokenAddress, transactionType: `HTS-${API.replace('_', '-')}`, sessionedContractAddress: currentContractAddress, @@ -229,6 +230,7 @@ const ManageTokenRelation = ({ baseContract }: PageProps) => { ...prev, { status: 'success', + transactionResultStorageKey, transactionTimeStamp: Date.now(), txHash: transactionHash as string, tokenAddress: paramValues.hederaTokenAddress, diff --git a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-management-contract/methods/manageTokenStatus/index.tsx b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-management-contract/methods/manageTokenStatus/index.tsx index 6f3c165df..97f34c5db 100644 --- a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-management-contract/methods/manageTokenStatus/index.tsx +++ b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-management-contract/methods/manageTokenStatus/index.tsx @@ -130,6 +130,7 @@ const ManageTokenStatus = ({ baseContract }: PageProps) => { toaster, transactionHash, setTransactionResults, + transactionResultStorageKey, transactionType: `HTS-TOKEN-${API}`, tokenAddress: paramValues.hederaTokenAddress, sessionedContractAddress: currentContractAddress, @@ -141,6 +142,7 @@ const ManageTokenStatus = ({ baseContract }: PageProps) => { ...prev, { status: 'success', + transactionResultStorageKey, transactionTimeStamp: Date.now(), txHash: transactionHash as string, transactionType: `HTS-TOKEN-${API}`, diff --git a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-management-contract/methods/manageTokenSupplyReduction/index.tsx b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-management-contract/methods/manageTokenSupplyReduction/index.tsx index 71e65a5a2..37fea6c62 100644 --- a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-management-contract/methods/manageTokenSupplyReduction/index.tsx +++ b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-management-contract/methods/manageTokenSupplyReduction/index.tsx @@ -165,6 +165,7 @@ const ManageTokenDeduction = ({ baseContract }: PageProps) => { toaster, transactionHash, setTransactionResults, + transactionResultStorageKey, tokenAddress: hederaTokenAddress, transactionType: transactionTypeMap[API], sessionedContractAddress: currentContractAddress, @@ -176,6 +177,7 @@ const ManageTokenDeduction = ({ baseContract }: PageProps) => { ...prev, { status: 'success', + transactionResultStorageKey, transactionTimeStamp: Date.now(), tokenAddress: hederaTokenAddress, txHash: transactionHash as string, diff --git a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-query-contract/methods/querySpecificToken/index.tsx b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-query-contract/methods/querySpecificToken/index.tsx index 67cbbb0f4..6c0601cd6 100644 --- a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-query-contract/methods/querySpecificToken/index.tsx +++ b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-query-contract/methods/querySpecificToken/index.tsx @@ -188,6 +188,7 @@ const QueryTokenSpecificInfomation = ({ baseContract }: PageProps) => { setTransactionResults, keyTypeCalled: keyType, err: tokenInfoResult.err, + transactionResultStorageKey, tokenAddress: paramValues.hederaTokenAddress, sessionedContractAddress: currentContractAddress, transactionHash: tokenInfoResult.transactionHash, @@ -233,6 +234,7 @@ const QueryTokenSpecificInfomation = ({ baseContract }: PageProps) => { status: 'success', keyTypeCalled: keyType, tokenInfo: cachedTokenInfo, + transactionResultStorageKey, transactionTimeStamp: Date.now(), tokenAddress: paramValues.hederaTokenAddress, sessionedContractAddress: currentContractAddress, diff --git a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-query-contract/methods/queryTokenGeneralInfo/index.tsx b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-query-contract/methods/queryTokenGeneralInfo/index.tsx index e49b5dfd3..afadd22f5 100644 --- a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-query-contract/methods/queryTokenGeneralInfo/index.tsx +++ b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-query-contract/methods/queryTokenGeneralInfo/index.tsx @@ -173,6 +173,7 @@ const QueryTokenGeneralInfomation = ({ baseContract }: PageProps) => { toaster, err: err, setTransactionResults, + transactionResultStorageKey, transactionHash: transactionHash, transactionType: transactionTypeMap[API], tokenAddress: paramValues.hederaTokenAddress, @@ -187,6 +188,7 @@ const QueryTokenGeneralInfomation = ({ baseContract }: PageProps) => { { APICalled: API, status: 'success', + transactionResultStorageKey, transactionTimeStamp: Date.now(), txHash: transactionHash as string, transactionType: transactionTypeMap[API], diff --git a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-query-contract/methods/queryTokenPermission/index.tsx b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-query-contract/methods/queryTokenPermission/index.tsx index 242ad438b..062360952 100644 --- a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-query-contract/methods/queryTokenPermission/index.tsx +++ b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-query-contract/methods/queryTokenPermission/index.tsx @@ -175,6 +175,7 @@ const QueryTokenPermissionInfomation = ({ baseContract }: PageProps) => { APICalled: API, setTransactionResults, err: tokenInfoResult.err, + transactionResultStorageKey, tokenAddress: paramValues.hederaTokenAddress, transactionType: `HTS-${API.replace('_', '-')}`, transactionHash: tokenInfoResult.transactionHash, @@ -199,6 +200,7 @@ const QueryTokenPermissionInfomation = ({ baseContract }: PageProps) => { APICalled: API, status: 'success', tokenInfo: cachedTokenInfo, + transactionResultStorageKey, transactionTimeStamp: Date.now(), tokenAddress: paramValues.hederaTokenAddress, transactionType: `HTS-${API.replace('_', '-')}`, diff --git a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-query-contract/methods/queryTokenStatus/index.tsx b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-query-contract/methods/queryTokenStatus/index.tsx index 5115b85df..e12d2fbf6 100644 --- a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-query-contract/methods/queryTokenStatus/index.tsx +++ b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-query-contract/methods/queryTokenStatus/index.tsx @@ -154,6 +154,7 @@ const QueryTokenStatusInfomation = ({ baseContract }: PageProps) => { APICalled: API, setTransactionResults, err: tokenInfoResult.err, + transactionResultStorageKey, accountAddress: paramValues.accountAddress, tokenAddress: paramValues.hederaTokenAddress, transactionType: `HTS-${API.replace('_', '-')}`, @@ -168,6 +169,7 @@ const QueryTokenStatusInfomation = ({ baseContract }: PageProps) => { { APICalled: API, status: 'success', + transactionResultStorageKey, transactionTimeStamp: Date.now(), accountAddress: paramValues.accountAddress, tokenAddress: paramValues.hederaTokenAddress, diff --git a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-query-contract/methods/queryTokenValidity/index.tsx b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-query-contract/methods/queryTokenValidity/index.tsx index 258623eb0..f08a1d535 100644 --- a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-query-contract/methods/queryTokenValidity/index.tsx +++ b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-query-contract/methods/queryTokenValidity/index.tsx @@ -111,6 +111,7 @@ const QueryTokenValidity = ({ baseContract }: PageProps) => { toaster, transactionHash, setTransactionResults, + transactionResultStorageKey, transactionType: 'HTS-IS-TOKEN', tokenAddress: paramValues.hederaTokenAddress, sessionedContractAddress: currentContractAddress, @@ -122,6 +123,7 @@ const QueryTokenValidity = ({ baseContract }: PageProps) => { ...prev, { status: 'success', + transactionResultStorageKey, isToken: Number(IsToken) === 1, transactionType: 'HTS-IS-TOKEN', txHash: transactionHash as string, diff --git a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-transfer-contract/method/transferCrypto/index.tsx b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-transfer-contract/method/transferCrypto/index.tsx index 7f031cb85..fe88cf2cf 100644 --- a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-transfer-contract/method/transferCrypto/index.tsx +++ b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-transfer-contract/method/transferCrypto/index.tsx @@ -251,6 +251,7 @@ const CryptoTransfer = ({ baseContract }: PageProps) => { toaster, transactionHash, setTransactionResults, + transactionResultStorageKey, transactionType: 'HTS-CRYPTO-TRANSFER', sessionedContractAddress: currentContractAddress, }); @@ -261,6 +262,7 @@ const CryptoTransfer = ({ baseContract }: PageProps) => { ...prev, { status: 'success', + transactionResultStorageKey, transactionTimeStamp: Date.now(), txHash: transactionHash as string, transactionType: 'HTS-CRYPTO-TRANSFER', diff --git a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-transfer-contract/method/transferMultipleTokens/index.tsx b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-transfer-contract/method/transferMultipleTokens/index.tsx index 2bf1e6b30..d74f3a344 100644 --- a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-transfer-contract/method/transferMultipleTokens/index.tsx +++ b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-transfer-contract/method/transferMultipleTokens/index.tsx @@ -241,6 +241,7 @@ const TransferMultipleTokens = ({ baseContract }: PageProps) => { APICalled: API, setTransactionResults, err: transactionResult.err, + transactionResultStorageKey, transactionType: 'HTS-TOKENS-TRANSFER', sessionedContractAddress: currentContractAddress, tokenAddress: commonParamValues.hederaTokenAddress, @@ -254,6 +255,7 @@ const TransferMultipleTokens = ({ baseContract }: PageProps) => { { APICalled: API, status: 'success', + transactionResultStorageKey, transactionTimeStamp: Date.now(), transactionType: 'HTS-TOKENS-TRANSFER', sessionedContractAddress: currentContractAddress, diff --git a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-transfer-contract/method/transferSingleToken/index.tsx b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-transfer-contract/method/transferSingleToken/index.tsx index d4b20f4d2..aa5cddfdf 100644 --- a/system-contract-dapp-playground/src/components/contract-interaction/hts/token-transfer-contract/method/transferSingleToken/index.tsx +++ b/system-contract-dapp-playground/src/components/contract-interaction/hts/token-transfer-contract/method/transferSingleToken/index.tsx @@ -146,6 +146,7 @@ const TransferSingleToken = ({ baseContract }: PageProps) => { APICalled: API, transactionHash, setTransactionResults, + transactionResultStorageKey, accountAddress: senderAddress, transactionType: 'HTS-TOKEN-TRANSFER', tokenAddress: paramValues.hederaTokenAddress, @@ -160,6 +161,7 @@ const TransferSingleToken = ({ baseContract }: PageProps) => { APICalled: API, receiverAddress, status: 'success', + transactionResultStorageKey, accountAddress: senderAddress, transactionTimeStamp: Date.now(), txHash: transactionHash as string, diff --git a/system-contract-dapp-playground/src/components/contract-interaction/ihrc/methods/index.tsx b/system-contract-dapp-playground/src/components/contract-interaction/ihrc/methods/index.tsx index cc5a0dbc8..c8fa16204 100644 --- a/system-contract-dapp-playground/src/components/contract-interaction/ihrc/methods/index.tsx +++ b/system-contract-dapp-playground/src/components/contract-interaction/ihrc/methods/index.tsx @@ -123,6 +123,7 @@ const HederaIHRC719Methods = ({ network }: PageProps) => { transactionHash, setTransactionResults, sessionedContractAddress: '', + transactionResultStorageKey, transactionType: `IHRC719-${API}`, tokenAddress: paramValues.hederaTokenAddress, }); @@ -133,6 +134,7 @@ const HederaIHRC719Methods = ({ network }: PageProps) => { ...prev, { status: 'success', + transactionResultStorageKey, sessionedContractAddress: '', transactionTimeStamp: Date.now(), txHash: transactionHash as string, diff --git a/system-contract-dapp-playground/src/components/contract-interaction/prng/methods/index.tsx b/system-contract-dapp-playground/src/components/contract-interaction/prng/methods/index.tsx index 3fbfedc0f..033f25f64 100644 --- a/system-contract-dapp-playground/src/components/contract-interaction/prng/methods/index.tsx +++ b/system-contract-dapp-playground/src/components/contract-interaction/prng/methods/index.tsx @@ -114,6 +114,7 @@ const HederaPRNGMethods = ({ baseContract }: PageProps) => { transactionHash, setTransactionResults, transactionType: `PRNG`, + transactionResultStorageKey, sessionedContractAddress: currentContractAddress, }); return; @@ -125,6 +126,7 @@ const HederaPRNGMethods = ({ baseContract }: PageProps) => { status: 'success', pseudoRandomSeed, transactionType: `PRNG`, + transactionResultStorageKey, transactionTimeStamp: Date.now(), txHash: transactionHash as string, sessionedContractAddress: currentContractAddress, diff --git a/system-contract-dapp-playground/src/sections/activity/index.tsx b/system-contract-dapp-playground/src/sections/activity/index.tsx index 2751852a1..f564705de 100644 --- a/system-contract-dapp-playground/src/sections/activity/index.tsx +++ b/system-contract-dapp-playground/src/sections/activity/index.tsx @@ -22,16 +22,21 @@ import Cookies from 'js-cookie'; import { motion } from 'framer-motion'; +import { AiOutlineMinus } from 'react-icons/ai'; import { FiExternalLink } from 'react-icons/fi'; import { useEffect, useMemo, useState } from 'react'; +import ConfirmModal from '@/components/common/ConfirmModal'; import { prepareTransactionList } from '@/utils/common/helpers'; import { MdNavigateBefore, MdNavigateNext } from 'react-icons/md'; +import { CommonErrorToast } from '@/components/toast/CommonToast'; +import { TransactionResult } from '@/types/contract-interactions/HTS'; +import { clearCachedTransactions, getArrayTypedValuesFromLocalStorage } from '@/api/localStorage'; +import { usePaginatedTxResults } from '@/components/contract-interaction/hts/shared/hooks/usePaginatedTxResults'; import { HEDERA_BRANDING_COLORS, - HEDERA_CHAKRA_INPUT_BOX_SIZES, HEDERA_CHAKRA_TABLE_VARIANTS, + HEDERA_CHAKRA_INPUT_BOX_SIZES, } from '@/utils/common/constants'; -import { usePaginatedTxResults } from '@/components/contract-interaction/hts/shared/hooks/usePaginatedTxResults'; import { Th, Tr, @@ -43,19 +48,23 @@ import { Select, Popover, Tooltip, + useToast, + useDisclosure, PopoverTrigger, PopoverContent, TableContainer, } from '@chakra-ui/react'; const ActivitySection = () => { + const toaster = useToast(); const TRANSACTION_PAGE_SIZE = 20; const hederaNetwork = Cookies.get('_network'); const [mounted, setMounted] = useState(false); - const [transactionList] = useState(prepareTransactionList()); + const { isOpen, onOpen, onClose } = useDisclosure(); const [order, setOrder] = useState<'OLDEST' | 'LATEST'>('OLDEST'); const parsedHederaNetwork = hederaNetwork && JSON.parse(hederaNetwork); const [currentTransactionPage, setCurrentTransactionPage] = useState(1); + const [transactionList, setTransactionList] = useState(prepareTransactionList()); // sort transactionList based on order const sortedTransactionList = useMemo( @@ -76,6 +85,58 @@ const ActivitySection = () => { order ); + /** @dev handle removing record */ + const handleRemoveRecord = (targetTransactionResult: TransactionResult) => { + // get the cached array stored in localStoraged + const { storageResult, err: localStorageBalanceErr } = getArrayTypedValuesFromLocalStorage( + targetTransactionResult.transactionResultStorageKey + ); + + // handle err + if (localStorageBalanceErr) { + CommonErrorToast({ + toaster, + title: 'Cannot access transaction results in storage', + description: "See client's console for more information", + }); + return; + } + + // remove record out of the storageResult array + const filteredTransactionResults = storageResult.filter( + (transactionResult: TransactionResult) => transactionResult.txHash !== targetTransactionResult.txHash + ); + + // storage the filteredTransactionResults back to storage + // @notice if filteredTransactionResults.length === 0, remove that key in storage + if (filteredTransactionResults.length === 0) { + localStorage.removeItem(targetTransactionResult.transactionResultStorageKey); + } else { + localStorage.setItem( + targetTransactionResult.transactionResultStorageKey, + JSON.stringify(filteredTransactionResults) + ); + } + + // update transactionList + setTransactionList((prev) => + prev.filter((transactionResult) => transactionResult.txHash !== targetTransactionResult.txHash) + ); + }; + + /** @dev handle removing all records */ + + const handleRemoveAllRecords = async () => { + // close modal + onClose(); + + // clear localStorage cache + clearCachedTransactions(); + + // update transactionList + setTransactionList([]); + }; + // ensures that the "application mounted" flag is set to ensure consistent UI rendering on both the server and client sides. useEffect(() => setMounted(true), []); @@ -101,21 +162,37 @@ const ActivitySection = () => {
- {/* Filter */} -
- -
+ {sortedTransactionList.length > 0 && ( +
+ {/* Filter */} +
+ +
+ + {/* remove all button */} +
+ + + +
+
+ )} {sortedTransactionList.length > 0 ? ( <> @@ -130,6 +207,7 @@ const ActivitySection = () => { Transaction Type Status Transaction hash + @@ -160,7 +238,6 @@ const ActivitySection = () => { {/* txHash */} - {/* transaction hash */}
navigator.clipboard.writeText(transaction.txHash)}> @@ -191,6 +268,20 @@ const ActivitySection = () => {
+ + {/* delete button */} + + + + + ); })} @@ -233,6 +324,20 @@ const ActivitySection = () => {

No transactions have been made.

)} + + + By completing this action, all the transactions you have made during this session will be + permanently erased from the DApp's cache, but they will still be accessible through HashScan + or other explorer solutions. +

+ } + modalHeader={'Sure to remove all?'} + handleAcknowledge={handleRemoveAllRecords} + /> ); }; diff --git a/system-contract-dapp-playground/src/types/contract-interactions/HTS/index.d.ts b/system-contract-dapp-playground/src/types/contract-interactions/HTS/index.d.ts index 351e609be..35c358ea6 100644 --- a/system-contract-dapp-playground/src/types/contract-interactions/HTS/index.d.ts +++ b/system-contract-dapp-playground/src/types/contract-interactions/HTS/index.d.ts @@ -37,6 +37,7 @@ export type TransactionResult = { tokenAddresses?: string[]; transactionTimeStamp: number; sessionedContractAddress: string; + transactionResultStorageKey: string; }; /** @dev an interface for the results returned back from interacting with Hedera System Smart Contracts */