Skip to content

Commit

Permalink
Revert "Peter/fix staking limit bug (#1515)"
Browse files Browse the repository at this point in the history
This reverts commit a896259.
  • Loading branch information
tomjeatt committed Aug 18, 2023
1 parent a896259 commit ecb0fed
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 44 deletions.
38 changes: 0 additions & 38 deletions src/hooks/api/escrow/use-get-account-stakable-limit.ts

This file was deleted.

17 changes: 11 additions & 6 deletions src/pages/Staking/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
VOTE_GOVERNANCE_TOKEN_SYMBOL,
VoteGovernanceTokenMonetaryAmount
} from '@/config/relay-chains';
import { useGetAccountStakableLimit } from '@/hooks/api/escrow/use-get-account-stakable-limit';
import { useGetBalances } from '@/hooks/api/tokens/use-get-balances';
import { useGetPrices } from '@/hooks/api/use-get-prices';
import { Transaction, useTransaction } from '@/hooks/transaction';
import { useSignMessage } from '@/hooks/use-sign-message';
Expand Down Expand Up @@ -109,7 +109,8 @@ const Staking = (): JSX.Element => {

const { bridgeLoaded } = useSelector((state: StoreType) => state.general);

const { data: maxStakableAmount } = useGetAccountStakableLimit();
const { data: balances, isLoading: isBalancesLoading } = useGetBalances();
const governanceTokenBalance = balances?.[GOVERNANCE_TOKEN.ticker];

const queryClient = useQueryClient();

Expand Down Expand Up @@ -318,7 +319,7 @@ const Staking = (): JSX.Element => {

const availableBalance = React.useMemo(() => {
if (
maxStakableAmount === undefined ||
isBalancesLoading ||
stakedAmountAndEndBlockIdle ||
stakedAmountAndEndBlockLoading ||
transactionFeeReserveIdle ||
Expand All @@ -331,17 +332,21 @@ const Staking = (): JSX.Element => {
if (transactionFeeReserve === undefined) {
throw new Error('Transaction fee reserve value returned undefined!');
}
if (governanceTokenBalance === undefined) {
throw new Error('Governance token balance value returned undefined!');
}

const calculatedBalance = maxStakableAmount.sub(transactionFeeReserve);
const calculatedBalance = governanceTokenBalance.free.sub(stakedAmount).sub(transactionFeeReserve);

return calculatedBalance.toBig().gte(0) ? calculatedBalance : newMonetaryAmount(0, GOVERNANCE_TOKEN);
}, [
maxStakableAmount,
isBalancesLoading,
governanceTokenBalance,
stakedAmountAndEndBlockIdle,
stakedAmountAndEndBlockLoading,
stakedAmount,
transactionFeeReserveIdle,
transactionFeeReserveLoading,
stakedAmount,
transactionFeeReserve
]);

Expand Down

2 comments on commit ecb0fed

@vercel
Copy link

@vercel vercel bot commented on ecb0fed Aug 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on ecb0fed Aug 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.