feat: reduce Polkadot unstaking period to 2 days#2186
Conversation
remove deprecated fast unstaking
|
Warning Review limit reached
Next review available in: 50 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR removes the Solo “Fast Unstake” feature and its routing, popup handling, hooks, components, buttons, and translations. It adds nominator-specific unbonding duration calculations, updates validator detection, and bumps the extension version to 2.12.1. ChangesFast Unstake removal and nominator unbonding duration
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Summary by QodoReduce Polkadot nominator unbonding to 2 days; remove fast unstake
AI Description
Diagram
High-Level Assessment
Files changed (19)
|
Code Review by Qodo
Context used✅ Compliance rules (platform):
14 rules 1.
|
| const nominatorFastUnbondDuration = apiAt.consts['staking']['nominatorFastUnbondDuration'].toPrimitive() as number; | ||
| const sessionsPerEra = apiAt.consts['staking']['sessionsPerEra'].toPrimitive() as number; | ||
|
|
||
| const { epochDuration, expectedBlockTime, maxNominations } = stakingConsts; |
There was a problem hiding this comment.
5. Staking const cache mismatch 🐞 Bug ☼ Reliability
useStakingConsts unconditionally reads apiAt.consts.staking.nominatorFastUnbondDuration and caches the result; existing localStorage entries (or chains lacking the const) can yield missing nominatorUnbondingDuration until the cache refreshes, breaking consumers.
Agent Prompt
### Issue description
`useStakingConsts` assumes `nominatorFastUnbondDuration` always exists and also trusts the cached localStorage object schema. When the cached object predates the new `nominatorUnbondingDuration` field (or the chain doesn’t expose the new const), consumers may see `undefined` values.
### Issue Context
The hook only refreshes cached consts when `eraIndex` changes. After an app upgrade, the era may not change immediately, so stale cached data can persist.
### Fix Focus Areas
- packages/extension-polkagate/src/hooks/useStakingConsts.ts[22-99]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| const redeemDate = useMemo(() => { | ||
| if (stakingInfo.stakingConsts) { | ||
| const date = Date.now() + stakingInfo.stakingConsts?.unbondingDuration * 24 * 60 * 60 * 1000; | ||
| const date = Date.now() + stakingInfo.stakingConsts?.nominatorUnbondingDuration * 24 * 60 * 60 * 1000; |
There was a problem hiding this comment.
6. Pool redeem date nan 🐞 Bug ≡ Correctness
useUnstakingPool computes redeemDate from stakingConsts.nominatorUnbondingDuration without validating it, so a missing/invalid value produces an “Invalid Date” string.
Agent Prompt
### Issue description
`redeemDate` is computed using `nominatorUnbondingDuration` without checking it is defined/finite. If it is missing (e.g., stale cached stakingConsts), `Date.now() + undefined * ...` becomes `NaN`.
### Issue Context
`stakingInfo.stakingConsts` comes from `useStakingConsts`, which may return cached values.
### Fix Focus Areas
- packages/extension-polkagate/src/hooks/useStakingApi/useUnstakingPool.ts[45-53]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| import useSelectedAccount from './useSelectedAccount'; | ||
| import useIsValidator from './useIsValidator'; | ||
|
|
||
| export interface StatsSolo { | ||
| value: number | BN | undefined; |
There was a problem hiding this comment.
7. Validator duration flicker 🐞 Bug ➹ Performance
useStakingInfoSolo re-queries validator status via useIsValidator (async) and treats undefined as false, temporarily showing nominator unbonding for validators and duplicating work already done in useSoloStakingInfo.
Agent Prompt
### Issue description
`useStakingInfoSolo` introduces a new validator-status fetch that starts as `undefined` and later resolves, which can briefly show the wrong unbonding duration; it also repeats the validator lookup already computed by `useSoloStakingInfo`.
### Issue Context
`useIsValidator` currently calls `api.query.staking.validators.keys()` and then checks inclusion, which is heavier than necessary and is now triggered on the info screens.
### Fix Focus Areas
- packages/extension-polkagate/src/hooks/useStakingInfoSolo.ts[26-47]
- packages/extension-polkagate/src/hooks/useIsValidator.ts[9-29]
- packages/extension-polkagate/src/hooks/useSoloStakingInfo.ts[166-176]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| path: '/solo/:genesisHash/pendingReward', | ||
| trigger: 'solo-stake-pending-rewards' | ||
| }, | ||
| { |
There was a problem hiding this comment.
3. Broken fastunstake navigation 🐞 Bug ≡ Correctness
Solo staking popup still navigates to /solo/:genesisHash/fastUnstake, but the route was removed from STAKING_ROUTES, so the button leads to an unhandled path.
Agent Prompt
### Issue description
The `/solo/:genesisHash/fastUnstake` route was removed, but the Solo staking UI still renders a “Fast Unstake” button and navigates to that route, causing broken navigation.
### Issue Context
Fast-unstake appears to be deprecated/removed in this PR; remaining entrypoints should be removed (or the route/component restored).
### Fix Focus Areas
- packages/extension-polkagate/src/popup/staking/solo-new/index.tsx[70-114]
- packages/extension-ui/src/Popup/routes/stakingRoutes.ts[83-128]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| /> | ||
| ); | ||
|
|
||
| case StakingPopUps.FAST_UNSTAKE: |
There was a problem hiding this comment.
4. Fullscreen fast_unstake dead 🐞 Bug ≡ Correctness
Fullscreen staking still opens StakingPopUps.FAST_UNSTAKE, but PopUpHandlerSolo no longer handles that enum value, so clicking it results in an empty popup state.
Agent Prompt
### Issue description
The fullscreen UI still exposes a FAST_UNSTAKE action, but the popup handler no longer renders anything for it, creating a dead interaction.
### Issue Context
This PR removes deprecated fast-unstake. Fullscreen UI should not offer a FAST_UNSTAKE popup unless it is implemented.
### Fix Focus Areas
- packages/extension-polkagate/src/fullscreen/stake/partials/StakingPortfolioAndTiles.tsx[162-189]
- packages/extension-polkagate/src/fullscreen/stake/util/utils.ts[22-40]
- packages/extension-polkagate/src/fullscreen/stake/new-solo/PopUpHandlerSolo.tsx[33-137]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/extension-polkagate/src/hooks/useStakingConsts.ts (1)
76-84: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick winStale localStorage cache will lack
nominatorUnbondingDuration, causingNaN/undefineddownstream.Old cached
StakingConsts(saved before this PR) won't havenominatorUnbondingDuration. Fresh consts are only fetched wheneraIndex !== savedConsts?.eraIndex(line 93), so if the era hasn't advanced since the last cache, the stale object is returned withnominatorUnbondingDurationasundefined. This causes:
useUnstakingPoolline 47:undefined * 24 * 60 * 60 * 1000→NaN→ "Invalid Date" in the unstaking confirmation flowstakingInfo/index.tsxlines 118-119: "undefined days" in the info textuseStakingInfoSololine 42:undefinedvalue for nominatorsThe issue self-corrects within one era (~24h on Polkadot), but affects the unstaking transaction UI in the interim.
🛡️ Proposed fix: invalidate stale cache entries missing the new field
if (localSavedStakingConsts) { const parsedConsts = JSON.parse(localSavedStakingConsts) as StakingConsts; + + // Invalidate stale cache entries that predate nominatorUnbondingDuration + if (parsedConsts.nominatorUnbondingDuration === undefined) { + window.localStorage.removeItem(`${chainName}_stakingConsts`); + return; + } + parsedConsts.existentialDeposit = new BN(parsedConsts.existentialDeposit); parsedConsts.minNominatorBond = new BN(parsedConsts.minNominatorBond);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/extension-polkagate/src/hooks/useStakingConsts.ts` around lines 76 - 84, The cached staking consts in useStakingConsts can be stale because older localStorage entries do not include nominatorUnbondingDuration, so the hook should invalidate or refresh any parsed cache missing that field before calling setSavedConsts. Update the useStakingConsts cache-read path to detect missing nominatorUnbondingDuration on the parsed StakingConsts and treat it like an invalid cache entry, forcing a refetch of fresh staking consts rather than returning the stale object.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/extension-polkagate/src/hooks/useStakingConsts.ts`:
- Line 35: The direct access to nominatorFastUnbondDuration in getStakingConsts
can fail on runtimes that do not expose the async staking constant, so guard
this lookup in useStakingConsts and fall back to bondingDuration or omit the
field when it is missing. Update the staking-const collection logic so the rest
of the constants still resolve even if nominatorFastUnbondDuration is
unavailable.
In `@packages/extension-polkagate/src/hooks/useStakingInfoSolo.ts`:
- Around line 29-30: The `useStakingInfoSolo` hook is currently deriving
`isValidator` from `useSelectedAccount()`, which can point to the wrong account
when this hook is used for a staking account different from the globally
selected one. Update the hook to derive the validator check from `stakingInfo`
instead, and pass that account’s address into `useIsValidator` alongside
`genesisHash` so the unbonding duration is calculated for the correct staking
account.
---
Outside diff comments:
In `@packages/extension-polkagate/src/hooks/useStakingConsts.ts`:
- Around line 76-84: The cached staking consts in useStakingConsts can be stale
because older localStorage entries do not include nominatorUnbondingDuration, so
the hook should invalidate or refresh any parsed cache missing that field before
calling setSavedConsts. Update the useStakingConsts cache-read path to detect
missing nominatorUnbondingDuration on the parsed StakingConsts and treat it like
an invalid cache entry, forcing a refetch of fresh staking consts rather than
returning the stale object.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: dca91fa7-97ab-41cc-a745-0845602df92b
📒 Files selected for processing (23)
packages/extension-polkagate/src/fullscreen/stake/new-solo/PopUpHandlerSolo.tsxpackages/extension-polkagate/src/fullscreen/stake/new-solo/fastUnstaking/index.tsxpackages/extension-polkagate/src/hooks/index.tspackages/extension-polkagate/src/hooks/useIsExposed.tspackages/extension-polkagate/src/hooks/useStakingApi/index.tspackages/extension-polkagate/src/hooks/useStakingApi/useFastUnstaking.tspackages/extension-polkagate/src/hooks/useStakingApi/useUnstakingPool.tspackages/extension-polkagate/src/hooks/useStakingConsts.tspackages/extension-polkagate/src/hooks/useStakingInfoSolo.tspackages/extension-polkagate/src/popup/staking/solo-new/fast-unstake/FastUnstake.tsxpackages/extension-polkagate/src/popup/staking/stakingInfo/index.tsxpackages/extension-polkagate/src/util/types.tspackages/extension-ui/src/Popup/routes/stakingRoutes.tspackages/extension/package.jsonpackages/extension/public/locales/de/translation.jsonpackages/extension/public/locales/en/translation.jsonpackages/extension/public/locales/es/translation.jsonpackages/extension/public/locales/fr/translation.jsonpackages/extension/public/locales/hi/translation.jsonpackages/extension/public/locales/pt/translation.jsonpackages/extension/public/locales/ru/translation.jsonpackages/extension/public/locales/zh/translation.jsonpackages/extension/src/packageInfo.ts
💤 Files with no reviewable changes (9)
- packages/extension-polkagate/src/hooks/useStakingApi/index.ts
- packages/extension-polkagate/src/hooks/index.ts
- packages/extension-polkagate/src/fullscreen/stake/new-solo/fastUnstaking/index.tsx
- packages/extension-polkagate/src/hooks/useStakingApi/useFastUnstaking.ts
- packages/extension-polkagate/src/hooks/useIsExposed.ts
- packages/extension-ui/src/Popup/routes/stakingRoutes.ts
- packages/extension-polkagate/src/fullscreen/stake/new-solo/PopUpHandlerSolo.tsx
- packages/extension-polkagate/src/popup/staking/solo-new/fast-unstake/FastUnstake.tsx
- packages/extension/public/locales/en/translation.json
| const existentialDepositString = apiAt.consts['balances']['existentialDeposit'].toString(); | ||
| const existentialDeposit = new BN(existentialDepositString); | ||
| const bondingDuration = apiAt.consts['staking']['bondingDuration'].toPrimitive() as number; | ||
| const nominatorFastUnbondDuration = apiAt.consts['staking']['nominatorFastUnbondDuration'].toPrimitive() as number; |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Search for references to nominatorFastUnbondDuration and related fast-unbond constants
rg -n "nominatorFastUnbondDuration\|fastUnbond\|FastUnbond" --type ts -C 3
# Check for chain definitions or runtime version gating
rg -n "chain.*runtime\|runtime.*version\|specVersion" --type ts -g '!**/node_modules/**' -C 2 | head -40Repository: PolkaGate/extension
Length of output: 157
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Locate the hook and inspect its surrounding implementation
git ls-files 'packages/extension-polkagate/src/hooks/useStakingConsts.ts'
wc -l packages/extension-polkagate/src/hooks/useStakingConsts.ts
cat -n packages/extension-polkagate/src/hooks/useStakingConsts.ts | sed -n '1,220p'
# Find any runtime/version gating or fallback handling around staking consts
rg -n "nominatorFastUnbondDuration|stakingConsts|getStakingConsts|consts\\['staking'\\]|consts\\.staking|tryCatch|catch" packages/extension-polkagate/src -C 3
# Search for supported chain/runtime detection in the package
rg -n "specVersion|runtimeVersion|chain.*runtime|runtime.*chain|supported chain|supports.*staking" packages/extension-polkagate/src -C 3Repository: PolkaGate/extension
Length of output: 50376
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the staking const hook in a bounded slice
wc -l packages/extension-polkagate/src/hooks/useStakingConsts.ts
cat -n packages/extension-polkagate/src/hooks/useStakingConsts.ts | sed -n '1,220p'
# Show any nearby runtime checks or defensive access around the new constant
rg -n "nominatorFastUnbondDuration|staking.*const|consts\\['staking'\\]|consts\\.staking|unwrapOr|isNone|option|catch" packages/extension-polkagate/src/hooks/useStakingConsts.ts packages/extension-polkagate/src -C 2
# Find supported chain lists / staking-capable chain metadata in the package
rg -n "supported.*chain|staking.*supported|is.*staking|nominate|bond|unbond|validator" packages/extension-polkagate/src -g '!**/*.map' -C 2 | head -120Repository: PolkaGate/extension
Length of output: 50376
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Read the staking const hook with line numbers in a narrow slice
sed -n '1,180p' packages/extension-polkagate/src/hooks/useStakingConsts.ts | nl -ba
# Find where this hook is consumed and whether callers already expect null/fallback behavior
rg -n "useStakingConsts\\(" packages/extension-polkagate/src -C 2
rg -n "stakingConsts" packages/extension-polkagate/src -C 2
# Check whether the same staking constants pattern is used elsewhere without guards
rg -n "consts\\['staking'\\]\\['(historyDepth|maxUnlockingChunks|bondingDuration|sessionsPerEra|maxExposurePageSize)'" packages/extension-polkagate/src -C 2Repository: PolkaGate/extension
Length of output: 197
🌐 Web query:
Polkadot staking pallet nominatorFastUnbondDuration runtime constant supported chains older runtimes
💡 Result:
The NominatorFastUnbondDuration runtime constant is a configuration parameter introduced in the pallet-staking-async module of the Polkadot SDK [1][2]. Key Technical Details: - Purpose: It defines the number of eras that pure (non-slashable) nominators must wait to unbond their funds [1][3]. - Mechanism: When the runtime flag AreNominatorsSlashable is set to false, nominators who have not recently acted as validators can utilize this shortened unbonding duration instead of the standard BondingDuration [1][4]. - Usage: If a nominator is slashable, or has recently served as a validator, they remain subject to the full BondingDuration to ensure slashes can be applied during the unbonding period [1][5]. - Recommendation: The recommended value is typically 2 eras [6][2]. Compatibility and Older Runtimes: - Availability: This constant is specific to pallet-staking-async [1][2]. It is not present in the traditional pallet-staking used in older Polkadot/Substrate runtimes. - Support: Chains utilizing standard, older versions of the staking pallet do not support this constant [2]. Migrating to the newer pallet-staking-async architecture is required to leverage this feature [2]. - Implementation: It was integrated into the Polkadot SDK via PR #10502, which was merged in January 2026 [2]. Consequently, it is only available in runtimes built on SDK versions released after this timeframe [2]. Top Results: [1][2][4][5]
Citations:
- 1: https://paritytech.github.io/polkadot-sdk/master/pallet_staking_async/trait.Config.html
- 2: [Staking] Allow nominators to be non-slashable and fast unbondable paritytech/polkadot-sdk#10502
- 3: https://paritytech.github.io/polkadot-sdk/master/pallet_staking_async/trait.DefaultConfig.html
- 4: https://paritytech.github.io/polkadot-sdk/master/pallet_staking_async/type.AreNominatorsSlashable.html
- 5: https://paritytech.github.io/polkadot-sdk/master/pallet_fast_unstake/trait.StakingInterface.html
- 6: staking-async: include the unlock era in the Unbonded event paritytech/polkadot-sdk#12578
Guard nominatorFastUnbondDuration with a fallback — this constant only exists on pallet-staking-async; older staking runtimes don’t expose it, so this direct access can make getStakingConsts fail and clear the full staking const set for that chain. Fallback to bondingDuration or skip the field when it’s absent.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/extension-polkagate/src/hooks/useStakingConsts.ts` at line 35, The
direct access to nominatorFastUnbondDuration in getStakingConsts can fail on
runtimes that do not expose the async staking constant, so guard this lookup in
useStakingConsts and fall back to bondingDuration or omit the field when it is
missing. Update the staking-const collection logic so the rest of the constants
still resolve even if nominatorFastUnbondDuration is unavailable.
| const address = useSelectedAccount()?.address; | ||
| const isValidator = useIsValidator(address, genesisHash); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Find all callers of useStakingInfoSolo to verify stakingInfo is always for the selected account
rg -n "useStakingInfoSolo" --type ts -C 5 -g '!**/useStakingInfoSolo.ts'Repository: PolkaGate/extension
Length of output: 157
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo '=== locate hook file ==='
fd -a 'useStakingInfoSolo.ts' .
echo '=== search broader references ==='
rg -n --hidden --glob '!**/node_modules/**' --glob '!**/dist/**' --glob '!**/build/**' 'useStakingInfoSolo|useStakingInfoSolo\s*\(' .
echo '=== search stakingInfo-related hook imports/calls in extension package ==='
rg -n --hidden --glob '!**/node_modules/**' --glob '!**/dist/**' --glob '!**/build/**' 'useStakingInfo|stakingInfo' packages/extension-polkagate/srcRepository: PolkaGate/extension
Length of output: 33774
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo '=== hook implementation ==='
sed -n '1,220p' packages/extension-polkagate/src/hooks/useStakingInfoSolo.ts
echo '=== fullscreen new-solo Info ==='
sed -n '1,220p' packages/extension-polkagate/src/fullscreen/stake/new-solo/Info.tsx
echo '=== fullscreen new-solo parent ==='
sed -n '1,220p' packages/extension-polkagate/src/fullscreen/stake/new-solo/index.tsx
echo '=== popup solo Info ==='
sed -n '1,180p' packages/extension-polkagate/src/popup/staking/solo-new/Info.tsxRepository: PolkaGate/extension
Length of output: 12448
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo '=== useIsValidator ==='
sed -n '1,220p' packages/extension-polkagate/src/hooks/useIsValidator.ts
echo '=== useSoloStakingInfo ==='
sed -n '1,220p' packages/extension-polkagate/src/hooks/useSoloStakingInfo.ts
echo '=== search SoloStakingInfo validator-related fields/usages ==='
rg -n --hidden --glob '!**/node_modules/**' --glob '!**/dist/**' --glob '!**/build/**' 'isValidator|validator' packages/extension-polkagate/src/hooks/useSoloStakingInfo.ts packages/extension-polkagate/src -g '!**/useIsValidator.ts'Repository: PolkaGate/extension
Length of output: 50375
🏁 Script executed:
#!/bin/bash
set -euo pipefail
rg -n --hidden --glob '!**/node_modules/**' --glob '!**/dist/**' --glob '!**/build/**' '/fullscreen-stake/solo/|fullscreenURL=.*solo|fullscreen-stake/pool' packages/extension-polkagate/srcRepository: PolkaGate/extension
Length of output: 4780
Derive isValidator from stakingInfo, not useSelectedAccount(). This hook can be rendered for a staking account that differs from the globally selected one, so the unbonding duration may be shown for the wrong address.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/extension-polkagate/src/hooks/useStakingInfoSolo.ts` around lines 29
- 30, The `useStakingInfoSolo` hook is currently deriving `isValidator` from
`useSelectedAccount()`, which can point to the wrong account when this hook is
used for a staking account different from the globally selected one. Update the
hook to derive the validator check from `stakingInfo` instead, and pass that
account’s address into `useIsValidator` alongside `genesisHash` so the unbonding
duration is calculated for the correct staking account.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/extension-polkagate/src/hooks/useIsValidator.ts`:
- Around line 15-23: Update the useEffect containing the validators query to
track cancellation during each invocation and return cleanup that marks the
invocation inactive. Only call setIsValidator for responses from the active
invocation, while preserving the existing query and error handling behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: aa231175-0139-482a-8635-1ecece1d0c04
📒 Files selected for processing (2)
packages/extension-polkagate/src/hooks/useIsValidator.tspackages/extension-polkagate/src/hooks/useStakingInfoSolo.ts
| useEffect(() => { | ||
| if (!api || !address) { | ||
| if (!api || !formatted) { | ||
| return; | ||
| } | ||
|
|
||
| api.query['staking']['validators'].keys().then((intentions) => { | ||
| const isValidator = intentions | ||
| .map(({ args }: { args: any[] }) => args[0].toString()) | ||
| .includes(formatted); | ||
|
|
||
| setIsValidator(isValidator); | ||
| api.query['staking']['validators'](formatted).then((prefs: { isStorageFallback?: boolean }) => { | ||
| setIsValidator(!prefs.isStorageFallback); | ||
| }).catch(console.error); | ||
| }, [address, api, formatted]); | ||
| }, [api, formatted]); |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Add cleanup to prevent stale async responses.
The effect has no cleanup function. If formatted changes while a query is in-flight, the old promise can resolve after the new one, leaving isValidator set for the wrong address until the next account switch.
🔒 Suggested fix: ignore stale responses with a cancelled flag
useEffect(() => {
if (!api || !formatted) {
return;
}
- api.query['staking']['validators'](formatted).then((prefs: { isStorageFallback?: boolean }) => {
- setIsValidator(!prefs.isStorageFallback);
- }).catch(console.error);
+ let cancelled = false;
+
+ api.query['staking']['validators'](formatted).then((prefs: { isStorageFallback?: boolean }) => {
+ if (!cancelled) {
+ setIsValidator(!prefs.isStorageFallback);
+ }
+ }).catch(console.error);
+
+ return () => { cancelled = true; };
}, [api, formatted]);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| useEffect(() => { | |
| if (!api || !address) { | |
| if (!api || !formatted) { | |
| return; | |
| } | |
| api.query['staking']['validators'].keys().then((intentions) => { | |
| const isValidator = intentions | |
| .map(({ args }: { args: any[] }) => args[0].toString()) | |
| .includes(formatted); | |
| setIsValidator(isValidator); | |
| api.query['staking']['validators'](formatted).then((prefs: { isStorageFallback?: boolean }) => { | |
| setIsValidator(!prefs.isStorageFallback); | |
| }).catch(console.error); | |
| }, [address, api, formatted]); | |
| }, [api, formatted]); | |
| useEffect(() => { | |
| if (!api || !formatted) { | |
| return; | |
| } | |
| let cancelled = false; | |
| api.query['staking']['validators'](formatted).then((prefs: { isStorageFallback?: boolean }) => { | |
| if (!cancelled) { | |
| setIsValidator(!prefs.isStorageFallback); | |
| } | |
| }).catch(console.error); | |
| return () => { cancelled = true; }; | |
| }, [api, formatted]); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/extension-polkagate/src/hooks/useIsValidator.ts` around lines 15 -
23, Update the useEffect containing the validators query to track cancellation
during each invocation and return cleanup that marks the invocation inactive.
Only call setIsValidator for responses from the active invocation, while
preserving the existing query and error handling behavior.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/extension-polkagate/src/popup/staking/solo-new/index.tsx (1)
73-73: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick winRemove the now-unused
onFastUnstakecallback.
onFastUnstakeis dead code — the Fast Unstake button that referenced it was removed from thebuttonsarray. Per coding guidelines, remove variables and functions made unused by your changes.🗑️ Proposed fix
- const onFastUnstake = useCallback(() => navigate('/solo/' + genesisHash + '/fastUnstake') as void, [genesisHash, navigate]); const onUnstake = useCallback(() => navigate('/solo/' + genesisHash + '/unstake') as void, [genesisHash, navigate]);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/extension-polkagate/src/popup/staking/solo-new/index.tsx` at line 73, Remove the unused onFastUnstake callback from the solo staking component, including its useCallback definition and dependencies, since no remaining button references it.Source: Coding guidelines
🧹 Nitpick comments (1)
packages/extension-polkagate/src/popup/staking/solo-new/index.tsx (1)
45-45: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRemove the unused
apidestructuring —apiis no longer referenced inpackages/extension-polkagate/src/popup/staking/solo-new/index.tsx, so drop it fromuseChainInfo(genesisHash).🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/extension-polkagate/src/popup/staking/solo-new/index.tsx` at line 45, Update the useChainInfo destructuring in the staking component to remove the unused api variable, retaining only the decimal and token values used by the component.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@packages/extension-polkagate/src/popup/staking/solo-new/index.tsx`:
- Line 73: Remove the unused onFastUnstake callback from the solo staking
component, including its useCallback definition and dependencies, since no
remaining button references it.
---
Nitpick comments:
In `@packages/extension-polkagate/src/popup/staking/solo-new/index.tsx`:
- Line 45: Update the useChainInfo destructuring in the staking component to
remove the unused api variable, retaining only the decimal and token values used
by the component.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 1973e101-c305-4283-b698-2e829c45db39
📒 Files selected for processing (12)
packages/extension-polkagate/src/fullscreen/stake/partials/StakingPortfolioAndTiles.tsxpackages/extension-polkagate/src/fullscreen/stake/util/utils.tspackages/extension-polkagate/src/hooks/useIsValidator.tspackages/extension-polkagate/src/popup/staking/solo-new/index.tsxpackages/extension/public/locales/de/translation.jsonpackages/extension/public/locales/en/translation.jsonpackages/extension/public/locales/es/translation.jsonpackages/extension/public/locales/fr/translation.jsonpackages/extension/public/locales/hi/translation.jsonpackages/extension/public/locales/pt/translation.jsonpackages/extension/public/locales/ru/translation.jsonpackages/extension/public/locales/zh/translation.json
💤 Files with no reviewable changes (9)
- packages/extension/public/locales/zh/translation.json
- packages/extension/public/locales/de/translation.json
- packages/extension/public/locales/hi/translation.json
- packages/extension/public/locales/es/translation.json
- packages/extension-polkagate/src/fullscreen/stake/util/utils.ts
- packages/extension/public/locales/ru/translation.json
- packages/extension/public/locales/en/translation.json
- packages/extension/public/locales/fr/translation.json
- packages/extension/public/locales/pt/translation.json
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/extension-polkagate/src/hooks/useIsValidator.ts
# [2.13.0](v2.12.1...v2.13.0) (2026-07-11) ### Features * reduce Polkadot unstaking period to 2 days ([#2186](#2186)) ([f0786dc](f0786dc))
remove deprecated fast unstaking
Summary by CodeRabbit