From dc2b761df2345bd207870fa340bd63d6ffcdc1cc Mon Sep 17 00:00:00 2001 From: Micha Vie Date: Tue, 23 Jul 2024 23:08:53 +0200 Subject: [PATCH] further staking extension fixes --- .../staking/src/delegation/_Delegator.tsx | 7 +++---- .../staking/src/delegation/_Withdrawer.tsx | 13 ++++++------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/extensions/staking/src/delegation/_Delegator.tsx b/src/extensions/staking/src/delegation/_Delegator.tsx index 1e719e7..140cec4 100644 --- a/src/extensions/staking/src/delegation/_Delegator.tsx +++ b/src/extensions/staking/src/delegation/_Delegator.tsx @@ -15,7 +15,7 @@ export const _Delegator = (props: Props) => { const app = useApp() const [entityBalance, setEntityBalance] = useState(0n) const [amount, setAmount] = useState('0') - const amountBig = 0n // shiftedBy(amount, Constants.Egld.Decimals) + const amountBig = shiftedBy(amount, Constants.Egld.Decimals) useEffect(() => { app.networkProvider @@ -24,12 +24,11 @@ export const _Delegator = (props: Props) => { }, []) const handleAdd = () => { - const valueBig = shiftedBy(amount, Constants.Egld.Decimals) - if (valueBig > entityBalance) { + if (amountBig > entityBalance) { app.showToast('Insufficient balance', 'error') return } - app.requestProposalAction(props.provider.contract, Config.Endpoints.Delegate, valueBig, [], []) + app.requestProposalAction(props.provider.contract, Config.Endpoints.Delegate, amountBig, [], []) } return ( diff --git a/src/extensions/staking/src/delegation/_Withdrawer.tsx b/src/extensions/staking/src/delegation/_Withdrawer.tsx index 509f754..5393778 100644 --- a/src/extensions/staking/src/delegation/_Withdrawer.tsx +++ b/src/extensions/staking/src/delegation/_Withdrawer.tsx @@ -13,16 +13,15 @@ type Props = { export const _Withdrawer = (props: Props) => { const app = useApp() - const [amount, setAmount] = useState('') + const [amount, setAmount] = useState('0') + const amountBig = shiftedBy(amount, Constants.Egld.Decimals) const handleWithdraw = () => { - // const valueBig = BigInt(amount).shiftedBy(Constants.Egld.Decimals) - const valueBig = BigInt(amount) * 10n ** BigInt(Constants.Egld.Decimals) - if (valueBig > props.delegation.userActiveStake) { + if (amountBig > props.delegation.userActiveStake) { app.showToast('Can not unstake more than is staked', 'error') return } - app.requestProposalAction(props.provider.contract, Config.Endpoints.UnDelegate, 0n, [valueBig], []) + app.requestProposalAction(props.provider.contract, Config.Endpoints.UnDelegate, 0n, [amountBig], []) } return ( @@ -60,7 +59,7 @@ export const _Withdrawer = (props: Props) => { autoFocus autoComplete="off" /> - {BigInt(amount) !== shiftedBy(props.delegation.userActiveStake, -Constants.Egld.Decimals) && ( + {amountBig !== props.delegation.userActiveStake && (
)} -

Balance: {toEgldDisplayAmount(props.delegation.userActiveStake)}

+

Staked: {toEgldDisplayAmount(props.delegation.userActiveStake)}