Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,9 @@ import { AccountsControllerGetAccountByAddressAction } from '@metamask/accounts-
import { Messenger } from '@metamask/messenger';
import { SnapControllerHandleRequestAction } from '@metamask/snaps-controllers';
import { TransactionControllerUpdateCustodialTransactionAction } from '@metamask/transaction-controller';
import { InstitutionalSnapController } from '../../../controllers/institutional-snap/InstitutionalSnapController';
import { RootMessenger } from '../../../lib/messenger';

const controllerName = 'InstitutionalSnapController';

export type InstitutionalSnapControllerPublishHookAction = {
type: `${typeof controllerName}:publishHook`;
handler: InstitutionalSnapController['deferPublicationHook'];
};

export type InstitutionalSnapControllerBeforeCheckPendingTransactionHookAction =
{
type: `${typeof controllerName}:beforeCheckPendingTransactionHook`;
handler: InstitutionalSnapController['beforeCheckPendingTransactionHook'];
};
import { InstitutionalSnapControllerMethodActions } from '../../../controllers/institutional-snap/InstitutionalSnapController-method-action-types';
import { RootMessenger } from '../../../lib/messenger';

export type InstitutionalSnapRequestSearchParameters = {
from: string;
Expand All @@ -26,20 +14,14 @@ export type InstitutionalSnapRequestSearchParameters = {
chainId: string;
};

type AllowedActions =
type Actions =
| SnapControllerHandleRequestAction
| AccountsControllerGetAccountByAddressAction
| TransactionControllerUpdateCustodialTransactionAction;

type Actions =
| AllowedActions
| InstitutionalSnapControllerPublishHookAction
| InstitutionalSnapControllerBeforeCheckPendingTransactionHookAction;
| TransactionControllerUpdateCustodialTransactionAction
| InstitutionalSnapControllerMethodActions;

export type InstitutionalSnapControllerMessenger = Messenger<
'InstitutionalSnapControllerMessenger',
Actions,
never
export type InstitutionalSnapControllerMessenger = ReturnType<
typeof getInstitutionalSnapControllerMessenger
>;

/**
Expand All @@ -54,7 +36,7 @@ export function getInstitutionalSnapControllerMessenger(
messenger: RootMessenger<Actions, never>,
) {
const institutionalSnapControllerMessenger = new Messenger<
typeof controllerName,
'InstitutionalSnapController',
Actions,
never,
typeof messenger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import { SubscriptionServiceAction } from '../../services/subscription/types';
import {
InstitutionalSnapControllerBeforeCheckPendingTransactionHookAction,
InstitutionalSnapControllerPublishHookAction,
} from './accounts/institutional-snap-controller-messenger';
} from '../../controllers/institutional-snap/InstitutionalSnapController-method-action-types';

type AllowedActions = MessengerActions<TransactionControllerMessenger>;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* This file is auto generated.
* Do not edit manually.
*/

import type { InstitutionalSnapController } from './InstitutionalSnapController';

export type InstitutionalSnapControllerPublishHookAction = {
type: `InstitutionalSnapController:publishHook`;
handler: InstitutionalSnapController['publishHook'];
};

export type InstitutionalSnapControllerBeforeCheckPendingTransactionHookAction =
{
type: `InstitutionalSnapController:beforeCheckPendingTransactionHook`;
handler: InstitutionalSnapController['beforeCheckPendingTransactionHook'];
};

/**
* Union of all InstitutionalSnapController action types.
*/
export type InstitutionalSnapControllerMethodActions =
| InstitutionalSnapControllerPublishHookAction
| InstitutionalSnapControllerBeforeCheckPendingTransactionHookAction;
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ describe('InstitutionalSnapController', () => {
});
});

