Skip to content

Commit

Permalink
fix: fast unstake eligibility based on bonding, not nominating (#2025)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ross Bulat authored Mar 12, 2024
1 parent 5fca5a2 commit 44a19c1
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/contexts/FastUnstake/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { useStaking } from 'contexts/Staking';
import type { AnyApi, AnyJson, MaybeAddress } from 'types';
import Worker from 'workers/stakers?worker';
import { useEffectIgnoreInitial } from '@w3ux/hooks';
import { useNominationStatus } from 'hooks/useNominationStatus';
import { validateLocalExposure } from 'contexts/Validators/Utils';
import { useNetwork } from 'contexts/Network';
import { useActiveAccounts } from 'contexts/ActiveAccounts';
Expand All @@ -38,15 +37,13 @@ export const FastUnstakeProvider = ({ children }: { children: ReactNode }) => {
const { activeEra } = useApi();
const { network } = useNetwork();
const { activeAccount } = useActiveAccounts();
const { getNominationStatus } = useNominationStatus();
const { inSetup, fetchEraStakers, isNominating } = useStaking();
const { inSetup, fetchEraStakers, isBonding } = useStaking();
const {
api,
isReady,
consts: { bondDuration },
networkMetrics: { fastUnstakeErasToCheckPerBlock },
} = useApi();
const { nominees } = getNominationStatus(activeAccount, 'nominator');

// store whether a fast unstake check is in progress.
const [checking, setChecking] = useState<boolean>(false);
Expand Down Expand Up @@ -112,7 +109,7 @@ export const FastUnstakeProvider = ({ children }: { children: ReactNode }) => {
activeAccount &&
isNotZero(activeEra.index) &&
fastUnstakeErasToCheckPerBlock > 0 &&
isNominating()
isBonding()
) {
// get any existing localStorage records for account.
const localMeta: LocalMeta | null = getLocalMeta();
Expand Down Expand Up @@ -143,8 +140,8 @@ export const FastUnstakeProvider = ({ children }: { children: ReactNode }) => {
if (
activeAccount &&
!inSetup() &&
!nominees.active.length &&
initialIsExposed === null
initialIsExposed === null &&
isBonding()
) {
// if localMeta existed, start checking from the next era.
const nextEra = localMeta?.checked.at(-1) || 0;
Expand All @@ -167,7 +164,7 @@ export const FastUnstakeProvider = ({ children }: { children: ReactNode }) => {
isReady,
activeEra.index,
fastUnstakeErasToCheckPerBlock,
isNominating(),
isBonding(),
]);

// handle worker message on completed exposure check.
Expand Down Expand Up @@ -242,7 +239,7 @@ export const FastUnstakeProvider = ({ children }: { children: ReactNode }) => {
!a ||
checkingRef.current ||
!activeAccount ||
!isNominating()
!isBonding()
) {
return;
}
Expand Down

0 comments on commit 44a19c1

Please sign in to comment.