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

dapp-feat: Wipe Cached Transaction Results feature complete (#390) #398

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
2 changes: 1 addition & 1 deletion system-contract-dapp-playground/.prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"printWidth": 100
"printWidth": 110
}
26 changes: 22 additions & 4 deletions system-contract-dapp-playground/src/api/localStorage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*
*/

import { OFFCIAL_NETWORK_NAME } from '@/utils/common/constants';

/**
* @dev get balances from LocalStorage
*
Expand All @@ -30,10 +32,7 @@ export const getBalancesFromLocalStorage = () => {
const storageBalances = localStorage.getItem('hedera_erc20_balances');
if (storageBalances) {
return {
storageBalances: new Map(Object.entries(JSON.parse(storageBalances))) as Map<
string,
number
>,
storageBalances: new Map(Object.entries(JSON.parse(storageBalances))) as Map<string, number>,
};
} else {
return { storageBalances: new Map() };
Expand Down Expand Up @@ -64,3 +63,22 @@ export const getArrayTypedValuesFromLocalStorage = (key: string) => {
return { err };
}
};

/**
* @dev clear all HEDERA transaction results cached in localStorage
*/
export const clearTransactionCache = () => {
// loop through localStorage items
if (localStorage) {
for (let i = 0; i < localStorage.length; i++) {
// get key
const key = localStorage.key(i);

// remove items that have keys start with HEDERA
if (key?.startsWith(OFFCIAL_NETWORK_NAME)) {
localStorage.removeItem(key);
i--;
}
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { handleAPIErrors } from '../../shared/methods/handleAPIErrors';
import { TRANSACTION_PAGE_SIZE } from '../../shared/states/commonStates';
import { useToastSuccessful } from '../../shared/hooks/useToastSuccessful';
import { usePaginatedTxResults } from '../../shared/hooks/usePaginatedTxResults';
import { HEDERA_TRANSACTION_RESULT_STORAGE_KEYS } from '@/utils/common/constants';
import TokenAddressesInputForm from '../../shared/components/TokenAddressesInputForm';
import { TransactionResultTable } from '../../shared/components/TransactionResultTable';
import { associateHederaTokensToAccounts } from '@/api/hedera/tokenCreateCustom-interactions';
Expand All @@ -46,16 +47,15 @@ const AssociateHederaToken = ({ baseContract }: PageProps) => {
// general states
const toaster = useToast();
const [isLoading, setIsLoading] = useState(false);
const initialParamValues = { associatingAddress: '' };
const [isSuccessful, setIsSuccessful] = useState(false);
const hederaNetwork = JSON.parse(Cookies.get('_network') as string);
const [currentTransactionPage, setCurrentTransactionPage] = useState(1);
const transactionResultStorageKey = 'HEDERA.HTS.TOKEN-CREATE.ASSOCIATE-TOKEN-RESULTS';
const [transactionResults, setTransactionResults] = useState<TransactionResult[]>([]);
const initialParamValues = {
associatingAddress: '',
};
const [paramValues, setParamValues] = useState<any>(initialParamValues);
const [transactionResults, setTransactionResults] = useState<TransactionResult[]>([]);
const initialTokenAddressesValues = { fieldKey: generatedRandomUniqueKey(9), fieldValue: '' };
const transactionResultStorageKey =
HEDERA_TRANSACTION_RESULT_STORAGE_KEYS['TOKEN-CREATE']['ASSOCIATE-TOKEN'];
const [hederaTokenAddresses, setHederaTokenAddresses] = useState<
{ fieldKey: string; fieldValue: string }[]
>([initialTokenAddressesValues]);
Expand All @@ -68,13 +68,10 @@ const AssociateHederaToken = ({ baseContract }: PageProps) => {
setCurrentTransactionPage,
setTransactionResults
);
}, [toaster]);
}, [toaster, transactionResultStorageKey]);

// declare a paginatedTransactionResults
const paginatedTransactionResults = usePaginatedTxResults(
currentTransactionPage,
transactionResults
);
const paginatedTransactionResults = usePaginatedTxResults(currentTransactionPage, transactionResults);

