Skip to content

Commit

Permalink
dapp-update: renamed QueryTokenRelation to QueryTokenInfo
Browse files Browse the repository at this point in the history
Signed-off-by: Logan Nguyen <[email protected]>
  • Loading branch information
quiet-node committed Sep 7, 2023
1 parent 2e85d67 commit 8e779f1
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

import {
queryTokenValidity,
queryTokenStatusInformation,
queryTokenGeneralInfomation,
queryTokenSpecificInfomation,
queryTokenRelationInformation,
queryTokenPermissionInformation,
} from '@/api/hedera/tokenQuery-interactions';
import { Contract } from 'ethers';
Expand Down Expand Up @@ -266,9 +266,9 @@ describe('TokenQueryContract Test Suite', () => {
});
});

describe('queryTokenRelationInformation test suite', () => {
it('should execute queryTokenRelationInformation wit API === "IS_KYC" then return info value from event', async () => {
const txRes = await queryTokenRelationInformation(
describe('queryTokenStatusInformation test suite', () => {
it('should execute queryTokenStatusInformation wit API === "IS_KYC" then return info value from event', async () => {
const txRes = await queryTokenStatusInformation(
baseContract as unknown as Contract,
'IS_KYC',
hederaTokenAddress,
Expand All @@ -280,8 +280,8 @@ describe('TokenQueryContract Test Suite', () => {
expect(txRes.KycGranted).toBe(mockedEventReturnedValue);
});

it('should execute queryTokenRelationInformation wit API === "IS_FROZEN" then return info value from event', async () => {
const txRes = await queryTokenRelationInformation(
it('should execute queryTokenStatusInformation wit API === "IS_FROZEN" then return info value from event', async () => {
const txRes = await queryTokenStatusInformation(
baseContract as unknown as Contract,
'IS_FROZEN',
hederaTokenAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ export const queryTokenPermissionInformation = async (
*
* @return Promise<TokenQuerySmartContractResult>
*/
export const queryTokenRelationInformation = async (
export const queryTokenStatusInformation = async (
baseContract: Contract,
API: 'IS_KYC' | 'IS_FROZEN',
hederaTokenAddress: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ interface TransactionResultTablePageProps {
| 'QuerySpecificInfo'
| 'QueryTokenGeneralInfo'
| 'QueryTokenPermission'
| 'QueryTokenRelation';
| 'QueryTokenStatus';
}

export const TransactionResultTable = ({
Expand Down Expand Up @@ -104,7 +104,7 @@ export const TransactionResultTable = ({
beginingHashIndex = 10;
endingHashIndex = -5;
break;
case 'QueryTokenRelation':
case 'QueryTokenStatus':
beginingHashIndex = 4;
endingHashIndex = -3;
break;
Expand All @@ -125,12 +125,10 @@ export const TransactionResultTable = ({
{API === 'TokenAssociate' && (
<Th color={HEDERA_BRANDING_COLORS.violet}>Associated Account</Th>
)}
{API === 'QueryTokenRelation' && <Th color={HEDERA_BRANDING_COLORS.violet}>Account</Th>}
{API === 'QueryTokenStatus' && <Th color={HEDERA_BRANDING_COLORS.violet}>Account</Th>}
{API === 'GrantKYC' && <Th color={HEDERA_BRANDING_COLORS.violet}>KYCed Account</Th>}
{API === 'QueryValidity' && <Th color={HEDERA_BRANDING_COLORS.violet}>Valid Token</Th>}
{API === 'QueryTokenRelation' && (
<Th color={HEDERA_BRANDING_COLORS.violet}>Relation</Th>
)}
{API === 'QueryTokenStatus' && <Th color={HEDERA_BRANDING_COLORS.violet}>Relation</Th>}
{(API === 'QueryTokenGeneralInfo' ||
API === 'QuerySpecificInfo' ||
API === 'QueryTokenPermission') && (
Expand All @@ -139,7 +137,7 @@ export const TransactionResultTable = ({
{(API === 'QueryTokenGeneralInfo' ||
API === 'QuerySpecificInfo' ||
API === 'QueryTokenPermission' ||
API === 'QueryTokenRelation') && (
API === 'QueryTokenStatus') && (
<Th color={HEDERA_BRANDING_COLORS.violet}>API called</Th>
)}
<Th />
Expand Down Expand Up @@ -229,7 +227,7 @@ export const TransactionResultTable = ({
API === 'QueryTokenGeneralInfo' ||
API === 'QuerySpecificInfo' ||
API === 'QueryTokenPermission' ||
API === 'QueryTokenRelation') && (
API === 'QueryTokenStatus') && (
<Td className="cursor-pointer">
{transactionResult.tokenAddress ? (
<div className="flex gap-1 items-center">
Expand Down Expand Up @@ -391,7 +389,7 @@ export const TransactionResultTable = ({
{(API === 'TokenMint' ||
API === 'TokenAssociate' ||
API === 'GrantKYC' ||
API === 'QueryTokenRelation') && (
API === 'QueryTokenStatus') && (
<Td className="cursor-pointer">
{transactionResult.accountAddress ? (
<div className="flex gap-1 items-center">
Expand Down Expand Up @@ -491,7 +489,7 @@ export const TransactionResultTable = ({
)}

{/* query - token info - Token Relation */}
{API === 'QueryTokenRelation' && (
{API === 'QueryTokenStatus' && (
<Td
className={`cursor-pointer ${
transactionResult.tokenInfo === 1 ? `text-hedera-green` : `text-red-400`
Expand All @@ -513,7 +511,7 @@ export const TransactionResultTable = ({
{(API === 'QueryTokenGeneralInfo' ||
API === 'QuerySpecificInfo' ||
API === 'QueryTokenPermission' ||
API === 'QueryTokenRelation') && (
API === 'QueryTokenStatus') && (
<Td>
{transactionResult.APICalled ? (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ interface ParamsProps {
| 'ALLOWANCE'
| 'GET_APPROVED'
| 'IS_APPROVAL'
| 'QueryTokenRelation';
| 'QueryTokenStatus';
}
/** @dev handle sanitizing Hedera token form inputs */
export const handleSanitizeHederaFormInputs = ({
Expand Down Expand Up @@ -304,7 +304,7 @@ export const handleSanitizeHederaFormInputs = ({
} else if (serialNumber === '' || Number(serialNumber) < 0) {
sanitizeErr = 'Invalid serial number';
}
} else if (API === 'QueryTokenRelation') {
} else if (API === 'QueryTokenStatus') {
if (!isAddress(hederaTokenAddress)) {
sanitizeErr = 'Invalid token address';
} else if (!isAddress(accountAddress)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@

import { Contract } from 'ethers';
import QueryTokenValidity from './queryTokenValidity';
import QueryTokenStatusInfomation from './queryTokenStatus';
import QueryTokenSpecificInfomation from './querySpecificToken';
import QueryTokenGeneralInfomation from './queryTokenGeneralInfo';
import QueryTokenPermissionInfomation from './queryTokenPermission';
import QueryTokenRelationInfomation from './queryTokenRelation';

interface PageProps {
method: string;
Expand All @@ -36,7 +36,7 @@ const HederaTokenQueryMethods = ({ baseContract, method }: PageProps) => {
{method === 'tokenValidity' && <QueryTokenValidity baseContract={baseContract} />}
{method === 'generalInfo' && <QueryTokenGeneralInfomation baseContract={baseContract} />}
{method === 'specificInfo' && <QueryTokenSpecificInfomation baseContract={baseContract} />}
{method === 'tokenRelation' && <QueryTokenRelationInfomation baseContract={baseContract} />}
{method === 'tokenStatus' && <QueryTokenStatusInfomation baseContract={baseContract} />}
{method === 'tokenPermission' && (
<QueryTokenPermissionInfomation baseContract={baseContract} />
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ import { TransactionResult } from '@/types/contract-interactions/HTS';
import { handleAPIErrors } from '../../../shared/methods/handleAPIErrors';
import { TRANSACTION_PAGE_SIZE } from '../../../shared/states/commonStates';
import { useToastSuccessful } from '../../../shared/hooks/useToastSuccessful';
import { queryTokenStatusInformation } from '@/api/hedera/tokenQuery-interactions';
import { usePaginatedTxResults } from '../../../shared/hooks/usePaginatedTxResults';
import { queryTokenRelationInformation } from '@/api/hedera/tokenQuery-interactions';
import { TransactionResultTable } from '../../../shared/components/TransactionResultTable';
import { handleSanitizeHederaFormInputs } from '../../../shared/methods/handleSanitizeFormInputs';
import { useUpdateTransactionResultsToLocalStorage } from '../../../shared/hooks/useUpdateLocalStorage';
import { htsQueryTokenRelationParamFields } from '@/utils/contract-interactions/HTS/token-query/constant';
import { htsQueryTokenStatusParamFields } from '@/utils/contract-interactions/HTS/token-query/constant';
import { handleRetrievingTransactionResultsFromLocalStorage } from '../../../shared/methods/handleRetrievingTransactionResultsFromLocalStorage';
import {
SharedExecuteButton,
Expand All @@ -46,14 +46,14 @@ interface PageProps {
type API_NAMES = 'IS_KYC' | 'IS_FROZEN';
type EVENT_NAMES = 'KycGranted' | 'Frozen';

const QueryTokenRelationInfomation = ({ baseContract }: PageProps) => {
const QueryTokenStatusInfomation = ({ baseContract }: PageProps) => {
// general states
const toaster = useToast();
const [isSuccessful, setIsSuccessful] = useState(false);
const hederaNetwork = JSON.parse(Cookies.get('_network') as string);
const [currentTransactionPage, setCurrentTransactionPage] = useState(1);
const [transactionResults, setTransactionResults] = useState<TransactionResult[]>([]);
const transactionResultStorageKey = 'HEDERA.HTS.TOKEN-QUERY.TOKEN-RELATION-INFO-RESULTS';
const transactionResultStorageKey = 'HEDERA.HTS.TOKEN-QUERY.TOKEN-STATUS-INFO-RESULTS';
const initialParamValues = {
hederaTokenAddress: '',
accountAddress: '',
Expand Down Expand Up @@ -104,14 +104,14 @@ const QueryTokenRelationInfomation = ({ baseContract }: PageProps) => {
setParamValues((prev: any) => ({ ...prev, [param]: e.target.value }));
};

/** @dev handle invoking the API to interact with smart contract and update token relation */
const handleQueryTokenRelationInfo = async (API: API_NAMES) => {
/** @dev handle invoking the API to interact with smart contract and update token status */
const handleQueryTokenStatusInfo = async (API: API_NAMES) => {
// destructuring param values
const { hederaTokenAddress, accountAddress } = paramValues;

// sanitize params
const sanitizeErr = handleSanitizeHederaFormInputs({
API: 'QueryTokenRelation',
API: 'QueryTokenStatus',
hederaTokenAddress,
accountAddress,
});
Expand All @@ -130,7 +130,7 @@ const QueryTokenRelationInfomation = ({ baseContract }: PageProps) => {
}));

// invoking method API
const tokenInfoResult = await queryTokenRelationInformation(
const tokenInfoResult = await queryTokenStatusInformation(
baseContract,
API,
hederaTokenAddress,
Expand Down Expand Up @@ -197,19 +197,19 @@ const QueryTokenRelationInfomation = ({ baseContract }: PageProps) => {
{/* hederaTokenAddress & targetApprovedAddress */}
{tokenCommonFields.map((param) => {
return (
<div className="w-full" key={(htsQueryTokenRelationParamFields as any)[param].paramKey}>
<div className="w-full" key={(htsQueryTokenStatusParamFields as any)[param].paramKey}>
<SharedFormInputField
param={param}
paramValue={paramValues[param]}
handleInputOnChange={handleInputOnChange}
paramKey={(htsQueryTokenRelationParamFields as any)[param].paramKey}
paramType={(htsQueryTokenRelationParamFields as any)[param].inputType}
paramSize={(htsQueryTokenRelationParamFields as any)[param].inputSize}
explanation={(htsQueryTokenRelationParamFields as any)[param].explanation}
paramClassName={(htsQueryTokenRelationParamFields as any)[param].inputClassname}
paramPlaceholder={(htsQueryTokenRelationParamFields as any)[param].inputPlaceholder}
paramKey={(htsQueryTokenStatusParamFields as any)[param].paramKey}
paramType={(htsQueryTokenStatusParamFields as any)[param].inputType}
paramSize={(htsQueryTokenStatusParamFields as any)[param].inputSize}
explanation={(htsQueryTokenStatusParamFields as any)[param].explanation}
paramClassName={(htsQueryTokenStatusParamFields as any)[param].inputClassname}
paramPlaceholder={(htsQueryTokenStatusParamFields as any)[param].inputPlaceholder}
paramFocusColor={
(htsQueryTokenRelationParamFields as any)[param].inputFocusBorderColor
(htsQueryTokenStatusParamFields as any)[param].inputFocusBorderColor
}
/>
</div>
Expand All @@ -225,7 +225,7 @@ const QueryTokenRelationInfomation = ({ baseContract }: PageProps) => {
isLoading={
APIButton.API === 'IS_KYC' ? isLoading.kycLoading : isLoading.frozenLoading
}
handleCreatingFungibleToken={() => handleQueryTokenRelationInfo(APIButton.API)}
handleCreatingFungibleToken={() => handleQueryTokenStatusInfo(APIButton.API)}
buttonTitle={APIButton.executeTitle}
/>
</div>
Expand All @@ -237,7 +237,7 @@ const QueryTokenRelationInfomation = ({ baseContract }: PageProps) => {
{/* transaction results table */}
{transactionResults.length > 0 && (
<TransactionResultTable
API="QueryTokenRelation"
API="QueryTokenStatus"
hederaNetwork={hederaNetwork}
transactionResults={transactionResults}
TRANSACTION_PAGE_SIZE={TRANSACTION_PAGE_SIZE}
Expand All @@ -252,4 +252,4 @@ const QueryTokenRelationInfomation = ({ baseContract }: PageProps) => {
);
};

export default QueryTokenRelationInfomation;
export default QueryTokenStatusInfomation;
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export const HEDERA_SMART_CONTRACTS_ASSETS = {
contractABI: TokenQueryContract.abi,
contractBytecode: TokenQueryContract.bytecode,
githubUrl: `${HEDERA_SMART_CONTRACT_OFFICIAL_GITHUB_URL}/blob/main/contracts/hts-precompile/examples/token-query/TokenQueryContract.sol`,
methods: ['tokenValidity', 'generalInfo', 'specificInfo', 'tokenPermission', 'tokenRelation'],
methods: ['tokenValidity', 'generalInfo', 'specificInfo', 'tokenPermission', 'tokenStatus'],
},
{
name: 'TokenTransferContract' as ContractName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const htsQueryTokenPermissionParamFields = {
};

/** @notice an object holding information for the queryTokenInfo's input fields */
export const htsQueryTokenRelationParamFields = {
export const htsQueryTokenStatusParamFields = {
hederaTokenAddress: {
inputType: 'text',
inputPlaceholder: 'Token address...',
Expand Down

0 comments on commit 8e779f1

Please sign in to comment.