Skip to content

Commit

Permalink
feat: add staking limit
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsimao committed Sep 26, 2023
1 parent 8ac793c commit 4142780
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
17 changes: 6 additions & 11 deletions src/hooks/api/escrow/use-get-account-staking-data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type AccountStakingData = {
amount: MonetaryAmount<CurrencyExt>;
apy: Big;
};
// limit: MonetaryAmount<CurrencyExt>;
limit: MonetaryAmount<CurrencyExt>;
};

const getUnlockData = (stakeEndBlock: number, currentBlockNumber: number): AccountUnlockStakingData => {
Expand All @@ -49,18 +49,13 @@ const getAccountStakingData = async (accountId: AccountId): Promise<AccountStaki
return null;
}

// const limitPromise = window.bridge.api.rpc.escrow.freeStakable(accountId);
const limitPromise = window.bridge.api.rpc.escrow.freeStakable(accountId);
const currentBlockNumberPromise = window.bridge.system.getCurrentBlockNumber();
const projectedPromise = window.bridge.escrow.getRewardEstimate(accountId);
const votingBalancePromise = window.bridge.escrow.votingBalance(accountId);

const [
// limit,
currentBlockNumber,
projected,
votingBalance
] = await Promise.all([
// limitPromise,
const [limit, currentBlockNumber, projected, votingBalance] = await Promise.all([
limitPromise,
currentBlockNumberPromise,
projectedPromise,
votingBalancePromise
Expand All @@ -72,8 +67,8 @@ const getAccountStakingData = async (accountId: AccountId): Promise<AccountStaki
unlock,
balance: stakedBalance.amount,
votingBalance,
projected
// limit
projected,
limit
};
};

Expand Down
5 changes: 3 additions & 2 deletions src/pages/Staking/components/StakingForm/StakingForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
stakingSchema,
useForm
} from '@/lib/form';
import { pickSmallerAmount } from '@/utils/helpers/currencies';
import { getTokenInputProps } from '@/utils/helpers/input';
import { getTokenPrice } from '@/utils/helpers/prices';
import { convertBlockNumbersToWeeks, convertWeeksToBlockNumbers } from '@/utils/helpers/staking';
Expand Down Expand Up @@ -62,8 +63,8 @@ const StakingForm = ({ accountData, networkData, onStaking, ...props }: StakingF
const hasStake = !!accountData;

const governanceBalance = getAvailableBalance(GOVERNANCE_TOKEN.ticker) || newMonetaryAmount(0, GOVERNANCE_TOKEN);
const inputBalance = governanceBalance;
// accountData?.limit && governanceBalance && pickSmallerAmount(governanceBalance, accountData.limit);
const inputBalance =
accountData?.limit && governanceBalance && pickSmallerAmount(governanceBalance, accountData.limit);

const getTransactionArgs = useCallback(
async (values: StakingFormData) => {
Expand Down
9 changes: 8 additions & 1 deletion src/test/mocks/@interlay/interbtc-api/parachain/api.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { newMonetaryAmount } from '@interlay/interbtc-api';
import { ApiPromise } from '@polkadot/api';
import { Text, TypeRegistry } from '@polkadot/types';
import { Registry } from '@polkadot/types/types';
import Big from 'big.js';

import { GOVERNANCE_TOKEN } from '@/config/relay-chains';

import { EXTRINSIC } from '../extrinsic';

const REGISTRY = ({ chainDecimals: [], chainSS58: 0, chainTokens: [] } as unknown) as Registry;
Expand All @@ -23,7 +26,8 @@ const DATA = { VESTING_SCHEDULES };
const MODULE = {
vestingSchedules: jest.fn().mockReturnValue(VESTING_SCHEDULES.EMPTY),
claimVesting: jest.fn().mockReturnValue(EXTRINSIC),
batchAll: jest.fn().mockReturnValue(EXTRINSIC)
batchAll: jest.fn().mockReturnValue(EXTRINSIC),
freeStakable: jest.fn().mockResolvedValue(newMonetaryAmount(10000000000000, GOVERNANCE_TOKEN, true))
};

// maps module to ApiPromise
Expand All @@ -34,6 +38,9 @@ const PROMISE: Partial<Record<keyof ApiPromise, unknown>> = {
system: {
chain: jest.fn().mockReturnValue(SYSTEM_CHAIN),
chainType: jest.fn().mockReturnValue(CHAIN_TYPE)
},
escrow: {
freeStakable: MODULE.freeStakable
}
},
query: {
Expand Down

0 comments on commit 4142780

Please sign in to comment.