Skip to content

fix(demo-wallet): small fixes in demo-wallet#480

Open
heyllog wants to merge 2 commits into
mainfrom
fix/demo-wallet
Open

fix(demo-wallet): small fixes in demo-wallet#480
heyllog wants to merge 2 commits into
mainfrom
fix/demo-wallet

Conversation

@heyllog

@heyllog heyllog commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes
    • Fixed network configuration URL for improved connectivity
    • Enhanced validation for 24-word mnemonic imports to reject invalid entries
    • Improved wallet data synchronization when switching between wallets or networks

@vercel

vercel Bot commented Jun 18, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
appkit-minter Ready Ready Preview, Comment Jun 19, 2026 9:34am
kit-demo-wallet Ready Ready Preview, Comment Jun 19, 2026 9:34am

Request Review

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR fixes wallet data reloading to key on activeWalletId instead of address in the useWalletDataUpdater hook and simplifies NFT slice wallet lookup to use currentWallet directly. It also corrects a malformed mainnet Toncenter URL, upgrades the Tetra network client to use ApiClientTonApi, tightens BIP39 mnemonic validation to reject 24-word inputs with invalid word indices, and updates comment wording in two formatter utilities.

Changes

Active Wallet Identity Fix

Layer / File(s) Summary
useWalletDataUpdater keyed on activeWalletId
apps/demo-wallet/src/core/hooks/use-wallet-data-updater.ts
activeWalletId is destructured from useWallet() and added to the wallet-change effect's dependency array; the effect comment is updated to explain why activeWalletId is used instead of address for network-switching correctness.
nftsSlice uses currentWallet directly
demo/wallet-core/src/store/slices/nftsSlice.ts
loadUserNfts, refreshNfts, and loadMoreNfts now read wallet from state.walletManagement.currentWallet instead of iterating walletKit.getWallets() and matching by address.

Network API Configuration Corrections

Layer / File(s) Summary
Network client and URL fixes
apps/demo-wallet/src/extension/background_main.ts
Imports ApiClientTonApi; corrects mainnet Toncenter URL from https:/toncenter.com to https://toncenter.com; replaces Tetra apiClient plain object with a typed ApiClientTonApi instance using Network.tetra() and ENV_TON_API_KEY_TETRA.

BIP39 Validation Fix and Comment Updates

Layer / File(s) Summary
isImportableBip39 stricter 24-word validation
apps/demo-wallet/src/features/wallets/utils/bip39-english.ts
Adds a guard rejecting word counts other than 12 or 24, and enforces invalidIndices.length === 0 for 24-word mnemonics (previously unconditionally accepted).
formatLargeValue threshold comment updates
apps/demo-wallet/src/core/utils/formatters.ts, packages/appkit/src/utils/amount/format-large-value.ts
Inline comments describing T/B/M cutoffs are reworded from value comparisons to integer-digit-count descriptions; no logic changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • ton-org/kit#459: Modifies the same useWalletDataUpdater hook's wallet-change effect, using address-guarded clearing and periodic balance/jetton/NFT refresh — directly related to this PR's activeWalletId-keyed reload change.

Poem

🐇 A URL with a missing slash,
A wallet id that causes a crash —
I hopped through the code,
Fixed every bad road,
Now 24 words need no invalid hash! ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'small fixes in demo-wallet' is vague and generic, using non-descriptive language that doesn't convey the specific changes (wallet data keying, API URL corrections, BIP39 validation, etc.). Consider a more specific title that highlights the main change, such as 'fix: correct wallet data updates and API configuration in demo-wallet' or 'fix: improve wallet switching and API endpoint configuration'.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/demo-wallet

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Guard NFT state writes against wallet switches during in-flight fetches.

These methods capture currentWallet, await wallet.getNfts(...), then write to shared state.nfts unconditionally. 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 refreshNfts and loadMoreNfts.

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

📥 Commits

Reviewing files that changed from the base of the PR and between db00ed0 and f7cd026.

📒 Files selected for processing (6)
  • apps/demo-wallet/src/core/hooks/use-wallet-data-updater.ts
  • apps/demo-wallet/src/core/utils/formatters.ts
  • apps/demo-wallet/src/extension/background_main.ts
  • apps/demo-wallet/src/features/wallets/utils/bip39-english.ts
  • demo/wallet-core/src/store/slices/nftsSlice.ts
  • packages/appkit/src/utils/amount/format-large-value.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant