Skip to content
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
3 changes: 3 additions & 0 deletions packages/tron-wallet-snap/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Reject scopes that are not supported Tron networks instead of accepting them unchecked ([#394](https://github.com/MetaMask/internal-snaps/pull/394))
- `onAmountInput`, `confirmSend`, `claimUnstakedTrx`, `claimTrxStakingRewards` and `resolveAccountAddress` now throw an `InvalidParamsError` for an asset or scope on an unsupported chain.
- Assets returned by the AssetsController on an unsupported chain now throw instead of being mapped.
- Render the confirmation "Estimated changes" section with the shared `EstimatedChanges` component from `@metamask/snap-networks-utils` ([#396](https://github.com/MetaMask/internal-snaps/pull/396))
- Estimated changes from the previous scan now stay visible while a confirmation re-scans, instead of showing a loading skeleton

Expand Down
11 changes: 7 additions & 4 deletions packages/tron-wallet-snap/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ module.exports = {
'<rootDir>/jest.setup.ts',
],

// Measure index.ts barrels (e.g. src/constants/index.ts) so SonarCloud new-code coverage sees them; the shared base config's blanket index.ts exclusion zeroes them in lcov.
coveragePathIgnorePatterns: ['jest\\.setup\\.ts$'],

// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
global: {
branches: 72.49,
functions: 79.91,
lines: 85.79,
statements: 85.79,
branches: 73.09,
functions: 80.43,
lines: 86.39,
statements: 86.38,
},
},
};
5 changes: 3 additions & 2 deletions 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": "1IlkNeNaW28YQoE0wK3OdDJctxoEBDqK6cxLQ0GyifY=",
"shasum": "R0LTwZZs0pys5NIQLXqxoG1g3q0Bllj+ginLZD78rMk=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down Expand Up @@ -68,7 +68,8 @@
"RemoteFeatureFlagController:getState",
"AssetsController:getAccountAssetByID",
"AssetsController:getAccountAssetsByIDs",
"AssetsController:getAccountAssetsByScope"
"AssetsController:getAccountAssetsByScope",
"AssetsController:getAssets"
]
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import type { Logger } from '@metamask/snap-networks-utils';
import type { FungibleAssetMetadata } from '@metamask/snaps-sdk';
import { array, assert } from '@metamask/superstruct';
import type { Infer } from '@metamask/superstruct';
import { CaipAssetTypeStruct, parseCaipAssetType } from '@metamask/utils';
import { CaipAssetTypeStruct } from '@metamask/utils';
import { parseTronCaipAssetType } from '../../utils/caip';

import { Network, SNAP_OWNED_ASSETS } from '../../constants';
import type { TokenCaipAssetType } from '../../services/assets/types';
Expand Down Expand Up @@ -96,8 +97,8 @@ export class TokenApiClient {
if (SNAP_OWNED_ASSETS.includes(assetType)) {
return false;
}
const { chainId } = parseCaipAssetType(assetType);
return TokenApiClient.supportedNetworks.includes(chainId as Network);
const { chainId } = parseTronCaipAssetType(assetType);
return TokenApiClient.supportedNetworks.includes(chainId);
});

if (supportedAssetTypes.length !== assetTypes.length) {
Expand Down

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous code's direct access to baseUrl was nice but doesn't play well with typescript because network always gets casted as string.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { buildUrl } from '@metamask/snap-networks-utils';
import { assert } from '@metamask/superstruct';

import type { Network } from '../../constants';
import { Network } from '../../constants';
import type { ConfigProvider } from '../../services/config';
import { hexToString } from '../../utils/hex';
import {
Expand Down Expand Up @@ -43,14 +43,14 @@ export class TronHttpClient {
const { baseUrls } = configProvider.config.tronHttpApi;

// Initialize clients for all networks
Object.entries(baseUrls).forEach(([network, baseUrl]) => {
Object.values(Network).forEach((network) => {
const headers: Record<string, string> = {
'Content-Type': 'application/json',
'Access-Control-Allow-Headers': '*',
'Access-Control-Allow-Origin': '*',
};

this.#clients.set(network as Network, { baseUrl, headers });
this.#clients.set(network, { baseUrl: baseUrls[network], headers });
});
}

Expand Down

@ulissesferreira ulissesferreira Oct 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous code's direct access to baseUrl was nice but doesn't play well with typescript because network always gets casted as string.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
} from '@metamask/snap-networks-utils';
import { assert } from '@metamask/superstruct';

import type { Network } from '../../constants';
import { Network } from '../../constants';
import type { ConfigProvider } from '../../services/config';
import type { TronHttpClient } from '../tron-http/TronHttpClient';
import type { ChainParameter } from '../tron-http/types';
Expand Down Expand Up @@ -80,14 +80,14 @@ export class TrongridApiClient {
const { baseUrls } = configProvider.config.trongridApi;

// Initialize clients for all networks
Object.entries(baseUrls).forEach(([network, baseUrl]) => {
Object.values(Network).forEach((network) => {
const headers: Record<string, string> = {
'Content-Type': 'application/json',
'Access-Control-Allow-Headers': '*',
'Access-Control-Allow-Origin': '*',
};

this.#clients.set(network as Network, { baseUrl, headers });
this.#clients.set(network, { baseUrl: baseUrls[network], headers });
});

this.#tronHttpClient = tronHttpClient;
Expand Down
14 changes: 14 additions & 0 deletions packages/tron-wallet-snap/src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { InvalidParamsError } from '@metamask/snaps-sdk';
import { BigNumber } from 'bignumber.js';

export const ZERO = BigNumber(0);
Expand Down Expand Up @@ -66,6 +67,19 @@ export const Network = {

export type Network = (typeof Network)[keyof typeof Network];

const NETWORK_SCOPES: readonly string[] = Object.values(Network);

export const isSupportedNetwork = (scope: string): scope is Network =>
NETWORK_SCOPES.includes(scope);

export const assertSupportedNetwork = (scope: string): Network => {
if (!isSupportedNetwork(scope)) {
throw new InvalidParamsError(`Unsupported network: "${scope}"`) as Error;
}

return scope;
};

export const KnownCaip19Id = {
TrxMainnet: `${Network.Mainnet}/slip44:195`,
TrxNile: `${Network.Nile}/slip44:195`,
Expand Down

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When working locally on each Snap we should have narrowed types for certain locally stored things that we know are chain specific. Keyring accounts are a good example.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { ExtendedKeyringAccount } from '@metamask/snap-networks-utils';

import type { Network } from '../constants';

export type TronKeyringAccount = Omit<ExtendedKeyringAccount, 'scopes'> & {
scopes: Network[];
};
Loading
Loading