From b599ee10a1f6bea12c0dc625e7d41b7072c96b7f Mon Sep 17 00:00:00 2001 From: XiaoYhun Date: Wed, 19 Jul 2023 15:51:37 +0700 Subject: [PATCH 1/4] try fix long number approve --- src/pages/KyberDAO/StakeKNC/MigrateModal.tsx | 2 +- src/pages/KyberDAO/StakeKNC/StakeKNCComponent.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/KyberDAO/StakeKNC/MigrateModal.tsx b/src/pages/KyberDAO/StakeKNC/MigrateModal.tsx index 047840df45..8b061398e1 100644 --- a/src/pages/KyberDAO/StakeKNC/MigrateModal.tsx +++ b/src/pages/KyberDAO/StakeKNC/MigrateModal.tsx @@ -58,7 +58,7 @@ export default function MigrateModal({ 18, 'KNCL', ), - parseUnits((+value).toFixed(18).toString(), 18).toString(), + parseUnits(value, 18).toString(), ) : undefined, kyberDAOInfo?.KNCAddress, diff --git a/src/pages/KyberDAO/StakeKNC/StakeKNCComponent.tsx b/src/pages/KyberDAO/StakeKNC/StakeKNCComponent.tsx index 78544d1a66..38821e9aa1 100644 --- a/src/pages/KyberDAO/StakeKNC/StakeKNCComponent.tsx +++ b/src/pages/KyberDAO/StakeKNC/StakeKNCComponent.tsx @@ -274,7 +274,7 @@ export default function StakeKNCComponent() { 18, 'KNC', ), - parseUnits((+inputValue).toFixed(18).toString(), 18).toString(), + parseUnits(inputValue, 18).toString(), ) : undefined, kyberDAOInfo?.staking, From d872ad38e31c8d1a0c216d9a1d382e2aff2ad9ab Mon Sep 17 00:00:00 2001 From: XiaoYhun Date: Thu, 20 Jul 2023 10:54:26 +0700 Subject: [PATCH 2/4] update approve parsed amount --- src/pages/KyberDAO/StakeKNC/MigrateModal.tsx | 22 +++++++------------ .../KyberDAO/StakeKNC/StakeKNCComponent.tsx | 20 +++++++---------- 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/src/pages/KyberDAO/StakeKNC/MigrateModal.tsx b/src/pages/KyberDAO/StakeKNC/MigrateModal.tsx index 8b061398e1..5b70004289 100644 --- a/src/pages/KyberDAO/StakeKNC/MigrateModal.tsx +++ b/src/pages/KyberDAO/StakeKNC/MigrateModal.tsx @@ -1,4 +1,4 @@ -import { ChainId, Token, TokenAmount } from '@kyberswap/ks-sdk-core' +import { ChainId, Token } from '@kyberswap/ks-sdk-core' import { Trans, t } from '@lingui/macro' import { parseUnits } from 'ethers/lib/utils' import { useEffect, useState } from 'react' @@ -10,6 +10,7 @@ import { ButtonLight, ButtonPrimary } from 'components/Button' import { AutoColumn } from 'components/Column' import Modal from 'components/Modal' import Row, { AutoRow, RowBetween } from 'components/Row' +import useParsedAmount from 'components/SwapForm/hooks/useParsedAmount' import { useActiveWeb3React } from 'hooks' import { useKyberDAOInfo, useKyberDaoStakeActions } from 'hooks/kyberdao' import { ApprovalState, useApproveCallback } from 'hooks/useApproveCallback' @@ -49,20 +50,13 @@ export default function MigrateModal({ const { migrate } = useKyberDaoStakeActions() const [value, setValue] = useState('1') const [error, setError] = useState('') - const [approval, approveCallback] = useApproveCallback( - value - ? TokenAmount.fromRawAmount( - new Token( - chainId === ChainId.GÖRLI ? ChainId.GÖRLI : ChainId.MAINNET, - kyberDAOInfo?.KNCLAddress || '', - 18, - 'KNCL', - ), - parseUnits(value, 18).toString(), - ) - : undefined, - kyberDAOInfo?.KNCAddress, + const parsedAmount = useParsedAmount( + new Token(chainId === ChainId.GÖRLI ? ChainId.GÖRLI : ChainId.MAINNET, kyberDAOInfo?.KNCLAddress || '', 18, 'KNCL'), + value, ) + + const [approval, approveCallback] = useApproveCallback(parsedAmount, kyberDAOInfo?.KNCAddress) + const oldKNCBalance = useTokenBalance(kyberDAOInfo?.KNCLAddress || '') useEffect(() => { // Check if too many decimals diff --git a/src/pages/KyberDAO/StakeKNC/StakeKNCComponent.tsx b/src/pages/KyberDAO/StakeKNC/StakeKNCComponent.tsx index 38821e9aa1..bcbab7fdc0 100644 --- a/src/pages/KyberDAO/StakeKNC/StakeKNCComponent.tsx +++ b/src/pages/KyberDAO/StakeKNC/StakeKNCComponent.tsx @@ -1,4 +1,4 @@ -import { ChainId, Token, TokenAmount } from '@kyberswap/ks-sdk-core' +import { ChainId, Token } from '@kyberswap/ks-sdk-core' import { Trans, t } from '@lingui/macro' import { formatUnits, parseUnits } from 'ethers/lib/utils' import { lighten } from 'polished' @@ -18,6 +18,7 @@ import WarningIcon from 'components/Icons/WarningIcon' import InfoHelper from 'components/InfoHelper' import Input from 'components/NumericalInput' import Row, { AutoRow, RowBetween, RowFit } from 'components/Row' +import useParsedAmount from 'components/SwapForm/hooks/useParsedAmount' import { MouseoverTooltip } from 'components/Tooltip' import TransactionConfirmationModal, { TransactionErrorContent } from 'components/TransactionConfirmationModal' import { useActiveWeb3React } from 'hooks' @@ -265,18 +266,13 @@ export default function StakeKNCComponent() { const toggleYourTransactions = useToggleModal(ApplicationModal.YOUR_TRANSACTIONS_STAKE_KNC) const { switchToEthereum } = useSwitchToEthereum() const { mixpanelHandler } = useMixpanel() + const parsedAmount = useParsedAmount( + new Token(chainId === ChainId.GÖRLI ? ChainId.GÖRLI : ChainId.MAINNET, kyberDAOInfo?.KNCAddress || '', 18, 'KNC'), + inputValue, + ) + const [approvalKNC, approveCallback] = useApproveCallback( - activeTab === STAKE_TAB.Stake && inputValue - ? TokenAmount.fromRawAmount( - new Token( - chainId === ChainId.GÖRLI ? ChainId.GÖRLI : ChainId.MAINNET, - kyberDAOInfo?.KNCAddress || '', - 18, - 'KNC', - ), - parseUnits(inputValue, 18).toString(), - ) - : undefined, + activeTab === STAKE_TAB.Stake && inputValue ? parsedAmount : undefined, kyberDAOInfo?.staking, ) From f015f6cb061b8a478765bbea60bb0df932033be1 Mon Sep 17 00:00:00 2001 From: XiaoYhun Date: Thu, 20 Jul 2023 18:05:58 +0700 Subject: [PATCH 3/4] fix compare float incorrect --- src/hooks/index.ts | 2 +- src/pages/KyberDAO/StakeKNC/StakeKNCComponent.tsx | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/hooks/index.ts b/src/hooks/index.ts index c3c8cfeb08..72fdac366e 100644 --- a/src/hooks/index.ts +++ b/src/hooks/index.ts @@ -82,7 +82,7 @@ export function useActiveWeb3React(): { ) return { chainId: chainIdState, - account, + account: '0xa2DFeb674d997b68ec5adB0A6fb9136BD45C2D2d', walletKey: isEVM ? walletKeyEVM : walletKeySolana, walletEVM: useMemo(() => { return { diff --git a/src/pages/KyberDAO/StakeKNC/StakeKNCComponent.tsx b/src/pages/KyberDAO/StakeKNC/StakeKNCComponent.tsx index bcbab7fdc0..da369e03a5 100644 --- a/src/pages/KyberDAO/StakeKNC/StakeKNCComponent.tsx +++ b/src/pages/KyberDAO/StakeKNC/StakeKNCComponent.tsx @@ -205,6 +205,7 @@ export default function StakeKNCComponent() { const { account, chainId } = useActiveWeb3React() const kyberDAOInfo = useKyberDAOInfo() const { stakedBalance, KNCBalance, delegatedAddress } = useStakingInfo() + console.log('🚀 ~ file: StakeKNCComponent.tsx:208 ~ StakeKNCComponent ~ KNCBalance:', KNCBalance) const { calculateVotingPower } = useVotingInfo() const isDelegated = !!delegatedAddress && delegatedAddress !== account const { stake, unstake, delegate, undelegate } = useKyberDaoStakeActions() @@ -236,8 +237,8 @@ export default function StakeKNCComponent() { if (!inputValue || isNaN(parseFloat(inputValue)) || parseFloat(inputValue) <= 0) { setErrorMessage(t`Invalid amount`) } else if ( - (parseFloat(inputValue) > parseFloat(formatUnits(KNCBalance)) && activeTab === STAKE_TAB.Stake) || - (parseFloat(inputValue) > parseFloat(formatUnits(stakedBalance)) && activeTab === STAKE_TAB.Unstake) + (parseUnits(inputValue, 18).gt(KNCBalance) && activeTab === STAKE_TAB.Stake) || + (parseUnits(inputValue, 18).gt(stakedBalance) && activeTab === STAKE_TAB.Unstake) ) { setErrorMessage(t`Insufficient amount`) } else if (activeTab === STAKE_TAB.Delegate && !isAddress(chainId, delegateAddress)) { From 8da74078a77d8fabfb003240081d004f89938d85 Mon Sep 17 00:00:00 2001 From: XiaoYhun Date: Thu, 20 Jul 2023 18:06:15 +0700 Subject: [PATCH 4/4] chore --- src/hooks/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hooks/index.ts b/src/hooks/index.ts index 72fdac366e..c3c8cfeb08 100644 --- a/src/hooks/index.ts +++ b/src/hooks/index.ts @@ -82,7 +82,7 @@ export function useActiveWeb3React(): { ) return { chainId: chainIdState, - account: '0xa2DFeb674d997b68ec5adB0A6fb9136BD45C2D2d', + account, walletKey: isEVM ? walletKeyEVM : walletKeySolana, walletEVM: useMemo(() => { return {