describe('deferPublicationHook', () => {
describe('publishHook', () => {
it('should handle deferred publication', async () => {
const result = await controller.deferPublicationHook(mockTransactionMeta);
const result = await controller.publishHook(mockTransactionMeta);

expect(result).toBe(false);
expect(messenger.call).toHaveBeenCalledWith(
Expand Down Expand Up @@ -206,7 +206,7 @@ describe('InstitutionalSnapController', () => {
return {};
});

const result = await controller.deferPublicationHook(mockTransactionMeta);
const result = await controller.publishHook(mockTransactionMeta);
expect(result).toBe(true);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
InstitutionalSnapRequestSearchParameters,
InstitutionalSnapResponse,
} from './institutional-snap-controller.types';
import type { InstitutionalSnapControllerMethodActions } from './InstitutionalSnapController-method-action-types';

const SNAP_ID = INSTITUTIONAL_WALLET_SNAP_ID;

Expand All @@ -40,28 +41,21 @@ export type InstitutionalSnapControllerGetStateAction =
InstitutionalSnapControllerControllerState
>;

export type InstitutionalSnapControllerPublishHookAction = {
type: `${typeof controllerName}:publishHook`;
handler: InstitutionalSnapController['deferPublicationHook'];
};

export type InstitutionalSnapControllerBeforeCheckPendingTransactionHookAction =
{
type: `${typeof controllerName}:beforeCheckPendingTransactionHook`;
handler: InstitutionalSnapController['beforeCheckPendingTransactionHook'];
};

export type InstitutionalSnapControllerStateChangeEvent =
ControllerStateChangeEvent<
typeof controllerName,
InstitutionalSnapControllerControllerState
>;

const MESSENGER_EXPOSED_METHODS = [
'publishHook',
'beforeCheckPendingTransactionHook',
] as const;

type Actions =
| AllowedActions
| InstitutionalSnapControllerGetStateAction
| InstitutionalSnapControllerPublishHookAction
| InstitutionalSnapControllerBeforeCheckPendingTransactionHookAction;
| InstitutionalSnapControllerMethodActions;

type Events = InstitutionalSnapControllerStateChangeEvent;

Expand Down Expand Up @@ -100,12 +94,13 @@ export class InstitutionalSnapController extends BaseController<
metadata,
});

this.#registerMessageHandlers();
this.messenger.registerMethodActionHandlers(
this,
MESSENGER_EXPOSED_METHODS,
);
}

async deferPublicationHook(
transactionMeta: TransactionMeta,
): Promise<boolean> {
async publishHook(transactionMeta: TransactionMeta): Promise<boolean> {
const shouldDefer = await this.#shouldDeferPublication(transactionMeta);

if (shouldDefer) {
Expand All @@ -128,18 +123,6 @@ export class InstitutionalSnapController extends BaseController<
return !(await this.#shouldDeferPublication(transactionMeta));
}

#registerMessageHandlers() {
this.messenger.registerActionHandler(
`${controllerName}:publishHook`,
this.deferPublicationHook.bind(this),
);

this.messenger.registerActionHandler(
`${controllerName}:beforeCheckPendingTransactionHook`,
this.beforeCheckPendingTransactionHook.bind(this),
);
}

async #handleSnapRequest(args: SnapRPCRequest) {
const response = await this.messenger.call(
'SnapController:handleRequest',
Expand Down
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
"test:e2e:single": "node test/e2e/run-e2e-test.js",
"ganache:start": "./development/run-ganache.sh",
"sentry:publish": "node ./development/sentry-publish.js",
"lint": "yarn lint:prettier && yarn lint:eslint && yarn lint:tsc && yarn lint:styles && yarn lint:images",
"lint:fix": "yarn lint:prettier:fix && yarn lint:eslint:fix && yarn lint:styles:fix && yarn circular-deps:update && yarn lint:images:fix && yarn lint:baseline:fix",
"lint": "yarn lint:prettier && yarn lint:eslint && yarn lint:tsc && yarn lint:styles && yarn lint:images && yarn messenger-action-types:check",
"lint:fix": "yarn lint:prettier:fix && yarn lint:eslint:fix && yarn lint:styles:fix && yarn circular-deps:update && yarn lint:images:fix && yarn lint:baseline:fix && yarn messenger-action-types:generate",
"lint:prettier": "prettier --check --cache -- '**/*.{json,md,mdx,yml}'",
"lint:prettier:fix": "prettier --write --cache -- '**/*.{json,md,mdx,yml}'",
"lint:changed": "node development/lint-changed.mts",
Expand Down Expand Up @@ -134,6 +134,8 @@
"test-storybook": "test-storybook -c .storybook",
"test-storybook:ci": "concurrently -k -s first -n \"SB,TEST\" -c \"magenta,blue\" \"yarn storybook:build && yarn http-server storybook-build --port 6006 \" \"wait-on tcp:6006 && echo 'Build done. Running storybook tests...' && yarn test-storybook\"",
"githooks:install": "husky install",
"messenger-action-types:check": "messenger-action-types app/ --check",
"messenger-action-types:generate": "messenger-action-types app/ --generate",
"fitness-functions": "tsx development/fitness-functions/index.ts",
"generate-beta-commit": "node ./development/generate-beta-commit.js",
"validate-branch-name": "validate-branch-name",
Expand Down Expand Up @@ -265,7 +267,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.1"
},
"dependencies": {
"@babel/runtime": "patch:@babel/runtime@npm%3A7.26.10#~/.yarn/patches/@babel-runtime-npm-7.26.10-fe8c62510a.patch",
Expand Down Expand Up @@ -351,7 +353,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.1",
"@metamask/metamask-eth-abis": "^3.1.1",
"@metamask/multichain-account-service": "^8.0.1",
"@metamask/multichain-api-client": "^0.10.1",
Expand Down Expand Up @@ -528,6 +530,7 @@
"@metamask/eth-json-rpc-provider": "^6.0.0",
"@metamask/forwarder": "^1.1.0",
"@metamask/foundryup": "^1.0.1",
"@metamask/messenger-cli": "^0.1.0",
"@metamask/phishing-warning": "^5.1.0",
"@metamask/preferences-controller": "^23.0.0",
"@metamask/snap-account-abstraction-keyring-site": "^1.0.0",
Expand Down
36 changes: 31 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7118,10 +7118,35 @@ __metadata:
languageName: node
linkType: hard

"@metamask/messenger@npm:^1.0.0":
version: 1.0.0
resolution: "@metamask/messenger@npm:1.0.0"
checksum: 10/ab1219a922d5acc86f2b1b557d79c75ca0c5f42572f50da8a2337bc5c8feb1ae95c0aaa2d2ee55b677acd4401fb2cc9c2dbacca7513edcddf20d88fb73fa7bea
"@metamask/messenger-cli@npm:^0.1.0":
version: 0.1.0
resolution: "@metamask/messenger-cli@npm:0.1.0"
dependencies:
"@metamask/utils": "npm:^11.9.0"
yargs: "npm:^17.7.2"
peerDependencies:
eslint: ">=8"
typescript: ">=5.0.0"
peerDependenciesMeta:
eslint:
optional: true
bin:
messenger-action-types: ./dist/cli.mjs
checksum: 10/dd359df00f2eba98dcfe5f3d8352d859f2e814220e709efe989ecb68c611ba32ea515fd6099a770a706066f1820abd07a134a2acf5fc6b883518c5d19991a8e2
languageName: node
linkType: hard

"@metamask/messenger@npm:^1.0.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

Expand Down Expand Up @@ -34139,7 +34164,8 @@ __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.1"
"@metamask/messenger-cli": "npm:^0.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