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

## [Unreleased]

### Added

- Add Core messenger plumbing (`getMessenger`, `RemoteFeatureFlagsProvider`, `AssetsProvider`) for upcoming AssetsController migration ([#95](https://github.com/MetaMask/internal-snaps/pull/95))

## [3.0.0]

### Added
Expand Down
4 changes: 4 additions & 0 deletions packages/tron-wallet-snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,14 @@
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
},
"devDependencies": {
"@metamask/assets-controller": "^13.0.0",
"@metamask/auto-changelog": "^6.1.1",
"@metamask/key-tree": "^10.1.1",
"@metamask/keyring-api": "^23.7.0",
"@metamask/keyring-snap-sdk": "^9.2.1",
"@metamask/messenger": "^2.0.0",
"@metamask/remote-feature-flag-controller": "^5.0.0",
"@metamask/snap-networks-utils": "^1.0.0",
"@metamask/snaps-cli": "^8.4.1",
"@metamask/snaps-jest": "^10.2.0",
"@metamask/snaps-sdk": "^11.2.0",
Expand Down
10 changes: 9 additions & 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": "s5YqLxf2VlRkjAfbTnHJCZXjWGdcaOi3h0JCe+wHeXo=",
"shasum": "B9kqmuUcYgPAD3ojseIm2HymqK77Q4NEzULU876+5Wc=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down Expand Up @@ -63,6 +63,14 @@
},
"endowment:assets": {
"scopes": ["tron:728126428"]
},
"endowment:messenger": {
"actions": [
"RemoteFeatureFlagController:getState",
"AssetsController:getAccountAssetByID",
"AssetsController:getAccountAssetsByIDs",
"AssetsController:getAccountAssetsByScope"
]
}
},
"platformVersion": "11.2.0",
Expand Down
35 changes: 34 additions & 1 deletion packages/tron-wallet-snap/src/context.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
import {
AssetsProvider,
RemoteFeatureFlagsProvider,
} from '@metamask/snap-networks-utils';
import type {
AssetsProviderMessenger,
RemoteFeatureFlagsProviderMessenger,
} from '@metamask/snap-networks-utils';
import { getMessenger } from '@metamask/snaps-sdk';

import { InMemoryCache } from './caching/InMemoryCache';
import { StateCache } from './caching/StateCache';
import { PriceApiClient } from './clients/price-api/PriceApiClient';
Expand Down Expand Up @@ -29,6 +39,7 @@ import { TransactionScanService } from './services/transaction-scan/TransactionS
import { TransactionsRepository } from './services/transactions/TransactionsRepository';
import { TransactionsService } from './services/transactions/TransactionsService';
import { WalletService } from './services/wallet/WalletService';
import type { CoreMessenger } from './types/core-messenger';
import logger, { noOpLogger } from './utils/logger';

/**
Expand Down Expand Up @@ -82,13 +93,24 @@ const priceApiClient = new PriceApiClient(configProvider, priceCache);
// Token API client
const tokenApiClient = new TokenApiClient(configProvider);

/**
* Core controllers plumbing
*/
const coreMessenger = getMessenger<CoreMessenger>();
const remoteFeatureFlagsProvider = new RemoteFeatureFlagsProvider({
messenger: coreMessenger as RemoteFeatureFlagsProviderMessenger,
});
const assetsProvider = new AssetsProvider({
messenger: coreMessenger as AssetsProviderMessenger,

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.

I haven't been able to automatically have this type set yet. Will ask @mikesposito when he is back to see if we can come up with some ideas.

});

// Security Alerts API client
const securityAlertsApiClient = new SecurityAlertsApiClient(
configProvider,
logger,
);

