Skip to content

Align transaction sync asset prefetch#529

Merged
0xh3rman merged 1 commit into
mainfrom
align-transaction-sync-assets
Jun 18, 2026
Merged

Align transaction sync asset prefetch#529
0xh3rman merged 1 commit into
mainfrom
align-transaction-sync-assets

Conversation

@0xh3rman

@0xh3rman 0xh3rman commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Problem

Opening Activity after a transaction could crash with SQLITE_CONSTRAINT_FOREIGNKEY on the balances -> asset foreign key. Android transaction sync called ensureWalletAssetsenableAssetlinkAssetToWallet(visible = true), inserting a balance row for every transaction-associated asset. When prefetchAssets was partial (the assets API returned fewer/no assets, e.g. on failure), the asset row was never materialized, so the balance insert violated the FK.

This also diverged from iOS behaviorally: enabling with visible = true auto-showed transaction tokens in the wallet list, whereas iOS only stores them hidden.

Fix

Mirror iOS TransactionsService.prefetchAssetsAssetsService.addBalancesIfMissing(newAssets) instead of ensuring/enabling wallet assets:

  • PrefetchAssets.prefetchAssets now returns the asset ids it newly persisted.
  • Transaction sync inserts a hidden (isVisible = false) balance row only for those newly prefetched assets, via AssetsRepository.addBalancesIfMissing.
  • The insert is FK-safe: addBalancesIfMissing filters to assets that exist locally — INSERT OR IGNORE resolves a primary-key conflict but does not suppress the balances -> asset foreign-key violation.

Net result: transaction-associated assets are tracked but stay hidden until the user enables them, matching iOS, and the crash path (enabling unmaterialized assets) is removed.

Verification

  • ./gradlew :data:coordinators:testDebugUnitTest --tests "*SyncTransactionsImplTest" --tests "*PrefetchAssetsImplTest" --tests "*EnsureWalletAssetsImplTest"
  • ./gradlew :data:repositories:testDebugUnitTest --tests "*AssetsRepositoryTest.addBalancesIfMissing_insertsHiddenBalanceOnlyForExistingAssets"
  • ./gradlew :app:testFdroidDebugUnitTest --tests "*NotificationNavigationTest"
  • ./gradlew :data:coordinators:lintDebug :data:repositories:lintDebug

@0xh3rman 0xh3rman requested review from DRadmir and gemdev111 June 17, 2026 14:06
@0xh3rman 0xh3rman force-pushed the align-transaction-sync-assets branch from 17bb9a1 to 75d5348 Compare June 17, 2026 23:30
@0xh3rman 0xh3rman merged commit 7bb1eab into main Jun 18, 2026
2 checks passed
@0xh3rman 0xh3rman deleted the align-transaction-sync-assets branch June 18, 2026 00:02
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.

3 participants