/** @dev handle form inputs on change */
const handleInputOnChange = (e: any, param: string, fieldKey?: string) => {
Expand Down Expand Up @@ -102,9 +99,7 @@ const AssociateHederaToken = ({ baseContract }: PageProps) => {
break;
case 'REMOVE':
if (hederaTokenAddresses.length > 1) {
setHederaTokenAddresses((prev) =>
prev.filter((field) => field.fieldKey !== removingFieldKey)
);
setHederaTokenAddresses((prev) => prev.filter((field) => field.fieldKey !== removingFieldKey));
}
}
};
Expand Down Expand Up @@ -199,15 +194,9 @@ const AssociateHederaToken = ({ baseContract }: PageProps) => {
paramType={(htsTokenAssociateParamFields as any)['associatingAddress'].inputType}
paramSize={(htsTokenAssociateParamFields as any)['associatingAddress'].inputSize}
explanation={(htsTokenAssociateParamFields as any)['associatingAddress'].explanation}
paramClassName={
(htsTokenAssociateParamFields as any)['associatingAddress'].inputClassname
}
paramPlaceholder={
(htsTokenAssociateParamFields as any)['associatingAddress'].inputPlaceholder
}
paramFocusColor={
(htsTokenAssociateParamFields as any)['associatingAddress'].inputFocusBorderColor
}
paramClassName={(htsTokenAssociateParamFields as any)['associatingAddress'].inputClassname}
paramPlaceholder={(htsTokenAssociateParamFields as any)['associatingAddress'].inputPlaceholder}
paramFocusColor={(htsTokenAssociateParamFields as any)['associatingAddress'].inputFocusBorderColor}
/>

{/* Token addresses */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { CommonErrorToast } from '@/components/toast/CommonToast';
import { handleAPIErrors } from '../../shared/methods/handleAPIErrors';
import { useToastSuccessful } from '../../shared/hooks/useToastSuccessful';
import { usePaginatedTxResults } from '../../shared/hooks/usePaginatedTxResults';
import { HEDERA_TRANSACTION_RESULT_STORAGE_KEYS } from '@/utils/common/constants';
import { SharedSigningKeysComponent } from '../../shared/components/SigningKeysForm';
import { createHederaFungibleToken } from '@/api/hedera/tokenCreateCustom-interactions';
import { TransactionResultTable } from '../../shared/components/TransactionResultTable';
Expand Down Expand Up @@ -62,7 +63,8 @@ const FungibleTokenCreate = ({ baseContract }: PageProps) => {
const [isDefaultFreeze, setIsDefaultFreeze] = useState(false);
const hederaNetwork = JSON.parse(Cookies.get('_network') as string);
const [currentTransactionPage, setCurrentTransactionPage] = useState(1);
const transactionResultStorageKey = 'HEDERA.HTS.TOKEN-CREATE.FUNGIBLE-TOKEN-RESULTS';
const transactionResultStorageKey =
HEDERA_TRANSACTION_RESULT_STORAGE_KEYS['TOKEN-CREATE']['FUNGIBLE-TOKEN'];
const [transactionResults, setTransactionResults] = useState<TransactionResult[]>([]);
const tokenCreateFields = {
info: ['name', 'symbol', 'memo'],
Expand Down Expand Up @@ -97,13 +99,10 @@ const FungibleTokenCreate = ({ baseContract }: PageProps) => {
setCurrentTransactionPage,
setTransactionResults
);
}, [toaster]);
}, [toaster, transactionResultStorageKey]);

// declare a paginatedTransactionResults
const paginatedTransactionResults = usePaginatedTxResults(
currentTransactionPage,
transactionResults
);
const paginatedTransactionResults = usePaginatedTxResults(currentTransactionPage, transactionResults);

