Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Improve Snap Controller typing #2029

Open
owencraston opened this issue Dec 11, 2023 · 0 comments
Open

fix: Improve Snap Controller typing #2029

owencraston opened this issue Dec 11, 2023 · 0 comments

Comments

@owencraston
Copy link

owencraston commented Dec 11, 2023

Description

while implementing the snaps controllers on mobile we came across several instances where the type checker was failing for what seemed to be invalid reasons. Some of this work has already been done by @FrederikBolding in this PR.

Testing

  • checkout this branch on mobile (feat/snaps-controllers-integration). if this PR is merged than you can do this on main
  • run yarn setup. this is only needed once.
  • remove all of the // @ts-ignore comments in the Engine.ts file
  • run yarn lint:tsc in your terminal
  • you should see the type errors
  • once fixed the yarn lint:tsc command should pass without the ts-ignore comments in the Engine.ts

Acceptance criteria

we should be able to remove all of the // @ts-ignore inside the `Engine.ts in mobile and have the type checker pass.

Affected code

const getSnapPermissionSpecifications = () => ({
      ...buildSnapEndowmentSpecifications(Object.keys(ExcludedSnapEndowments)),
      ...buildSnapRestrictedMethodSpecifications(
        Object.keys(ExcludedSnapPermissions),
        {
          encrypt: encryptor.encrypt.bind(encryptor),
          decrypt: encryptor.decrypt.bind(encryptor),
          // eslint-disable-next-line @typescript-eslint/ban-ts-comment
          // @ts-ignore
          clearSnapState: this.controllerMessenger.call.bind(
            this.controllerMessenger,
            'SnapController:clearSnapState',
          ),
          getMnemonic: getPrimaryKeyringMnemonic.bind(this),
          getUnlockPromise: getAppState.bind(this),
          getSnap: this.controllerMessenger.call.bind(
            this.controllerMessenger,
            'SnapController:get',
          ),
          // eslint-disable-next-line @typescript-eslint/ban-ts-comment
          // @ts-ignore
          handleSnapRpcRequest: this.controllerMessenger.call.bind(
            this.controllerMessenger,
            'SnapController:handleRequest',
          ),
          // eslint-disable-next-line @typescript-eslint/ban-ts-comment
          // @ts-ignore
          getSnapState: this.controllerMessenger.call.bind(
            this.controllerMessenger,
            'SnapController:getSnapState',
          ),
          // eslint-disable-next-line @typescript-eslint/ban-ts-comment
          // @ts-ignore
          updateSnapState: this.controllerMessenger.call.bind(
            this.controllerMessenger,
            'SnapController:updateSnapState',
          ),
          maybeUpdatePhishingList: this.controllerMessenger.call.bind(
            this.controllerMessenger,
            'PhishingController:maybeUpdateState',
          ),
          isOnPhishingList: (origin: string) =>
            this.controllerMessenger.call(
              'PhishingController:testOrigin',
              origin,
            ).result,
          showDialog: (
            origin: string,
            type: EnumToUnion<DialogType>,
            content: any, // should be Component from '@metamask/snaps-ui';
            placeholder?: any,
          ) =>
            approvalController.addAndShowApprovalRequest({
              origin,
              type,
              requestData: { content, placeholder },
            }),
          showInAppNotification: (origin: string, args: NotificationArgs) => {
            Logger.log(
              'Snaps/ showInAppNotification called with args: ',
              args,
              ' and origin: ',
              origin,
            );
          },
        },
      ),
    });

...
allowedActions: [...
'ExecutionService:executeSnap',
        // eslint-disable-next-line @typescript-eslint/ban-ts-comment
        // @ts-ignore
        'ExecutionService:getRpcRequestHandler',

...
const snapController = new SnapController({
      environmentEndowmentPermissions: Object.values(EndowmentPermissions),
      featureFlags: {
        // eslint-disable-next-line @typescript-eslint/ban-ts-comment
        // @ts-ignore
        requireAllowList,
      },
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant