Skip to content

Conversation

@piyalbasu
Copy link
Contributor

@piyalbasu piyalbasu commented Oct 15, 2025

Closes #2309

While testing perf improvements, I noticed something interesting: I get highly variable response times for /account-balances on Mainnet, but it's fairly consistent (and fast) on Testnet. Upon further investigation, it looks like adding the Blockaid status in Freighter BE is actually to blame here. Blockaid scans can sometimes a long time (adding up to several seconds sometimes), even when the list of assets remain static.

My suggestion here is to treat blockaid scans like we're treating other ancillary information like account history and icons: let's remove it from the critical path in Account and simply append it afterwards.

In this PR, the initial call to /account-balances includes a is_scan_skipped flag that will return just account balances. Once the UI is already rendered, we will then make the more expensive call to /account-balances that includes our Blockaid statuses.

Why make a 2nd call to /account-balances rather than just remove the automatic scanning in /account-balances and add the Blockaid results ourselves?

  1. For backwards compatibility with older versions of Freighter and for Freighter Mobile, I want to only change /account-balances behavior by intentionally passing a flag. This approach allows that

  2. I think it's still valuable to have an all-in-one response that contains both balances + blockaid scan results. For ex, when we poll for balance updates, it's useful to get all the info in one shot. In this scenario, we're much less concerned with a slightly longer response time as the UI is already usable.

  3. This continues to centralize the logic for merging Blockaid scan results with account-balances in Freighter BE instead of duplicating it across client UI's

Companion BE PR: stellar/freighter-backend#274

@piyalbasu
Copy link
Contributor Author

piyalbasu commented Oct 16, 2025

In this video, I'm connected to the Freighter BE dev instance. I do a few quick close and opens to give a taste of what the loading time generally looks like with the improvement from this PR. I am loading balances without the Blockaid scan and then immediately making an async call to get the Blockaid scan results. Doing some tests, I'm getting the initial /account-balances to load in around 500-900ms without the Blockaid warning while the subsequent call with the Blockaid results can take anywhere from 1.5 - 2.5s!

One UX concession we are making here is that the Blockaid warning icon pops in after the UI has already loaded. (You can see this at the end of the video). @sdfcharles Is this a concession you're willing to make for these perf gainz? IMO, users holding malicious assets is probably a small subset of our users

Screen.Recording.2025-10-16.at.4.26.29.PM.mov

@piyalbasu
Copy link
Contributor Author

For comparison, here's what is currently in production:

Screen.Recording.2025-10-16.at.4.27.16.PM.mov

@piyalbasu piyalbasu marked this pull request as ready for review October 16, 2025 20:33
@sdfcharles
Copy link

In this video, I'm connected to the Freighter BE dev instance. I do a few quick close and opens to give a taste of what the loading time generally looks like with the improvement from this PR. I am loading balances without the Blockaid scan and then immediately making an async call to get the Blockaid scan results. Doing some tests, I'm getting the initial /account-balances to load in around 500-900ms without the Blockaid warning while the subsequent call with the Blockaid results can take anywhere from 1.5 - 2.5s!

One UX concession we are making here is that the Blockaid warning icon pops in after the UI has already loaded. (You can see this at the end of the video). @sdfcharles Is this a concession you're willing to make for these perf gainz? IMO, users holding malicious assets is probably a small subset of our users

Screen.Recording.2025-10-16.at.4.26.29.PM.mov

@piyalbasu love the speed improvement! yes defs willing to have the icons pop in after if this improves load time 🙏


