From 250394922f8aa572ce7e125de7db7a0f4c08b4e9 Mon Sep 17 00:00:00 2001 From: Ulisses Ferreira Date: Fri, 31 Jul 2026 15:42:51 +0100 Subject: [PATCH 1/6] refactor(tron-wallet-snap): move handlers into dedicated folders Pure organizational move with import path updates only. No AssetsService API renames or behavior changes. --- packages/tron-wallet-snap/src/context.ts | 8 ++-- .../src/handlers/{ => assets}/assets.ts | 6 +-- .../handlers/{ => cronjob}/cronjob.test.tsx | 34 +++++++-------- .../src/handlers/{ => cronjob}/cronjob.tsx | 42 +++++++++---------- .../handlers/{ => keyring}/keyring-types.ts | 0 .../handlers/{ => keyring}/keyring.test.ts | 18 ++++---- .../src/handlers/{ => keyring}/keyring.ts | 36 ++++++++-------- .../handlers/{ => user-input}/userInput.ts | 12 +++--- .../confirmation/ConfirmationHandler.test.ts | 2 +- .../confirmation/ConfirmationHandler.ts | 2 +- .../src/services/send/SendService.test.ts | 2 +- .../src/services/send/SendService.ts | 2 +- .../services/staking/StakingService.test.ts | 2 +- .../src/services/wallet/README.md | 4 +- .../src/services/wallet/WalletService.test.ts | 2 +- .../src/services/wallet/WalletService.ts | 2 +- .../views/ConfirmSignMessage/render.test.tsx | 2 +- .../ConfirmSignTransaction.test.tsx | 2 +- .../ConfirmSignTransaction/render.test.tsx | 2 +- .../views/ConfirmSignTransaction/render.tsx | 2 +- .../ConfirmTransactionRequest/render.test.tsx | 2 +- .../ConfirmTransactionRequest/render.tsx | 2 +- .../src/utils/executeOnChainActions.ts | 2 +- .../src/validation/keyring-structs.test.ts | 2 +- .../src/validation/structs.ts | 2 +- 25 files changed, 96 insertions(+), 96 deletions(-) rename packages/tron-wallet-snap/src/handlers/{ => assets}/assets.ts (90%) rename packages/tron-wallet-snap/src/handlers/{ => cronjob}/cronjob.test.tsx (96%) rename packages/tron-wallet-snap/src/handlers/{ => cronjob}/cronjob.tsx (92%) rename packages/tron-wallet-snap/src/handlers/{ => keyring}/keyring-types.ts (100%) rename packages/tron-wallet-snap/src/handlers/{ => keyring}/keyring.test.ts (97%) rename packages/tron-wallet-snap/src/handlers/{ => keyring}/keyring.ts (92%) rename packages/tron-wallet-snap/src/handlers/{ => user-input}/userInput.ts (83%) diff --git a/packages/tron-wallet-snap/src/context.ts b/packages/tron-wallet-snap/src/context.ts index 029ec8eb..db5c9641 100644 --- a/packages/tron-wallet-snap/src/context.ts +++ b/packages/tron-wallet-snap/src/context.ts @@ -7,12 +7,12 @@ import { TokenApiClient } from './clients/token-api/TokenApiClient'; import { TronHttpClient } from './clients/tron-http/TronHttpClient'; import { TrongridApiClient } from './clients/trongrid/TrongridApiClient'; import { TronWebFactory } from './clients/tronweb/TronWebFactory'; -import { AssetsHandler } from './handlers/assets'; +import { AssetsHandler } from './handlers/assets/assets'; import { ClientRequestHandler } from './handlers/clientRequest/clientRequest'; -import { CronHandler } from './handlers/cronjob'; -import { KeyringHandler } from './handlers/keyring'; +import { CronHandler } from './handlers/cronjob/cronjob'; +import { KeyringHandler } from './handlers/keyring/keyring'; import { RpcHandler } from './handlers/rpc/rpc'; -import { UserInputHandler } from './handlers/userInput'; +import { UserInputHandler } from './handlers/user-input/userInput'; import { AccountsRepository } from './services/accounts/AccountsRepository'; import { AccountsService } from './services/accounts/AccountsService'; import { AssetsRepository } from './services/assets/AssetsRepository'; diff --git a/packages/tron-wallet-snap/src/handlers/assets.ts b/packages/tron-wallet-snap/src/handlers/assets/assets.ts similarity index 90% rename from packages/tron-wallet-snap/src/handlers/assets.ts rename to packages/tron-wallet-snap/src/handlers/assets/assets.ts index d0d72324..f7cc5428 100644 --- a/packages/tron-wallet-snap/src/handlers/assets.ts +++ b/packages/tron-wallet-snap/src/handlers/assets/assets.ts @@ -9,9 +9,9 @@ import type { OnAssetsMarketDataResponse, } from '@metamask/snaps-sdk'; -import type { AssetsService } from '../services/assets/AssetsService'; -import type { ILogger } from '../utils/logger'; -import { createPrefixedLogger } from '../utils/logger'; +import type { AssetsService } from '../../services/assets/AssetsService'; +import type { ILogger } from '../../utils/logger'; +import { createPrefixedLogger } from '../../utils/logger'; export class AssetsHandler { readonly #logger: ILogger; diff --git a/packages/tron-wallet-snap/src/handlers/cronjob.test.tsx b/packages/tron-wallet-snap/src/handlers/cronjob/cronjob.test.tsx similarity index 96% rename from packages/tron-wallet-snap/src/handlers/cronjob.test.tsx rename to packages/tron-wallet-snap/src/handlers/cronjob/cronjob.test.tsx index f00cacc2..fd4123d9 100644 --- a/packages/tron-wallet-snap/src/handlers/cronjob.test.tsx +++ b/packages/tron-wallet-snap/src/handlers/cronjob/cronjob.test.tsx @@ -1,24 +1,24 @@ -import type { PriceApiClient } from '../clients/price-api/PriceApiClient'; -import type { SnapClient } from '../clients/snap/SnapClient'; -import type { TronHttpClient } from '../clients/tron-http/TronHttpClient'; -import type { TronWebFactory } from '../clients/tronweb/TronWebFactory'; +import type { PriceApiClient } from '../../clients/price-api/PriceApiClient'; +import type { SnapClient } from '../../clients/snap/SnapClient'; +import type { TronHttpClient } from '../../clients/tron-http/TronHttpClient'; +import type { TronWebFactory } from '../../clients/tronweb/TronWebFactory'; import { Network, TRACK_TX_INTERVAL, TRACK_TX_MAX_ATTEMPTS, -} from '../constants'; -import type { AccountsService } from '../services/accounts/AccountsService'; -import type { State, UnencryptedStateValue } from '../services/state/State'; -import { TransactionExpirationRefresherService } from '../services/transaction-expiration-refresher/TransactionExpirationRefresherService'; -import type { JsonTransactionRawData } from '../services/transaction-expiration-refresher/types'; -import type { TransactionScanService } from '../services/transaction-scan/TransactionScanService'; -import { SimulationStatus } from '../services/transaction-scan/types'; -import type { TransactionScanResult } from '../services/transaction-scan/types'; -import { FetchStatus } from '../types/snap'; -import { CONFIRM_SIGN_TRANSACTION_INTERFACE_NAME } from '../ui/confirmation/views/ConfirmSignTransaction/types'; -import type { ConfirmSignTransactionContext } from '../ui/confirmation/views/ConfirmSignTransaction/types'; -import type { ConfirmTransactionRequestContext } from '../ui/confirmation/views/ConfirmTransactionRequest/types'; -import type { ILogger } from '../utils/logger'; +} from '../../constants'; +import type { AccountsService } from '../../services/accounts/AccountsService'; +import type { State, UnencryptedStateValue } from '../../services/state/State'; +import { TransactionExpirationRefresherService } from '../../services/transaction-expiration-refresher/TransactionExpirationRefresherService'; +import type { JsonTransactionRawData } from '../../services/transaction-expiration-refresher/types'; +import type { TransactionScanService } from '../../services/transaction-scan/TransactionScanService'; +import { SimulationStatus } from '../../services/transaction-scan/types'; +import type { TransactionScanResult } from '../../services/transaction-scan/types'; +import { FetchStatus } from '../../types/snap'; +import { CONFIRM_SIGN_TRANSACTION_INTERFACE_NAME } from '../../ui/confirmation/views/ConfirmSignTransaction/types'; +import type { ConfirmSignTransactionContext } from '../../ui/confirmation/views/ConfirmSignTransaction/types'; +import type { ConfirmTransactionRequestContext } from '../../ui/confirmation/views/ConfirmTransactionRequest/types'; +import type { ILogger } from '../../utils/logger'; import { BackgroundEventMethod, CronHandler } from './cronjob'; /** diff --git a/packages/tron-wallet-snap/src/handlers/cronjob.tsx b/packages/tron-wallet-snap/src/handlers/cronjob/cronjob.tsx similarity index 92% rename from packages/tron-wallet-snap/src/handlers/cronjob.tsx rename to packages/tron-wallet-snap/src/handlers/cronjob/cronjob.tsx index 05b5d5a2..bcc30cbf 100644 --- a/packages/tron-wallet-snap/src/handlers/cronjob.tsx +++ b/packages/tron-wallet-snap/src/handlers/cronjob/cronjob.tsx @@ -1,29 +1,29 @@ import type { JsonRpcRequest } from '@metamask/snaps-sdk'; -import type { PriceApiClient } from '../clients/price-api/PriceApiClient'; -import type { SnapClient } from '../clients/snap/SnapClient'; -import type { TronHttpClient } from '../clients/tron-http/TronHttpClient'; -import type { Network } from '../constants'; -import { TRACK_TX_INTERVAL, TRACK_TX_MAX_ATTEMPTS } from '../constants'; -import type { TronKeyringAccount } from '../entities/keyring-account'; -import type { AccountsService } from '../services/accounts/AccountsService'; -import type { State, UnencryptedStateValue } from '../services/state/State'; -import type { TransactionExpirationRefresherService } from '../services/transaction-expiration-refresher/TransactionExpirationRefresherService'; +import type { PriceApiClient } from '../../clients/price-api/PriceApiClient'; +import type { SnapClient } from '../../clients/snap/SnapClient'; +import type { TronHttpClient } from '../../clients/tron-http/TronHttpClient'; +import type { Network } from '../../constants'; +import { TRACK_TX_INTERVAL, TRACK_TX_MAX_ATTEMPTS } from '../../constants'; +import type { TronKeyringAccount } from '../../entities/keyring-account'; +import type { AccountsService } from '../../services/accounts/AccountsService'; +import type { State, UnencryptedStateValue } from '../../services/state/State'; +import type { TransactionExpirationRefresherService } from '../../services/transaction-expiration-refresher/TransactionExpirationRefresherService'; import type { JsonTransactionRawData, TransactionRawData, -} from '../services/transaction-expiration-refresher/types'; -import { EXPIRED_TRANSACTION_SCAN } from '../services/transaction-scan/buildExpiredScanResult'; -import type { TransactionScanService } from '../services/transaction-scan/TransactionScanService'; -import { FetchStatus } from '../types/snap'; -import { ConfirmSignTransaction } from '../ui/confirmation/views/ConfirmSignTransaction/ConfirmSignTransaction'; -import { CONFIRM_SIGN_TRANSACTION_INTERFACE_NAME } from '../ui/confirmation/views/ConfirmSignTransaction/types'; -import type { ConfirmSignTransactionContext } from '../ui/confirmation/views/ConfirmSignTransaction/types'; -import { ConfirmTransactionRequest } from '../ui/confirmation/views/ConfirmTransactionRequest/ConfirmTransactionRequest'; -import { CONFIRM_TRANSACTION_INTERFACE_NAME } from '../ui/confirmation/views/ConfirmTransactionRequest/types'; -import type { ConfirmTransactionRequestContext } from '../ui/confirmation/views/ConfirmTransactionRequest/types'; -import type { ILogger } from '../utils/logger'; -import { createPrefixedLogger } from '../utils/logger'; +} from '../../services/transaction-expiration-refresher/types'; +import { EXPIRED_TRANSACTION_SCAN } from '../../services/transaction-scan/buildExpiredScanResult'; +import type { TransactionScanService } from '../../services/transaction-scan/TransactionScanService'; +import { FetchStatus } from '../../types/snap'; +import { ConfirmSignTransaction } from '../../ui/confirmation/views/ConfirmSignTransaction/ConfirmSignTransaction'; +import { CONFIRM_SIGN_TRANSACTION_INTERFACE_NAME } from '../../ui/confirmation/views/ConfirmSignTransaction/types'; +import type { ConfirmSignTransactionContext } from '../../ui/confirmation/views/ConfirmSignTransaction/types'; +import { ConfirmTransactionRequest } from '../../ui/confirmation/views/ConfirmTransactionRequest/ConfirmTransactionRequest'; +import { CONFIRM_TRANSACTION_INTERFACE_NAME } from '../../ui/confirmation/views/ConfirmTransactionRequest/types'; +import type { ConfirmTransactionRequestContext } from '../../ui/confirmation/views/ConfirmTransactionRequest/types'; +import type { ILogger } from '../../utils/logger'; +import { createPrefixedLogger } from '../../utils/logger'; export enum CronjobMethod { ContinuouslySynchronizeSelectedAccounts = 'onSynchronizeSelectedAccountsCronjob', diff --git a/packages/tron-wallet-snap/src/handlers/keyring-types.ts b/packages/tron-wallet-snap/src/handlers/keyring/keyring-types.ts similarity index 100% rename from packages/tron-wallet-snap/src/handlers/keyring-types.ts rename to packages/tron-wallet-snap/src/handlers/keyring/keyring-types.ts diff --git a/packages/tron-wallet-snap/src/handlers/keyring.test.ts b/packages/tron-wallet-snap/src/handlers/keyring/keyring.test.ts similarity index 97% rename from packages/tron-wallet-snap/src/handlers/keyring.test.ts rename to packages/tron-wallet-snap/src/handlers/keyring/keyring.test.ts index b3c68105..35a6f9d7 100644 --- a/packages/tron-wallet-snap/src/handlers/keyring.test.ts +++ b/packages/tron-wallet-snap/src/handlers/keyring/keyring.test.ts @@ -9,15 +9,15 @@ import { } from '@metamask/snaps-sdk'; import { bytesToBase64, bytesToHex, stringToBytes } from '@metamask/utils'; -import type { SnapClient } from '../clients/snap/SnapClient'; -import { Network } from '../constants'; -import type { TronKeyringAccount } from '../entities/keyring-account'; -import type { AccountsService } from '../services/accounts/AccountsService'; -import type { AssetsService } from '../services/assets/AssetsService'; -import type { ConfirmationHandler } from '../services/confirmation/ConfirmationHandler'; -import type { TransactionsService } from '../services/transactions/TransactionsService'; -import type { WalletService } from '../services/wallet/WalletService'; -import { mockLogger } from '../utils/mockLogger'; +import type { SnapClient } from '../../clients/snap/SnapClient'; +import { Network } from '../../constants'; +import type { TronKeyringAccount } from '../../entities/keyring-account'; +import type { AccountsService } from '../../services/accounts/AccountsService'; +import type { AssetsService } from '../../services/assets/AssetsService'; +import type { ConfirmationHandler } from '../../services/confirmation/ConfirmationHandler'; +import type { TransactionsService } from '../../services/transactions/TransactionsService'; +import type { WalletService } from '../../services/wallet/WalletService'; +import { mockLogger } from '../../utils/mockLogger'; import { KeyringHandler } from './keyring'; import { TronMultichainMethod } from './keyring-types'; diff --git a/packages/tron-wallet-snap/src/handlers/keyring.ts b/packages/tron-wallet-snap/src/handlers/keyring/keyring.ts similarity index 92% rename from packages/tron-wallet-snap/src/handlers/keyring.ts rename to packages/tron-wallet-snap/src/handlers/keyring/keyring.ts index 7864a0c6..0e6f63f5 100644 --- a/packages/tron-wallet-snap/src/handlers/keyring.ts +++ b/packages/tron-wallet-snap/src/handlers/keyring/keyring.ts @@ -34,20 +34,20 @@ import type { } from '@metamask/utils'; import { sortBy } from 'lodash'; -import type { SnapClient } from '../clients/snap/SnapClient'; -import { ESSENTIAL_ASSETS } from '../constants'; -import type { Network } from '../constants'; -import { asStrictKeyringAccount } from '../entities/keyring-account'; -import type { TronKeyringAccount } from '../entities/keyring-account'; -import type { AccountsService } from '../services/accounts/AccountsService'; -import type { CreateAccountOptions } from '../services/accounts/types'; -import type { AssetsService } from '../services/assets/AssetsService'; -import type { ConfirmationHandler } from '../services/confirmation/ConfirmationHandler'; -import type { TransactionsService } from '../services/transactions/TransactionsService'; -import type { WalletService } from '../services/wallet/WalletService'; -import { sanitizeSensitiveError } from '../utils/errors'; -import { createPrefixedLogger } from '../utils/logger'; -import type { ILogger } from '../utils/logger'; +import type { SnapClient } from '../../clients/snap/SnapClient'; +import { ESSENTIAL_ASSETS } from '../../constants'; +import type { Network } from '../../constants'; +import { asStrictKeyringAccount } from '../../entities/keyring-account'; +import type { TronKeyringAccount } from '../../entities/keyring-account'; +import type { AccountsService } from '../../services/accounts/AccountsService'; +import type { CreateAccountOptions } from '../../services/accounts/types'; +import type { AssetsService } from '../../services/assets/AssetsService'; +import type { ConfirmationHandler } from '../../services/confirmation/ConfirmationHandler'; +import type { TransactionsService } from '../../services/transactions/TransactionsService'; +import type { WalletService } from '../../services/wallet/WalletService'; +import { sanitizeSensitiveError } from '../../utils/errors'; +import { createPrefixedLogger } from '../../utils/logger'; +import type { ILogger } from '../../utils/logger'; import { CreateAccountOptionsStruct, DeleteAccountStruct, @@ -60,14 +60,14 @@ import { SignTransactionRequestStruct, TronKeyringRequestStruct, UuidStruct, -} from '../validation/structs'; -import type { TronWalletKeyringRequest } from '../validation/structs'; +} from '../../validation/structs'; +import type { TronWalletKeyringRequest } from '../../validation/structs'; import { validateOrigin, validateRequest, validateResponse, -} from '../validation/validators'; -import { BackgroundEventMethod } from './cronjob'; +} from '../../validation/validators'; +import { BackgroundEventMethod } from '../cronjob/cronjob'; import { TronMultichainMethod } from './keyring-types'; export class KeyringHandler implements Keyring { diff --git a/packages/tron-wallet-snap/src/handlers/userInput.ts b/packages/tron-wallet-snap/src/handlers/user-input/userInput.ts similarity index 83% rename from packages/tron-wallet-snap/src/handlers/userInput.ts rename to packages/tron-wallet-snap/src/handlers/user-input/userInput.ts index 4aadc48e..a90ce451 100644 --- a/packages/tron-wallet-snap/src/handlers/userInput.ts +++ b/packages/tron-wallet-snap/src/handlers/user-input/userInput.ts @@ -1,11 +1,11 @@ import type { InterfaceContext, UserInputEvent } from '@metamask/snaps-sdk'; -import type { SnapClient } from '../clients/snap/SnapClient'; -import { createEventHandlers as createSignMessageEvents } from '../ui/confirmation/views/ConfirmSignMessage/events'; -import { createEventHandlers as createSignTransactionEvents } from '../ui/confirmation/views/ConfirmSignTransaction/events'; -import { createEventHandlers as createTransactionConfirmationEvents } from '../ui/confirmation/views/ConfirmTransactionRequest/events'; -import { createPrefixedLogger } from '../utils/logger'; -import type { ILogger } from '../utils/logger'; +import type { SnapClient } from '../../clients/snap/SnapClient'; +import { createEventHandlers as createSignMessageEvents } from '../../ui/confirmation/views/ConfirmSignMessage/events'; +import { createEventHandlers as createSignTransactionEvents } from '../../ui/confirmation/views/ConfirmSignTransaction/events'; +import { createEventHandlers as createTransactionConfirmationEvents } from '../../ui/confirmation/views/ConfirmTransactionRequest/events'; +import { createPrefixedLogger } from '../../utils/logger'; +import type { ILogger } from '../../utils/logger'; export class UserInputHandler { readonly #logger: ILogger; diff --git a/packages/tron-wallet-snap/src/services/confirmation/ConfirmationHandler.test.ts b/packages/tron-wallet-snap/src/services/confirmation/ConfirmationHandler.test.ts index e7551f30..705559d7 100644 --- a/packages/tron-wallet-snap/src/services/confirmation/ConfirmationHandler.test.ts +++ b/packages/tron-wallet-snap/src/services/confirmation/ConfirmationHandler.test.ts @@ -6,7 +6,7 @@ import type { TronWebFactory } from '../../clients/tronweb/TronWebFactory'; import { KnownCaip19Id, Network, Networks, ZERO } from '../../constants'; import type { AssetEntity, ResourceAsset } from '../../entities/assets'; import type { TronKeyringAccount } from '../../entities/keyring-account'; -import { TronMultichainMethod } from '../../handlers/keyring-types'; +import { TronMultichainMethod } from '../../handlers/keyring/keyring-types'; import { getIconUrlForKnownAsset } from '../../ui/confirmation/utils/getIconUrlForKnownAsset'; import { render as renderConfirmSignTransaction } from '../../ui/confirmation/views/ConfirmSignTransaction/render'; import { render as renderConfirmTransactionRequest } from '../../ui/confirmation/views/ConfirmTransactionRequest/render'; diff --git a/packages/tron-wallet-snap/src/services/confirmation/ConfirmationHandler.ts b/packages/tron-wallet-snap/src/services/confirmation/ConfirmationHandler.ts index f90078d2..a246fa23 100644 --- a/packages/tron-wallet-snap/src/services/confirmation/ConfirmationHandler.ts +++ b/packages/tron-wallet-snap/src/services/confirmation/ConfirmationHandler.ts @@ -9,7 +9,7 @@ import { Networks, ZERO } from '../../constants'; import type { Network } from '../../constants'; import type { AssetEntity } from '../../entities/assets'; import type { TronKeyringAccount } from '../../entities/keyring-account'; -import { TronMultichainMethod } from '../../handlers/keyring-types'; +import { TronMultichainMethod } from '../../handlers/keyring/keyring-types'; import { TRX_IMAGE_SVG } from '../../static/tron-logo'; import { FetchStatus } from '../../types/snap'; import { getIconUrlForKnownAsset } from '../../ui/confirmation/utils/getIconUrlForKnownAsset'; diff --git a/packages/tron-wallet-snap/src/services/send/SendService.test.ts b/packages/tron-wallet-snap/src/services/send/SendService.test.ts index 1bd026a9..8702de9a 100644 --- a/packages/tron-wallet-snap/src/services/send/SendService.test.ts +++ b/packages/tron-wallet-snap/src/services/send/SendService.test.ts @@ -12,7 +12,7 @@ import { } from '../../constants'; import type { AssetEntity } from '../../entities/assets'; import { SendErrorCodes } from '../../handlers/clientRequest/types'; -import { BackgroundEventMethod } from '../../handlers/cronjob'; +import { BackgroundEventMethod } from '../../handlers/cronjob/cronjob'; import { mockLogger } from '../../utils/mockLogger'; import { TransactionExpirationRefresherService } from '../transaction-expiration-refresher/TransactionExpirationRefresherService'; import { SendService } from './SendService'; diff --git a/packages/tron-wallet-snap/src/services/send/SendService.ts b/packages/tron-wallet-snap/src/services/send/SendService.ts index 3e988e4f..f9f22e1e 100644 --- a/packages/tron-wallet-snap/src/services/send/SendService.ts +++ b/packages/tron-wallet-snap/src/services/send/SendService.ts @@ -15,7 +15,7 @@ import type { Network } from '../../constants'; import { Networks, TRACK_TX_INTERVAL, ZERO } from '../../constants'; import type { AssetEntity } from '../../entities/assets'; import { SendErrorCodes } from '../../handlers/clientRequest/types'; -import { BackgroundEventMethod } from '../../handlers/cronjob'; +import { BackgroundEventMethod } from '../../handlers/cronjob/cronjob'; import { toRawAmount, trxToSun } from '../../utils/conversion'; import { createPrefixedLogger } from '../../utils/logger'; import type { ILogger } from '../../utils/logger'; diff --git a/packages/tron-wallet-snap/src/services/staking/StakingService.test.ts b/packages/tron-wallet-snap/src/services/staking/StakingService.test.ts index 985a8366..ba4f770c 100644 --- a/packages/tron-wallet-snap/src/services/staking/StakingService.test.ts +++ b/packages/tron-wallet-snap/src/services/staking/StakingService.test.ts @@ -8,7 +8,7 @@ import { Network, } from '../../constants'; import type { TronKeyringAccount } from '../../entities/keyring-account'; -import { BackgroundEventMethod } from '../../handlers/cronjob'; +import { BackgroundEventMethod } from '../../handlers/cronjob/cronjob'; import { trxToSun } from '../../utils/conversion'; import { mockLogger } from '../../utils/mockLogger'; import type { AccountsService } from '../accounts/AccountsService'; diff --git a/packages/tron-wallet-snap/src/services/wallet/README.md b/packages/tron-wallet-snap/src/services/wallet/README.md index 507dcb6f..4da222a5 100644 --- a/packages/tron-wallet-snap/src/services/wallet/README.md +++ b/packages/tron-wallet-snap/src/services/wallet/README.md @@ -144,7 +144,7 @@ yarn test WalletService.test.ts ## Related Files -- `handlers/keyring.ts` - KeyringHandler that uses this service -- `handlers/keyring-types.ts` - Method and error type definitions +- `handlers/keyring/keyring.ts` - KeyringHandler that uses this service +- `handlers/keyring/keyring-types.ts` - Method and error type definitions - `validation/structs.ts` - Validation schemas - `services/confirmation/ConfirmationHandler.ts` - User confirmation handling diff --git a/packages/tron-wallet-snap/src/services/wallet/WalletService.test.ts b/packages/tron-wallet-snap/src/services/wallet/WalletService.test.ts index 02ce29c1..32fe424d 100644 --- a/packages/tron-wallet-snap/src/services/wallet/WalletService.test.ts +++ b/packages/tron-wallet-snap/src/services/wallet/WalletService.test.ts @@ -8,7 +8,7 @@ import type { TronKeyringAccount } from '../../entities/keyring-account'; import { TronMultichainErrors, TronMultichainMethod, -} from '../../handlers/keyring-types'; +} from '../../handlers/keyring/keyring-types'; import { mockLogger } from '../../utils/mockLogger'; import type { AccountsService } from '../accounts/AccountsService'; import { WalletService } from './WalletService'; diff --git a/packages/tron-wallet-snap/src/services/wallet/WalletService.ts b/packages/tron-wallet-snap/src/services/wallet/WalletService.ts index 168a10ba..ebfbbefb 100644 --- a/packages/tron-wallet-snap/src/services/wallet/WalletService.ts +++ b/packages/tron-wallet-snap/src/services/wallet/WalletService.ts @@ -9,7 +9,7 @@ import type { TronKeyringAccount } from '../../entities/keyring-account'; import { TronMultichainErrors, TronMultichainMethod, -} from '../../handlers/keyring-types'; +} from '../../handlers/keyring/keyring-types'; import { createPrefixedLogger } from '../../utils/logger'; import type { ILogger } from '../../utils/logger'; import { diff --git a/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmSignMessage/render.test.tsx b/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmSignMessage/render.test.tsx index ae7f5826..37b3f0de 100644 --- a/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmSignMessage/render.test.tsx +++ b/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmSignMessage/render.test.tsx @@ -4,7 +4,7 @@ import { bytesToBase64, stringToBytes } from '@metamask/utils'; import type { SnapClient } from '../../../../clients/snap/SnapClient'; import { Network } from '../../../../constants'; import type { TronKeyringAccount } from '../../../../entities/keyring-account'; -import { TronMultichainMethod } from '../../../../handlers/keyring-types'; +import { TronMultichainMethod } from '../../../../handlers/keyring/keyring-types'; import type { Preferences } from '../../../../types/snap'; import { render } from './render'; diff --git a/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmSignTransaction/ConfirmSignTransaction.test.tsx b/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmSignTransaction/ConfirmSignTransaction.test.tsx index 158199ba..af658109 100644 --- a/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmSignTransaction/ConfirmSignTransaction.test.tsx +++ b/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmSignTransaction/ConfirmSignTransaction.test.tsx @@ -1,6 +1,6 @@ import { Network } from '../../../../constants'; import type { TronKeyringAccount } from '../../../../entities/keyring-account'; -import { TronMultichainMethod } from '../../../../handlers/keyring-types'; +import { TronMultichainMethod } from '../../../../handlers/keyring/keyring-types'; import { TRANSACTION_TAPOS_EXPIRED } from '../../../../services/transaction-scan/isTransactionDeadlinePassedError'; import { SimulationStatus } from '../../../../services/transaction-scan/types'; import type { diff --git a/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmSignTransaction/render.test.tsx b/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmSignTransaction/render.test.tsx index 2a11d7db..0010b181 100644 --- a/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmSignTransaction/render.test.tsx +++ b/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmSignTransaction/render.test.tsx @@ -6,7 +6,7 @@ import { Network } from '../../../../constants'; import type { SnapExecutionContext } from '../../../../context'; import type { AssetEntity } from '../../../../entities/assets'; import type { TronKeyringAccount } from '../../../../entities/keyring-account'; -import { TronMultichainMethod } from '../../../../handlers/keyring-types'; +import { TronMultichainMethod } from '../../../../handlers/keyring/keyring-types'; import type { AssetsService } from '../../../../services/assets/AssetsService'; import type { FeeCalculatorService } from '../../../../services/send/FeeCalculatorService'; import type { diff --git a/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmSignTransaction/render.tsx b/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmSignTransaction/render.tsx index 8340ce50..cc06a17e 100644 --- a/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmSignTransaction/render.tsx +++ b/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmSignTransaction/render.tsx @@ -8,7 +8,7 @@ import type { Transaction } from 'tronweb/lib/esm/types'; import { Network, Networks, ZERO } from '../../../../constants'; import snapContext from '../../../../context'; import type { TronKeyringAccount } from '../../../../entities/keyring-account'; -import { BackgroundEventMethod } from '../../../../handlers/cronjob'; +import { BackgroundEventMethod } from '../../../../handlers/cronjob/cronjob'; import { EXPIRED_TRANSACTION_SCAN } from '../../../../services/transaction-scan/buildExpiredScanResult'; import type { TransactionScanResult } from '../../../../services/transaction-scan/types'; import { TRX_IMAGE_SVG } from '../../../../static/tron-logo'; diff --git a/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmTransactionRequest/render.test.tsx b/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmTransactionRequest/render.test.tsx index ad441bab..f318478b 100644 --- a/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmTransactionRequest/render.test.tsx +++ b/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmTransactionRequest/render.test.tsx @@ -7,7 +7,7 @@ import { import type { SnapClient } from '../../../../clients/snap/SnapClient'; import { Network } from '../../../../constants'; import type { AssetEntity } from '../../../../entities/assets'; -import { BackgroundEventMethod } from '../../../../handlers/cronjob'; +import { BackgroundEventMethod } from '../../../../handlers/cronjob/cronjob'; import type { State, UnencryptedStateValue, diff --git a/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmTransactionRequest/render.tsx b/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmTransactionRequest/render.tsx index 7e6bbf86..5e87a09f 100644 --- a/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmTransactionRequest/render.tsx +++ b/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmTransactionRequest/render.tsx @@ -6,7 +6,7 @@ import { Network } from '../../../../constants'; import snapContext from '../../../../context'; import type { AssetEntity } from '../../../../entities/assets'; import type { TronKeyringAccount } from '../../../../entities/keyring-account'; -import { BackgroundEventMethod } from '../../../../handlers/cronjob'; +import { BackgroundEventMethod } from '../../../../handlers/cronjob/cronjob'; import type { ComputeFeeResult } from '../../../../services/send/types'; import type { State, diff --git a/packages/tron-wallet-snap/src/utils/executeOnChainActions.ts b/packages/tron-wallet-snap/src/utils/executeOnChainActions.ts index 1911cf04..4c3e142a 100644 --- a/packages/tron-wallet-snap/src/utils/executeOnChainActions.ts +++ b/packages/tron-wallet-snap/src/utils/executeOnChainActions.ts @@ -4,7 +4,7 @@ import type { SnapClient } from '../clients/snap/SnapClient'; import type { TronWebFactory } from '../clients/tronweb/TronWebFactory'; import type { Network } from '../constants'; import type { TronKeyringAccount } from '../entities/keyring-account'; -import { BackgroundEventMethod } from '../handlers/cronjob'; +import { BackgroundEventMethod } from '../handlers/cronjob/cronjob'; import type { AccountsService } from '../services/accounts/AccountsService'; /** diff --git a/packages/tron-wallet-snap/src/validation/keyring-structs.test.ts b/packages/tron-wallet-snap/src/validation/keyring-structs.test.ts index 25bdf178..e4e656c8 100644 --- a/packages/tron-wallet-snap/src/validation/keyring-structs.test.ts +++ b/packages/tron-wallet-snap/src/validation/keyring-structs.test.ts @@ -2,7 +2,7 @@ import { assert, StructError } from '@metamask/superstruct'; import { bytesToBase64, bytesToHex, stringToBytes } from '@metamask/utils'; import { Network } from '../constants'; -import { TronMultichainMethod } from '../handlers/keyring-types'; +import { TronMultichainMethod } from '../handlers/keyring/keyring-types'; import { SignMessageRequestStruct, SignTransactionRequestStruct, diff --git a/packages/tron-wallet-snap/src/validation/structs.ts b/packages/tron-wallet-snap/src/validation/structs.ts index 093d05b3..2ce737cb 100644 --- a/packages/tron-wallet-snap/src/validation/structs.ts +++ b/packages/tron-wallet-snap/src/validation/structs.ts @@ -28,7 +28,7 @@ import { import { TronWeb } from 'tronweb'; import { Network } from '../constants'; -import { TronMultichainMethod } from '../handlers/keyring-types'; +import { TronMultichainMethod } from '../handlers/keyring/keyring-types'; import { MaximumResourceCaipAssetTypeStruct, NativeCaipAssetTypeStruct, From dab03e959b6052be48eea94b35aeb3e88293fcfd Mon Sep 17 00:00:00 2001 From: Ulisses Ferreira Date: Fri, 31 Jul 2026 15:43:19 +0100 Subject: [PATCH 2/6] refactor(tron-wallet-snap): rename AssetsService account asset readers Align public reader names with the final AssetsController-oriented API: getAccountAssets, getAccountAssetsByIDs, getAccountAssetByID. --- .../clientRequest/clientRequest.test.ts | 50 +++++++++---------- .../handlers/clientRequest/clientRequest.ts | 20 ++++---- .../src/services/assets/AssetsService.ts | 6 +-- .../confirmation/ConfirmationHandler.test.ts | 12 ++--- .../confirmation/ConfirmationHandler.ts | 2 +- .../src/services/send/SendService.test.ts | 40 +++++++-------- .../src/services/send/SendService.ts | 2 +- .../ConfirmSignTransaction/render.test.tsx | 8 +-- .../views/ConfirmSignTransaction/render.tsx | 2 +- 9 files changed, 71 insertions(+), 71 deletions(-) diff --git a/packages/tron-wallet-snap/src/handlers/clientRequest/clientRequest.test.ts b/packages/tron-wallet-snap/src/handlers/clientRequest/clientRequest.test.ts index 5719c0e7..76545f89 100644 --- a/packages/tron-wallet-snap/src/handlers/clientRequest/clientRequest.test.ts +++ b/packages/tron-wallet-snap/src/handlers/clientRequest/clientRequest.test.ts @@ -115,7 +115,7 @@ type WithClientRequestHandlerCallback = (payload: { Pick >; mockAssetsService: jest.Mocked< - Pick + Pick >; mockSendService: jest.Mocked< Pick< @@ -165,10 +165,10 @@ async function withClientRequestHandler( }; const mockAssetsService: jest.Mocked< - Pick + Pick > = { - getAssetsByAccountId: jest.fn(), - getAssetByAccountId: jest.fn(), + getAccountAssetsByIDs: jest.fn(), + getAccountAssetByID: jest.fn(), }; const mockSendService: jest.Mocked< @@ -304,7 +304,7 @@ describe('ClientRequestHandler', () => { } as unknown as jest.Mocked; mockAssetsService = { - getAssetsByAccountId: jest.fn(), + getAccountAssetsByIDs: jest.fn(), } as unknown as jest.Mocked; mockSendService = {} as unknown as jest.Mocked; @@ -736,7 +736,7 @@ describe('ClientRequestHandler', () => { mockTronWeb.trx.sign.mockResolvedValue(signedTransaction); // Mock available resources - mockAssetsService.getAssetsByAccountId.mockResolvedValue([ + mockAssetsService.getAccountAssetsByIDs.mockResolvedValue([ { rawAmount: '5000' }, // Bandwidth { rawAmount: '100000' }, // Energy ] as any); @@ -781,7 +781,7 @@ describe('ClientRequestHandler', () => { ).toHaveBeenCalledWith('TriggerSmartContract', expect.any(String)); // trx.sign is NOT called - fee computation uses unsigned transactions expect(mockTronWeb.trx.sign).not.toHaveBeenCalled(); - expect(mockAssetsService.getAssetsByAccountId).toHaveBeenCalledWith( + expect(mockAssetsService.getAccountAssetsByIDs).toHaveBeenCalledWith( TEST_ACCOUNT_ID, [Networks[scope].bandwidth.id, Networks[scope].energy.id], ); @@ -873,7 +873,7 @@ describe('ClientRequestHandler', () => { }; mockTronWeb.trx.sign.mockResolvedValue(signedTransaction); - mockAssetsService.getAssetsByAccountId.mockResolvedValue([ + mockAssetsService.getAccountAssetsByIDs.mockResolvedValue([ { rawAmount: '1000' }, // Bandwidth { rawAmount: '0' }, // Energy (not needed for native transfer) ] as any); @@ -966,7 +966,7 @@ describe('ClientRequestHandler', () => { }); // No resources available - mockAssetsService.getAssetsByAccountId.mockResolvedValue([ + mockAssetsService.getAccountAssetsByIDs.mockResolvedValue([ undefined, // No bandwidth asset undefined, // No energy asset ] as any); @@ -1490,7 +1490,7 @@ describe('ClientRequestHandler - signAndSendTransaction', () => { } as unknown as jest.Mocked; mockAssetsService = { - getAssetsByAccountId: jest.fn(), + getAccountAssetsByIDs: jest.fn(), } as unknown as jest.Mocked; mockSendService = {} as unknown as jest.Mocked; @@ -1762,7 +1762,7 @@ describe('ClientRequestHandler - onAmountInput', () => { ]; mockAccountsService.findById.mockResolvedValue(mockAccount); - mockAssetsService.getAssetsByAccountId.mockResolvedValue(mockAssets); + mockAssetsService.getAccountAssetsByIDs.mockResolvedValue(mockAssets); const result = await handler.handle(request); @@ -1820,7 +1820,7 @@ describe('ClientRequestHandler - onAmountInput', () => { ]; mockAccountsService.findById.mockResolvedValue(mockAccount); - mockAssetsService.getAssetsByAccountId.mockResolvedValue(mockAssets); + mockAssetsService.getAccountAssetsByIDs.mockResolvedValue(mockAssets); mockSendService.buildTransaction.mockResolvedValue(builtTransaction); mockFeeCalculatorService.computeFee.mockResolvedValue(mockFees); @@ -1892,7 +1892,7 @@ describe('ClientRequestHandler - onAmountInput', () => { ]; mockAccountsService.findById.mockResolvedValue(mockAccount); - mockAssetsService.getAssetsByAccountId.mockResolvedValue(mockAssets); + mockAssetsService.getAccountAssetsByIDs.mockResolvedValue(mockAssets); mockSendService.buildTransaction.mockResolvedValue(builtTransaction); mockFeeCalculatorService.computeFee.mockResolvedValue(mockFees); @@ -1943,7 +1943,7 @@ describe('ClientRequestHandler - onAmountInput', () => { ]; mockAccountsService.findById.mockResolvedValue(mockAccount); - mockAssetsService.getAssetsByAccountId.mockResolvedValue(mockAssets); + mockAssetsService.getAccountAssetsByIDs.mockResolvedValue(mockAssets); const result = await handler.handle(request); @@ -2004,7 +2004,7 @@ describe('ClientRequestHandler - onAmountInput', () => { ]; mockAccountsService.findById.mockResolvedValue(mockAccount); - mockAssetsService.getAssetsByAccountId.mockResolvedValue(mockAssets); + mockAssetsService.getAccountAssetsByIDs.mockResolvedValue(mockAssets); mockSendService.buildTransaction.mockResolvedValue(builtTransaction); mockFeeCalculatorService.computeFee.mockResolvedValue(mockFees); @@ -2094,10 +2094,10 @@ describe('ClientRequestHandler - computeStakeFee', () => { const nativeAssetId = Networks[scope].nativeToken.id; // Mock native balance and resources - mockAssetsService.getAssetByAccountId.mockResolvedValue({ + mockAssetsService.getAccountAssetByID.mockResolvedValue({ uiAmount: '100', } as AssetEntity); - mockAssetsService.getAssetsByAccountId.mockResolvedValue([ + mockAssetsService.getAccountAssetsByIDs.mockResolvedValue([ { rawAmount: '5000' }, // Bandwidth { rawAmount: '100000' }, // Energy ] as AssetEntity[]); @@ -2130,11 +2130,11 @@ describe('ClientRequestHandler - computeStakeFee', () => { 'ENERGY', 'TGJn1wnUYHJbvN88cynZbsAz2EMeZq73yx', ); - expect(mockAssetsService.getAssetByAccountId).toHaveBeenCalledWith( + expect(mockAssetsService.getAccountAssetByID).toHaveBeenCalledWith( TEST_ACCOUNT_ID, nativeAssetId, ); - expect(mockAssetsService.getAssetsByAccountId).toHaveBeenCalledWith( + expect(mockAssetsService.getAccountAssetsByIDs).toHaveBeenCalledWith( TEST_ACCOUNT_ID, [Networks[scope].bandwidth.id, Networks[scope].energy.id], ); @@ -2179,7 +2179,7 @@ describe('ClientRequestHandler - computeStakeFee', () => { } as any); // Account has only 5 TRX - mockAssetsService.getAssetByAccountId.mockResolvedValue({ + mockAssetsService.getAccountAssetByID.mockResolvedValue({ uiAmount: '5', } as AssetEntity); @@ -2237,7 +2237,7 @@ describe('ClientRequestHandler - confirmSend validation', () => { uiAmount: '100', rawAmount: '100000000', } as NativeAsset; - mockAssetsService.getAssetByAccountId.mockResolvedValue(mockAsset); + mockAssetsService.getAccountAssetByID.mockResolvedValue(mockAsset); // validateSend returns insufficient balance mockSendService.validateSend.mockResolvedValue({ @@ -2306,7 +2306,7 @@ describe('ClientRequestHandler - confirmSend validation', () => { uiAmount: '100', rawAmount: '100000000', } as NativeAsset; - mockAssetsService.getAssetByAccountId.mockResolvedValue(mockAsset); + mockAssetsService.getAccountAssetByID.mockResolvedValue(mockAsset); // validateSend returns insufficient balance to cover fee mockSendService.validateSend.mockResolvedValue({ @@ -2368,13 +2368,13 @@ describe('ClientRequestHandler - confirmSend validation', () => { uiAmount: '100', rawAmount: '100000000', } as NativeAsset; - mockAssetsService.getAssetByAccountId.mockResolvedValue(mockAsset); + mockAssetsService.getAccountAssetByID.mockResolvedValue(mockAsset); // validateSend returns valid. mockSendService.validateSend.mockResolvedValue({ valid: true }); // Mock the rest of the flow. - mockAssetsService.getAssetsByAccountId.mockResolvedValue([ + mockAssetsService.getAccountAssetsByIDs.mockResolvedValue([ { rawAmount: '1000' }, // Bandwidth { rawAmount: '50000' }, // Energy ] as any); @@ -2530,7 +2530,7 @@ describe('ClientRequestHandler - confirmSend validation', () => { } as any); // Asset not found - (mockAssetsService.getAssetByAccountId as jest.Mock).mockResolvedValue( + (mockAssetsService.getAccountAssetByID as jest.Mock).mockResolvedValue( null, ); diff --git a/packages/tron-wallet-snap/src/handlers/clientRequest/clientRequest.ts b/packages/tron-wallet-snap/src/handlers/clientRequest/clientRequest.ts index bca2223d..a897ba2b 100644 --- a/packages/tron-wallet-snap/src/handlers/clientRequest/clientRequest.ts +++ b/packages/tron-wallet-snap/src/handlers/clientRequest/clientRequest.ts @@ -370,7 +370,7 @@ export class ClientRequestHandler { const scope = chainId as Network; const [asset, nativeTokenAsset, bandwidthAsset, energyAsset] = - await this.#assetsService.getAssetsByAccountId(accountId, [ + await this.#assetsService.getAccountAssetsByIDs(accountId, [ assetId, Networks[scope].nativeToken.id, Networks[scope].bandwidth.id, @@ -483,7 +483,7 @@ export class ClientRequestHandler { }; } - const asset = await this.#assetsService.getAssetByAccountId( + const asset = await this.#assetsService.getAccountAssetByID( fromAccountId, assetId, ); @@ -527,7 +527,7 @@ export class ClientRequestHandler { /** * Get available Energy and Bandwidth from account assets. */ - this.#assetsService.getAssetsByAccountId(fromAccountId, [ + this.#assetsService.getAccountAssetsByIDs(fromAccountId, [ Networks[scope].bandwidth.id, Networks[scope].energy.id, ]), @@ -673,7 +673,7 @@ export class ClientRequestHandler { * Get available Energy and Bandwidth from account assets. */ const [bandwidthAsset, energyAsset] = - await this.#assetsService.getAssetsByAccountId(accountId, [ + await this.#assetsService.getAccountAssetsByIDs(accountId, [ Networks[scope].bandwidth.id, Networks[scope].energy.id, ]); @@ -728,7 +728,7 @@ export class ClientRequestHandler { const scope = Network.Mainnet; - const asset = await this.#assetsService.getAssetByAccountId( + const asset = await this.#assetsService.getAccountAssetByID( fromAccountId, Networks[scope].nativeToken.id, ); @@ -759,7 +759,7 @@ export class ClientRequestHandler { * Get available Energy and Bandwidth from account assets. */ const [bandwidthAsset, energyAsset] = - await this.#assetsService.getAssetsByAccountId(fromAccountId, [ + await this.#assetsService.getAccountAssetsByIDs(fromAccountId, [ Networks[scope].bandwidth.id, Networks[scope].energy.id, ]); @@ -804,7 +804,7 @@ export class ClientRequestHandler { const { accountId, assetId, value } = request.params; await this.#accountsService.findByIdOrThrow(accountId); - const asset = await this.#assetsService.getAssetByAccountId( + const asset = await this.#assetsService.getAccountAssetByID( accountId, assetId, ); @@ -851,7 +851,7 @@ export class ClientRequestHandler { const account = await this.#accountsService.findByIdOrThrow(fromAccountId); - const asset = await this.#assetsService.getAssetByAccountId( + const asset = await this.#assetsService.getAccountAssetByID( fromAccountId, assetId, ); @@ -913,7 +913,7 @@ export class ClientRequestHandler { const stakedAssetId = `${assetId}-staked-for-${purpose.toLowerCase()}`; await this.#accountsService.findByIdOrThrow(accountId); - const asset = await this.#assetsService.getAssetByAccountId( + const asset = await this.#assetsService.getAccountAssetByID( accountId, stakedAssetId, ); @@ -967,7 +967,7 @@ export class ClientRequestHandler { const account = await this.#accountsService.findByIdOrThrow(accountId); - const asset = await this.#assetsService.getAssetByAccountId( + const asset = await this.#assetsService.getAccountAssetByID( accountId, stakedAssetId, ); diff --git a/packages/tron-wallet-snap/src/services/assets/AssetsService.ts b/packages/tron-wallet-snap/src/services/assets/AssetsService.ts index 4675a349..a33f16e5 100644 --- a/packages/tron-wallet-snap/src/services/assets/AssetsService.ts +++ b/packages/tron-wallet-snap/src/services/assets/AssetsService.ts @@ -155,11 +155,11 @@ export class AssetsService { return caipAssetId.includes('swift:0/iso4217:'); } - async getAllAssetsByAccountId(accountId: string): Promise { + async getAccountAssets(accountId: string): Promise { return this.#assetsRepository.getByAccountId(accountId); } - async getAssetsByAccountId( + async getAccountAssetsByIDs( accountId: string, assetTypes: string[], ): Promise<(AssetEntity | null)[]> { @@ -169,7 +169,7 @@ export class AssetsService { ); } - async getAssetByAccountId( + async getAccountAssetByID( accountId: string, assetType: string, ): Promise { diff --git a/packages/tron-wallet-snap/src/services/confirmation/ConfirmationHandler.test.ts b/packages/tron-wallet-snap/src/services/confirmation/ConfirmationHandler.test.ts index 705559d7..6df1bffa 100644 --- a/packages/tron-wallet-snap/src/services/confirmation/ConfirmationHandler.test.ts +++ b/packages/tron-wallet-snap/src/services/confirmation/ConfirmationHandler.test.ts @@ -106,7 +106,7 @@ type WithConfirmationHandlerCallback = (payload: { }; }; }; - mockAssetsService: jest.Mocked>; + mockAssetsService: jest.Mocked>; mockFeeCalculatorService: jest.Mocked< Pick >; @@ -142,9 +142,9 @@ async function withConfirmationHandler( }; const mockAssetsService: jest.Mocked< - Pick + Pick > = { - getAssetsByAccountId: jest.fn().mockResolvedValue([null, null]), + getAccountAssetsByIDs: jest.fn().mockResolvedValue([null, null]), }; const mockFeeCalculatorService: jest.Mocked< @@ -260,7 +260,7 @@ describe('ConfirmationHandler', () => { scope: Network.Mainnet, }); - expect(mockAssetsService.getAssetsByAccountId).toHaveBeenCalledWith( + expect(mockAssetsService.getAccountAssetsByIDs).toHaveBeenCalledWith( TEST_ACCOUNT_ID, [ Networks[Network.Mainnet].bandwidth.id, @@ -273,7 +273,7 @@ describe('ConfirmationHandler', () => { it('uses ZERO when bandwidth and energy assets are null', async () => { await withConfirmationHandler( async ({ handler, mockAssetsService, mockFeeCalculatorService }) => { - mockAssetsService.getAssetsByAccountId.mockResolvedValue([ + mockAssetsService.getAccountAssetsByIDs.mockResolvedValue([ null, null, ]); @@ -317,7 +317,7 @@ describe('ConfirmationHandler', () => { uiAmount: '3000', iconUrl: '', }; - mockAssetsService.getAssetsByAccountId.mockResolvedValue([ + mockAssetsService.getAccountAssetsByIDs.mockResolvedValue([ bandwidthAsset, energyAsset, ]); diff --git a/packages/tron-wallet-snap/src/services/confirmation/ConfirmationHandler.ts b/packages/tron-wallet-snap/src/services/confirmation/ConfirmationHandler.ts index a246fa23..2d4daae9 100644 --- a/packages/tron-wallet-snap/src/services/confirmation/ConfirmationHandler.ts +++ b/packages/tron-wallet-snap/src/services/confirmation/ConfirmationHandler.ts @@ -235,7 +235,7 @@ export class ConfirmationHandler { ); const [bandwidthAsset, energyAsset] = - await this.#assetsService.getAssetsByAccountId(account.id, [ + await this.#assetsService.getAccountAssetsByIDs(account.id, [ Networks[scope].bandwidth.id, Networks[scope].energy.id, ]); diff --git a/packages/tron-wallet-snap/src/services/send/SendService.test.ts b/packages/tron-wallet-snap/src/services/send/SendService.test.ts index 8702de9a..4fc2c234 100644 --- a/packages/tron-wallet-snap/src/services/send/SendService.test.ts +++ b/packages/tron-wallet-snap/src/services/send/SendService.test.ts @@ -82,7 +82,7 @@ describe('SendService', () => { }; mockAssetsService = { - getAssetsByAccountId: jest.fn(), + getAccountAssetsByIDs: jest.fn(), }; mockTronWeb = { @@ -297,7 +297,7 @@ describe('SendService', () => { }; mockAssetsService = { - getAssetsByAccountId: jest.fn(), + getAccountAssetsByIDs: jest.fn(), }; mockTronWeb = { @@ -360,7 +360,7 @@ describe('SendService', () => { const amount = new BigNumber(10); // Sending 10 TRX // User has 100 TRX, 1000 bandwidth, 0 energy - mockAssetsService.getAssetsByAccountId.mockResolvedValue([ + mockAssetsService.getAccountAssetsByIDs.mockResolvedValue([ { uiAmount: '100', rawAmount: '100000000' }, // TRX balance (asset being sent) { uiAmount: '100', rawAmount: '100000000' }, // TRX balance (native token) { rawAmount: '1000' }, // Bandwidth @@ -398,7 +398,7 @@ describe('SendService', () => { }); expect(result).toStrictEqual({ valid: true }); - expect(mockAssetsService.getAssetsByAccountId).toHaveBeenCalledWith( + expect(mockAssetsService.getAccountAssetsByIDs).toHaveBeenCalledWith( TEST_ACCOUNT_ID, [nativeTokenId, nativeTokenId, bandwidthId, energyId], ); @@ -409,7 +409,7 @@ describe('SendService', () => { const amount = new BigNumber(100); // Trying to send 100 TRX // User only has 50 TRX - mockAssetsService.getAssetsByAccountId.mockResolvedValue([ + mockAssetsService.getAccountAssetsByIDs.mockResolvedValue([ { uiAmount: '50', rawAmount: '50000000' }, // TRX balance (asset being sent) { uiAmount: '50', rawAmount: '50000000' }, // TRX balance (native token) { rawAmount: '1000' }, // Bandwidth @@ -437,7 +437,7 @@ describe('SendService', () => { const amount = new BigNumber(99); // Sending 99 TRX // User has 100 TRX but no bandwidth (fees will be charged in TRX) - mockAssetsService.getAssetsByAccountId.mockResolvedValue([ + mockAssetsService.getAccountAssetsByIDs.mockResolvedValue([ { uiAmount: '100', rawAmount: '100000000' }, // TRX balance (asset being sent) { uiAmount: '100', rawAmount: '100000000' }, // TRX balance (native token) { rawAmount: '0' }, // No bandwidth @@ -477,7 +477,7 @@ describe('SendService', () => { const amount = new BigNumber(98); // Sending 98 TRX // User has 100 TRX, no bandwidth - mockAssetsService.getAssetsByAccountId.mockResolvedValue([ + mockAssetsService.getAccountAssetsByIDs.mockResolvedValue([ { uiAmount: '100', rawAmount: '100000000' }, // TRX balance { uiAmount: '100', rawAmount: '100000000' }, // TRX balance (native token) { rawAmount: '0' }, // No bandwidth @@ -516,7 +516,7 @@ describe('SendService', () => { const amount = new BigNumber(50); // Sending 50 USDT // User has 100 USDT, 10 TRX for fees, some energy - mockAssetsService.getAssetsByAccountId.mockResolvedValue([ + mockAssetsService.getAccountAssetsByIDs.mockResolvedValue([ { uiAmount: '100', rawAmount: '100000000' }, // USDT balance (asset being sent) { uiAmount: '10', rawAmount: '10000000' }, // TRX balance (native token for fees) { rawAmount: '500' }, // Bandwidth @@ -570,7 +570,7 @@ describe('SendService', () => { const amount = new BigNumber(100); // Trying to send 100 USDT // User only has 50 USDT - mockAssetsService.getAssetsByAccountId.mockResolvedValue([ + mockAssetsService.getAccountAssetsByIDs.mockResolvedValue([ { uiAmount: '50', rawAmount: '50000000' }, // USDT balance (not enough) { uiAmount: '100', rawAmount: '100000000' }, // TRX balance (plenty for fees) { rawAmount: '1000' }, // Bandwidth @@ -597,7 +597,7 @@ describe('SendService', () => { const amount = new BigNumber(50); // Sending 50 USDT // User has 100 USDT but only 1 TRX (not enough for fees) - mockAssetsService.getAssetsByAccountId.mockResolvedValue([ + mockAssetsService.getAccountAssetsByIDs.mockResolvedValue([ { uiAmount: '100', rawAmount: '100000000' }, // USDT balance (plenty) { uiAmount: '1', rawAmount: '1000000' }, // TRX balance (not enough for fees) { rawAmount: '0' }, // No bandwidth @@ -636,7 +636,7 @@ describe('SendService', () => { const amount = new BigNumber(50); // Sending 50 USDT // User has 100 USDT and exactly 5 TRX for fees - mockAssetsService.getAssetsByAccountId.mockResolvedValue([ + mockAssetsService.getAccountAssetsByIDs.mockResolvedValue([ { uiAmount: '100', rawAmount: '100000000' }, // USDT balance { uiAmount: '5', rawAmount: '5000000' }, // TRX balance (exact for fees) { rawAmount: '0' }, // No bandwidth @@ -674,7 +674,7 @@ describe('SendService', () => { const amount = new BigNumber(10); // All balances are undefined - mockAssetsService.getAssetsByAccountId.mockResolvedValue([ + mockAssetsService.getAccountAssetsByIDs.mockResolvedValue([ undefined, // No asset balance undefined, // No native token balance undefined, // No bandwidth @@ -700,7 +700,7 @@ describe('SendService', () => { const asset = createNativeAsset(); const amount = new BigNumber(0); // Sending 0 TRX - mockAssetsService.getAssetsByAccountId.mockResolvedValue([ + mockAssetsService.getAccountAssetsByIDs.mockResolvedValue([ { uiAmount: '1', rawAmount: '1000000' }, // 1 TRX balance { uiAmount: '1', rawAmount: '1000000' }, // 1 TRX native { rawAmount: '0' }, // No bandwidth @@ -736,7 +736,7 @@ describe('SendService', () => { const asset = createTrc20Asset(); const amount = new BigNumber(10); - mockAssetsService.getAssetsByAccountId.mockResolvedValue([ + mockAssetsService.getAccountAssetsByIDs.mockResolvedValue([ { uiAmount: '100', rawAmount: '100000000' }, // USDT balance { uiAmount: '0', rawAmount: '0' }, // 0 TRX balance { rawAmount: '10000' }, // Plenty of bandwidth @@ -790,7 +790,7 @@ describe('SendService', () => { const asset = createNativeAsset(); const amount = new BigNumber(1); // Sending 1 TRX to new account - mockAssetsService.getAssetsByAccountId.mockResolvedValue([ + mockAssetsService.getAccountAssetsByIDs.mockResolvedValue([ { uiAmount: '2', rawAmount: '2000000' }, // 2 TRX balance { uiAmount: '2', rawAmount: '2000000' }, // 2 TRX native { rawAmount: '1000' }, // Bandwidth (enough) @@ -835,7 +835,7 @@ describe('SendService', () => { const asset = createNativeAsset(); const amount = new BigNumber(1.5); // Sending 1.5 TRX to new account - mockAssetsService.getAssetsByAccountId.mockResolvedValue([ + mockAssetsService.getAccountAssetsByIDs.mockResolvedValue([ { uiAmount: '2', rawAmount: '2000000' }, // 2 TRX balance { uiAmount: '2', rawAmount: '2000000' }, // 2 TRX native { rawAmount: '1000' }, // Bandwidth (enough) @@ -885,7 +885,7 @@ describe('SendService', () => { const asset = createNativeAsset(); const amount = new BigNumber(10); - mockAssetsService.getAssetsByAccountId.mockResolvedValue([ + mockAssetsService.getAccountAssetsByIDs.mockResolvedValue([ { uiAmount: '100', rawAmount: '100000000' }, { uiAmount: '100', rawAmount: '100000000' }, { rawAmount: '1000' }, @@ -932,7 +932,7 @@ describe('SendService', () => { const asset = createNativeAsset(); const amount = new BigNumber('0.99'); - mockAssetsService.getAssetsByAccountId.mockResolvedValue([ + mockAssetsService.getAccountAssetsByIDs.mockResolvedValue([ { uiAmount: '100', rawAmount: '100000000' }, { uiAmount: '100', rawAmount: '100000000' }, { rawAmount: '1000' }, @@ -971,7 +971,7 @@ describe('SendService', () => { const asset = createTrc20Asset(); const amount = new BigNumber('0.99'); - mockAssetsService.getAssetsByAccountId.mockResolvedValue([ + mockAssetsService.getAccountAssetsByIDs.mockResolvedValue([ { uiAmount: '100', rawAmount: '100000000' }, { uiAmount: '100', rawAmount: '100000000' }, { rawAmount: '1000' }, @@ -1017,7 +1017,7 @@ describe('SendService', () => { const asset = createNativeAsset(); const amount = new BigNumber(10); - mockAssetsService.getAssetsByAccountId.mockResolvedValue([ + mockAssetsService.getAccountAssetsByIDs.mockResolvedValue([ { uiAmount: '100', rawAmount: '100000000' }, { uiAmount: '100', rawAmount: '100000000' }, { rawAmount: '1000' }, diff --git a/packages/tron-wallet-snap/src/services/send/SendService.ts b/packages/tron-wallet-snap/src/services/send/SendService.ts index f9f22e1e..b897a939 100644 --- a/packages/tron-wallet-snap/src/services/send/SendService.ts +++ b/packages/tron-wallet-snap/src/services/send/SendService.ts @@ -112,7 +112,7 @@ export class SendService { * Get the user's current balances for the asset being sent and TRX (for fees). */ const [assetBalance, nativeTokenAsset, bandwidthAsset, energyAsset] = - await this.#assetsService.getAssetsByAccountId(fromAccountId, [ + await this.#assetsService.getAccountAssetsByIDs(fromAccountId, [ asset.assetType, nativeTokenId, Networks[scope].bandwidth.id, diff --git a/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmSignTransaction/render.test.tsx b/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmSignTransaction/render.test.tsx index 0010b181..5a12d65c 100644 --- a/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmSignTransaction/render.test.tsx +++ b/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmSignTransaction/render.test.tsx @@ -142,7 +142,7 @@ type WithSnapContextCallback = (payload: { isTransactionExpired: jest.Mock; }; mockState: { setKey: jest.Mock }; - mockAssetsService: jest.Mocked>; + mockAssetsService: jest.Mocked>; mockFeeCalculatorService: jest.Mocked< Pick >; @@ -162,9 +162,9 @@ async function withSnapContext( testFunction: WithSnapContextCallback, ): Promise { const mockAssetsService: jest.Mocked< - Pick + Pick > = { - getAssetsByAccountId: jest.fn().mockResolvedValue(mockAssets), + getAccountAssetsByIDs: jest.fn().mockResolvedValue(mockAssets), }; const mockFeeCalculatorService: jest.Mocked< @@ -706,7 +706,7 @@ describe('ConfirmSignTransaction render', () => { it('sets isInsufficientBalance when the TRX balance cannot cover the transaction and fee', async () => { await withSnapContext(async ({ mockSnapClient, mockAssetsService }) => { - mockAssetsService.getAssetsByAccountId.mockResolvedValue([ + mockAssetsService.getAccountAssetsByIDs.mockResolvedValue([ { rawAmount: '50000', uiAmount: '0.05' } as AssetEntity, // TRX ...mockAssets.slice(1), ]); diff --git a/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmSignTransaction/render.tsx b/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmSignTransaction/render.tsx index cc06a17e..c93b40b4 100644 --- a/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmSignTransaction/render.tsx +++ b/packages/tron-wallet-snap/src/ui/confirmation/views/ConfirmSignTransaction/render.tsx @@ -93,7 +93,7 @@ export async function render( // Parallelize: Get preferences + Fetch account assets const [preferences, accountAssets] = await Promise.all([ snapClient.getPreferences().catch(() => DEFAULT_CONTEXT.preferences), - assetsService.getAssetsByAccountId(account.id, [ + assetsService.getAccountAssetsByIDs(account.id, [ Networks[scope as Network].nativeToken.id, Networks[scope as Network].bandwidth.id, Networks[scope as Network].energy.id, From 990cbb5a3e99f446a79984b593b3607f5adada8e Mon Sep 17 00:00:00 2001 From: Ulisses Ferreira Date: Fri, 31 Jul 2026 17:53:44 +0100 Subject: [PATCH 3/6] fix(tron-wallet-snap): use explicit cronjob handler import path Handler folder move requires importing from ../cronjob/cronjob rather than the bare folder path so the Snap bundle resolves correctly. --- .../src/handlers/clientRequest/clientRequest.test.ts | 2 +- .../src/handlers/clientRequest/clientRequest.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/tron-wallet-snap/src/handlers/clientRequest/clientRequest.test.ts b/packages/tron-wallet-snap/src/handlers/clientRequest/clientRequest.test.ts index 76545f89..ca80490a 100644 --- a/packages/tron-wallet-snap/src/handlers/clientRequest/clientRequest.test.ts +++ b/packages/tron-wallet-snap/src/handlers/clientRequest/clientRequest.test.ts @@ -38,7 +38,7 @@ import type { TransactionRawData } from '../../services/transaction-expiration-r import type { TransactionsService } from '../../services/transactions/TransactionsService'; import { trxToSun } from '../../utils/conversion'; import { mockLogger } from '../../utils/mockLogger'; -import { BackgroundEventMethod } from '../cronjob'; +import { BackgroundEventMethod } from '../cronjob/cronjob'; import { ClientRequestHandler } from './clientRequest'; import { ClientRequestMethod, SendErrorCodes } from './types'; import type { OnAmountInputRequestStruct } from './validation'; diff --git a/packages/tron-wallet-snap/src/handlers/clientRequest/clientRequest.ts b/packages/tron-wallet-snap/src/handlers/clientRequest/clientRequest.ts index a897ba2b..4cf1594b 100644 --- a/packages/tron-wallet-snap/src/handlers/clientRequest/clientRequest.ts +++ b/packages/tron-wallet-snap/src/handlers/clientRequest/clientRequest.ts @@ -46,7 +46,7 @@ import { assertTransactionSignerConsistency, assertTransactionStructure, } from '../../validation/transaction'; -import { BackgroundEventMethod } from '../cronjob'; +import { BackgroundEventMethod } from '../cronjob/cronjob'; import { ClientRequestMethod, SendErrorCodes } from './types'; import { ClaimTrxStakingRewardsRequestStruct, From 0e17e41664430a5cf4cd03f3436607464a16b538 Mon Sep 17 00:00:00 2001 From: Ulisses Ferreira Date: Fri, 31 Jul 2026 22:48:10 +0100 Subject: [PATCH 4/6] fix(tron-wallet-snap): update eslint suppressions and manifest shasum Handler files moved into subfolders in WPN-1497, so point eslint suppressions at the new paths and refresh snap.manifest.json after the handler import path fix changed the bundle hash. --- eslint-suppressions.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/eslint-suppressions.json b/eslint-suppressions.json index 3e958920..dfe5b09e 100644 --- a/eslint-suppressions.json +++ b/eslint-suppressions.json @@ -257,7 +257,7 @@ "count": 1 } }, - "packages/tron-wallet-snap/src/handlers/cronjob.test.tsx": { + "packages/tron-wallet-snap/src/handlers/cronjob/cronjob.test.tsx": { "@typescript-eslint/explicit-function-return-type": { "count": 2 }, @@ -265,7 +265,7 @@ "count": 4 } }, - "packages/tron-wallet-snap/src/handlers/keyring.test.ts": { + "packages/tron-wallet-snap/src/handlers/keyring/keyring.test.ts": { "@typescript-eslint/no-explicit-any": { "count": 10 }, @@ -273,7 +273,7 @@ "count": 1 } }, - "packages/tron-wallet-snap/src/handlers/keyring.ts": { + "packages/tron-wallet-snap/src/handlers/keyring/keyring.ts": { "import-x/no-extraneous-dependencies": { "count": 1 } From ea2e7f86fb4562664d56222e9c711bc2bc40c62e Mon Sep 17 00:00:00 2001 From: Ulisses Ferreira Date: Mon, 3 Aug 2026 00:25:37 +0100 Subject: [PATCH 5/6] fix(tron-wallet-snap): update manifest shasum for Linux CI build --- packages/tron-wallet-snap/snap.manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/tron-wallet-snap/snap.manifest.json b/packages/tron-wallet-snap/snap.manifest.json index 82993016..3109d095 100644 --- a/packages/tron-wallet-snap/snap.manifest.json +++ b/packages/tron-wallet-snap/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/MetaMask/internal-snaps.git" }, "source": { - "shasum": "0TZh63x04Gncx8UgHBoWnQ4RmX6kmTL6RmJTyqgJ7G8=", + "shasum": "usXLgel0d0xK1e9bK4seRDCTXwZ9c+H2vv7wS29omms=", "location": { "npm": { "filePath": "dist/bundle.js", From f7323ec4b4836658f2fe3f92dd3d801dba15ea64 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 3 Aug 2026 14:00:12 +0000 Subject: [PATCH 6/6] fix(tron-wallet-snap): update manifest shasum to match CI production build The previous shasum was computed locally with .env.example URLs, which differs from the CI production environment secrets. Use the shasum reported by the CI build job to keep the working tree clean. Co-authored-by: Ulisses Ferreira --- packages/tron-wallet-snap/snap.manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/tron-wallet-snap/snap.manifest.json b/packages/tron-wallet-snap/snap.manifest.json index ad9d916b..401124ab 100644 --- a/packages/tron-wallet-snap/snap.manifest.json +++ b/packages/tron-wallet-snap/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/MetaMask/internal-snaps.git" }, "source": { - "shasum": "9vYQY+HG5oHsXriNEPUWw2FbLO/b4iKuf8IsUIE4QtM=", + "shasum": "0E86PeuwFcabw+zj98vn+O/XML6E9aDeng1o7+Qq47s=", "location": { "npm": { "filePath": "dist/bundle.js",