Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions apps/demo-wallet/src/core/hooks/use-wallet-data-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useEffect } from 'react';
import { useAuth, useJettons, useNfts, useRates, useWallet } from '@demo/wallet-core';

export const useWalletDataUpdater = () => {
const { address, updateBalance, hasWallet, currentWallet, loadAllWallets } = useWallet();
const { address, activeWalletId, updateBalance, hasWallet, currentWallet, loadAllWallets } = useWallet();
const { isUnlocked } = useAuth();
const { loadUserJettons, clearJettons } = useJettons();
const { loadUserNfts, clearNfts, refreshNfts } = useNfts();
Expand All @@ -23,7 +23,9 @@ export const useWalletDataUpdater = () => {
}
}, [hasWallet, isUnlocked, currentWallet, loadAllWallets]);

// Update on address change
// Update on wallet change. Keyed on activeWalletId, not address: same-key wallets on
// different networks (testnet/mainnet) share the same address string, so switching between
// them wouldn't re-run this effect and stale jettons/NFTs/rates would persist.
useEffect(() => {
if (!address) return;

Expand All @@ -35,7 +37,17 @@ export const useWalletDataUpdater = () => {
await Promise.allSettled([updateBalance(), loadUserJettons(), loadUserNfts()]);
await loadRates();
})();
}, [address, updateBalance, loadUserJettons, loadUserNfts, loadRates, clearNfts, clearJettons, clearRates]);
}, [
activeWalletId,
address,
updateBalance,
loadUserJettons,
loadUserNfts,
loadRates,
clearNfts,
clearJettons,
clearRates,
]);

// Periodic refresh — sequential to avoid overloading the backend (ported from main):
// balance → jettons → rates → NFTs, chained via setTimeout, every 20s. Rates self-throttle
Expand Down
6 changes: 3 additions & 3 deletions apps/demo-wallet/src/core/utils/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ export const formatLargeValue = (amount: string, decimals: number = 2, minimumFr
const cleanAmount = amount.toString().replace(/\s/g, '');
const intPart = cleanAmount.split('.')[0] || '0';

// > 100 000 000 000 000 => 100T
// 13+ integer digits (>= 1e12) => trillions, e.g. "1.23T"
if (intPart.length > 12) {
return `${(Number(intPart.slice(0, -10)) / 100).toLocaleString('en-US')}T`;
}
// > 100 000 000 000 => 100B
// 10+ integer digits (>= 1e9) => billions, e.g. "1.23B"
if (intPart.length > 9) {
return `${(Number(intPart.slice(0, -7)) / 100).toLocaleString('en-US')}B`;
}
// > 10 000 000 => 10M
// 7+ integer digits (>= 1e6) => millions, e.g. "1.23M"
if (intPart.length > 6) {
return `${(Number(intPart.slice(0, -4)) / 100).toLocaleString('en-US')}M`;
}
Expand Down
15 changes: 8 additions & 7 deletions apps/demo-wallet/src/extension/background_main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// eslint-disable-next-line no-console
console.log('TON Wallet Demo extension background script loaded');

import { Network, ExtensionStorageAdapter, TonWalletKit, fetchManifest } from '@ton/walletkit';
import { Network, ExtensionStorageAdapter, TonWalletKit, fetchManifest, ApiClientTonApi } from '@ton/walletkit';
import type { InjectedToExtensionBridgeRequestPayload } from '@ton/walletkit';
import browser from 'webextension-polyfill';
import { onMessage } from '@truecarry/webext-bridge/background';
Expand Down Expand Up @@ -49,7 +49,7 @@ async function initializeWalletKit() {
networks: {
[Network.mainnet().chainId]: {
apiClient: {
url: 'https:/toncenter.com',
url: 'https://toncenter.com',
key: ENV_TON_API_KEY_MAINNET,
},
},
Expand All @@ -60,12 +60,13 @@ async function initializeWalletKit() {
},
},

// TODO: Update tetra api client
// Tetra is a TonAPI host, so it needs the TonAPI client (TonAPI
// paths + Bearer auth), not the default Toncenter client.
[Network.tetra().chainId]: {
apiClient: {
url: 'https://tetra.tonapi.io',
key: ENV_TON_API_KEY_TETRA,
},
apiClient: new ApiClientTonApi({
network: Network.tetra(),
apiKey: ENV_TON_API_KEY_TETRA,
}),
},
},

Expand Down
5 changes: 2 additions & 3 deletions apps/demo-wallet/src/features/wallets/utils/bip39-english.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ export function evaluateBip39Slots(words24: readonly string[]): Bip39SlotValidat

export function isImportableBip39(v: Bip39SlotValidation): boolean {
const n = v.nonEmptyWords.length;
if (n === 24) return true;
if (n === 12) return v.invalidIndices.length === 0;
return false;
if (n !== 12 && n !== 24) return false;
return v.invalidIndices.length === 0;
}

export type MnemonicPasteResult = {
Expand Down
9 changes: 3 additions & 6 deletions demo/wallet-core/src/store/slices/nftsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ export const createNftsSlice: NftsSliceCreator = (set: SetState, get) => ({
try {
log.info('Loading user NFTs', { address, limit });

const wallets = state.walletCore.walletKit.getWallets();
const wallet = wallets.find((w) => w.getAddress() === address);
const wallet = state.walletManagement.currentWallet;

if (!wallet) {
throw new Error('Wallet not found');
Expand Down Expand Up @@ -112,8 +111,7 @@ export const createNftsSlice: NftsSliceCreator = (set: SetState, get) => ({
try {
log.info('Refreshing user NFTs', { address });

const wallets = state.walletCore.walletKit.getWallets();
const wallet = wallets.find((w) => w.getAddress() === address);
const wallet = state.walletManagement.currentWallet;

if (!wallet) {
throw new Error('Wallet not found');
Expand Down Expand Up @@ -166,8 +164,7 @@ export const createNftsSlice: NftsSliceCreator = (set: SetState, get) => ({
try {
log.info('Loading more user NFTs', { address, offset: state.nfts.offset });

const wallets = state.walletCore.walletKit.getWallets();
const wallet = wallets.find((w) => w.getAddress() === address);
const wallet = state.walletManagement.currentWallet;

if (!wallet) {
throw new Error('Wallet not found');
Expand Down
6 changes: 3 additions & 3 deletions packages/appkit/src/utils/amount/format-large-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ export const formatLargeValue = (amount: string, decimals: number = 2, minimumFr
const cleanAmount = amount.toString().replace(/\s/g, '');
const intPart = cleanAmount.split('.')[0] || '0';

// value > 100 000 000 000 000 => 100 T
// 13+ integer digits (>= 1e12) => trillions, e.g. "1.23T"
if (intPart.length > 12) {
const value = Number(intPart.slice(0, -10)) / 100;
return `${value.toLocaleString('en-US')}T`;
}

// value > 100 000 000 000 => 100 B
// 10+ integer digits (>= 1e9) => billions, e.g. "1.23B"
if (intPart.length > 9) {
const value = Number(intPart.slice(0, -7)) / 100;
return `${value.toLocaleString('en-US')}B`;
}

// value > 10 000 000 => 10 M
// 7+ integer digits (>= 1e6) => millions, e.g. "1.23M"
if (intPart.length > 6) {
const value = Number(intPart.slice(0, -4)) / 100;
return `${value.toLocaleString('en-US')}M`;
Expand Down
Loading