fix(demo-wallet): small fixes in demo-wallet#480
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThe PR fixes wallet data reloading to key on ChangesActive Wallet Identity Fix
Network API Configuration Corrections
BIP39 Validation Fix and Comment Updates
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
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)
demo/wallet-core/src/store/slices/nftsSlice.ts (1)
57-77:⚠️ Potential issue | 🟠 Major | ⚡ Quick winGuard NFT state writes against wallet switches during in-flight fetches.
These methods capture
currentWallet, awaitwallet.getNfts(...), then write to sharedstate.nftsunconditionally. If active wallet changes before the await resolves, stale results can overwrite the new wallet’s NFT state.Suggested fix pattern
loadUserNfts: async (userAddress?: string, limit: number = 20) => { const state = get(); + const requestWalletId = state.walletManagement.activeWalletId; const address = userAddress || state.walletManagement.address; ... try { const wallet = state.walletManagement.currentWallet; if (!wallet) throw new Error('Wallet not found'); const result: NFTsResponse = await wallet.getNfts({ pagination: { limit, offset: 0 }, }); + if (get().walletManagement.activeWalletId !== requestWalletId) { + return; // discard stale response + } set((state) => { state.nfts.userNfts = result.nfts; ... }); } catch (error) { + if (get().walletManagement.activeWalletId !== requestWalletId) { + return; // discard stale error write + } ... } }Apply the same request-wallet guard in
refreshNftsandloadMoreNfts.Also applies to: 111-131, 164-184
🤖 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 `@demo/wallet-core/src/store/slices/nftsSlice.ts` around lines 57 - 77, The issue is that after awaiting wallet.getNfts() in the set callback, the code unconditionally writes to state.nfts even if the active wallet has changed during the fetch. Add a guard check before writing state in the set callback to verify that state.walletManagement.currentWallet still matches the wallet that was captured before the await. Apply this same guard pattern to the refreshNfts method (around lines 111-131) and the loadMoreNfts method (around lines 164-184) to prevent stale NFT results from overwriting the current wallet's NFT state during wallet switches.
🤖 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 `@demo/wallet-core/src/store/slices/nftsSlice.ts`:
- Around line 57-77: The issue is that after awaiting wallet.getNfts() in the
set callback, the code unconditionally writes to state.nfts even if the active
wallet has changed during the fetch. Add a guard check before writing state in
the set callback to verify that state.walletManagement.currentWallet still
matches the wallet that was captured before the await. Apply this same guard
pattern to the refreshNfts method (around lines 111-131) and the loadMoreNfts
method (around lines 164-184) to prevent stale NFT results from overwriting the
current wallet's NFT state during wallet switches.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 0c80b839-41fb-4b09-bb66-f83d6074c974
📒 Files selected for processing (6)
apps/demo-wallet/src/core/hooks/use-wallet-data-updater.tsapps/demo-wallet/src/core/utils/formatters.tsapps/demo-wallet/src/extension/background_main.tsapps/demo-wallet/src/features/wallets/utils/bip39-english.tsdemo/wallet-core/src/store/slices/nftsSlice.tspackages/appkit/src/utils/amount/format-large-value.ts
Summary by CodeRabbit