Skip to content
This repository was archived by the owner on Sep 3, 2026. It is now read-only.

Commit 98d0859

Browse files
author
Pavel Lesyuk
committed
fix(demo-wallet): loading skeletons, error states, offset pagination, empty-state stubs
Sections (History, Assets, NFTs) previously shimmered forever on a failed list fetch and could flash a false "empty" while still loading. Add explicit loading / error / empty handling backed by real load state. Store (wallet-core): - Add isLoadingEvents / eventsLoaded / eventsError / accountStatus to walletManagement, driven from loadEvents. - Coalesce concurrent loadEvents calls for the same (limit, offset) onto one in-flight request (removes the duplicate concurrent /traces requests that the StrictMode double-invoke amplified); a different window (Load more) chains after and is never dropped. - Best-effort single retry on a transient toncenter timeout. - Fetch account status (addressInformation) so the UI can distinguish a fresh/uninitialized account (truly no transactions) from a still-loading or failed fetch. - Reset the new flags + in-flight guard on wallet switch / remove / clear. UI (demo-wallet): - Add a reusable animated Skeleton primitive (gray shimmer within the app palette, respects prefers-reduced-motion) with layout-matched variants for the Asset row, NFT tile and History row. - Show shimmers while loading on both the dashboard preview cards and the full Assets / NFTs / History pages. - Empty-state stubs ("No NFTs yet" / "No transactions yet") show only after a successful load returned nothing (or a confirmed fresh account) — never while loading or after a failed fetch. On the dashboard a genuinely-empty wallet shows the stub instead of the section being hidden. - Error states: the dashboard preview hides the section on a load error; the full page shows a short "Unable to load ..." line instead of an endless shimmer. - History "Load more" pages by offset -- (25,0) -> (25,25) -> (25,50) -- appending each page to the accumulated list (deduped by eventId) instead of refetching a growing limit; shows a spinner while the next page loads. Work around a server-side toncenter limitation where GET /api/v3/traces?limit=N returns 500 ("timeout: context deadline exceeded") for small N (observed 1..10) but succeeds for 25: default the events batch to 25 everywhere. Because the dashboard preview and History now request the same first page (limit 25, offset 0), the store coalesces them into one /traces request. Assets: surface the mainnet base tokens (native Gram + USDT + XAUt) at a zero balance when not held, on BOTH the dashboard preview and the full Assets page, via the shared useAssetRows hook so both render the exact same list (the preview shows its first N); held jettons are merged in and win on any address collision. Mainnet-only; testnet and held-token display unchanged.
1 parent b2686a6 commit 98d0859

16 files changed

Lines changed: 597 additions & 192 deletions

File tree

‎apps/demo-wallet/src/App.css‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,38 @@
5151
}
5252
}
5353

