Skip to content

Commit

Permalink
dapp-feat: finished integrating ManageTokenInfo APIs to interact with…
Browse files Browse the repository at this point in the history
… TokenManage contract (#364)

Signed-off-by: Logan Nguyen <[email protected]>
  • Loading branch information
quiet-node authored Sep 1, 2023
1 parent b6fc10f commit 58cc9ec
Show file tree
Hide file tree
Showing 9 changed files with 1,147 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface HookProps {
toastDescription?: string;
setParamValues: Dispatch<any>;
initialTokenAddressesValues?: any;
initialKeyValues?: CommonKeyObject[];
transactionResults: TransactionResult[];
setIsSuccessful: Dispatch<SetStateAction<boolean>>;
setWithCustomFee?: Dispatch<SetStateAction<boolean>>;
Expand All @@ -54,6 +55,7 @@ export const useToastSuccessful = ({
setChosenKeys,
setParamValues,
setIsSuccessful,
initialKeyValues,
toastDescription,
resetParamValues,
setWithCustomFee,
Expand All @@ -78,6 +80,7 @@ export const useToastSuccessful = ({
if (setMetadata) setMetadata([]);
setParamValues(resetParamValues);
if (setWithCustomFee) setWithCustomFee(false);
if (initialKeyValues && setKeys) setKeys(initialKeyValues);
if (setKeyTypesToShow) setKeyTypesToShow(new Set(HederaTokenKeyTypes));
if (setTokenAddresses) setTokenAddresses([initialTokenAddressesValues]);
if (setChosenKeys) setChosenKeys(new Set<IHederaTokenServiceKeyType>());
Expand All @@ -94,13 +97,14 @@ export const useToastSuccessful = ({
setChosenKeys,
setParamValues,
setIsSuccessful,
initialKeyValues,
setWithCustomFee,
resetParamValues,
toastDescription,
setTokenAddresses,
resetParamValues,
setKeyTypesToShow,
setCurrentTransactionPage,
setTokenAddresses,
transactionResults.length,
setCurrentTransactionPage,
initialTokenAddressesValues,
]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,35 @@ interface ParamsProps {
name?: string;
amount?: string;
symbol?: string;
second?: string;
treasury?: string;
decimals?: string;
msgValue?: string;
feeValue?: string;
maxSupply?: string;
initSupply?: string;
serialNumber?: string;
withCustomFee?: boolean;
accountAddress?: string;
feeTokenAddress?: string;
keys?: CommonKeyObject[];
tokenAddresses?: string[];
autoRenewPeriod?: string;
autoRenewAccount?: string;
recipientAddress?: string;
tokenAddresses?: string[];
associatingAddress?: string;
tokenAddressToMint?: string;
hederaTokenAddress?: string;
grantingKYCAccountAddress?: string;
API: 'TokenCreate' | 'Mint' | 'Associate' | 'GrantKYC';
API:
| 'TokenCreate'
| 'Mint'
| 'Associate'
| 'GrantKYC'
| 'UpdateTokenInfo'
| 'UpdateTokenExpiry'
| 'APPROVED_FUNGIBLE'
| 'APPROVED_NON_FUNGIBLE'
| 'SET_APPROVAL';
}
/** @dev handle sanitizing Hedera token form inputs */
export const handleSanitizeHederaFormInputs = ({
Expand All @@ -49,15 +63,20 @@ export const handleSanitizeHederaFormInputs = ({
keys,
amount,
symbol,
msgValue,
second,
decimals,
treasury,
feeValue,
maxSupply,
initSupply,
serialNumber,
withCustomFee,
tokenAddresses,
accountAddress,
feeTokenAddress,
autoRenewPeriod,
recipientAddress,
autoRenewAccount,
tokenAddressToMint,
associatingAddress,
hederaTokenAddress,
Expand Down Expand Up @@ -104,7 +123,7 @@ export const handleSanitizeHederaFormInputs = ({
}

// service fee
if (!sanitizeErr && msgValue === '') {
if (!sanitizeErr && feeValue === '') {
sanitizeErr = 'Service fee field cannot be empty';
}
} else if (API === 'Mint') {
Expand Down Expand Up @@ -132,6 +151,54 @@ export const handleSanitizeHederaFormInputs = ({
} else if (!isAddress(grantingKYCAccountAddress)) {
sanitizeErr = 'Invalid token address';
}
} else if (API === 'UpdateTokenInfo') {
if (!isAddress(hederaTokenAddress)) {
sanitizeErr = 'Invalid token address';
} else if (name === '') {
sanitizeErr = "Token name can't be empty";
} else if (symbol === '') {
sanitizeErr = "Token symbol can't be empty";
} else if (!isAddress(treasury)) {
sanitizeErr = 'Invalid treasury address';
} else if (maxSupply === '' || Number(maxSupply) < 0) {
sanitizeErr = 'Max supply cannot be negative';
} else if (feeValue === '') {
sanitizeErr = 'Gas limit should be set for this transaction';
}
} else if (API === 'UpdateTokenExpiry') {
if (!isAddress(hederaTokenAddress)) {
sanitizeErr = 'Invalid token address';
} else if (second === '' || Number(second) < 0) {
sanitizeErr = 'Invalid expiry time';
} else if (!isAddress(autoRenewAccount)) {
sanitizeErr = 'Invalid auto renew account address';
} else if (autoRenewPeriod === '' || Number(autoRenewPeriod) < 0) {
sanitizeErr = 'Invalid auto renew period';
} else if (feeValue === '') {
sanitizeErr = 'Gas limit should be set for this transaction';
}
} else if (API === 'APPROVED_FUNGIBLE') {
if (!isAddress(hederaTokenAddress)) {
sanitizeErr = 'Invalid token address';
} else if (!isAddress(accountAddress)) {
sanitizeErr = 'Invalid account address';
} else if (amount === '' || Number(amount) < 0) {
sanitizeErr = 'Invalid amount to approved';
}
} else if (API === 'APPROVED_NON_FUNGIBLE') {
if (!isAddress(hederaTokenAddress)) {
sanitizeErr = 'Invalid token address';
} else if (!isAddress(accountAddress)) {
sanitizeErr = 'Invalid account address';
} else if (serialNumber === '' || Number(serialNumber) < 0) {
sanitizeErr = 'Invalid serial number approved';
}
} else if (API === 'SET_APPROVAL') {
if (!isAddress(hederaTokenAddress)) {
sanitizeErr = 'Invalid token address';
} else if (!isAddress(accountAddress)) {
sanitizeErr = 'Invalid account address';
}
}

return sanitizeErr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ const FungibleTokenCreate = ({ baseContract }: PageProps) => {
executeBtnTitle={'Create Fungible Token'}
handleInputOnChange={handleInputOnChange}
explanation={
'Represents the fee in HBAR directly paid to the contract system of the Hedera Token Service'
'Represents the transaction fee paid in HBAR directly paid to the contract system of the Hedera Token Service'
}
handleInvokingAPIMethod={handleCreatingFungibleToken}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*-
*
* Hedera Smart Contracts
*
* Copyright (C) 2023 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

import { SharedFormInputField } from '../../../shared/components/ParamInputForm';
import { htsUpdateTokenExpiryParamFields } from '@/utils/contract-interactions/HTS/token-management/constant';

interface PageProps {
paramValues: any;
tokenInfoFields: string[];
handleInputOnChange: (e: any, param: string) => void;
}

const TokenExpiryForm = ({ paramValues, tokenInfoFields, handleInputOnChange }: PageProps) => {
return (
<div className="flex flex-col gap-6">
{/* hederaTokenAddress & second & autoRenewAccount && autoRenewPeriod */}
{tokenInfoFields.map((param) => {
return (
<div className="w-full" key={(htsUpdateTokenExpiryParamFields as any)[param].paramKey}>
<SharedFormInputField
param={param}
paramValue={paramValues[param]}
handleInputOnChange={handleInputOnChange}
paramKey={(htsUpdateTokenExpiryParamFields as any)[param].paramKey}
paramType={(htsUpdateTokenExpiryParamFields as any)[param].inputType}
paramSize={(htsUpdateTokenExpiryParamFields as any)[param].inputSize}
explanation={(htsUpdateTokenExpiryParamFields as any)[param].explanation}
paramClassName={(htsUpdateTokenExpiryParamFields as any)[param].inputClassname}
paramPlaceholder={(htsUpdateTokenExpiryParamFields as any)[param].inputPlaceholder}
paramFocusColor={
(htsUpdateTokenExpiryParamFields as any)[param].inputFocusBorderColor
}
/>
</div>
);
})}
</div>
);
};

export default TokenExpiryForm;
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*-
*
* Hedera Smart Contracts
*
* Copyright (C) 2023 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

import { SharedFormInputField, SharedFormButton } from '../../../shared/components/ParamInputForm';
import { htsTokenCreateParamFields } from '@/utils/contract-interactions/HTS/token-create-custom/constant';
import { htsUpdateTokenInfoParamFields } from '@/utils/contract-interactions/HTS/token-management/constant';

interface PageProps {
paramValues: any;
tokenInfoFields: string[][];
setParamValues: (value: any) => void;
handleInputOnChange: (e: any, param: string) => void;
}

const TokenInfoForm = ({
paramValues,
setParamValues,
tokenInfoFields,
handleInputOnChange,
}: PageProps) => {
return (
<div className="flex flex-col gap-6">
{/* name & symbol & memo*/}
<div className="flex gap-3">
{(tokenInfoFields as string[][])[0].map((param) => {
return (
<div className="w-full" key={(htsUpdateTokenInfoParamFields as any)[param].paramKey}>
<SharedFormInputField
param={param}
paramValue={paramValues[param]}
handleInputOnChange={handleInputOnChange}
paramKey={(htsUpdateTokenInfoParamFields as any)[param].paramKey}
paramType={(htsUpdateTokenInfoParamFields as any)[param].inputType}
paramSize={(htsUpdateTokenInfoParamFields as any)[param].inputSize}
explanation={(htsUpdateTokenInfoParamFields as any)[param].explanation}
paramClassName={(htsUpdateTokenInfoParamFields as any)[param].inputClassname}
paramPlaceholder={(htsUpdateTokenInfoParamFields as any)[param].inputPlaceholder}
paramFocusColor={
(htsUpdateTokenInfoParamFields as any)[param].inputFocusBorderColor
}
/>
</div>
);
})}
</div>

{/* Token supply type */}
<div className="w-full flex gap-3">
{/* infinite */}
<SharedFormButton
switcher={!paramValues.tokenSupplyType}
buttonTitle={'Supply Type - INFINITE'}
handleButtonOnClick={() => {
setParamValues((prev: any) => ({ ...prev, tokenSupplyType: false }));
}}
explanation={
(htsUpdateTokenInfoParamFields as any)['tokenSupplyType'].explanation.infinite
}
/>

{/* finite */}
<SharedFormButton
switcher={paramValues.tokenSupplyType}
buttonTitle={'Supply Type - FINITE'}
handleButtonOnClick={() => {
setParamValues((prev: any) => ({ ...prev, tokenSupplyType: true }));
}}
explanation={(htsUpdateTokenInfoParamFields as any)['tokenSupplyType'].explanation.finite}
/>
</div>

{/* treasury & maxSupply */}
{tokenInfoFields[1].map((param) => {
return (
<div className="w-full" key={(htsUpdateTokenInfoParamFields as any)[param].paramKey}>
<SharedFormInputField
param={param}
paramValue={paramValues[param]}
handleInputOnChange={handleInputOnChange}
paramKey={(htsUpdateTokenInfoParamFields as any)[param].paramKey}
paramType={(htsUpdateTokenInfoParamFields as any)[param].inputType}
paramSize={(htsUpdateTokenInfoParamFields as any)[param].inputSize}
explanation={(htsUpdateTokenInfoParamFields as any)[param].explanation}
paramClassName={(htsUpdateTokenInfoParamFields as any)[param].inputClassname}
paramPlaceholder={(htsUpdateTokenInfoParamFields as any)[param].inputPlaceholder}
paramFocusColor={(htsUpdateTokenInfoParamFields as any)[param].inputFocusBorderColor}
/>
</div>
);
})}

{/* freeze status */}
<div className="w-full flex gap-3">
{/* false */}
<SharedFormButton
switcher={!paramValues.isDefaultFreeze}
buttonTitle={'Freeze Status - false'}
explanation={(htsTokenCreateParamFields as any)['freezeStatus'].explanation.off}
handleButtonOnClick={() => {
setParamValues((prev: any) => ({ ...prev, isDefaultFreeze: false }));
}}
/>

{/* true */}
<SharedFormButton
switcher={paramValues.isDefaultFreeze}
buttonTitle={'Freeze Status - true'}
explanation={(htsTokenCreateParamFields as any)['freezeStatus'].explanation.on}
handleButtonOnClick={() => {
setParamValues((prev: any) => ({ ...prev, isDefaultFreeze: true }));
}}
/>
</div>
</div>
);
};

export default TokenInfoForm;
Loading

0 comments on commit 58cc9ec

Please sign in to comment.