@metamask/assets-controllers 83.1.0 → 85.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +39 -2
- package/dist/AccountTrackerController.cjs +20 -21
- package/dist/AccountTrackerController.cjs.map +1 -1
- package/dist/AccountTrackerController.d.cts +4 -3
- package/dist/AccountTrackerController.d.cts.map +1 -1
- package/dist/AccountTrackerController.d.mts +4 -3
- package/dist/AccountTrackerController.d.mts.map +1 -1
- package/dist/AccountTrackerController.mjs +20 -21
- package/dist/AccountTrackerController.mjs.map +1 -1
- package/dist/AssetsContractController.cjs +10 -10
- package/dist/AssetsContractController.cjs.map +1 -1
- package/dist/AssetsContractController.d.cts +3 -3
- package/dist/AssetsContractController.d.cts.map +1 -1
- package/dist/AssetsContractController.d.mts +3 -3
- package/dist/AssetsContractController.d.mts.map +1 -1
- package/dist/AssetsContractController.mjs +10 -10
- package/dist/AssetsContractController.mjs.map +1 -1
- package/dist/CurrencyRateController.cjs +68 -15
- package/dist/CurrencyRateController.cjs.map +1 -1
- package/dist/CurrencyRateController.d.cts +18 -10
- package/dist/CurrencyRateController.d.cts.map +1 -1
- package/dist/CurrencyRateController.d.mts +18 -10
- package/dist/CurrencyRateController.d.mts.map +1 -1
- package/dist/CurrencyRateController.mjs +68 -15
- package/dist/CurrencyRateController.mjs.map +1 -1
- package/dist/DeFiPositionsController/DeFiPositionsController.cjs +7 -7
- package/dist/DeFiPositionsController/DeFiPositionsController.cjs.map +1 -1
- package/dist/DeFiPositionsController/DeFiPositionsController.d.cts +3 -2
- package/dist/DeFiPositionsController/DeFiPositionsController.d.cts.map +1 -1
- package/dist/DeFiPositionsController/DeFiPositionsController.d.mts +3 -2
- package/dist/DeFiPositionsController/DeFiPositionsController.d.mts.map +1 -1
- package/dist/DeFiPositionsController/DeFiPositionsController.mjs +7 -7
- package/dist/DeFiPositionsController/DeFiPositionsController.mjs.map +1 -1
- package/dist/MultichainAssetsController/MultichainAssetsController.cjs +54 -22
- package/dist/MultichainAssetsController/MultichainAssetsController.cjs.map +1 -1
- package/dist/MultichainAssetsController/MultichainAssetsController.d.cts +18 -3
- package/dist/MultichainAssetsController/MultichainAssetsController.d.cts.map +1 -1
- package/dist/MultichainAssetsController/MultichainAssetsController.d.mts +18 -3
- package/dist/MultichainAssetsController/MultichainAssetsController.d.mts.map +1 -1
- package/dist/MultichainAssetsController/MultichainAssetsController.mjs +54 -22
- package/dist/MultichainAssetsController/MultichainAssetsController.mjs.map +1 -1
- package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.cjs +13 -13
- package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.cjs.map +1 -1
- package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.d.cts +4 -3
- package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.d.cts.map +1 -1
- package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.d.mts +4 -3
- package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.d.mts.map +1 -1
- package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.mjs +13 -13
- package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.mjs.map +1 -1
- package/dist/MultichainBalancesController/MultichainBalancesController.cjs +9 -9
- package/dist/MultichainBalancesController/MultichainBalancesController.cjs.map +1 -1
- package/dist/MultichainBalancesController/MultichainBalancesController.d.cts +3 -2
- package/dist/MultichainBalancesController/MultichainBalancesController.d.cts.map +1 -1
- package/dist/MultichainBalancesController/MultichainBalancesController.d.mts +3 -2
- package/dist/MultichainBalancesController/MultichainBalancesController.d.mts.map +1 -1
- package/dist/MultichainBalancesController/MultichainBalancesController.mjs +9 -9
- package/dist/MultichainBalancesController/MultichainBalancesController.mjs.map +1 -1
- package/dist/NftController.cjs +25 -25
- package/dist/NftController.cjs.map +1 -1
- package/dist/NftController.d.cts +3 -3
- package/dist/NftController.d.cts.map +1 -1
- package/dist/NftController.d.mts +3 -3
- package/dist/NftController.d.mts.map +1 -1
- package/dist/NftController.mjs +25 -25
- package/dist/NftController.mjs.map +1 -1
- package/dist/NftDetectionController.cjs +5 -6
- package/dist/NftDetectionController.cjs.map +1 -1
- package/dist/NftDetectionController.d.cts +5 -5
- package/dist/NftDetectionController.d.cts.map +1 -1
- package/dist/NftDetectionController.d.mts +5 -5
- package/dist/NftDetectionController.d.mts.map +1 -1
- package/dist/NftDetectionController.mjs +5 -6
- package/dist/NftDetectionController.mjs.map +1 -1
- package/dist/RatesController/RatesController.cjs +5 -5
- package/dist/RatesController/RatesController.cjs.map +1 -1
- package/dist/RatesController/RatesController.d.cts.map +1 -1
- package/dist/RatesController/RatesController.d.mts.map +1 -1
- package/dist/RatesController/RatesController.mjs +5 -5
- package/dist/RatesController/RatesController.mjs.map +1 -1
- package/dist/RatesController/types.cjs.map +1 -1
- package/dist/RatesController/types.d.cts +3 -2
- package/dist/RatesController/types.d.cts.map +1 -1
- package/dist/RatesController/types.d.mts +3 -2
- package/dist/RatesController/types.d.mts.map +1 -1
- package/dist/RatesController/types.mjs.map +1 -1
- package/dist/TokenBalancesController.cjs +22 -22
- package/dist/TokenBalancesController.cjs.map +1 -1
- package/dist/TokenBalancesController.d.cts +3 -2
- package/dist/TokenBalancesController.d.cts.map +1 -1
- package/dist/TokenBalancesController.d.mts +3 -2
- package/dist/TokenBalancesController.d.mts.map +1 -1
- package/dist/TokenBalancesController.mjs +22 -22
- package/dist/TokenBalancesController.mjs.map +1 -1
- package/dist/TokenDetectionController.cjs +24 -24
- package/dist/TokenDetectionController.cjs.map +1 -1
- package/dist/TokenDetectionController.d.cts +4 -3
- package/dist/TokenDetectionController.d.cts.map +1 -1
- package/dist/TokenDetectionController.d.mts +4 -3
- package/dist/TokenDetectionController.d.mts.map +1 -1
- package/dist/TokenDetectionController.mjs +24 -24
- package/dist/TokenDetectionController.mjs.map +1 -1
- package/dist/TokenListController.cjs +4 -4
- package/dist/TokenListController.cjs.map +1 -1
- package/dist/TokenListController.d.cts +3 -2
- package/dist/TokenListController.d.cts.map +1 -1
- package/dist/TokenListController.d.mts +3 -2
- package/dist/TokenListController.d.mts.map +1 -1
- package/dist/TokenListController.mjs +4 -4
- package/dist/TokenListController.mjs.map +1 -1
- package/dist/TokenRatesController.cjs +6 -6
- package/dist/TokenRatesController.cjs.map +1 -1
- package/dist/TokenRatesController.d.cts +3 -2
- package/dist/TokenRatesController.d.cts.map +1 -1
- package/dist/TokenRatesController.d.mts +3 -2
- package/dist/TokenRatesController.d.mts.map +1 -1
- package/dist/TokenRatesController.mjs +6 -6
- package/dist/TokenRatesController.mjs.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.cjs +4 -4
- package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.cjs.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.d.cts +3 -2
- package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.d.cts.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.d.mts +3 -2
- package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.d.mts.map +1 -1
- package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.mjs +4 -4
- package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.mjs.map +1 -1
- package/dist/TokensController.cjs +17 -17
- package/dist/TokensController.cjs.map +1 -1
- package/dist/TokensController.d.cts +3 -2
- package/dist/TokensController.d.cts.map +1 -1
- package/dist/TokensController.d.mts +3 -2
- package/dist/TokensController.d.mts.map +1 -1
- package/dist/TokensController.mjs +17 -17
- package/dist/TokensController.mjs.map +1 -1
- package/dist/balances.cjs +20 -12
- package/dist/balances.cjs.map +1 -1
- package/dist/balances.d.cts +7 -3
- package/dist/balances.d.cts.map +1 -1
- package/dist/balances.d.mts +7 -3
- package/dist/balances.d.mts.map +1 -1
- package/dist/balances.mjs +20 -12
- package/dist/balances.mjs.map +1 -1
- package/dist/selectors/token-selectors.cjs +5 -1
- package/dist/selectors/token-selectors.cjs.map +1 -1
- package/dist/selectors/token-selectors.d.cts +21 -14
- package/dist/selectors/token-selectors.d.cts.map +1 -1
- package/dist/selectors/token-selectors.d.mts +21 -14
- package/dist/selectors/token-selectors.d.mts.map +1 -1
- package/dist/selectors/token-selectors.mjs +5 -1
- package/dist/selectors/token-selectors.mjs.map +1 -1
- package/dist/token-prices-service/abstract-token-prices-service.cjs.map +1 -1
- package/dist/token-prices-service/abstract-token-prices-service.d.cts +30 -0
- package/dist/token-prices-service/abstract-token-prices-service.d.cts.map +1 -1
- package/dist/token-prices-service/abstract-token-prices-service.d.mts +30 -0
- package/dist/token-prices-service/abstract-token-prices-service.d.mts.map +1 -1
- package/dist/token-prices-service/abstract-token-prices-service.mjs.map +1 -1
- package/dist/token-prices-service/codefi-v2.cjs +75 -0
- package/dist/token-prices-service/codefi-v2.cjs.map +1 -1
- package/dist/token-prices-service/codefi-v2.d.cts +15 -1
- package/dist/token-prices-service/codefi-v2.d.cts.map +1 -1
- package/dist/token-prices-service/codefi-v2.d.mts +15 -1
- package/dist/token-prices-service/codefi-v2.d.mts.map +1 -1
- package/dist/token-prices-service/codefi-v2.mjs +75 -0
- package/dist/token-prices-service/codefi-v2.mjs.map +1 -1
- package/package.json +26 -25
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultichainBalancesController.mjs","sourceRoot":"","sources":["../../src/MultichainBalancesController/MultichainBalancesController.ts"],"names":[],"mappings":";;;;;;AAMA,OAAO,EACL,cAAc,EAIf,kCAAkC;AACnC,OAAO,EAAE,gBAAgB,EAAE,8BAA8B;AAQzD,OAAO,EAAE,aAAa,EAAE,sCAAsC;AAG9D,OAAO,EAAE,WAAW,EAAE,8BAA8B;AASpD,MAAM,cAAc,GAAG,8BAA8B,CAAC;AAgBtD;;;;;;;GAOG;AACH,MAAM,UAAU,2CAA2C;IACzD,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,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CAAC,OAAO,CAC5C,CAAC,CAAC,SAAS,EAAE,aAAa,CAAC,EAAE,EAAE;YAC7B,IAAI,SAAS,IAAI,KAAK,CAAC,QAAQ,EAAE;gBAC/B,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC,CAAC;aACzD;QACH,CAAC,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;GAIG;AACH,KAAK,+DAAyB,SAAiB;IAC7C,IAAI,SAAS,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;QACpC,IAAI,CAAC,MAAM,CAAC,CAAC,KAA+C,EAAE,EAAE;YAC9D,OAAO,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;KACJ;AACH,CAAC;AAED;;;;;;;GAOG;AACH,KAAK,oDACH,SAAiB,EACjB,MAAc,EACd,UAA2B;IAE3B,OAAO,MAAM,uBAAA,IAAI,wFAAW,MAAf,IAAI,EAAY,MAAM,CAAC,CAAC,kBAAkB,CACrD,SAAS,EACT,UAAU,CACX,CAAC;AACJ,CAAC,6FAQU,MAAc;IACvB,OAAO,IAAI,aAAa,CAAC;QACvB,IAAI,EAAE,KAAK,EAAE,OAAuB,EAAE,EAAE,CACtC,CAAC,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,8BAA8B,EAAE;YAC/D,MAAM,EAAE,MAAgB;YACxB,MAAM,EAAE,UAAU;YAClB,OAAO,EAAE,WAAW,CAAC,gBAAgB;YACrC,OAAO;SACR,CAAC,CAAkB;KACvB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type {\n AccountsControllerAccountAddedEvent,\n AccountsControllerAccountRemovedEvent,\n AccountsControllerListMultichainAccountsAction,\n AccountsControllerAccountBalancesUpdatesEvent,\n} from '@metamask/accounts-controller';\nimport {\n BaseController,\n type ControllerGetStateAction,\n type ControllerStateChangeEvent,\n type RestrictedMessenger,\n} from '@metamask/base-controller';\nimport { isEvmAccountType } from '@metamask/keyring-api';\nimport type {\n Balance,\n CaipAssetType,\n AccountBalancesUpdatedEventPayload,\n} from '@metamask/keyring-api';\nimport type { KeyringControllerGetStateAction } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport { KeyringClient } from '@metamask/keyring-snap-client';\nimport type { HandleSnapRequest } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport type { Json, JsonRpcRequest } from '@metamask/utils';\nimport type { Draft } from 'immer';\n\nimport type {\n MultichainAssetsControllerGetStateAction,\n MultichainAssetsControllerAccountAssetListUpdatedEvent,\n} from '../MultichainAssetsController';\n\nconst controllerName = 'MultichainBalancesController';\n\n/**\n * State used by the {@link MultichainBalancesController} to cache account balances.\n */\nexport type MultichainBalancesControllerState = {\n balances: {\n [account: string]: {\n [asset: string]: {\n amount: string;\n unit: string;\n };\n };\n };\n};\n\n/**\n * Constructs the default {@link MultichainBalancesController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link MultichainBalancesController} state.\n */\nexport function getDefaultMultichainBalancesControllerState(): MultichainBalancesControllerState {\n return { balances: {} };\n}\n\n/**\n * Returns the state of the {@link MultichainBalancesController}.\n */\nexport type MultichainBalancesControllerGetStateAction =\n ControllerGetStateAction<\n typeof controllerName,\n MultichainBalancesControllerState\n >;\n\n/**\n * Event emitted when the state of the {@link MultichainBalancesController} changes.\n */\nexport type MultichainBalancesControllerStateChange =\n ControllerStateChangeEvent<\n typeof controllerName,\n MultichainBalancesControllerState\n >;\n\n/**\n * Actions exposed by the {@link MultichainBalancesController}.\n */\nexport type MultichainBalancesControllerActions =\n MultichainBalancesControllerGetStateAction;\n\n/**\n * Events emitted by {@link MultichainBalancesController}.\n */\nexport type MultichainBalancesControllerEvents =\n MultichainBalancesControllerStateChange;\n\n/**\n * Actions that this controller is allowed to call.\n */\ntype AllowedActions =\n | HandleSnapRequest\n | AccountsControllerListMultichainAccountsAction\n | MultichainAssetsControllerGetStateAction\n | KeyringControllerGetStateAction;\n\n/**\n * Events that this controller is allowed to subscribe.\n */\ntype AllowedEvents =\n | AccountsControllerAccountAddedEvent\n | AccountsControllerAccountRemovedEvent\n | AccountsControllerAccountBalancesUpdatesEvent\n | MultichainAssetsControllerAccountAssetListUpdatedEvent;\n/**\n * Messenger type for the MultichainBalancesController.\n */\nexport type MultichainBalancesControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n MultichainBalancesControllerActions | AllowedActions,\n MultichainBalancesControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\n/**\n * {@link MultichainBalancesController}'s metadata.\n *\n * This allows us to choose if fields of the state should be persisted or not\n * using the `persist` flag; and if they can be sent to Sentry or not, using\n * the `anonymous` flag.\n */\nconst balancesControllerMetadata = {\n balances: {\n includeInStateLogs: false,\n persist: true,\n anonymous: false,\n usedInUi: true,\n },\n};\n\n/**\n * The MultichainBalancesController is responsible for fetching and caching account\n * balances.\n */\nexport class MultichainBalancesController extends BaseController<\n typeof controllerName,\n MultichainBalancesControllerState,\n MultichainBalancesControllerMessenger\n> {\n constructor({\n messenger,\n state = {},\n }: {\n messenger: MultichainBalancesControllerMessenger;\n state?: Partial<MultichainBalancesControllerState>;\n }) {\n super({\n messenger,\n name: controllerName,\n metadata: balancesControllerMetadata,\n state: {\n ...getDefaultMultichainBalancesControllerState(),\n ...state,\n },\n });\n\n // Fetch initial balances for all non-EVM accounts\n for (const account of this.#listAccounts()) {\n // Fetching the balance is asynchronous and we cannot use `await` here.\n // eslint-disable-next-line no-void\n void this.updateBalance(account.id);\n }\n\n this.messagingSystem.subscribe(\n 'AccountsController:accountRemoved',\n (account: string) => this.#handleOnAccountRemoved(account),\n );\n this.messagingSystem.subscribe(\n 'AccountsController:accountBalancesUpdated',\n (balanceUpdate: AccountBalancesUpdatedEventPayload) =>\n this.#handleOnAccountBalancesUpdated(balanceUpdate),\n );\n\n this.messagingSystem.subscribe(\n 'MultichainAssetsController:accountAssetListUpdated',\n async ({ assets }) => {\n const newAccountAssets = Object.entries(assets).map(\n ([accountId, { added }]) => ({\n accountId,\n assets: [...added],\n }),\n );\n await this.#handleOnAccountAssetListUpdated(newAccountAssets);\n },\n );\n }\n\n /**\n * Updates the balances for the given accounts.\n *\n * @param accounts - The accounts to update the balances for.\n */\n async #handleOnAccountAssetListUpdated(\n accounts: {\n accountId: string;\n assets: CaipAssetType[];\n }[],\n ): Promise<void> {\n const { isUnlocked } = this.messagingSystem.call(\n 'KeyringController:getState',\n );\n\n if (!isUnlocked) {\n return;\n }\n const balancesToUpdate: MultichainBalancesControllerState['balances'] = {};\n\n for (const { accountId, assets } of accounts) {\n const account = this.#getAccount(accountId);\n if (account.metadata.snap) {\n const accountBalance = await this.#getBalances(\n account.id,\n account.metadata.snap.id,\n assets,\n );\n balancesToUpdate[accountId] = accountBalance;\n }\n }\n\n if (Object.keys(balancesToUpdate).length === 0) {\n return;\n }\n\n this.update((state: Draft<MultichainBalancesControllerState>) => {\n for (const [accountId, accountBalances] of Object.entries(\n balancesToUpdate,\n )) {\n if (\n !state.balances[accountId] ||\n Object.keys(state.balances[accountId]).length === 0\n ) {\n state.balances[accountId] = accountBalances;\n } else {\n for (const assetId in accountBalances) {\n if (!state.balances[accountId][assetId]) {\n state.balances[accountId][assetId] = accountBalances[assetId];\n }\n }\n }\n }\n });\n }\n\n /**\n * Updates the balances of one account. This method doesn't return\n * anything, but it updates the state of the controller.\n *\n * @param accountId - The account ID.\n * @param assets - The list of asset types for this account to upadte.\n */\n async #updateBalance(\n accountId: string,\n assets: CaipAssetType[],\n ): Promise<void> {\n const { isUnlocked } = this.messagingSystem.call(\n 'KeyringController:getState',\n );\n\n if (!isUnlocked) {\n return;\n }\n\n try {\n const account = this.#getAccount(accountId);\n\n if (account.metadata.snap) {\n const accountBalance = await this.#getBalances(\n account.id,\n account.metadata.snap.id,\n assets,\n );\n\n this.update((state: Draft<MultichainBalancesControllerState>) => {\n state.balances[accountId] = accountBalance;\n });\n }\n } catch (error) {\n // FIXME: Maybe we shouldn't catch all errors here since this method is also being\n // used in the public methods. This means if something else uses `updateBalance` it\n // won't be able to catch and gets the error itself...\n console.error(\n `Failed to fetch balances for account ${accountId}:`,\n error,\n );\n }\n }\n\n /**\n * Updates the balances of one account. This method doesn't return\n * anything, but it updates the state of the controller.\n *\n * @param accountId - The account ID.\n */\n async updateBalance(accountId: string): Promise<void> {\n await this.#updateBalance(accountId, this.#listAccountAssets(accountId));\n }\n\n /**\n * Lists the multichain accounts coming from the `AccountsController`.\n *\n * @returns A list of multichain accounts.\n */\n #listMultichainAccounts(): InternalAccount[] {\n return this.messagingSystem.call(\n 'AccountsController:listMultichainAccounts',\n );\n }\n\n /**\n * Lists the accounts that we should get balances for.\n *\n * @returns A list of accounts that we should get balances for.\n */\n #listAccounts(): InternalAccount[] {\n const accounts = this.#listMultichainAccounts();\n return accounts.filter((account) => this.#isNonEvmAccount(account));\n }\n\n /**\n * Lists the accounts assets.\n *\n * @param accountId - The account ID.\n * @returns The list of assets for this account, returns an empty list if none.\n */\n #listAccountAssets(accountId: string): CaipAssetType[] {\n // TODO: Add an action `MultichainAssetsController:getAccountAssets` maybe?\n const assetsState = this.messagingSystem.call(\n 'MultichainAssetsController:getState',\n );\n\n return assetsState.accountsAssets[accountId] ?? [];\n }\n\n /**\n * Get a non-EVM account from its ID.\n *\n * @param accountId - The account ID.\n * @returns The non-EVM account.\n */\n #getAccount(accountId: string): InternalAccount {\n const account: InternalAccount | undefined = this.#listAccounts().find(\n (multichainAccount) => multichainAccount.id === accountId,\n );\n\n if (!account) {\n throw new Error(`Unknown account: ${accountId}`);\n }\n\n return account;\n }\n\n /**\n * Checks for non-EVM accounts.\n *\n * @param account - The new account to be checked.\n * @returns True if the account is a non-EVM account, false otherwise.\n */\n #isNonEvmAccount(account: InternalAccount): boolean {\n return (\n !isEvmAccountType(account.type) &&\n // Non-EVM accounts are backed by a Snap for now\n account.metadata.snap !== undefined\n );\n }\n\n /**\n * Handles balance updates received from the AccountsController.\n *\n * @param balanceUpdate - The balance update event containing new balances.\n */\n #handleOnAccountBalancesUpdated(\n balanceUpdate: AccountBalancesUpdatedEventPayload,\n ): void {\n this.update((state: Draft<MultichainBalancesControllerState>) => {\n Object.entries(balanceUpdate.balances).forEach(\n ([accountId, assetBalances]) => {\n if (accountId in state.balances) {\n Object.assign(state.balances[accountId], assetBalances);\n }\n },\n );\n });\n }\n\n /**\n * Handles changes when a new account has been removed.\n *\n * @param accountId - The account ID being removed.\n */\n async #handleOnAccountRemoved(accountId: string): Promise<void> {\n if (accountId in this.state.balances) {\n this.update((state: Draft<MultichainBalancesControllerState>) => {\n delete state.balances[accountId];\n });\n }\n }\n\n /**\n * Get the balances for an account.\n *\n * @param accountId - ID of the account to get balances for.\n * @param snapId - ID of the Snap which manages the account.\n * @param assetTypes - Array of asset types to get balances for.\n * @returns A map of asset types to balances.\n */\n async #getBalances(\n accountId: string,\n snapId: string,\n assetTypes: CaipAssetType[],\n ): Promise<Record<CaipAssetType, Balance>> {\n return await this.#getClient(snapId).getAccountBalances(\n accountId,\n assetTypes,\n );\n }\n\n /**\n * Gets a `KeyringClient` for a Snap.\n *\n * @param snapId - ID of the Snap to get the client for.\n * @returns A `KeyringClient` for the Snap.\n */\n #getClient(snapId: string): KeyringClient {\n return new KeyringClient({\n send: async (request: JsonRpcRequest) =>\n (await this.messagingSystem.call('SnapController:handleRequest', {\n snapId: snapId as SnapId,\n origin: 'metamask',\n handler: HandlerType.OnKeyringRequest,\n request,\n })) as Promise<Json>,\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MultichainBalancesController.mjs","sourceRoot":"","sources":["../../src/MultichainBalancesController/MultichainBalancesController.ts"],"names":[],"mappings":";;;;;;AAMA,OAAO,EACL,cAAc,EAIf,kCAAkC;AACnC,OAAO,EA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AkB;KACvB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type {\n AccountsControllerAccountAddedEvent,\n AccountsControllerAccountRemovedEvent,\n AccountsControllerListMultichainAccountsAction,\n AccountsControllerAccountBalancesUpdatesEvent,\n} from '@metamask/accounts-controller';\nimport {\n BaseController,\n type StateMetadata,\n type ControllerGetStateAction,\n type ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport { isEvmAccountType } from '@metamask/keyring-api';\nimport type {\n Balance,\n CaipAssetType,\n AccountBalancesUpdatedEventPayload,\n} from '@metamask/keyring-api';\nimport type { KeyringControllerGetStateAction } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport { KeyringClient } from '@metamask/keyring-snap-client';\nimport type { Messenger } from '@metamask/messenger';\nimport type { HandleSnapRequest } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport type { Json, JsonRpcRequest } from '@metamask/utils';\nimport type { Draft } from 'immer';\n\nimport type {\n MultichainAssetsControllerGetStateAction,\n MultichainAssetsControllerAccountAssetListUpdatedEvent,\n} from '../MultichainAssetsController';\n\nconst controllerName = 'MultichainBalancesController';\n\n/**\n * State used by the {@link MultichainBalancesController} to cache account balances.\n */\nexport type MultichainBalancesControllerState = {\n balances: {\n [account: string]: {\n [asset: string]: {\n amount: string;\n unit: string;\n };\n };\n };\n};\n\n/**\n * Constructs the default {@link MultichainBalancesController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link MultichainBalancesController} state.\n */\nexport function getDefaultMultichainBalancesControllerState(): MultichainBalancesControllerState {\n return { balances: {} };\n}\n\n/**\n * Returns the state of the {@link MultichainBalancesController}.\n */\nexport type MultichainBalancesControllerGetStateAction =\n ControllerGetStateAction<\n typeof controllerName,\n MultichainBalancesControllerState\n >;\n\n/**\n * Event emitted when the state of the {@link MultichainBalancesController} changes.\n */\nexport type MultichainBalancesControllerStateChange =\n ControllerStateChangeEvent<\n typeof controllerName,\n MultichainBalancesControllerState\n >;\n\n/**\n * Actions exposed by the {@link MultichainBalancesController}.\n */\nexport type MultichainBalancesControllerActions =\n MultichainBalancesControllerGetStateAction;\n\n/**\n * Events emitted by {@link MultichainBalancesController}.\n */\nexport type MultichainBalancesControllerEvents =\n MultichainBalancesControllerStateChange;\n\n/**\n * Actions that this controller is allowed to call.\n */\ntype AllowedActions =\n | HandleSnapRequest\n | AccountsControllerListMultichainAccountsAction\n | MultichainAssetsControllerGetStateAction\n | KeyringControllerGetStateAction;\n\n/**\n * Events that this controller is allowed to subscribe.\n */\ntype AllowedEvents =\n | AccountsControllerAccountAddedEvent\n | AccountsControllerAccountRemovedEvent\n | AccountsControllerAccountBalancesUpdatesEvent\n | MultichainAssetsControllerAccountAssetListUpdatedEvent;\n/**\n * Messenger type for the MultichainBalancesController.\n */\nexport type MultichainBalancesControllerMessenger = Messenger<\n typeof controllerName,\n MultichainBalancesControllerActions | AllowedActions,\n MultichainBalancesControllerEvents | AllowedEvents\n>;\n\n/**\n * {@link MultichainBalancesController}'s metadata.\n *\n * This allows us to choose if fields of the state should be persisted or not\n * using the `persist` flag; and if they can be sent to Sentry or not, using\n * the `anonymous` flag.\n */\nconst balancesControllerMetadata: StateMetadata<MultichainBalancesControllerState> =\n {\n balances: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n };\n\n/**\n * The MultichainBalancesController is responsible for fetching and caching account\n * balances.\n */\nexport class MultichainBalancesController extends BaseController<\n typeof controllerName,\n MultichainBalancesControllerState,\n MultichainBalancesControllerMessenger\n> {\n constructor({\n messenger,\n state = {},\n }: {\n messenger: MultichainBalancesControllerMessenger;\n state?: Partial<MultichainBalancesControllerState>;\n }) {\n super({\n messenger,\n name: controllerName,\n metadata: balancesControllerMetadata,\n state: {\n ...getDefaultMultichainBalancesControllerState(),\n ...state,\n },\n });\n\n // Fetch initial balances for all non-EVM accounts\n for (const account of this.#listAccounts()) {\n // Fetching the balance is asynchronous and we cannot use `await` here.\n // eslint-disable-next-line no-void\n void this.updateBalance(account.id);\n }\n\n this.messenger.subscribe(\n 'AccountsController:accountRemoved',\n (account: string) => this.#handleOnAccountRemoved(account),\n );\n this.messenger.subscribe(\n 'AccountsController:accountBalancesUpdated',\n (balanceUpdate: AccountBalancesUpdatedEventPayload) =>\n this.#handleOnAccountBalancesUpdated(balanceUpdate),\n );\n\n this.messenger.subscribe(\n 'MultichainAssetsController:accountAssetListUpdated',\n async ({ assets }) => {\n const newAccountAssets = Object.entries(assets).map(\n ([accountId, { added }]) => ({\n accountId,\n assets: [...added],\n }),\n );\n await this.#handleOnAccountAssetListUpdated(newAccountAssets);\n },\n );\n }\n\n /**\n * Updates the balances for the given accounts.\n *\n * @param accounts - The accounts to update the balances for.\n */\n async #handleOnAccountAssetListUpdated(\n accounts: {\n accountId: string;\n assets: CaipAssetType[];\n }[],\n ): Promise<void> {\n const { isUnlocked } = this.messenger.call('KeyringController:getState');\n\n if (!isUnlocked) {\n return;\n }\n const balancesToUpdate: MultichainBalancesControllerState['balances'] = {};\n\n for (const { accountId, assets } of accounts) {\n const account = this.#getAccount(accountId);\n if (account.metadata.snap) {\n const accountBalance = await this.#getBalances(\n account.id,\n account.metadata.snap.id,\n assets,\n );\n balancesToUpdate[accountId] = accountBalance;\n }\n }\n\n if (Object.keys(balancesToUpdate).length === 0) {\n return;\n }\n\n this.update((state: Draft<MultichainBalancesControllerState>) => {\n for (const [accountId, accountBalances] of Object.entries(\n balancesToUpdate,\n )) {\n if (\n !state.balances[accountId] ||\n Object.keys(state.balances[accountId]).length === 0\n ) {\n state.balances[accountId] = accountBalances;\n } else {\n for (const assetId in accountBalances) {\n if (!state.balances[accountId][assetId]) {\n state.balances[accountId][assetId] = accountBalances[assetId];\n }\n }\n }\n }\n });\n }\n\n /**\n * Updates the balances of one account. This method doesn't return\n * anything, but it updates the state of the controller.\n *\n * @param accountId - The account ID.\n * @param assets - The list of asset types for this account to upadte.\n */\n async #updateBalance(\n accountId: string,\n assets: CaipAssetType[],\n ): Promise<void> {\n const { isUnlocked } = this.messenger.call('KeyringController:getState');\n\n if (!isUnlocked) {\n return;\n }\n\n try {\n const account = this.#getAccount(accountId);\n\n if (account.metadata.snap) {\n const accountBalance = await this.#getBalances(\n account.id,\n account.metadata.snap.id,\n assets,\n );\n\n this.update((state: Draft<MultichainBalancesControllerState>) => {\n state.balances[accountId] = accountBalance;\n });\n }\n } catch (error) {\n // FIXME: Maybe we shouldn't catch all errors here since this method is also being\n // used in the public methods. This means if something else uses `updateBalance` it\n // won't be able to catch and gets the error itself...\n console.error(\n `Failed to fetch balances for account ${accountId}:`,\n error,\n );\n }\n }\n\n /**\n * Updates the balances of one account. This method doesn't return\n * anything, but it updates the state of the controller.\n *\n * @param accountId - The account ID.\n */\n async updateBalance(accountId: string): Promise<void> {\n await this.#updateBalance(accountId, this.#listAccountAssets(accountId));\n }\n\n /**\n * Lists the multichain accounts coming from the `AccountsController`.\n *\n * @returns A list of multichain accounts.\n */\n #listMultichainAccounts(): InternalAccount[] {\n return this.messenger.call('AccountsController:listMultichainAccounts');\n }\n\n /**\n * Lists the accounts that we should get balances for.\n *\n * @returns A list of accounts that we should get balances for.\n */\n #listAccounts(): InternalAccount[] {\n const accounts = this.#listMultichainAccounts();\n return accounts.filter((account) => this.#isNonEvmAccount(account));\n }\n\n /**\n * Lists the accounts assets.\n *\n * @param accountId - The account ID.\n * @returns The list of assets for this account, returns an empty list if none.\n */\n #listAccountAssets(accountId: string): CaipAssetType[] {\n // TODO: Add an action `MultichainAssetsController:getAccountAssets` maybe?\n const assetsState = this.messenger.call(\n 'MultichainAssetsController:getState',\n );\n\n return assetsState.accountsAssets[accountId] ?? [];\n }\n\n /**\n * Get a non-EVM account from its ID.\n *\n * @param accountId - The account ID.\n * @returns The non-EVM account.\n */\n #getAccount(accountId: string): InternalAccount {\n const account: InternalAccount | undefined = this.#listAccounts().find(\n (multichainAccount) => multichainAccount.id === accountId,\n );\n\n if (!account) {\n throw new Error(`Unknown account: ${accountId}`);\n }\n\n return account;\n }\n\n /**\n * Checks for non-EVM accounts.\n *\n * @param account - The new account to be checked.\n * @returns True if the account is a non-EVM account, false otherwise.\n */\n #isNonEvmAccount(account: InternalAccount): boolean {\n return (\n !isEvmAccountType(account.type) &&\n // Non-EVM accounts are backed by a Snap for now\n account.metadata.snap !== undefined\n );\n }\n\n /**\n * Handles balance updates received from the AccountsController.\n *\n * @param balanceUpdate - The balance update event containing new balances.\n */\n #handleOnAccountBalancesUpdated(\n balanceUpdate: AccountBalancesUpdatedEventPayload,\n ): void {\n this.update((state: Draft<MultichainBalancesControllerState>) => {\n Object.entries(balanceUpdate.balances).forEach(\n ([accountId, assetBalances]) => {\n if (accountId in state.balances) {\n Object.assign(state.balances[accountId], assetBalances);\n }\n },\n );\n });\n }\n\n /**\n * Handles changes when a new account has been removed.\n *\n * @param accountId - The account ID being removed.\n */\n async #handleOnAccountRemoved(accountId: string): Promise<void> {\n if (accountId in this.state.balances) {\n this.update((state: Draft<MultichainBalancesControllerState>) => {\n delete state.balances[accountId];\n });\n }\n }\n\n /**\n * Get the balances for an account.\n *\n * @param accountId - ID of the account to get balances for.\n * @param snapId - ID of the Snap which manages the account.\n * @param assetTypes - Array of asset types to get balances for.\n * @returns A map of asset types to balances.\n */\n async #getBalances(\n accountId: string,\n snapId: string,\n assetTypes: CaipAssetType[],\n ): Promise<Record<CaipAssetType, Balance>> {\n return await this.#getClient(snapId).getAccountBalances(\n accountId,\n assetTypes,\n );\n }\n\n /**\n * Gets a `KeyringClient` for a Snap.\n *\n * @param snapId - ID of the Snap to get the client for.\n * @returns A `KeyringClient` for the Snap.\n */\n #getClient(snapId: string): KeyringClient {\n return new KeyringClient({\n send: async (request: JsonRpcRequest) =>\n (await this.messenger.call('SnapController:handleRequest', {\n snapId: snapId as SnapId,\n origin: 'metamask',\n handler: HandlerType.OnKeyringRequest,\n request,\n })) as Promise<Json>,\n });\n }\n}\n"]}
|
package/dist/NftController.cjs
CHANGED
|
@@ -31,19 +31,19 @@ const nftControllerMetadata = {
|
|
|
31
31
|
allNftContracts: {
|
|
32
32
|
includeInStateLogs: false,
|
|
33
33
|
persist: true,
|
|
34
|
-
|
|
34
|
+
includeInDebugSnapshot: false,
|
|
35
35
|
usedInUi: true,
|
|
36
36
|
},
|
|
37
37
|
allNfts: {
|
|
38
38
|
includeInStateLogs: false,
|
|
39
39
|
persist: true,
|
|
40
|
-
|
|
40
|
+
includeInDebugSnapshot: false,
|
|
41
41
|
usedInUi: true,
|
|
42
42
|
},
|
|
43
43
|
ignoredNfts: {
|
|
44
44
|
includeInStateLogs: false,
|
|
45
45
|
persist: true,
|
|
46
|
-
|
|
46
|
+
includeInDebugSnapshot: false,
|
|
47
47
|
usedInUi: false,
|
|
48
48
|
},
|
|
49
49
|
};
|
|
@@ -95,14 +95,14 @@ class NftController extends base_controller_1.BaseController {
|
|
|
95
95
|
_NftController_useIpfsSubdomains.set(this, void 0);
|
|
96
96
|
_NftController_isIpfsGatewayEnabled.set(this, void 0);
|
|
97
97
|
_NftController_onNftAdded.set(this, void 0);
|
|
98
|
-
__classPrivateFieldSet(this, _NftController_selectedAccountId, this.
|
|
98
|
+
__classPrivateFieldSet(this, _NftController_selectedAccountId, this.messenger.call('AccountsController:getSelectedAccount').id, "f");
|
|
99
99
|
__classPrivateFieldSet(this, _NftController_ipfsGateway, ipfsGateway, "f");
|
|
100
100
|
__classPrivateFieldSet(this, _NftController_displayNftMedia, displayNftMedia, "f");
|
|
101
101
|
__classPrivateFieldSet(this, _NftController_useIpfsSubdomains, useIpfsSubdomains, "f");
|
|
102
102
|
__classPrivateFieldSet(this, _NftController_isIpfsGatewayEnabled, isIpfsGatewayEnabled, "f");
|
|
103
103
|
__classPrivateFieldSet(this, _NftController_onNftAdded, onNftAdded, "f");
|
|
104
|
-
this.
|
|
105
|
-
this.
|
|
104
|
+
this.messenger.subscribe('PreferencesController:stateChange', __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_onPreferencesControllerStateChange).bind(this));
|
|
105
|
+
this.messenger.subscribe('AccountsController:selectedEvmAccountChange', __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_onSelectedAccountChange).bind(this));
|
|
106
106
|
}
|
|
107
107
|
getNftApi() {
|
|
108
108
|
return `${controller_utils_1.NFT_API_BASE_URL}/tokens`;
|
|
@@ -170,7 +170,7 @@ class NftController extends base_controller_1.BaseController {
|
|
|
170
170
|
async isNftOwner(ownerAddress, nftAddress, tokenId, networkClientId) {
|
|
171
171
|
// Checks the ownership for ERC-721.
|
|
172
172
|
try {
|
|
173
|
-
const owner = await this.
|
|
173
|
+
const owner = await this.messenger.call('AssetsContractController:getERC721OwnerOf', nftAddress, tokenId, networkClientId);
|
|
174
174
|
return ownerAddress.toLowerCase() === owner.toLowerCase();
|
|
175
175
|
}
|
|
176
176
|
catch {
|
|
@@ -178,7 +178,7 @@ class NftController extends base_controller_1.BaseController {
|
|
|
178
178
|
}
|
|
179
179
|
// Checks the ownership for ERC-1155.
|
|
180
180
|
try {
|
|
181
|
-
const balance = await this.
|
|
181
|
+
const balance = await this.messenger.call('AssetsContractController:getERC1155BalanceOf', ownerAddress, nftAddress, tokenId, networkClientId);
|
|
182
182
|
return !balance.isZero();
|
|
183
183
|
}
|
|
184
184
|
catch {
|
|
@@ -242,7 +242,7 @@ class NftController extends base_controller_1.BaseController {
|
|
|
242
242
|
});
|
|
243
243
|
// If NFT contract was not added, do not add individual NFT
|
|
244
244
|
const nftContract = newNftContracts.find((contract) => contract.address.toLowerCase() === checksumHexAddress.toLowerCase());
|
|
245
|
-
const { configuration: { chainId }, } = this.
|
|
245
|
+
const { configuration: { chainId }, } = this.messenger.call('NetworkController:getNetworkClientById', networkClientId);
|
|
246
246
|
// This is the case when the NFT is added manually and not detected automatically
|
|
247
247
|
// TODO: An improvement would be to make the chainId a required field and return it when getting the NFT information
|
|
248
248
|
if (!nftMetadata.chainId) {
|
|
@@ -273,7 +273,7 @@ class NftController extends base_controller_1.BaseController {
|
|
|
273
273
|
// Get all unsanitized nft metadata
|
|
274
274
|
const unsanitizedResults = await Promise.all(nftsWithChecksumAdr.map(async (nft) => {
|
|
275
275
|
// Each NFT should have a chainId; convert nft.chainId to networkClientId
|
|
276
|
-
const networkClientId = this.
|
|
276
|
+
const networkClientId = this.messenger.call('NetworkController:findNetworkClientIdByChainId', (0, controller_utils_1.toHex)(nft.chainId));
|
|
277
277
|
const resMetadata = networkClientId
|
|
278
278
|
? await __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getNftInformation).call(this, nft.address, nft.tokenId, networkClientId)
|
|
279
279
|
: undefined;
|
|
@@ -332,7 +332,7 @@ class NftController extends base_controller_1.BaseController {
|
|
|
332
332
|
*/
|
|
333
333
|
removeNft(address, tokenId, networkClientId, { userAddress } = {}) {
|
|
334
334
|
const addressToSearch = __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getAddressOrSelectedAddress).call(this, userAddress);
|
|
335
|
-
const { configuration: { chainId }, } = this.
|
|
335
|
+
const { configuration: { chainId }, } = this.messenger.call('NetworkController:getNetworkClientById', networkClientId);
|
|
336
336
|
const checksumHexAddress = (0, controller_utils_1.toChecksumHexAddress)(address);
|
|
337
337
|
__classPrivateFieldGet(this, _NftController_instances, "m", _NftController_removeIndividualNft).call(this, checksumHexAddress, tokenId, {
|
|
338
338
|
chainId,
|
|
@@ -359,7 +359,7 @@ class NftController extends base_controller_1.BaseController {
|
|
|
359
359
|
*/
|
|
360
360
|
removeAndIgnoreNft(address, tokenId, networkClientId, { userAddress } = {}) {
|
|
361
361
|
const addressToSearch = __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getAddressOrSelectedAddress).call(this, userAddress);
|
|
362
|
-
const { configuration: { chainId }, } = this.
|
|
362
|
+
const { configuration: { chainId }, } = this.messenger.call('NetworkController:getNetworkClientById', networkClientId);
|
|
363
363
|
const checksumHexAddress = (0, controller_utils_1.toChecksumHexAddress)(address);
|
|
364
364
|
__classPrivateFieldGet(this, _NftController_instances, "m", _NftController_removeAndIgnoreIndividualNft).call(this, checksumHexAddress, tokenId, {
|
|
365
365
|
chainId,
|
|
@@ -396,7 +396,7 @@ class NftController extends base_controller_1.BaseController {
|
|
|
396
396
|
*/
|
|
397
397
|
async checkAndUpdateSingleNftOwnershipStatus(nft, batch, networkClientId, { userAddress } = {}) {
|
|
398
398
|
const addressToSearch = __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getAddressOrSelectedAddress).call(this, userAddress);
|
|
399
|
-
const { configuration: { chainId }, } = this.
|
|
399
|
+
const { configuration: { chainId }, } = this.messenger.call('NetworkController:getNetworkClientById', networkClientId);
|
|
400
400
|
const { address, tokenId } = nft;
|
|
401
401
|
let isOwned = nft.isCurrentlyOwned;
|
|
402
402
|
try {
|
|
@@ -443,7 +443,7 @@ class NftController extends base_controller_1.BaseController {
|
|
|
443
443
|
*/
|
|
444
444
|
async checkAndUpdateAllNftsOwnershipStatus(networkClientId, { userAddress, } = {}) {
|
|
445
445
|
const addressToSearch = __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getAddressOrSelectedAddress).call(this, userAddress);
|
|
446
|
-
const { configuration: { chainId }, } = this.
|
|
446
|
+
const { configuration: { chainId }, } = this.messenger.call('NetworkController:getNetworkClientById', networkClientId);
|
|
447
447
|
const { allNfts } = this.state;
|
|
448
448
|
const nfts = allNfts[addressToSearch]?.[chainId] || [];
|
|
449
449
|
const updatedNfts = await Promise.all(nfts.map(async (nft) => {
|
|
@@ -468,7 +468,7 @@ class NftController extends base_controller_1.BaseController {
|
|
|
468
468
|
*/
|
|
469
469
|
updateNftFavoriteStatus(address, tokenId, favorite, networkClientId, { userAddress, } = {}) {
|
|
470
470
|
const addressToSearch = __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getAddressOrSelectedAddress).call(this, userAddress);
|
|
471
|
-
const { configuration: { chainId }, } = this.
|
|
471
|
+
const { configuration: { chainId }, } = this.messenger.call('NetworkController:getNetworkClientById', networkClientId);
|
|
472
472
|
const { allNfts } = this.state;
|
|
473
473
|
const nfts = [...(allNfts[addressToSearch]?.[chainId] || [])];
|
|
474
474
|
const index = nfts.findIndex((nft) => nft.address === address && nft.tokenId === tokenId);
|
|
@@ -584,7 +584,7 @@ class NftController extends base_controller_1.BaseController {
|
|
|
584
584
|
});
|
|
585
585
|
}
|
|
586
586
|
async _requestApproval(suggestedNftMeta) {
|
|
587
|
-
return this.
|
|
587
|
+
return this.messenger.call('ApprovalController:addRequest', {
|
|
588
588
|
id: suggestedNftMeta.id,
|
|
589
589
|
origin: suggestedNftMeta.origin,
|
|
590
590
|
type: controller_utils_1.ApprovalType.WatchAsset,
|
|
@@ -623,7 +623,7 @@ _NftController_mutex = new WeakMap(), _NftController_selectedAccountId = new Wea
|
|
|
623
623
|
* @param preferencesState.openSeaEnabled - Controls whether the NFT API is used (extension).
|
|
624
624
|
*/
|
|
625
625
|
async function _NftController_onPreferencesControllerStateChange({ ipfsGateway, isIpfsGatewayEnabled, displayNftMedia, openSeaEnabled, }) {
|
|
626
|
-
const selectedAccount = this.
|
|
626
|
+
const selectedAccount = this.messenger.call('AccountsController:getSelectedAccount');
|
|
627
627
|
__classPrivateFieldSet(this, _NftController_selectedAccountId, selectedAccount.id, "f");
|
|
628
628
|
const newDisplayNftMedia = Boolean(displayNftMedia || openSeaEnabled);
|
|
629
629
|
// Get current state values
|
|
@@ -827,7 +827,7 @@ async function _NftController_getNftInformationFromTokenURI(contractAddress, tok
|
|
|
827
827
|
async function _NftController_getNftURIAndStandard(contractAddress, tokenId, networkClientId) {
|
|
828
828
|
// try ERC721 uri
|
|
829
829
|
try {
|
|
830
|
-
const uri = await this.
|
|
830
|
+
const uri = await this.messenger.call('AssetsContractController:getERC721TokenURI', contractAddress, tokenId, networkClientId);
|
|
831
831
|
return [uri, controller_utils_1.ERC721];
|
|
832
832
|
}
|
|
833
833
|
catch {
|
|
@@ -835,7 +835,7 @@ async function _NftController_getNftURIAndStandard(contractAddress, tokenId, net
|
|
|
835
835
|
}
|
|
836
836
|
// try ERC1155 uri
|
|
837
837
|
try {
|
|
838
|
-
const tokenURI = await this.
|
|
838
|
+
const tokenURI = await this.messenger.call('AssetsContractController:getERC1155TokenURI', contractAddress, tokenId, networkClientId);
|
|
839
839
|
/**
|
|
840
840
|
* According to EIP1155 the URI value allows for ID substitution
|
|
841
841
|
* in case the string `{id}` exists.
|
|
@@ -863,7 +863,7 @@ async function _NftController_getNftURIAndStandard(contractAddress, tokenId, net
|
|
|
863
863
|
* @returns Promise resolving to the current NFT name and image.
|
|
864
864
|
*/
|
|
865
865
|
async function _NftController_getNftInformation(contractAddress, tokenId, networkClientId) {
|
|
866
|
-
const { configuration: { chainId }, } = this.
|
|
866
|
+
const { configuration: { chainId }, } = this.messenger.call('NetworkController:getNetworkClientById', networkClientId);
|
|
867
867
|
const [blockchainMetadata, nftApiMetadata] = await Promise.all([
|
|
868
868
|
(0, controller_utils_1.safelyExecute)(() => __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_getNftInformationFromTokenURI).call(this, contractAddress, tokenId, networkClientId)),
|
|
869
869
|
__classPrivateFieldGet(this, _NftController_displayNftMedia, "f") && chainId === '0x1'
|
|
@@ -892,8 +892,8 @@ async function _NftController_getNftContractInformationFromContract(
|
|
|
892
892
|
// TODO for calls to blockchain we need to explicitly pass the currentNetworkClientId since its relying on the provider
|
|
893
893
|
contractAddress, networkClientId) {
|
|
894
894
|
const [name, symbol] = await Promise.all([
|
|
895
|
-
this.
|
|
896
|
-
this.
|
|
895
|
+
this.messenger.call('AssetsContractController:getERC721AssetName', contractAddress, networkClientId),
|
|
896
|
+
this.messenger.call('AssetsContractController:getERC721AssetSymbol', contractAddress, networkClientId),
|
|
897
897
|
]);
|
|
898
898
|
return {
|
|
899
899
|
collection: { name },
|
|
@@ -1022,7 +1022,7 @@ async function _NftController_addNftContract(networkClientId, { tokenAddress, us
|
|
|
1022
1022
|
try {
|
|
1023
1023
|
const checksumHexAddress = (0, controller_utils_1.toChecksumHexAddress)(tokenAddress);
|
|
1024
1024
|
const { allNftContracts } = this.state;
|
|
1025
|
-
const { configuration: { chainId }, } = this.
|
|
1025
|
+
const { configuration: { chainId }, } = this.messenger.call('NetworkController:getNetworkClientById', networkClientId);
|
|
1026
1026
|
const nftContracts = allNftContracts[userAddress]?.[chainId] || [];
|
|
1027
1027
|
const existingEntry = nftContracts.find((nftContract) => nftContract.address.toLowerCase() ===
|
|
1028
1028
|
checksumHexAddress.toLowerCase());
|
|
@@ -1140,7 +1140,7 @@ async function _NftController_addNftContract(networkClientId, { tokenAddress, us
|
|
|
1140
1140
|
return address;
|
|
1141
1141
|
}
|
|
1142
1142
|
// If the address is not defined (or empty), we fallback to the currently selected account's address
|
|
1143
|
-
const selectedAccount = this.
|
|
1143
|
+
const selectedAccount = this.messenger.call('AccountsController:getAccount', __classPrivateFieldGet(this, _NftController_selectedAccountId, "f"));
|
|
1144
1144
|
return selectedAccount?.address || '';
|
|
1145
1145
|
}, _NftController_updateNftUpdateForAccount =
|
|
1146
1146
|
/**
|
|
@@ -1218,7 +1218,7 @@ async function _NftController_bulkSanitizeNftMetadata(metadataList) {
|
|
|
1218
1218
|
}
|
|
1219
1219
|
try {
|
|
1220
1220
|
// Use bulkScanUrls to check all URLs at once
|
|
1221
|
-
const bulkScanResponse = await this.
|
|
1221
|
+
const bulkScanResponse = await this.messenger.call('PhishingController:bulkScanUrls', urlsToCheck);
|
|
1222
1222
|
// Apply scan results to all metadata objects
|
|
1223
1223
|
Object.entries(bulkScanResponse.results).forEach(([url, result]) => {
|
|
1224
1224
|
if (result.recommendedAction === phishing_controller_1.RecommendedAction.Block) {
|