Skip to content
This repository was archived by the owner on Jul 31, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snap-tron-wallet.git"
},
"source": {
"shasum": "tSxhnKoJe+iTI1HJ13ENq81vPK99Q12rj7owcUCpqxQ=",
"shasum": "bTXn+pVsNZSewtiTkc7urDjf8QG92UbjkqeKn3Wz4HI=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
53 changes: 50 additions & 3 deletions packages/snap/src/services/accounts/AccountsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import { createPrefixedLogger, type ILogger } from '../../utils/logger';
import { DerivationPathStruct } from '../../validation/structs';
import type { AssetsService } from '../assets/AssetsService';
import type { ConfigProvider } from '../config';
import { MigrationStage } from '../migration/stage';
import type { TronAssetsControllerAdapter } from '../migration/TronAssetsControllerAdapter';
import type { TransactionsService } from '../transactions/TransactionsService';

/**
Expand Down Expand Up @@ -110,27 +112,32 @@ export class AccountsService {

readonly #snapClient: SnapClient;

readonly #tronAssetsControllerAdapter: TronAssetsControllerAdapter;

constructor({
accountsRepository,
configProvider,
logger,
assetsService,
snapClient,
transactionsService,
tronAssetsControllerAdapter,
}: {
accountsRepository: AccountsRepository;
configProvider: ConfigProvider;
logger: ILogger;
assetsService: AssetsService;
snapClient: SnapClient;
transactionsService: TransactionsService;
tronAssetsControllerAdapter: TronAssetsControllerAdapter;
}) {
this.#logger = createPrefixedLogger(logger, '[🔑 AccountsService]');
this.#configProvider = configProvider;
this.#accountsRepository = accountsRepository;
this.#assetsService = assetsService;
this.#transactionsService = transactionsService;
this.#snapClient = snapClient;
this.#tronAssetsControllerAdapter = tronAssetsControllerAdapter;
}

/**
Expand Down Expand Up @@ -509,11 +516,51 @@ export class AccountsService {
}),
);

const assets = assetResponses.flatMap((response) =>
response.status === 'fulfilled' ? response.value : [],
const synchronizedAssets = await Promise.all(
assetResponses.map(async (response, index) => {
if (response.status !== 'fulfilled') {
return { assets: [], shouldPersist: false, combination: undefined };
}

const combination = combinations[index];

if (!combination) {
return { assets: [], shouldPersist: false, combination: undefined };
}

const { scope } = combination;
const stage =
await this.#tronAssetsControllerAdapter.getMigrationStage(scope);

if (stage >= MigrationStage.ReadAssetsControllerOnly) {
this.#logger.info(
'Asset tracking and persistence disabled for controller-only stage',
{ scope, stage },
);
return {
assets: response.value,
shouldPersist: false,
combination: { ...combination, stage },
};
}

return {
assets: response.value,
shouldPersist: true,
combination: { ...combination, stage },
};
}),
);
const assets = synchronizedAssets.flatMap(
({ assets: responseAssets }) => responseAssets,
);
const hasPersistableScope = synchronizedAssets.some(
({ shouldPersist }) => shouldPersist,
);

await this.#assetsService.saveMany(assets);
if (hasPersistableScope || combinations.length === 0) {
await this.#assetsService.saveMany(assets);
}
}

async synchronizeTransactions(accounts: TronKeyringAccount[]): Promise<void> {
Expand Down