54+
/* Loading skeleton shimmer. A gray band sweeps left→right across a gray base.
55+
Stays within the app's gray palette (gray-100 base, gray-200 highlight). */
56+
@keyframes skeleton-shimmer {
57+
0% {
58+
background-position: 150% 0;
59+
}
60+
100% {
61+
background-position: -50% 0;
62+
}
63+
}
64+
65+
.skeleton-shimmer {
66+
background-color: #f3f4f6; /* gray-100 — matches existing animate-pulse skeletons */
67+
background-image: linear-gradient(
68+
90deg,
69+
rgba(229, 231, 235, 0) 0%,
70+
rgba(229, 231, 235, 0.9) 50%,
71+
rgba(229, 231, 235, 0) 100%
72+
); /* gray-200 highlight band */
73+
background-size: 200% 100%;
74+
background-repeat: no-repeat;
75+
animation: skeleton-shimmer 1.4s ease-in-out infinite;
76+
}
77+
78+
/* Respect reduced-motion: fall back to a gentle static gray (no sweep). */
79+
@media (prefers-reduced-motion: reduce) {
80+
.skeleton-shimmer {
81+
background-image: none;
82+
animation: none;
83+
}
84+
}
85+
5486
.card {
5587
padding: 2em;
5688
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Copyright (c) TonTech.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
*/
8+
9+
export * from './skeleton';
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright (c) TonTech.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
*/
8+
9+
import type { FC, HTMLAttributes } from 'react';
10+
11+
import { cn } from '@/core/lib/utils';
12+
13+
/**
14+
* Reusable animated skeleton placeholder. A gray band sweeps across a gray base
15+
* (see the `.skeleton-shimmer` rule in App.css) — within the app's gray palette.
16+
* Size and shape come from the passed className (width/height/rounding).
17+
*
18+
* @example <Skeleton className="h-4 w-24 rounded" />
19+
*/
20+
export const Skeleton: FC<HTMLAttributes<HTMLDivElement>> = ({ className, ...props }) => (
21+
<div aria-hidden className={cn('skeleton-shimmer rounded-md', className)} {...props} />
22+
);

‎apps/demo-wallet/src/features/assets/components/asset-row/asset-row.tsx‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import React from 'react';
1010

1111
import { FallbackImage } from '@/core/components/ui/fallback-image';
12+
import { Skeleton } from '@/core/components/ui/skeleton';
1213
import { useCountUp } from '@/core/hooks/use-count-up';
1314
import { formatLargeValue } from '@/core/utils';
1415

@@ -63,16 +64,17 @@ export const AssetRow: React.FC<AssetRowData> = ({ icon, fallbackText, name, sym
6364
);
6465
};
6566

67+
/** Loading placeholder mirroring {@link AssetRow}: circular icon, name/amount lines, right-side value. */
6668
export const AssetRowSkeleton: React.FC = () => (
6769
<div className="flex items-center gap-3 py-2">
68-
<span className="w-10 h-10 rounded-full bg-gray-100 animate-pulse flex-shrink-0" />
70+
<Skeleton className="w-10 h-10 rounded-full flex-shrink-0" />
6971
<div className="flex-1 min-w-0 space-y-1.5">
70-
<div className="h-4 w-24 rounded bg-gray-100 animate-pulse" />
71-
<div className="h-3 w-32 rounded bg-gray-100 animate-pulse" />
72+
<Skeleton className="h-4 w-24" />
73+
<Skeleton className="h-3 w-32" />
7274
</div>
7375
<div className="text-right space-y-1.5">
74-
<div className="h-4 w-16 rounded bg-gray-100 animate-pulse ml-auto" />
75-
<div className="h-3 w-12 rounded bg-gray-100 animate-pulse ml-auto" />
76+
<Skeleton className="h-4 w-16 ml-auto" />
77+
<Skeleton className="h-3 w-12 ml-auto" />
7678
</div>
7779
</div>
7880
);

‎apps/demo-wallet/src/features/assets/components/assets-screen/assets-screen.tsx‎

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,46 @@
88

99
import type { FC } from 'react';
1010
import { useNavigate } from 'react-router-dom';
11+
import { useJettons } from '@demo/wallet-core';
1112

1213
import { AssetRow, AssetRowSkeleton } from '../asset-row';
1314
import { useAssetRows } from '../../hooks/use-asset-rows';
1415

1516
import { NewLayout } from '@/core/components/shared/new-layout';
1617
import { ScreenHeader } from '@/core/components/shared/screen-header';
1718

18-
/** Full assets page: every token on the active wallet's balance (TON + all jettons). */
19+
/**
20+
* Full assets page: Gram + every held jetton, plus (on mainnet) the base tokens at a zero
21+
* balance when not held. Same list the dashboard preview shows the first N of — see
22+
* {@link useAssetRows}.
23+
*/
1924
export const AssetsScreen: FC = () => {
2025
const navigate = useNavigate();
26+
const { userJettons, isLoadingJettons, lastJettonsUpdate, error } = useJettons();
2127
const { tonRow, jettonRows, assetsReady } = useAssetRows();
2228

29+
// A jettons fetch that has never succeeded and failed → short error line (not an endless
30+
// shimmer). Once jettons have loaded once, a transient refresh error won't show the error.
31+
const isError = lastJettonsUpdate === 0 && userJettons.length === 0 && error !== null && !isLoadingJettons;
32+
2333
return (
2434
<NewLayout header={<ScreenHeader title="Assets" onBack={() => navigate('/wallet')} />}>
25-
<div className="space-y-1">
26-
{assetsReady && tonRow ? (
27-
<>
28-
<AssetRow {...tonRow} />
29-
{jettonRows.map((row) => (
30-
<AssetRow key={row.id} {...row} />
31-
))}
32-
</>
33-
) : (
34-
<>
35-
<AssetRowSkeleton />
36-
<AssetRowSkeleton />
37-
<AssetRowSkeleton />
38-
</>
39-
)}
40-
</div>
35+
{assetsReady && tonRow ? (
36+
<div className="space-y-1">
37+
<AssetRow {...tonRow} />
38+
{jettonRows.map((row) => (
39+
<AssetRow key={row.id} {...row} />
40+
))}
41+
</div>
42+
) : isError ? (
43+
<p className="py-12 text-center text-sm text-gray-400">Unable to load assets</p>
44+
) : (
45+
<div className="space-y-1">
46+
<AssetRowSkeleton />
47+
<AssetRowSkeleton />
48+
<AssetRowSkeleton />
49+
</div>
50+
)}
4151
</NewLayout>
4252
);
4353
};

‎apps/demo-wallet/src/features/assets/hooks/use-asset-rows.ts‎

Lines changed: 97 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
*
77
*/
88

9-
import { useMemo } from 'react';
10-
import { useJettons, useRates, useWallet } from '@demo/wallet-core';
9+
import { useEffect, useMemo, useState } from 'react';
10+
import { useJettons, useRates, useWallet, useWalletKit } from '@demo/wallet-core';
11+
import type { JettonInfo } from '@ton/walletkit';
1112

1213
import type { AssetRowData } from '../components/asset-row';
1314

@@ -16,6 +17,18 @@ import { findRate, formatRate, toDecimal, tokenImageUrls } from '@/core/utils';
1617

1718
const GRAM_DECIMALS = 9;
1819

20+
/**
21+
* Base tokens always surfaced on mainnet (for discoverability) even at a zero balance, so a
22+
* fresh wallet shows Gram + these below the native row. Held balances always win: if the user
23+
* holds one of these, its live row (with the real balance) replaces the zero-balance base row.
24+
* The hardcoded name/symbol are only a fallback shown until live metadata loads. Addresses are
25+
* the mainnet jetton masters and MUST match the on-chain contracts.
26+
*/
27+
const DEFAULT_JETTONS: { address: string; symbol: string; name: string }[] = [
28+
{ address: 'EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs', symbol: 'USDT', name: 'Tether USD' },
29+
{ address: 'EQA1R_LuQCLHlMgOo1S4G7Y7W1cd0FrAkbA10Zq7rddKxi9k', symbol: 'XAUT', name: 'Tether Gold' },
30+
];
31+
1932
/** Candidate icon URLs (best-first), appending the inline base64 image as a last resort. */
2033
export const imageSources = (urls: string[] | undefined, dataBase64?: string): string[] => [
2134
...(urls ?? []),
@@ -24,19 +37,52 @@ export const imageSources = (urls: string[] | undefined, dataBase64?: string): s
2437

2538
interface AssetRows {
2639
tonRow: AssetRowData | null;
27-
/** All held jettons as rows, sorted by fiat value desc (verified first as a tiebreaker). */
40+
/**
41+
* Jetton rows sorted by fiat value desc (verified first as a tiebreaker): every held jetton,
42+
* plus — on mainnet — the {@link DEFAULT_JETTONS} base tokens at a zero balance when not held.
43+
*/
2844
jettonRows: AssetRowData[];
2945
assetsReady: boolean;
3046
}
3147

32-
/** Builds the TON row + a row per held jetton. Shared by the dashboard preview and the full assets page. */
48+
/**
49+
* Builds the TON row + a row per jetton. Shared by the dashboard preview and the full assets
50+
* page, so both surfaces show the SAME list (the preview renders its first N). On mainnet the
51+
* {@link DEFAULT_JETTONS} base tokens are always included (at a zero balance if not held) for
52+
* discoverability; held jettons are merged in and win on any address collision.
53+
*/
3354
export const useAssetRows = (): AssetRows => {
34-
const { balance } = useWallet();
55+
const { balance, currentWallet, getActiveWallet } = useWallet();
3556
const { userJettons, lastJettonsUpdate } = useJettons();
3657
const { entries: rates, lastUpdated: ratesUpdated } = useRates();
58+
const walletKit = useWalletKit();
3759

3860
const assetsReady = balance !== undefined && lastJettonsUpdate > 0 && ratesUpdated > 0;
3961

62+
const isMainnet = getActiveWallet()?.network === 'mainnet';
63+
64+
// Live metadata (name/icon) for the base tokens, fetched from the API — mainnet only. Until
65+
// it arrives the base rows fall back to the hardcoded def name/symbol.
66+
const [defaultInfos, setDefaultInfos] = useState<Record<string, JettonInfo>>({});
67+
useEffect(() => {
68+
if (!isMainnet || !walletKit || !currentWallet) return;
69+
const network = currentWallet.getNetwork();
70+
let cancelled = false;
71+
void Promise.all(
72+
DEFAULT_JETTONS.map((def) => walletKit.jettons.getJettonInfo(def.address, network).catch(() => null)),
73+
).then((infos) => {
74+
if (cancelled) return;
75+
const next: Record<string, JettonInfo> = {};
76+
infos.forEach((info, i) => {
77+
if (info) next[DEFAULT_JETTONS[i].address] = info;
78+
});
79+
setDefaultInfos(next);
80+
});
81+
return () => {
82+
cancelled = true;
83+
};
84+
}, [isMainnet, walletKit, currentWallet]);
85+
4086
const tonRow = useMemo<AssetRowData | null>(() => {
4187
if (!assetsReady) return null;
4288
const rateEntry = rates['GRAM'];
@@ -55,29 +101,59 @@ export const useAssetRows = (): AssetRows => {
55101

56102
const jettonRows = useMemo<AssetRowData[]>(() => {
57103
if (!assetsReady) return [];
58-
return userJettons
59-
.map((jetton) => {
60-
const rateEntry = findRate(rates, jetton.address);
61-
const decimals = jetton.decimalsNumber ?? 9;
62-
const amount = toDecimal(jetton.balance, decimals);
63-
const symbol = getJettonsSymbol(jetton) ?? '';
64-
return {
104+
105+
const held = userJettons.map((jetton) => {
106+
const rateEntry = findRate(rates, jetton.address);
107+
const decimals = jetton.decimalsNumber ?? 9;
108+
const amount = toDecimal(jetton.balance, decimals);
109+
const symbol = getJettonsSymbol(jetton) ?? '';
110+
return {
111+
row: {
112+
id: jetton.address,
113+
icon: imageSources(tokenImageUrls(jetton.info?.image), jetton.info?.image?.data),
114+
fallbackText: symbol.slice(0, 2).toUpperCase() || '??',
115+
name: getJettonsName(jetton) ?? symbol,
116+
symbol,
117+
amount,
118+
rateLabel: rateEntry ? formatRate(rateEntry.rate) : undefined,
119+
fiat: rateEntry ? amount * rateEntry.rate : undefined,
120+
} satisfies AssetRowData,
121+
isVerified: jetton.isVerified,
122+
};
123+
});
124+
125+
// Mainnet: add each base token the wallet doesn't already hold as a zero-balance row
126+
// (dedupe against held jettons by address; held wins so its real balance is kept).
127+
const combined = [...held];
128+
if (isMainnet) {
129+
const heldByAddress = new Map(userJettons.map((jetton) => [jetton.address, jetton]));
130+
for (const def of DEFAULT_JETTONS) {
131+
if (heldByAddress.has(def.address)) continue;
132+
const info = defaultInfos[def.address];
133+
const rateEntry = findRate(rates, def.address);
134+
const amount = 0;
135+
combined.push({
65136
row: {
66-
id: jetton.address,
67-
icon: imageSources(tokenImageUrls(jetton.info?.image), jetton.info?.image?.data),
68-
fallbackText: symbol.slice(0, 2).toUpperCase() || '??',
69-
name: getJettonsName(jetton) ?? symbol,
70-
symbol,
137+
id: def.address,
138+
icon: imageSources(info?.image ? [info.image] : undefined, info?.image_data),
139+
fallbackText: def.symbol.slice(0, 2).toUpperCase(),
140+
name: info?.name || def.name,
141+
symbol: info?.symbol || def.symbol,
71142
amount,
72143
rateLabel: rateEntry ? formatRate(rateEntry.rate) : undefined,
73144
fiat: rateEntry ? amount * rateEntry.rate : undefined,
74145
} satisfies AssetRowData,
75-
isVerified: jetton.isVerified,
76-
};
77-
})
146+
// Canonical mainnet tokens are verified: keeps them above unverified junk in
147+
// the sort, but below any held token that has a fiat value.
148+
isVerified: true,
149+
});
150+
}
151+
}
152+
153+
return combined
78154
.sort((a, b) => (b.row.fiat ?? 0) - (a.row.fiat ?? 0) || Number(b.isVerified) - Number(a.isVerified))
79155
.map((entry) => entry.row);
80-
}, [assetsReady, userJettons, rates]);
156+
}, [assetsReady, userJettons, rates, isMainnet, defaultInfos]);
81157

82158
return { tonRow, jettonRows, assetsReady };
83159
};

0 commit comments

Comments
 (0)