/** @dev handle form inputs on change */
const handleInputOnChange = (e: any, param: string) => {
Expand Down Expand Up @@ -309,12 +308,8 @@ const FungibleTokenCreate = ({ baseContract }: PageProps) => {
paramSize={(htsTokenCreateParamFields as any)['feeTokenAddress'].inputSize}
explanation={(htsTokenCreateParamFields as any)['feeTokenAddress'].explanation}
paramClassName={(htsTokenCreateParamFields as any)['feeTokenAddress'].inputClassname}
paramPlaceholder={
(htsTokenCreateParamFields as any)['feeTokenAddress'].inputPlaceholder
}
paramFocusColor={
(htsTokenCreateParamFields as any)['feeTokenAddress'].inputFocusBorderColor
}
paramPlaceholder={(htsTokenCreateParamFields as any)['feeTokenAddress'].inputPlaceholder}
paramFocusColor={(htsTokenCreateParamFields as any)['feeTokenAddress'].inputFocusBorderColor}
/>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { handleAPIErrors } from '../../shared/methods/handleAPIErrors';
import { TRANSACTION_PAGE_SIZE } from '../../shared/states/commonStates';
import { useToastSuccessful } from '../../shared/hooks/useToastSuccessful';
import { usePaginatedTxResults } from '../../shared/hooks/usePaginatedTxResults';
import { HEDERA_TRANSACTION_RESULT_STORAGE_KEYS } from '@/utils/common/constants';
import { grantTokenKYCToAccount } from '@/api/hedera/tokenCreateCustom-interactions';
import { TransactionResultTable } from '../../shared/components/TransactionResultTable';
import { handleSanitizeHederaFormInputs } from '../../shared/methods/handleSanitizeFormInputs';
Expand All @@ -48,7 +49,7 @@ const GrantTokenKYC = ({ baseContract }: PageProps) => {
const hederaNetwork = JSON.parse(Cookies.get('_network') as string);
const [currentTransactionPage, setCurrentTransactionPage] = useState(1);
const grantKYCFields = ['hederaTokenAddress', 'grantingKYCAccountAddress'];
const transactionResultStorageKey = 'HEDERA.HTS.TOKEN-CREATE.TOKEN-KYC-RESULTS';
const transactionResultStorageKey = HEDERA_TRANSACTION_RESULT_STORAGE_KEYS['TOKEN-CREATE']['TOKEN-KYC'];
const [transactionResults, setTransactionResults] = useState<TransactionResult[]>([]);
const initialParamValues = {
hederaTokenAddress: '',
Expand All @@ -64,13 +65,10 @@ const GrantTokenKYC = ({ baseContract }: PageProps) => {
setCurrentTransactionPage,
setTransactionResults
);
}, [toaster]);
}, [toaster, transactionResultStorageKey]);

// declare a paginatedTransactionResults
const paginatedTransactionResults = usePaginatedTxResults(
currentTransactionPage,
transactionResults
);
const paginatedTransactionResults = usePaginatedTxResults(currentTransactionPage, transactionResults);

