Skip to content

Commit e9b95d3

Browse files
Add UI actions for pairing
1 parent ee1f159 commit e9b95d3

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

packages/snaps-controllers/src/devices/DeviceController.ts

+25-11
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ import type {
44
ControllerStateChangeEvent,
55
} from '@metamask/base-controller';
66
import { BaseController } from '@metamask/base-controller';
7-
8-
import type {
9-
TransactionControllerUnapprovedTransactionAddedEvent,
10-
SignatureStateChange,
11-
TransactionControllerTransactionStatusUpdatedEvent,
12-
} from '../types';
137
import { createDeferredPromise } from '@metamask/utils';
148

159
const controllerName = 'DeviceController';
@@ -21,7 +15,20 @@ export type DeviceControllerGetStateAction = ControllerGetStateAction<
2115
DeviceControllerState
2216
>;
2317

24-
export type DeviceControllerActions = DeviceControllerGetStateAction;
18+
export type DeviceControllerResolvePairingAction = {
19+
type: `${typeof controllerName}:resolvePairing`;
20+
handler: DeviceController['resolvePairing'];
21+
};
22+
23+
export type DeviceControllerRejectPairingAction = {
24+
type: `${typeof controllerName}:rejectPairing`;
25+
handler: DeviceController['rejectPairing'];
26+
};
27+
28+
export type DeviceControllerActions =
29+
| DeviceControllerGetStateAction
30+
| DeviceControllerResolvePairingAction
31+
| DeviceControllerRejectPairingAction;
2532

2633
export type DeviceControllerStateChangeEvent = ControllerStateChangeEvent<
2734
typeof controllerName,
@@ -30,10 +37,7 @@ export type DeviceControllerStateChangeEvent = ControllerStateChangeEvent<
3037

3138
export type DeviceControllerEvents = DeviceControllerStateChangeEvent;
3239

33-
export type DeviceControllerAllowedEvents =
34-
| TransactionControllerUnapprovedTransactionAddedEvent
35-
| TransactionControllerTransactionStatusUpdatedEvent
36-
| SignatureStateChange;
40+
export type DeviceControllerAllowedEvents = never;
3741

3842
export type DeviceControllerMessenger = RestrictedControllerMessenger<
3943
typeof controllerName,
@@ -85,6 +89,16 @@ export class DeviceController extends BaseController<
8589
name: controllerName,
8690
state: { ...state, devices: {} },
8791
});
92+
93+
this.messagingSystem.registerActionHandler(
94+
`${controllerName}:resolvePairing`,
95+
async (...args) => this.resolvePairing(...args),
96+
);
97+
98+
this.messagingSystem.registerActionHandler(
99+
`${controllerName}:rejectPairing`,
100+
async (...args) => this.rejectPairing(...args),
101+
);
88102
}
89103

90104
async requestDevices(snapId: string) {

0 commit comments

Comments
 (0)