Skip to content

Commit

Permalink
further staking extension fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
michavie committed Jul 23, 2024
1 parent 4fb6858 commit dc2b761
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
7 changes: 3 additions & 4 deletions src/extensions/staking/src/delegation/_Delegator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const _Delegator = (props: Props) => {
const app = useApp()
const [entityBalance, setEntityBalance] = useState<bigint>(0n)
const [amount, setAmount] = useState('0')
const amountBig = 0n // shiftedBy(amount, Constants.Egld.Decimals)
const amountBig = shiftedBy(amount, Constants.Egld.Decimals)

useEffect(() => {
app.networkProvider
Expand All @@ -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 (
Expand Down
13 changes: 6 additions & 7 deletions src/extensions/staking/src/delegation/_Withdrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 && (
<div className="absolute bottom-1/2 right-4 transform translate-y-1/2">
<button
type="button"
Expand All @@ -74,7 +73,7 @@ export const _Withdrawer = (props: Props) => {
</div>
)}
</div>
<p className="text-right mb-4">Balance: {toEgldDisplayAmount(props.delegation.userActiveStake)}</p>
<p className="text-right mb-4">Staked: {toEgldDisplayAmount(props.delegation.userActiveStake)}</p>
<Button onClick={handleWithdraw} color="blue" disabled={+amount <= 0} className="block w-full">
Add Unstake Action to Proposal
</Button>
Expand Down

0 comments on commit dc2b761

Please sign in to comment.