/** @dev handle form inputs on change */
const handleInputOnChange = (e: any, param: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { TRANSACTION_PAGE_SIZE } from '../../shared/states/commonStates';
import MetadataInputForm from '../../shared/components/MetadataInputForm';
import { useToastSuccessful } from '../../shared/hooks/useToastSuccessful';
import { usePaginatedTxResults } from '../../shared/hooks/usePaginatedTxResults';
import { HEDERA_TRANSACTION_RESULT_STORAGE_KEYS } from '@/utils/common/constants';
import { TransactionResultTable } from '../../shared/components/TransactionResultTable';
import { handleSanitizeHederaFormInputs } from '../../shared/methods/handleSanitizeFormInputs';
import { useUpdateTransactionResultsToLocalStorage } from '../../shared/hooks/useUpdateLocalStorage';
Expand All @@ -40,10 +41,7 @@ import {
SharedFormInputField,
SharedExecuteButton,
} from '../../shared/components/ParamInputForm';
import {
mintHederaToken,
mintHederaTokenToAddress,
} from '@/api/hedera/tokenCreateCustom-interactions';
import { mintHederaToken, mintHederaTokenToAddress } from '@/api/hedera/tokenCreateCustom-interactions';

interface PageProps {
baseContract: Contract;
Expand All @@ -59,7 +57,7 @@ const MintHederaToken = ({ baseContract }: PageProps) => {
const [APIMethods, setAPIMethods] = useState<API_NAMES>('FUNGIBLE');
const hederaNetwork = JSON.parse(Cookies.get('_network') as string);
const [currentTransactionPage, setCurrentTransactionPage] = useState(1);
const transactionResultStorageKey = 'HEDERA.HTS.TOKEN-CREATE.MINT-TOKEN-RESULTS';
const transactionResultStorageKey = HEDERA_TRANSACTION_RESULT_STORAGE_KEYS['TOKEN-CREATE']['MINT-TOKEN'];
const [transactionResults, setTransactionResults] = useState<TransactionResult[]>([]);
const [metadata, setMetadata] = useState<{ metaKey: string; metaValue: string }[]>([]);
const tokenMintFields = useMemo(() => {
Expand Down Expand Up @@ -95,13 +93,10 @@ const MintHederaToken = ({ baseContract }: PageProps) => {
setCurrentTransactionPage,
setTransactionResults
);
}, [toaster]);
}, [toaster, transactionResultStorageKey]);

/** @dev declare a paginatedTransactionResults */
const paginatedTransactionResults = usePaginatedTxResults(
currentTransactionPage,
transactionResults
);
const paginatedTransactionResults = usePaginatedTxResults(currentTransactionPage, transactionResults);

/** @dev handle form inputs on change */
const handleInputOnChange = (e: any, param: string, metaKey?: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { CommonErrorToast } from '@/components/toast/CommonToast';
import { handleAPIErrors } from '../../shared/methods/handleAPIErrors';
import { useToastSuccessful } from '../../shared/hooks/useToastSuccessful';
import { usePaginatedTxResults } from '../../shared/hooks/usePaginatedTxResults';
import { HEDERA_TRANSACTION_RESULT_STORAGE_KEYS } from '@/utils/common/constants';
import { SharedSigningKeysComponent } from '../../shared/components/SigningKeysForm';
import { TransactionResultTable } from '../../shared/components/TransactionResultTable';
import { createHederaNonFungibleToken } from '@/api/hedera/tokenCreateCustom-interactions';
Expand Down Expand Up @@ -62,7 +63,8 @@ const NonFungibleTokenCreate = ({ baseContract }: PageProps) => {
const HEDERA_NETWORK = JSON.parse(Cookies.get('_network') as string);
const [currentTransactionPage, setCurrentTransactionPage] = useState(1);
const [transactionResults, setTransactionResults] = useState<TransactionResult[]>([]);
const transactionResultStorageKey = 'HEDERA.HTS.TOKEN-CREATE.NON-FUNGIBLE-TOKEN-RESULTS';
const transactionResultStorageKey =
HEDERA_TRANSACTION_RESULT_STORAGE_KEYS['TOKEN-CREATE']['NON-FUNGIBLE-TOKEN'];
const tokenCreateFields = {
info: ['name', 'symbol', 'memo', 'maxSupply', 'treasury'],
feeTokenAddress: 'feeTokenAddress',
Expand Down Expand Up @@ -91,13 +93,10 @@ const NonFungibleTokenCreate = ({ baseContract }: PageProps) => {
setCurrentTransactionPage,
setTransactionResults
);
}, [toaster]);
}, [toaster, transactionResultStorageKey]);

// declare a paginatedTransactionResults
const paginatedTransactionResults = usePaginatedTxResults(
currentTransactionPage,
transactionResults
);
const paginatedTransactionResults = usePaginatedTxResults(currentTransactionPage, transactionResults);

