Resolve asset icons by what renders, and refresh cached icons against the asset lists
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 32/100
- Issue type
- Feature
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
- Domain
- api, frontend, performance
Research direction
Start with @shared/api/helpers/getIconFromTokenList.ts and @shared/api/internal.ts, then trace useGetIcons.tsx, AccountAssets/index.tsx, and the SignTransaction hook. Verify the shared resolution path across account, search, sign-transaction, and history surfaces against the acceptance criteria: fallback rendering works, cached icons refresh without blanking, and list-backed assets avoid TOML requests.
Written by the indexing model from the issue text.
Description
TL;DR
Asset icons come from several sources that can disagree — the curated asset
lists and the issuer's SEP-1 TOML — and any of them can carry a URL that no
browser will render. Resolution today picks one URL, hands it to an <img>, and
never revisits it: if it doesn't load, nothing tries the next source, and once an
icon is cached we keep it for the life of the install even after a list publishes
a different one.
Three changes:
- Resolution returns every candidate URL in priority order instead of one,
and the icon component walks them on error. The browser verifies each as part
of the render it was already doing — nothing is probed ahead of time, and
nothing is added before first paint. - On a 7-day timer, cached icons are compared against the current lists.
Where they differ, the new candidates are tried and the first that loads
replaces the cached one. Entries that still agree are left untouched, so
nothing correct is discarded and no icon blanks while it re-resolves. - The asset lists become the preferred source everywhere, with the SEP-1
TOML kept as a lazy last resort for assets no enabled list carries.
The governing rule throughout is prefer a stale icon over no icon: every
ambiguous case — no list carries the asset, no candidate loads, the TOML fetch
fails — keeps what is already cached. A refresh may replace one working icon
with another, never end with less than it started with.
Details (for agents)
Problem
The resolver can neither tell a good claim from a bad one nor notice when one
changes. Three gaps:
Order is treated as validity. #2994 made the highest-priority list win
rather than the last one read — the right tiebreak, but not a correctness check.
getIconFromTokenLists
returns one URL straight to an <img>. If it does not load, nothing tries the
next source, even when another list carries one that works.
Cached icons are never revisited. getAssetIcons
gates on the cache before reading any list data, and the second-pass lookup only
considers assets missing from it.
Once an asset resolves, list data is never consulted for it again — so a rotated
icon URL is invisible for the life of the install, and if the old URL still
loads, nothing ever signals anything is wrong.
Nothing observes list change. The icon pass is triggered by an effect keyed
on balances, guarded by a deep compare against the previous balance set; its
comment states the intent outright:
For a steady-state user — same assets, warm cache — the lookup pass never runs
again.
Two things compound this: retryAssetIcon
re-resolves through the TOML alone and never re-checks the lists, and
AssetIcon latches its error state
— once an image fails the row keeps the broken-image glyph for the life of the
component, so a recovery is invisible until the popup is reopened.
Proposal
1. Resolution returns ordered candidates. getIconFromTokenLists becomes a
collector: every matching icon URL across all enabled lists, deduped, in list
order. Order decides try-order, not truth. (#2993 already wrote this piece as
getIconCandidatesFromTokenLists.) Build the candidate map with a single pass
over the lists — Map<"code:issuer" | contract, string[]> — so per-asset
resolution is O(1) rather than a walk; today's shape is O(A·N) with a regex
compiled inside the inner record loop, and indexing makes the whole pass
O(N + A).
2. AssetIcon walks the candidates. onError advances an index instead of
latching hasError. The broken-image glyph appears only after the last
candidate fails, and the first URL that fires onLoad is what gets cached.
3. Refresh cached icons against the lists on a TTL. Read from the cache and
render exactly as today. Separately, if the refresh TTL has expired:
- Load the asset lists (reusing
cachedTokenListswhen the session already has
them) and compute the candidate URLs for each cached asset. - If the cached URL is still among that asset's candidates, leave it alone.
- If the candidates differ — including where the cached URL came from the TOML
and a list has since started carrying the asset — walk them in order and load
each until one succeeds. The first that loads replaces the cached entry. - For an asset no enabled list carries, re-resolve through the issuer TOML:
one batched/ledger-key/accountscall covering every such issuer, then the
TOML fetches in parallel. A newly listed image replaces the cached entry; a
failed fetch, unreachable domain, or TOML with no image is a no-op. - Reset the TTL.
Suggested TTL: 7 days, matching the <storageKey>_date convention in
background/helpers/cachedFetch.ts. One scalar key beside the icon map — an
absent value reads as expired, so existing installs refresh on first run. No
entry-shape change, no migration.
Mechanically this is one change to the pass-2 guard:
if (Object.keys(assetsWithoutIcons).length > 0 || refreshDue)
The balance-change guards upstream stay as they are. Because the
previous-balances ref is per-mount and the popup remounts on every open, that
guard passes once per popup open — so the TTL gets its chance without any new
alarm, service-worker timer, or trigger surface.
Constraints
Each is worth a test.
- Prefer a stale icon over no icon. No candidates, none loaded, TOML fetch
failed, TOML lists no image — in all of them, keep what is cached. - The render path never waits. The cache read stays synchronous: a cache hit
renders immediately, with no list fetch. The refresh runs in the existing
async post-render pass and swaps a replaced URL in afterward. - The swap has to survive the memo.
shouldAssetIconSkipUpdate
comparesassetIcons,isSuspiciousandisMalicious— noticon. If the
prop carrying the candidates is not in the comparator, the refresh resolves
correctly and renders nothing, and the whole mechanism is silently inert. - Loading a candidate is confined to the refresh. Nothing probes a URL ahead
of render — that shape was explored in #2993 and rejected. The only
load-before-adopt is refresh step 3: after render, at most once per TTL, and
only for assets whose candidate set actually changed. It is needed because
adopting optimistically risks replacing a working icon with a broken one. - The refresh honours source precedence. A TOML lookup happens only for
assets no enabled list carries; an asset the lists answer must never trigger a
ledger-key or TOML request, on any path.
Source precedence
getAssetIcons already prefers the lists. Two places do not:
- Sign-transaction resolves TOML before the lists —
getIconUrlFromIssuerfirst,
reaching the lists only on a miss, and again in the second branch at
:276.
Paying two round trips for assets already answerable in memory. Flip to match
every other surface. retryAssetIconconsults only the TOML, abandoning the preferred source
the moment an icon fails. Replaced here by the candidate walk, which is
list-first by construction.
TOML is resolved lazily, only once the list candidates are exhausted — never
fetched merely to build a candidate list, which would put two round trips per
asset on the resolution path.
The refresh upgrades TOML-derived entries to list URLs. Such a URL is by
definition not among the list candidates, so once a list starts carrying the
asset the refresh adopts one. This falls out of the refresh rule with no special
case and is how list-preference holds over time rather than only at first
resolution — do not optimize by skipping TOML-derived entries.
The recurring fan-out to issuer-controlled domains is an accepted tradeoff; the
TTL length is the lever if it ever matters.
Surfaces
The account view, asset search, sign-transaction rows and history rows resolve
icons three different ways today, and search renders list URLs directly,
bypassing the icon cache entirely — so a picker and the account list can
disagree within a single session. All four should share one resolution path:
same candidates, same fallback, same cache.
Cost
- In-memory: the three default lists total ~148 records. Per-asset
resolution today is O(A·N); indexed, the whole pass is O(N + A). - Network, steady state: unchanged. The cache read serves every render.
- Network, refresh tick: ~54 KB across the three default lists plus the
SEP-0042 schema, sub-second in parallel, off the critical path, at most once
per TTL window. Plus one image load per asset whose candidates changed
(normally none), and for assets no list carries, one batched ledger-key call
plus a parallel TOML fetch each.
Adjacent cleanup
Contract matching uses new RegExp(contractId, "i")
where a case-insensitive equality check is meant — currently a substring match,
compiled once per record inside the inner loop. Same function, worth fixing
while it is open.
Acceptance criteria
- An asset carried by two lists, where the higher-priority list's URL does not
load, renders the second list's icon rather than the broken-image glyph. - That fallback adds no network request before first paint; a cache hit still
renders at current speed. - An asset whose list entry URL changes upstream picks up the new URL within
one TTL window, without the icon blanking in the meantime. - An asset dropped from every list keeps rendering its cached icon.
- A refresh in which no new candidate loads leaves the cached icon in place.
- The refresh issues no ledger-key or TOML request for any asset an enabled
list carries, and at most one batched ledger-key call in total. - An asset no list carries adopts a new icon when its issuer's TOML lists a
different one. - That same asset keeps its cached icon when the TOML fetch fails, the domain
is unreachable, or the TOML no longer lists an image. - An asset whose icon was TOML-derived adopts a list URL once any enabled list
starts carrying it. - Sign-transaction resolves an asset the lists carry without issuing a
ledger-key or TOML request. - A URL that fails after a successful render recovers on the next candidate
without requiring the popup to be reopened.
Related: #2994 (ordering fix this builds on), #2993 (probe approach,
rejected), #2992 (proposes expiring the cache instead; recommend closing as
superseded).
- Dominant language
- TypeScript
- Stars
- 122
- Forks
- 62
- Avg merge
- 4d 19h
- Merged PRs (30d)
- 41
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from stellar/freighter
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 2 days
-
Write the banner publishing guidePossibly taken @aristidesstaffieri claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
stellar/freighter#3152 · 1 assignee ·
Maintainers usually reply within 2 days
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 2 days
-
Dont call blockaid on empty token listMay be free again A pull request for this issue was closed without being merged. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 2 days
-
follow-up
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 2 days
All issues in stellar/freighter
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
zabuton-app/meguri#875 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 86/100
iruzen-dono/workless#117 ·
Maintainers usually reply within 1 day
-
area:api area:web wave wave:trivial
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
vetro-protocol/vetro-monorepo#1321 ·
Maintainers usually reply within 1 day