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
1 change: 1 addition & 0 deletions app/components/UI/Card/hooks/useCardDelegation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,7 @@ describe('useCardDelegation', () => {
{
networkClientId: mockNetworkClientId,
origin: TransactionTypes.MMM_CARD,
isInternal: true,
type: TransactionType.tokenMethodApprove,
deviceConfirmedOn: WalletDevice.MM_MOBILE,
requireApproval: true,
Expand Down
1 change: 1 addition & 0 deletions app/components/UI/Card/hooks/useCardDelegation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export const useCardDelegation = (token?: CardFundingToken | null) => {
{
networkClientId,
origin: TransactionTypes.MMM_CARD,
isInternal: true,
type: TransactionType.tokenMethodApprove,
deviceConfirmedOn: WalletDevice.MM_MOBILE,
requireApproval: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export const useMerklClaimTransaction = (asset: TokenI | undefined) => {
deviceConfirmedOn: WalletDevice.MM_MOBILE,
networkClientId,
origin: MERKL_CLAIM_ORIGIN,
isInternal: true,
type: TransactionType.musdClaim,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ describe('musdConversionTransaction', () => {
skipInitialGasEstimate: true,
networkClientId,
origin: ORIGIN_METAMASK,
isInternal: true,
type: TransactionType.musdConversion,
},
);
Expand Down Expand Up @@ -506,6 +507,7 @@ describe('musdConversionTransaction', () => {
skipInitialGasEstimate: true,
networkClientId: 'networkClientId',
origin: ORIGIN_METAMASK,
isInternal: true,
type: TransactionType.musdConversion,
},
);
Expand Down
2 changes: 2 additions & 0 deletions app/components/UI/Earn/utils/musdConversionTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ function buildMusdConversionTx(params: {
skipInitialGasEstimate: true;
networkClientId: string;
origin: typeof ORIGIN_METAMASK;
isInternal: true;
type: TransactionType.musdConversion;
};
} {
Expand All @@ -139,6 +140,7 @@ function buildMusdConversionTx(params: {
skipInitialGasEstimate: true,
networkClientId,
origin: ORIGIN_METAMASK,
isInternal: true,
type: TransactionType.musdConversion,
},
};
Expand Down
1 change: 1 addition & 0 deletions app/components/UI/Money/hooks/useMoneyAccount.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ describe('useMoneyAccountWithdrawal', () => {
},
options: {
origin: ORIGIN_METAMASK,
isInternal: true,
requireApproval: true,
type: 'moneyAccountWithdraw' as never,
},
Expand Down
1 change: 1 addition & 0 deletions app/components/UI/Money/hooks/useMoneyAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export function useMoneyAccountDeposit() {
from: primaryMoneyAccount.address as Hex,
networkClientId,
origin: ORIGIN_METAMASK,
isInternal: true,
disableHook: true,
disableSequential: true,
transactions: [approveTx, depositTx],
Expand Down
2 changes: 2 additions & 0 deletions app/components/UI/Money/utils/moneyAccountTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ export interface MoneyAccountWithdrawResult {
params: { to: Hex; data: Hex; value: Hex };
options: {
origin: typeof ORIGIN_METAMASK;
isInternal: boolean;
requireApproval: boolean;
type: TransactionType;
};
Expand Down Expand Up @@ -260,6 +261,7 @@ export async function buildMoneyAccountWithdraw({
},
options: {
origin: ORIGIN_METAMASK,
isInternal: true,
requireApproval: true,
type: TransactionType.moneyAccountWithdraw,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ describe('usePerpsWithdrawConfirmation', () => {
expect(mockAddTransactionBatch).toHaveBeenCalledWith({
from: MOCK_ACCOUNT,
origin: ORIGIN_METAMASK,
isInternal: true,
networkClientId: MOCK_NETWORK_CLIENT_ID,
disableHook: true,
disableSequential: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function usePerpsWithdrawConfirmation() {
await addTransactionBatch({
from: selectedAccount as Hex,
origin: ORIGIN_METAMASK,
isInternal: true,
networkClientId,
disableHook: true,
disableSequential: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,7 @@ export class PredictController extends BaseController<
const batchResult = await addTransactionBatch({
from: signer.address as Hex,
origin: ORIGIN_METAMASK,
isInternal: true,
networkClientId,
disableHook: true,
disableSequential: true,
Expand Down
2 changes: 2 additions & 0 deletions app/components/UI/Stake/hooks/usePoolStakedClaim/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const attemptMultiCallClaimTransaction = async (
deviceConfirmedOn: WalletDevice.MM_MOBILE,
networkClientId,
origin: ORIGIN_METAMASK,
isInternal: true,
type: TransactionType.stakingClaim,
});
};
Expand Down Expand Up @@ -94,6 +95,7 @@ const attemptSingleClaimTransaction = async (
deviceConfirmedOn: WalletDevice.MM_MOBILE,
networkClientId,
origin: ORIGIN_METAMASK,
isInternal: true,
type: TransactionType.stakingClaim,
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const attemptDepositTransaction =
deviceConfirmedOn: WalletDevice.MM_MOBILE,
networkClientId,
origin: ORIGIN_METAMASK,
isInternal: true,
type: TransactionType.stakingDeposit,
});
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const attemptUnstakeTransaction =
deviceConfirmedOn: WalletDevice.MM_MOBILE,
networkClientId,
origin: ORIGIN_METAMASK,
isInternal: true,
type: TransactionType.stakingUnstake,
});
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ function useAddTransactionBatch() {
addTransactionBatch({
from: selectedAccount as Hex,
origin: ORIGIN_METAMASK,
isInternal: true,
networkClientId,
disableHook: true,
disableSequential: true,
Expand Down
1 change: 1 addition & 0 deletions app/components/Views/confirmations/utils/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ export const submitEvmTransaction = async ({

await addTransaction(trxnParams, {
origin: MMM_ORIGIN,
isInternal: true,
networkClientId,
type: transactionType,
securityAlertResponse,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ describe('BridgeStatusController Init', () => {
addTransactionBatchFn(mockTxBatch);
expect(
mockTransactionController.addTransactionBatch,
).toHaveBeenCalledWith(mockTxBatch);
).toHaveBeenCalledWith({ ...mockTxBatch, isInternal: true });
});

it('handles undefined persistedState', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ export const bridgeStatusControllerInit: MessengerClientInitFunction<
state: persistedState.BridgeStatusController,
clientId: BridgeClientId.MOBILE,
fetchFn: handleFetch,
addTransactionBatchFn: (
...args: Parameters<typeof transactionController.addTransactionBatch>
) => transactionController.addTransactionBatch(...args),
addTransactionBatchFn: (request) =>
transactionController.addTransactionBatch({
...request,
isInternal: true,
}),
traceFn: trace as TraceCallback,
config: {
customBridgeApiBaseUrl: BRIDGE_API_BASE_URL,
Expand Down
4 changes: 3 additions & 1 deletion app/core/Engine/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,9 @@ export type MessengerClientsByName = {
export type ControllerMessenger = Messenger<
string,
ActionConstraint,
EventConstraint
EventConstraint,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
any
>;

/**
Expand Down
74 changes: 34 additions & 40 deletions app/core/Snaps/SnapsMethodMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,19 @@ const snapMethodMiddlewareBuilder = (
controllerMessenger: RootExtendedMessenger,
origin: string,
subjectType: SubjectType,
) =>
createSnapsMethodMiddleware(subjectType === SubjectType.Snap, {
) => {
// The messenger 1.2 typings overload `.call`'s `this` per action, which makes
// partial application via `.bind` reject under strict checking. This helper
// re-applies the call with the same `this` for the tightly-typed pre-bound
// callbacks below.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const callMessenger = ((...args: any[]) =>
(
controllerMessenger.call as (
...callArgs: unknown[]
) => unknown
)(...args)) as typeof controllerMessenger.call;
return createSnapsMethodMiddleware(subjectType === SubjectType.Snap, {
getUnlockPromise: () => {
if (engineContext.KeyringController.isUnlocked()) {
return Promise.resolve();
Expand All @@ -81,8 +92,7 @@ const snapMethodMiddlewareBuilder = (
);
});
},
getSnaps: controllerMessenger.call.bind(
controllerMessenger,
getSnaps: callMessenger.bind(undefined,
SnapControllerGetPermittedSnapsAction,
origin,
),
Expand All @@ -100,13 +110,11 @@ const snapMethodMiddlewareBuilder = (
origin,
),
getAllowedKeyringMethods: keyringSnapPermissionsBuilder(origin),
getSnapFile: controllerMessenger.call.bind(
controllerMessenger,
getSnapFile: callMessenger.bind(undefined,
SnapControllerGetSnapFileAction,
origin as SnapId,
),
installSnaps: controllerMessenger.call.bind(
controllerMessenger,
installSnaps: callMessenger.bind(undefined,
SnapControllerInstallSnapsAction,
origin,
),
Expand All @@ -115,13 +123,11 @@ const snapMethodMiddlewareBuilder = (
origin,
RestrictedMethods.wallet_snap,
),
createInterface: controllerMessenger.call.bind(
controllerMessenger,
createInterface: callMessenger.bind(undefined,
SnapInterfaceControllerCreateInterfaceAction,
origin as SnapId,
),
updateInterface: controllerMessenger.call.bind(
controllerMessenger,
updateInterface: callMessenger.bind(undefined,
SnapInterfaceControllerUpdateInterfaceAction,
origin as SnapId,
),
Expand All @@ -137,39 +143,32 @@ const snapMethodMiddlewareBuilder = (
origin as SnapId,
id,
),
resolveInterface: controllerMessenger.call.bind(
controllerMessenger,
resolveInterface: callMessenger.bind(undefined,
SnapInterfaceControllerResolveInterfaceAction,
origin as SnapId,
),
getSnap: controllerMessenger.call.bind(
controllerMessenger,
getSnap: callMessenger.bind(undefined,
SnapControllerGetSnapAction,
),
trackError: (error: Error) => captureException(error),
trackEvent: trackSnapEvent,
openWebSocket: controllerMessenger.call.bind(
controllerMessenger,
openWebSocket: callMessenger.bind(undefined,
WebSocketServiceOpenAction,
origin as SnapId,
),
closeWebSocket: controllerMessenger.call.bind(
controllerMessenger,
closeWebSocket: callMessenger.bind(undefined,
WebSocketServiceCloseAction,
origin as SnapId,
),
sendWebSocketMessage: controllerMessenger.call.bind(
controllerMessenger,
sendWebSocketMessage: callMessenger.bind(undefined,
WebSocketServiceSendMessageAction,
origin as SnapId,
),
getWebSockets: controllerMessenger.call.bind(
controllerMessenger,
getWebSockets: callMessenger.bind(undefined,
WebSocketServiceGetAllAction,
origin as SnapId,
),
updateInterfaceState: controllerMessenger.call.bind(
controllerMessenger,
updateInterfaceState: callMessenger.bind(undefined,
SnapInterfaceControllerUpdateInterfaceStateAction,
origin as SnapId,
),
Expand Down Expand Up @@ -225,18 +224,15 @@ const snapMethodMiddlewareBuilder = (
})
.filter(Boolean);
},
clearSnapState: controllerMessenger.call.bind(
controllerMessenger,
clearSnapState: callMessenger.bind(undefined,
SnapControllerClearSnapStateAction,
origin as SnapId,
),
getSnapState: controllerMessenger.call.bind(
controllerMessenger,
getSnapState: callMessenger.bind(undefined,
SnapControllerGetSnapStateAction,
origin as SnapId,
),
updateSnapState: controllerMessenger.call.bind(
controllerMessenger,
updateSnapState: callMessenger.bind(undefined,
SnapControllerUpdateSnapStateAction,
origin as SnapId,
),
Expand All @@ -247,27 +243,25 @@ const snapMethodMiddlewareBuilder = (
...event,
snapId: origin as SnapId,
}),
cancelBackgroundEvent: controllerMessenger.call.bind(
controllerMessenger,
cancelBackgroundEvent: callMessenger.bind(undefined,
CronjobControllerCancelAction,
origin as SnapId,
),
getBackgroundEvents: controllerMessenger.call.bind(
controllerMessenger,
getBackgroundEvents: callMessenger.bind(undefined,
CronjobControllerGetAction,
origin as SnapId,
),
getNetworkConfigurationByChainId: controllerMessenger.call.bind(
controllerMessenger,
getNetworkConfigurationByChainId: callMessenger.bind(undefined,
'NetworkController:getNetworkConfigurationByChainId',
),
getNetworkClientById: controllerMessenger.call.bind(
controllerMessenger,
getNetworkClientById: callMessenger.bind(
undefined,
'NetworkController:getNetworkClientById',
),
startTrace: trace,
endTrace,
});
};

export default snapMethodMiddlewareBuilder;
///: END:ONLY_INCLUDE_IF
16 changes: 15 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,20 @@
"prettier --write"
]
},
"previewBuilds": {
"@metamask/transaction-controller": {
"type": "breaking",
"previewVersion": "65.0.0-preview-156c8ccf7"
},
"@metamask/transaction-pay-controller": {
"type": "non-breaking",
"previewVersion": "20.0.1-preview-156c8ccf7"
},
"@metamask/bridge-status-controller": {
"type": "non-breaking",
"previewVersion": "71.1.0-preview-156c8ccf7"
}
},
"resolutions": {
"@appium/schema/json-schema": "^0.4.0",
"@metamask/react-native-payments/validator": "^13.7.0",
Expand Down Expand Up @@ -286,7 +300,7 @@
"@metamask/keyring-utils": "^3.2.0",
"@metamask/logging-controller": "^8.0.0",
"@metamask/message-signing-snap": "^1.1.2",
"@metamask/messenger": "^1.1.0",
"@metamask/messenger": "^1.2.0",
"@metamask/metamask-eth-abis": "3.1.1",
"@metamask/mobile-wallet-protocol-core": "^0.4.0",
"@metamask/mobile-wallet-protocol-wallet-client": "^0.3.0",
Expand Down
Loading
Loading