// Business Services - depend on Repositories, State and other Services
// Business Services
const assetsService = new AssetsService({
logger,
state,
Expand All @@ -98,6 +120,8 @@ const assetsService = new AssetsService({
priceApiClient,
tokenApiClient,
snapClient,
remoteFeatureFlagsProvider,
assetsProvider,
});

const transactionsService = new TransactionsService({
Expand Down Expand Up @@ -235,6 +259,12 @@ export type SnapExecutionContext = {
confirmationHandler: ConfirmationHandler;
transactionScanService: TransactionScanService;
transactionExpirationRefresherService: TransactionExpirationRefresherService;
/**
* Core messenger plumbing (routing wired in a follow-up PR).
*/
coreMessenger: CoreMessenger;
remoteFeatureFlagsProvider: RemoteFeatureFlagsProvider;
assetsProvider: AssetsProvider;
/**
* Handlers
*/
Expand Down Expand Up @@ -267,6 +297,9 @@ const snapContext: SnapExecutionContext = {
confirmationHandler,
transactionScanService,
transactionExpirationRefresherService,
coreMessenger,
remoteFeatureFlagsProvider,
assetsProvider,
/**
* Handlers
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import type { KeyringAccount } from '@metamask/keyring-api';
import {
AssetsProvider,
RemoteFeatureFlagsProvider,
} from '@metamask/snap-networks-utils';
import type {
AssetConversion,
AssetMetadata,
Expand Down Expand Up @@ -47,6 +51,8 @@ export class AssetsService {
priceApiClient: PriceApiClient;
tokenApiClient: TokenApiClient;
snapClient: SnapClient;
remoteFeatureFlagsProvider: RemoteFeatureFlagsProvider;
assetsProvider: AssetsProvider;
}) {
this.#snapAdapter = new SnapAssetsAdapter({
logger,
Expand Down
26 changes: 26 additions & 0 deletions packages/tron-wallet-snap/src/types/core-messenger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type {
AssetsControllerGetAccountAssetByIDAction,
AssetsControllerGetAccountAssetsByIDsAction,
AssetsControllerGetAccountAssetsByScopeAction,
} from '@metamask/assets-controller';
import type { Messenger } from '@metamask/messenger';
import type { RemoteFeatureFlagControllerGetStateAction } from '@metamask/remote-feature-flag-controller';

/**
* Namespace for this Snap's Core messenger endowment.
*/
export const TRON_WALLET_SNAP_MESSENGER_NAMESPACE = 'TronWalletSnap' as const;

export type CoreMessengerActions =
| RemoteFeatureFlagControllerGetStateAction
| AssetsControllerGetAccountAssetByIDAction
| AssetsControllerGetAccountAssetsByIDsAction
| AssetsControllerGetAccountAssetsByScopeAction;

/**
* Messenger type passed to `getMessenger` for Core controller actions.
*/
export type CoreMessenger = Messenger<
typeof TRON_WALLET_SNAP_MESSENGER_NAMESPACE,
CoreMessengerActions
>;
6 changes: 5 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3312,7 +3312,7 @@ __metadata:
languageName: node
linkType: hard

"@metamask/snap-networks-utils@workspace:packages/snap-networks-utils":
"@metamask/snap-networks-utils@npm:^1.0.0, @metamask/snap-networks-utils@workspace:packages/snap-networks-utils":
version: 0.0.0-use.local
resolution: "@metamask/snap-networks-utils@workspace:packages/snap-networks-utils"
dependencies:
Expand Down Expand Up @@ -3780,10 +3780,14 @@ __metadata:
version: 0.0.0-use.local
resolution: "@metamask/tron-wallet-snap@workspace:packages/tron-wallet-snap"
dependencies:
"@metamask/assets-controller": "npm:^13.0.0"
"@metamask/auto-changelog": "npm:^6.1.1"
"@metamask/key-tree": "npm:^10.1.1"
"@metamask/keyring-api": "npm:^23.7.0"
"@metamask/keyring-snap-sdk": "npm:^9.2.1"
"@metamask/messenger": "npm:^2.0.0"
"@metamask/remote-feature-flag-controller": "npm:^5.0.0"
"@metamask/snap-networks-utils": "npm:^1.0.0"
"@metamask/snaps-cli": "npm:^8.4.1"
"@metamask/snaps-jest": "npm:^10.2.0"
"@metamask/snaps-sdk": "npm:^11.2.0"
Expand Down
Loading