Skip to content
Draft
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
26 changes: 26 additions & 0 deletions app/scripts/controller-init/accounts-api-service-init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { AccountsApiServiceMessenger } from '@metamask-previews/accounts-api';
import { AccountsApiService } from '@metamask-previews/accounts-api';

import type { ControllerInitFunction } from './types';

/**
* Initialize the Accounts API service.
*
* @param request - The request object.
* @param request.controllerMessenger - The messenger to use for the service.
* @returns The initialized service.
*/
export const AccountsApiServiceInit: ControllerInitFunction<
AccountsApiService,
AccountsApiServiceMessenger
> = ({ controllerMessenger }) => {
const service = new AccountsApiService({
messenger: controllerMessenger,
});

return {
persistedStateKey: null,
memStateKey: null,
controller: service,
};
};
5 changes: 4 additions & 1 deletion app/scripts/controller-init/controller-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ import {
ProfileMetricsService,
} from '@metamask/profile-metrics-controller';
import { PerpsController } from '@metamask/perps-controller';
import { AccountsApiService } from '@metamask-previews/accounts-api';

import OnboardingController from '../controllers/onboarding';
import { PreferencesController } from '../controllers/preferences-controller';
import { InstitutionalSnapController } from '../controllers/institutional-snap/InstitutionalSnapController';
Expand Down Expand Up @@ -211,7 +213,8 @@ export type Controller =
| StaticAssetsController
| ProfileMetricsController
| ProfileMetricsService
| ConnectivityController;
| ConnectivityController
| AccountsApiService;

/**
* Flat state object for all controllers supporting or required by modular initialization.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { AccountsApiServiceMessenger } from '@metamask-previews/accounts-api';
import type { MessengerActions, MessengerEvents } from '@metamask/messenger';
import { Messenger } from '@metamask/messenger';
import { RootMessenger } from '../../lib/messenger';

type AllowedActions = MessengerActions<AccountsApiServiceMessenger>;

type AllowedEvents = MessengerEvents<AccountsApiServiceMessenger>;

/**
* Create a messenger restricted to the allowed actions and events of the
* AccountsApiService.
*
* @param messenger - The base messenger used to create the restricted
* messenger.
*/
export function getAccountsApiServiceMessenger(
messenger: RootMessenger<AllowedActions, AllowedEvents>,
): AccountsApiServiceMessenger {
const serviceMessenger = new Messenger<
'AccountsApiService',
AllowedActions,
AllowedEvents,
typeof messenger
>({
namespace: 'AccountsApiService',
parent: messenger,
});
return serviceMessenger;
}
5 changes: 5 additions & 0 deletions app/scripts/controller-init/messengers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ import { getProfileMetricsControllerMessenger } from './profile-metrics-controll
import { getProfileMetricsServiceMessenger } from './profile-metrics-service-messenger';
import { getStorageServiceMessenger } from './storage-service-messenger';
import { getPerpsControllerMessenger } from './perps-controller-messenger';
import { getAccountsApiServiceMessenger } from './accounts-api-service-messenger';