if (isMainnetNetwork) {
try {
const balancesResult = await fetchBalances(
Copy link
Contributor

Choose a reason for hiding this comment

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

So it seems like the reason to call fetch balances again is for convenience. We only need to scan the assets at this point but then you would have to merge them into the balances or change the schema that expects it that way in the view. It's probably worth a comment explaining this since it's unexpected to call the same endpoint twice in a row, wdyt?.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call! I'll add.

And yes, this is mostly for convenience: we have to make an API call anyway for the scan, so may as well as return the fully formed balances with scan results

@piyalbasu piyalbasu merged commit c50cbc1 into release/5.36.0 Oct 17, 2025
3 checks passed
@piyalbasu piyalbasu deleted the feature/fetch-scanned-status-async branch October 17, 2025 15:49
piyalbasu added a commit that referenced this pull request Nov 24, 2025
* Feature/move history fetch to bg (#2273)

* upgrade to yarn 2 and use resolutions to block vulnerable package versions (#2239)

* upgrade to yarn 2 and use resolutions to block vulnerable package versions

* rm deprecated .yarnrc

* rm yarnpath

* try committing yarn binary to repo

* try corepack enable for gha

* update run tests cmd

* rm yarnpath

* rm npm i yarn

* update all pipelines

* rm superfluous history types

* ensure invoke host function tx shows contract parameters (#2243)

* ensure invoke host function tx shows contract parameters

* add test for fallback if contract spec retrieval fails

* Bugfix/rm auth param names (#2244)

* ensure invoke host function tx shows contract parameters

* add test for fallback if contract spec retrieval fails

* do not show contract parameters for authorizations

* add tests for create contract v1 and invoke contract

* add issuer for changeTrust op (#2246)

* add issuer for changeTrust op

* programmatically disable overflow:hidden when copying a value

* Revert "add issuer for changeTrust op (#2246)" (#2247)

This reverts commit 19c8a68.

* Bugfix/add issuer for changetrust (#2249)

* ensure invoke host function tx shows contract parameters

* add test for fallback if contract spec retrieval fails

* do not show contract parameters for authorizations

* add tests for create contract v1 and invoke contract

* add issuer for changeTrust op

* programmatically disable overflow:hidden when copying a value

* cache account balances and poll for updates

* fix CI tests

* rm `force:true` which was causing action to happen too fast

* do a fresh balance fetch on account/network change

* first pass at async history

* pr comments

* allow for history caching

* add more sentry tracking for Account and Wallets views (#2268)

* add more sentry tracking for Account and Wallets views

* adding more sentry reporting

* gracefully degrade on errors from Blockaid (#2269)

* gracefully degrade on errors from Blockaid

* should not be necessary to skip dapp scanning on custom network

* rm extra dep

* add a test for persisting configurations in the send flow (#2271)

* add a test for persisting configurations in the send flow

* rm logs and update muxed acct; lower xlm payment

* rm slow loading simulation

* handle missing scan-tx result; add disabled state for Confirm Anyway (#2272)

* handle missing scan-tx result; add disabled state for Confirm Anyway

* assertions to show correct confirm button on Blockaid error

* add cache for balances to ensure we do a fresh lookup when needed (#2275)

* add cache for balances to ensure we do a fresh lookup when needed

* add try...catch to token-prices polling

* rm log

* only dispatch saveBalancesForAccount when fresh data has been fetched

* adjust test to wait for UI change

* replace yarn setup with just yarn

* rm unnecessary return

* clear token details on redux clear action

* make history row construction async and check for redux state for updates

* add tests for assetdetails

* increase timeout for flakey test

* pr comments

* refresh account history every time account balances refresh

* check for updated appdata before showing password modal (#2300)

* check for updated appdata before showing password modal

* update error msg

* rm unused redirect logic

* stringify errors rather than using `cause` (#2302)

* Feature/move icons to own hook (#2308)

* move get icons out of critical path; rely on background's cache

* add tests and comments

* add comment

* add comment

* only dispatch if we have cached icons

* PR comments

* skip blockaid scan on first fetch of account-balances (#2310)

* skip blockaid scan on first fetch of account-balances

* rm stub change

* rm more stubs

* rm log

* add comments and update boolean naming

* Dropdown menu option to copy wallet address (#2316)

* add button to copy address from dropdown

* Added translations

* revert translation file changes

* revert translation file changes

* Added translations

* revert changes to translation files

* move copy address button to first dropdown position

* scroll on long strings; pretty print json (#2320)

* scroll on long strings; pretty print json

* rm log

* add correct snapshot for json message

* rm log

* finish comment

* add error case for JSON

* don't use carat for lib

* update yarn.lock

* move scrollbar to btm of container; reduce json font size

* update snapshot

* re-searching so should abort any in flight API requests (#2323)

* re-searching so should abort any in flight API requests

* add comment

* fix test name

* make test more reliable

* add check for correct search results

* fix jest locator

* [FEATURE] new send/swap navigation flow (#2353)

* adds SelectionTile and AddressTile, updates nav flows to match updates. Adds query parameter for default values in send flow

* Added translations

* adds address tile and uses it in swap flow, tweaks selection tile styles

* adds unit tests for new tile components

* Added translations

* updates swap navigation flow to match updates, updates tests flows to match

* updates back icon for send and swap steps, fixes bad test references

* tweaks locator in address tile tests

* adds store state to asset tile tests, removes asset icon mock

* updates SelectionTile prop name, adds isSuspicious prop for AssetTile

* adds placeholder value in TokenList for missing token USD value

* uses real IdenticonImg in address tile unit tests

* adds query param validation for send and swap flow

* Update extension/src/popup/views/SendPayment/index.tsx

Co-authored-by: Cássio Marcos Goulart <[email protected]>

* adds missing import

* adds class for tile icon

---------

Co-authored-by: Cássio Marcos Goulart <[email protected]>

* [FEATURE] adds send and swap buttons to asset detail view (#2351)

* adds send and swap buttons to asset detail view

* uses secondary button styles

* removes run snapshots job (#2355)

* release/5.35.4 (#2354)

* upgrade to ledger-hq/hw-transport-webhid (#2350)

* upgrade to ledger-hq/hw-transport-webhid

* add tests

* add ledger support for new trustline flow (#2352)

* upgrade to ledger-hq/hw-transport-webhid

* add ledger support for new trustline flow

* only re-fetch balances if we were successful

* test for fetching balances on success

* add reset spys

* adjust spacing at top of hw wallet modal

* Now that `Done` button properly shows, click it in tests (#2356)

* skip flakey test

* skip flakey test

* renames local vars to follow convention

* adds tests for LP share and tweaks LP title

* adds links with query params for asset detail CTAs

---------

Co-authored-by: Piyal Basu <[email protected]>

* only fetch asset list data if needed (#2369)

* only fetch asset list data if needed

* correctly show icon loading state

* [BUG] SAC token management improvements (#2374)

* adds SAC detection when changing trust in the add and remove token flows

* updates arg signature for isAssetSac

* Feature/cache token prices (#2373)

* cache token prices and batch loading wallets

* use similar methodology for token price and account balance caching

* fix loading state trigger

* fix tests

* use helper for cache clearing

* set isFetchingTokenPrices to false in catch handler

* rollback error change

* load backend settings async on Account view (#2381)

* load backend settings async on Account view

* rm console.logs

* Feature/use ledger key for home domains (#2363)

* use ledger-key/accounts endpoint for home domains

* fix tests

* create generic ledger key account helper; add tests

* rm unneeded data-test prop

* rm unused import

* [CHORE] git process updates (#2361)

* moves the add translations hook to the pre commit stage, removes standalone translations commit

* adds script to update app version, removes version update from submit production action, adds update version step to test run action for release branches

* removes version input, now uses package version

* fetch asset domains in one calls

* fix tests

* cache home domains while iterating over account history rows

* fitler non-G keys

* rm .only

* fix test param

* PR comments

---------

Co-authored-by: aristides <[email protected]>

* update version numbers for release

* rm unnecessary calls to make flows even faster (#2391)

* makes send swap buttons stay in the container in full screen mode (#2392)

* makes send swap buttons stay in the container in full screen mode

* add a pause to make sure flakey e2e test has time to save changes

* use redux selector for allAccounts to properly update rename (#2403)

* use redux selector for allAccounts to properly update rename

* add longer timeout for flakey btn

* Add docs for 5.36.0 (#2408)

---------

Co-authored-by: leofelix077 <[email protected]>
Co-authored-by: aristides <[email protected]>
Co-authored-by: Cássio Marcos Goulart <[email protected]>
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.

4 participants