/** @dev handle form inputs on change */
const handleInputOnChange = (e: any, param: string) => {
Expand Down Expand Up @@ -239,12 +238,8 @@ const NonFungibleTokenCreate = ({ baseContract }: PageProps) => {
paramSize={(htsTokenCreateParamFields as any)['feeTokenAddress'].inputSize}
explanation={(htsTokenCreateParamFields as any)['feeTokenAddress'].explanation}
paramClassName={(htsTokenCreateParamFields as any)['feeTokenAddress'].inputClassname}
paramPlaceholder={
(htsTokenCreateParamFields as any)['feeTokenAddress'].inputPlaceholder
}
paramFocusColor={
(htsTokenCreateParamFields as any)['feeTokenAddress'].inputFocusBorderColor
}
paramPlaceholder={(htsTokenCreateParamFields as any)['feeTokenAddress'].inputPlaceholder}
paramFocusColor={(htsTokenCreateParamFields as any)['feeTokenAddress'].inputFocusBorderColor}
/>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@ import { handleAPIErrors } from '../../../shared/methods/handleAPIErrors';
import { TRANSACTION_PAGE_SIZE } from '../../../shared/states/commonStates';
import { useToastSuccessful } from '../../../shared/hooks/useToastSuccessful';
import { manageTokenDeduction } from '@/api/hedera/tokenManagement-interactions';
import { HEDERA_TRANSACTION_RESULT_STORAGE_KEYS } from '@/utils/common/constants';
import { usePaginatedTxResults } from '../../../shared/hooks/usePaginatedTxResults';
import { TransactionResultTable } from '../../../shared/components/TransactionResultTable';
import { handleSanitizeHederaFormInputs } from '../../../shared/methods/handleSanitizeFormInputs';
import { useUpdateTransactionResultsToLocalStorage } from '../../../shared/hooks/useUpdateLocalStorage';
import { htsTokenDeductionParamFields } from '@/utils/contract-interactions/HTS/token-management/constant';
import { handleRetrievingTransactionResultsFromLocalStorage } from '../../../shared/methods/handleRetrievingTransactionResultsFromLocalStorage';
import {
SharedFormInputField,
SharedExecuteButtonWithFee,
} from '../../../shared/components/ParamInputForm';
import { SharedFormInputField, SharedExecuteButtonWithFee } from '../../../shared/components/ParamInputForm';

interface PageProps {
baseContract: Contract;
Expand All @@ -51,7 +49,7 @@ const ManageTokenDelete = ({ baseContract }: PageProps) => {
const hederaNetwork = JSON.parse(Cookies.get('_network') as string);
const [currentTransactionPage, setCurrentTransactionPage] = useState(1);
const [transactionResults, setTransactionResults] = useState<TransactionResult[]>([]);
const transactionResultStorageKey = 'HEDERA.HTS.TOKEN-MANAGEMENT.TOKEN-DELETE-RESULTS';
const transactionResultStorageKey = HEDERA_TRANSACTION_RESULT_STORAGE_KEYS['TOKEN-MANAGE']['TOKEN-DELETE'];
const initialParamValues = {
feeValue: '',
hederaTokenAddress: '',
Expand All @@ -65,13 +63,10 @@ const ManageTokenDelete = ({ baseContract }: PageProps) => {
setCurrentTransactionPage,
setTransactionResults
);
}, [toaster]);
}, [toaster, transactionResultStorageKey]);

// declare a paginatedTransactionResults
const paginatedTransactionResults = usePaginatedTxResults(
currentTransactionPage,
transactionResults
);
const paginatedTransactionResults = usePaginatedTxResults(currentTransactionPage, transactionResults);
/** @dev handle form inputs on change */
const handleInputOnChange = (e: any, param: string) => {
setParamValues((prev: any) => ({ ...prev, [param]: e.target.value }));
Expand Down Expand Up @@ -162,15 +157,9 @@ const ManageTokenDelete = ({ baseContract }: PageProps) => {
paramType={(htsTokenDeductionParamFields as any)['hederaTokenAddress'].inputType}
paramSize={(htsTokenDeductionParamFields as any)['hederaTokenAddress'].inputSize}
explanation={(htsTokenDeductionParamFields as any)['hederaTokenAddress'].explanation}
paramClassName={
(htsTokenDeductionParamFields as any)['hederaTokenAddress'].inputClassname
}
paramPlaceholder={
(htsTokenDeductionParamFields as any)['hederaTokenAddress'].inputPlaceholder
}
paramFocusColor={
(htsTokenDeductionParamFields as any)['hederaTokenAddress'].inputFocusBorderColor
}
paramClassName={(htsTokenDeductionParamFields as any)['hederaTokenAddress'].inputClassname}
paramPlaceholder={(htsTokenDeductionParamFields as any)['hederaTokenAddress'].inputPlaceholder}
paramFocusColor={(htsTokenDeductionParamFields as any)['hederaTokenAddress'].inputFocusBorderColor}
/>

<div className="w-full">
Expand Down
Loading