Align transaction sync asset prefetch#529
Merged
Merged
Conversation
gemdev111
approved these changes
Jun 17, 2026
DRadmir
approved these changes
Jun 17, 2026
17bb9a1 to
75d5348
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Opening Activity after a transaction could crash with
SQLITE_CONSTRAINT_FOREIGNKEYon thebalances -> assetforeign key. Android transaction sync calledensureWalletAssets→enableAsset→linkAssetToWallet(visible = true), inserting a balance row for every transaction-associated asset. WhenprefetchAssetswas 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 = trueauto-showed transaction tokens in the wallet list, whereas iOS only stores them hidden.Fix
Mirror iOS
TransactionsService.prefetchAssets→AssetsService.addBalancesIfMissing(newAssets)instead of ensuring/enabling wallet assets:PrefetchAssets.prefetchAssetsnow returns the asset ids it newly persisted.isVisible = false) balance row only for those newly prefetched assets, viaAssetsRepository.addBalancesIfMissing.addBalancesIfMissingfilters to assets that exist locally —INSERT OR IGNOREresolves a primary-key conflict but does not suppress thebalances -> assetforeign-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