Skip to content
6 changes: 3 additions & 3 deletions eslint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,23 +257,23 @@
"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
},
"@typescript-eslint/no-explicit-any": {
"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
},
"import-x/no-extraneous-dependencies": {
"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
}
Expand Down
2 changes: 1 addition & 1 deletion packages/tron-wallet-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/internal-snaps.git"
},
"source": {
"shasum": "xQEloRiq1TZIyQM1F+rtfw4PGQDMakX2jIOlGtDt6ks=",
"shasum": "0E86PeuwFcabw+zj98vn+O/XML6E9aDeng1o7+Qq47s=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
8 changes: 4 additions & 4 deletions packages/tron-wallet-snap/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -115,7 +115,7 @@ type WithClientRequestHandlerCallback<ReturnValue> = (payload: {
Pick<AccountsService, 'findById' | 'findByIdOrThrow' | 'deriveTronKeypair'>
>;
mockAssetsService: jest.Mocked<
Pick<AssetsService, 'getAssetsByAccountId' | 'getAssetByAccountId'>
Pick<AssetsService, 'getAccountAssetsByIDs' | 'getAccountAssetByID'>
>;
mockSendService: jest.Mocked<
Pick<
Expand Down Expand Up @@ -165,10 +165,10 @@ async function withClientRequestHandler<ReturnValue>(
};

const mockAssetsService: jest.Mocked<
Pick<AssetsService, 'getAssetsByAccountId' | 'getAssetByAccountId'>
Pick<AssetsService, 'getAccountAssetsByIDs' | 'getAccountAssetByID'>
> = {
getAssetsByAccountId: jest.fn(),
getAssetByAccountId: jest.fn(),
getAccountAssetsByIDs: jest.fn(),
getAccountAssetByID: jest.fn(),
};

const mockSendService: jest.Mocked<
Expand Down Expand Up @@ -304,7 +304,7 @@ describe('ClientRequestHandler', () => {
} as unknown as jest.Mocked<AccountsService>;

mockAssetsService = {
getAssetsByAccountId: jest.fn(),
getAccountAssetsByIDs: jest.fn(),
} as unknown as jest.Mocked<AssetsService>;

mockSendService = {} as unknown as jest.Mocked<SendService>;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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],
);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1490,7 +1490,7 @@ describe('ClientRequestHandler - signAndSendTransaction', () => {
} as unknown as jest.Mocked<AccountsService>;

mockAssetsService = {
getAssetsByAccountId: jest.fn(),
getAccountAssetsByIDs: jest.fn(),
} as unknown as jest.Mocked<AssetsService>;

mockSendService = {} as unknown as jest.Mocked<SendService>;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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[]);
Expand Down Expand Up @@ -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],
);
Expand Down Expand Up @@ -2179,7 +2179,7 @@ describe('ClientRequestHandler - computeStakeFee', () => {
} as any);

// Account has only 5 TRX
mockAssetsService.getAssetByAccountId.mockResolvedValue({
mockAssetsService.getAccountAssetByID.mockResolvedValue({
uiAmount: '5',
} as AssetEntity);

Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -483,7 +483,7 @@ export class ClientRequestHandler {
};
}

const asset = await this.#assetsService.getAssetByAccountId(
const asset = await this.#assetsService.getAccountAssetByID(
fromAccountId,
assetId,
);
Expand Down Expand Up @@ -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,
]),
Expand Down Expand Up @@ -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,
]);
Expand Down Expand Up @@ -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,
);
Expand Down Expand Up @@ -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,
]);
Expand Down Expand Up @@ -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,
);
Expand Down Expand Up @@ -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,
);
Expand Down Expand Up @@ -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,
);
Expand Down Expand Up @@ -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,
);
Expand Down
Loading
Loading