diff --git a/pages/airdrops/[address]/claim.tsx b/pages/airdrops/[address]/claim.tsx index 5df0bc92..2c4a646d 100644 --- a/pages/airdrops/[address]/claim.tsx +++ b/pages/airdrops/[address]/claim.tsx @@ -166,21 +166,21 @@ const ClaimAirdropPage: NextPage = () => { }, [contractAddress, wallet.address, wallet.initialized, wallets[0]?.terraAddress]) useEffect(() => { - setBalance(Number(wallet.balance[0]?.amount)) - }, [wallet.balance]) + if (cw20TokenAddress) { + if (!cw20BaseContract) return - useEffect(() => { - if (!cw20BaseContract || !cw20TokenAddress) return + const contractMessages = cw20BaseContract.use(cw20TokenAddress) - const contractMessages = cw20BaseContract.use(cw20TokenAddress) - - contractMessages - ?.balance(wallet.address) - .then((data: string) => { - setBalance(parseInt(data)) - }) - .catch(console.error) - }, [cw20TokenAddress, wallet.address]) + contractMessages + ?.balance(wallet.address) + .then((data: string) => { + setBalance(parseInt(data)) + }) + .catch(console.error) + } else { + setBalance(Number(wallet.balance[0]?.amount)) + } + }, [cw20TokenAddress, wallet.address, wallet.balance]) useEffect(() => { if (!cw20BaseContract || !cw20TokenAddress) return @@ -281,7 +281,7 @@ const ClaimAirdropPage: NextPage = () => {
juno - {convertDenomToReadable(amount)} {cw20TokenInfo?.symbol} + {convertDenomToReadable(amount, cw20TokenInfo?.decimals)} {cw20TokenInfo?.symbol}
@@ -293,10 +293,10 @@ const ClaimAirdropPage: NextPage = () => { {cw20TokenAddress} - {convertDenomToReadable(amount)} {cw20TokenInfo?.symbol} + {convertDenomToReadable(amount, cw20TokenInfo?.decimals)} {cw20TokenInfo?.symbol} - {convertDenomToReadable(balance)} {cw20TokenInfo?.symbol} + {convertDenomToReadable(balance, cw20TokenInfo?.decimals)} {cw20TokenInfo?.symbol}
{JSON.stringify(proofs, null, 2)}
diff --git a/pages/airdrops/fund.tsx b/pages/airdrops/fund.tsx index 463a1ac9..6c7062ee 100644 --- a/pages/airdrops/fund.tsx +++ b/pages/airdrops/fund.tsx @@ -50,6 +50,7 @@ const FundAirdropPage: NextPage = () => { const [balance, setBalance] = useState(null) const [target, setTarget] = useState(null) const [denom, setDenom] = useState(null) + const [decimals, setDecimals] = useState(6) const [method, setMethod] = useState('mint') @@ -78,6 +79,7 @@ const FundAirdropPage: NextPage = () => { setTarget(_target) setAmount(needed < 0 ? '0' : needed.toString()) setDenom(_denom) + setDecimals(data.decimals) }) .catch((err: any) => { toast.error(err.message, { @@ -207,7 +209,7 @@ const FundAirdropPage: NextPage = () => { {balance ? ( <> - {convertDenomToReadable(target)} + {convertDenomToReadable(target, decimals)} ) : ( '...' @@ -216,7 +218,7 @@ const FundAirdropPage: NextPage = () => { {balance ? ( <> - {convertDenomToReadable(balance)} + {convertDenomToReadable(balance, decimals)} ) : ( '...' @@ -225,7 +227,7 @@ const FundAirdropPage: NextPage = () => { {target && balance ? ( <> - {convertDenomToReadable(amount)} + {convertDenomToReadable(amount, decimals)} ) : ( '...' diff --git a/pages/airdrops/manage.tsx b/pages/airdrops/manage.tsx index ec907433..2234dd71 100644 --- a/pages/airdrops/manage.tsx +++ b/pages/airdrops/manage.tsx @@ -38,6 +38,8 @@ const ManageAirdropPage: NextPage = () => { const [balance, setBalance] = useState(null) const [target, setTarget] = useState(null) const [denom, setDenom] = useState(null) + const [decimals, setDecimals] = useState(6) + const [recipientAddress, setRecipientAddress] = useState(null) const [isExpired, setIsExpired] = useState(false) @@ -69,6 +71,7 @@ const ManageAirdropPage: NextPage = () => { setTarget(_target) setAmount(needed < 0 ? '0' : needed.toString()) setDenom(_denom) + setDecimals(data.decimals) }) .catch((err: any) => { toast.error(err.message, { @@ -266,7 +269,7 @@ const ManageAirdropPage: NextPage = () => { {balance ? ( <> - {convertDenomToReadable(target)} + {convertDenomToReadable(target, decimals)} ) : ( '...' @@ -275,7 +278,7 @@ const ManageAirdropPage: NextPage = () => { {balance ? ( <> - {convertDenomToReadable(balance)} + {convertDenomToReadable(balance, decimals)} ) : ( '...' @@ -284,7 +287,7 @@ const ManageAirdropPage: NextPage = () => { {target && balance ? ( <> - {convertDenomToReadable(amount)} + {convertDenomToReadable(amount, decimals)} ) : ( '...' diff --git a/utils/contracts/cw20/execute.ts b/utils/contracts/cw20/execute.ts index f1e3cbfb..409af52e 100644 --- a/utils/contracts/cw20/execute.ts +++ b/utils/contracts/cw20/execute.ts @@ -102,7 +102,7 @@ export type DispatchExecuteArgs = { | { type: Select<'decrease-allowance'>; recipient: string; amount: string } | { type: Select<'transfer'>; recipient: string; amount: string } | { type: Select<'transfer-from'>; owner: string; recipient: string; amount: string } - | { type: Select<'send'>; contract: string; amount: string; msg: any } + | { type: Select<'send'>; recipient: string; amount: string; msg: any } | { type: Select<'send-from'>; owner: string; recipient: string; amount: string; msg: any } | { type: Select<'update-marketing'>; project: string; description: string; marketing: string } | { type: Select<'update-logo'>; logo: { url: string } } @@ -138,7 +138,7 @@ export const dispatchExecute = async (args: DispatchExecuteArgs) => { return messages.transferFrom(txSigner, args.owner, args.recipient, args.amount.toString()) } case 'send': { - return messages.send(txSigner, args.contract, args.amount.toString(), args.msg) + return messages.send(txSigner, args.recipient, args.amount.toString(), args.msg) } case 'send-from': { return messages.sendFrom(txSigner, args.owner, args.recipient, args.amount.toString(), args.msg) @@ -188,8 +188,8 @@ export const previewExecutePayload = (args: DispatchExecuteArgs) => { return messages()?.transferFrom(contract, owner, recipient, amount.toString()) } case 'send': { - const { contract, amount, msg } = args - return messages()?.send(contract, contract, amount.toString(), msg) + const { contract, recipient, amount, msg } = args + return messages()?.send(contract, recipient, amount.toString(), msg) } case 'send-from': { const { contract, amount, msg, owner, recipient } = args diff --git a/utils/convertDenomToReadable.ts b/utils/convertDenomToReadable.ts index f31f5ab4..1ad24bec 100644 --- a/utils/convertDenomToReadable.ts +++ b/utils/convertDenomToReadable.ts @@ -1,3 +1,3 @@ -export const convertDenomToReadable = (amount: string | number | null) => { - return Number(amount) / 1000000 +export const convertDenomToReadable = (amount: string | number | null, decimal = 6) => { + return Number(amount) / Math.pow(10, decimal) }