Skip to content

Commit

Permalink
fix: simplify fast unstake subscription (#2002)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ross Bulat authored Feb 28, 2024
1 parent 68f701b commit 8edfc0c
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/contexts/FastUnstake/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,17 @@ export const FastUnstakeProvider = ({ children }: { children: ReactNode }) => {
for (const unsub of unsubs.current) {
unsub();
}

// Resubscribe to fast unstake queue.
}, [activeAccount, network]);

// Subscribe to fast unstake queue as soon as api is ready.
useEffect(() => {
if (isReady) {
subscribeToFastUnstakeQueue();
}
}, [isReady]);

// initiate fast unstake check for accounts that are nominating but not active.
useEffectIgnoreInitial(() => {
if (
Expand Down Expand Up @@ -126,7 +135,6 @@ export const FastUnstakeProvider = ({ children }: { children: ReactNode }) => {
}

// Initial local meta: localMeta

setStateWithRef(initialMeta, setMeta, metaRef);
setStateWithRef(initialIsExposed, setIsExposed, isExposedRef);

Expand All @@ -145,14 +153,8 @@ export const FastUnstakeProvider = ({ children }: { children: ReactNode }) => {
: activeEra.index;

// Check from the possible next era `maybeNextEra`.

processEligibility(activeAccount, maybeNextEra);
}

// subscribe to fast unstake queue immediately if synced in localStorage and still up to date.
if (initialIsExposed === false) {
subscribeToFastUnstakeQueue();
}
}

return () => {
Expand Down Expand Up @@ -223,9 +225,6 @@ export const FastUnstakeProvider = ({ children }: { children: ReactNode }) => {
setStateWithRef(false, setIsExposed, isExposedRef);

// Finished, not exposed.

// subscribe to fast unstake queue for user and queue counter.
subscribeToFastUnstakeQueue();
} else {
// continue checking the next era.
checkEra(new BigNumber(era).minus(1));
Expand Down Expand Up @@ -272,7 +271,7 @@ export const FastUnstakeProvider = ({ children }: { children: ReactNode }) => {

// subscribe to fastUnstake queue
const subscribeToFastUnstakeQueue = async () => {
if (!api || !activeAccount) {
if (!api) {
return;
}
const subscribeQueue = async (a: MaybeAddress) => {
Expand Down

0 comments on commit 8edfc0c

Please sign in to comment.