Skip to content

Commit

Permalink
Define getState action, stateChange event for PPOMController
Browse files Browse the repository at this point in the history
  • Loading branch information
MajorLift committed Jul 26, 2024
1 parent 857d4cb commit 244a10a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ export type {
PPOMState,
UsePPOM,
PPOMControllerActions,
PPOMControllerEvents,
PPOMControllerGetStateAction,
PPOMControllerStateChangeEvent,
PPOMControllerMessenger,
} from './ppom-controller';
export { NETWORK_CACHE_DURATION, PPOMController } from './ppom-controller';
Expand Down
12 changes: 9 additions & 3 deletions src/ppom-controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RestrictedControllerMessenger } from '@metamask/base-controller';
import type { ControllerGetStateAction, ControllerStateChangeEvent, RestrictedControllerMessenger } from '@metamask/base-controller';

Check failure on line 1 in src/ppom-controller.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

Replace `·ControllerGetStateAction,·ControllerStateChangeEvent,·RestrictedControllerMessenger·` with `⏎··ControllerGetStateAction,⏎··ControllerStateChangeEvent,⏎··RestrictedControllerMessenger,⏎`

Check failure on line 1 in src/ppom-controller.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

Replace `·ControllerGetStateAction,·ControllerStateChangeEvent,·RestrictedControllerMessenger·` with `⏎··ControllerGetStateAction,⏎··ControllerStateChangeEvent,⏎··RestrictedControllerMessenger,⏎`
import { BaseController } from '@metamask/base-controller';
import { safelyExecute, timeoutFetch } from '@metamask/controller-utils';
import type {
Expand Down Expand Up @@ -127,7 +127,13 @@ export type UsePPOM = {
handler: (callback: (ppom: PPOM) => Promise<unknown>) => Promise<unknown>;
};

export type PPOMControllerActions = UsePPOM;
export type PPOMControllerGetStateAction = ControllerGetStateAction<typeof controllerName, PPOMState>;

Check failure on line 130 in src/ppom-controller.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

Replace `typeof·controllerName,·PPOMState` with `⏎··typeof·controllerName,⏎··PPOMState⏎`

Check failure on line 130 in src/ppom-controller.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

Replace `typeof·controllerName,·PPOMState` with `⏎··typeof·controllerName,⏎··PPOMState⏎`

export type PPOMControllerActions = PPOMControllerGetStateAction | UsePPOM;

export type PPOMControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, PPOMState>;

Check failure on line 134 in src/ppom-controller.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

Replace `typeof·controllerName,·PPOMState` with `⏎··typeof·controllerName,⏎··PPOMState⏎`

Check failure on line 134 in src/ppom-controller.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

Replace `typeof·controllerName,·PPOMState` with `⏎··typeof·controllerName,⏎··PPOMState⏎`

export type PPOMControllerEvents = PPOMControllerStateChangeEvent;

export type AllowedEvents = NetworkControllerNetworkDidChangeEvent;

Expand All @@ -136,7 +142,7 @@ export type AllowedActions = NetworkControllerGetNetworkClientByIdAction;
export type PPOMControllerMessenger = RestrictedControllerMessenger<
typeof controllerName,
PPOMControllerActions | AllowedActions,
AllowedEvents,
PPOMControllerEvents | AllowedEvents,
AllowedActions['type'],
AllowedEvents['type']
>;
Expand Down
4 changes: 2 additions & 2 deletions test/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
AllowedEvents,
PPOMControllerActions,
} from '../src/ppom-controller';
import { PPOMController } from '../src/ppom-controller';
import { PPOMController, PPOMControllerEvents } from '../src/ppom-controller';

Check failure on line 13 in test/test-utils.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

Import "PPOMControllerEvents" is only used as types

Check failure on line 13 in test/test-utils.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

Import "PPOMControllerEvents" is only used as types
import type { StorageKey } from '../src/ppom-storage';
import { SUPPORTED_NETWORK_CHAINIDS } from '../src/util';

Expand Down Expand Up @@ -181,7 +181,7 @@ export class PPOMClass {
export const buildPPOMController = (options?: any) => {
const controllerMessenger: ControllerMessenger<
PPOMControllerActions | AllowedActions,
AllowedEvents
PPOMControllerEvents | AllowedEvents
> = new ControllerMessenger();
const messenger = controllerMessenger.getRestricted({
name: 'PPOMController',
Expand Down

0 comments on commit 244a10a

Please sign in to comment.