export type { AccountOrderControllerMessenger } from './account-order-controller-messenger';
export { getAccountOrderControllerMessenger } from './account-order-controller-messenger';
Expand Down Expand Up @@ -789,4 +790,8 @@ export const CONTROLLER_MESSENGERS = {
getMessenger: getProfileMetricsServiceMessenger,
getInitMessenger: noop,
},
AccountsApiService: {
getMessenger: getAccountsApiServiceMessenger,
getInitMessenger: noop,
},
} as const;
2 changes: 2 additions & 0 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ import {
import { MessengerSubscriptions } from './lib/MessengerSubscriptions';
import { ProfileMetricsControllerInit } from './controller-init/profile-metrics-controller-init';
import { ProfileMetricsServiceInit } from './controller-init/profile-metrics-service-init';
import { AccountsApiServiceInit } from './controller-init/accounts-api-service-init';

export const METAMASK_CONTROLLER_EVENTS = {
// Fired after state changes that impact the extension badge (unapproved msg count)
Expand Down Expand Up @@ -679,6 +680,7 @@ export default class MetamaskController extends EventEmitter {
...(getIsAssetsUnifiedStateIncludedInBuild()
? { AssetsController: AssetsControllerInit }
: {}),
AccountsApiService: AccountsApiServiceInit,
};

const {
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
"fast-xml-parser": "^5.5.7",
"minimatch@npm:^10.1.1": "10.2.4",
"@metamask/snaps-controllers": "^19.0.0",
"@metamask/messenger@npm:^0.3.0": "^1.0.0"
"@metamask/messenger@npm:^0.3.0": "^1.1.0"
},
"dependencies": {
"@babel/runtime": "patch:@babel/runtime@npm%3A7.26.10#~/.yarn/patches/@babel-runtime-npm-7.26.10-fe8c62510a.patch",
Expand All @@ -291,6 +291,7 @@
"@ledgerhq/hw-transport-webhid": "^6.31.0",
"@material-ui/core": "^4.12.4",
"@material-ui/pickers": "^3.3.11",
"@metamask-previews/accounts-api": "0.0.0-preview-0fc9da15f",
"@metamask/abi-utils": "^3.0.0",
"@metamask/account-api": "^1.0.0",
"@metamask/account-tree-controller": "^7.0.0",
Expand Down Expand Up @@ -351,7 +352,7 @@
"@metamask/logo": "^4.0.0",
"@metamask/message-manager": "^14.0.0",
"@metamask/message-signing-snap": "1.1.4",
"@metamask/messenger": "^1.0.0",
"@metamask/messenger": "^1.1.0",
"@metamask/metamask-eth-abis": "^3.1.1",
"@metamask/multichain-account-service": "^8.0.1",
"@metamask/multichain-api-client": "^0.10.1",
Expand Down
2 changes: 1 addition & 1 deletion shared/constants/data-services.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// A list of all names of data services available in the client.
export const DATA_SERVICES: string[] = [];
export const DATA_SERVICES: string[] = ['AccountsApiService'];
1 change: 1 addition & 0 deletions ui/components/multichain/activity-v2/activity-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const ActivityList = ({ filter }: Props) => {
hasNextPage,
isFetchingNextPage,
} = useTransactionsQuery(filter);
console.log('Got transactions data!', data);

// Local transactions - may not be in API yet
const localTransactions = useSelector(selectLocalTransactions);
Expand Down
23 changes: 12 additions & 11 deletions ui/components/multichain/activity-v2/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useCallback, useMemo } from 'react';
import { useSelector } from 'react-redux';
import { useInfiniteQuery, useQueryClient } from '@tanstack/react-query';
import { useQueryClient } from '@tanstack/react-query';
import { useInfiniteQuery } from '@metamask/react-data-query';
import type { CaipChainId } from '@metamask/utils';
import { TransactionType } from '@metamask/transaction-controller';
import { useI18nContext } from '../../../hooks/useI18nContext';
Expand Down Expand Up @@ -66,22 +67,22 @@ export function useTransactionsQuery(filter?: ActivityListFilter) {
[evmAddress, internalTxHashes],
);

const queryOptions =
apiClient.accounts.getV4MultiAccountTransactionsInfiniteQueryOptions({
accountAddresses,
networks,
includeTxMetadata: true,
});

// @ts-expect-error apiClient returns v5 types, repo still in v4
return useInfiniteQuery({
...queryOptions,
queryKey: [
'AccountsApiService:fetchMultiAccountTransactionsV4',
{
accountAddresses,
},
{
networks,
includeTxMetadata: true,
},
],
select: selectFn,
enabled:
Boolean(useExternalServices) &&
networks.length > 0 &&
accountAddresses.length > 0,
retry: false,
keepPreviousData: true,
refetchOnMount: true,
refetchOnWindowFocus: true,
Expand Down
65 changes: 64 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5571,6 +5571,20 @@ __metadata:
languageName: node
linkType: hard

"@metamask-previews/accounts-api@npm:0.0.0-preview-0fc9da15f":
version: 0.0.0-preview-0fc9da15f
resolution: "@metamask-previews/accounts-api@npm:0.0.0-preview-0fc9da15f"
dependencies:
"@metamask/base-data-service": "npm:^0.1.1"
"@metamask/controller-utils": "npm:^11.20.0"
"@metamask/messenger": "npm:^1.1.1"
"@metamask/superstruct": "npm:^3.1.0"
"@metamask/utils": "npm:^11.9.0"
"@tanstack/query-core": "npm:^4.43.0"
checksum: 10/f73fd0a1f0b3e93c8f9ac2e39d1cfef5c7f6513236c537bff3d4430a43ea4c806ddfd9c37eee4d57a17e7ed061577cbdb5e38a054c2f0c49f90eaf1d5ce95e13
languageName: node
linkType: hard

"@metamask/7715-permission-types@npm:^0.5.0":
version: 0.5.0
resolution: "@metamask/7715-permission-types@npm:0.5.0"
Expand Down Expand Up @@ -5910,6 +5924,19 @@ __metadata:
languageName: node
linkType: hard

"@metamask/base-data-service@npm:^0.1.1":
version: 0.1.1
resolution: "@metamask/base-data-service@npm:0.1.1"
dependencies:
"@metamask/controller-utils": "npm:^11.19.0"
"@metamask/messenger": "npm:^1.0.0"
"@metamask/utils": "npm:^11.9.0"
"@tanstack/query-core": "npm:^4.43.0"
fast-deep-equal: "npm:^3.1.3"
checksum: 10/b746cfaad6625d61e0d5e3202488d1f3139ef1e4b8f04c7b07a3e0fbe474c1307c73bacb1cf5d9288e946719137c52f1bc1fd40e9e44800f65b8729bbed7311d
languageName: node
linkType: hard

"@metamask/bitcoin-wallet-snap@npm:^1.10.1":
version: 1.10.1
resolution: "@metamask/bitcoin-wallet-snap@npm:1.10.1"
Expand Down Expand Up @@ -6096,6 +6123,27 @@ __metadata:
languageName: node
linkType: hard

"@metamask/controller-utils@npm:^11.20.0":
version: 11.20.0
resolution: "@metamask/controller-utils@npm:11.20.0"
dependencies:
"@metamask/eth-query": "npm:^4.0.0"
"@metamask/ethjs-unit": "npm:^0.3.0"
"@metamask/utils": "npm:^11.9.0"
"@spruceid/siwe-parser": "npm:2.1.0"
"@types/bn.js": "npm:^5.1.5"
bignumber.js: "npm:^9.1.2"
bn.js: "npm:^5.2.1"
cockatiel: "npm:^3.1.2"
eth-ens-namehash: "npm:^2.0.8"
fast-deep-equal: "npm:^3.1.3"
lodash: "npm:^4.17.21"
peerDependencies:
"@babel/runtime": ^7.0.0
checksum: 10/a2ba778d00508a606ef4657cd6591a89f8f54136b3dd41f4f96f8effa2e9ad20de347e3c554f643cb248a002a17b478f95eafd4e3b4c3eca4bb40ae2e6bf7fdc
languageName: node
linkType: hard

"@metamask/core-backend@npm:^6.1.1, @metamask/core-backend@npm:^6.2.0, @metamask/core-backend@npm:^6.2.1":
version: 6.2.1
resolution: "@metamask/core-backend@npm:6.2.1"
Expand Down Expand Up @@ -7125,6 +7173,20 @@ __metadata:
languageName: node
linkType: hard

"@metamask/messenger@npm:^1.1.0, @metamask/messenger@npm:^1.1.1":
version: 1.1.1
resolution: "@metamask/messenger@npm:1.1.1"
dependencies:
"@metamask/utils": "npm:^11.9.0"
yargs: "npm:^17.7.2"
peerDependencies:
typescript: ">=5.0.0"
bin:
messenger-generate-action-types: ./dist/generate-action-types/cli.mjs
checksum: 10/a959af95e9e117aa0f7ad1c280f7817fef2c0b575c76837b1a6c884c9c9ef1dd0faeaef0c2c0c2035f68c7638d1f87cd172956ee962dec97d8ab6176fa6964e3
languageName: node
linkType: hard

"@metamask/metamask-eth-abis@npm:^3.1.1":
version: 3.1.1
resolution: "@metamask/metamask-eth-abis@npm:3.1.1"
Expand Down Expand Up @@ -34044,6 +34106,7 @@ __metadata:
"@lydell/node-pty": "npm:^1.1.0"
"@material-ui/core": "npm:^4.12.4"
"@material-ui/pickers": "npm:^3.3.11"
"@metamask-previews/accounts-api": "npm:0.0.0-preview-0fc9da15f"
"@metamask/abi-utils": "npm:^3.0.0"
"@metamask/account-api": "npm:^1.0.0"
"@metamask/account-tree-controller": "npm:^7.0.0"
Expand Down Expand Up @@ -34118,7 +34181,7 @@ __metadata:
"@metamask/logo": "npm:^4.0.0"
"@metamask/message-manager": "npm:^14.0.0"
"@metamask/message-signing-snap": "npm:1.1.4"
"@metamask/messenger": "npm:^1.0.0"
"@metamask/messenger": "npm:^1.1.0"
"@metamask/metamask-eth-abis": "npm:^3.1.1"
"@metamask/multichain-account-service": "npm:^8.0.1"
"@metamask/multichain-api-client": "npm:^0.10.1"
Expand Down
Loading