Skip to content

Commit

Permalink
Multichain: Lint (#27745)
Browse files Browse the repository at this point in the history
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/27745?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
jiexi authored Oct 9, 2024
1 parent a19cf08 commit 6c3bc39
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { JsonRpcRequest } from '@metamask/utils';
import { JsonRpcRequest } from 'json-rpc-engine';
import MultichainMiddlewareManager, {
ExtendedJsonRpcMiddleware,
} from './MultichainMiddlewareManager';
Expand All @@ -14,7 +14,7 @@ describe('MultichainMiddlewareManager', () => {
middlewareSpy,
);
multichainMiddlewareManager.middleware(
{ scope: 'eip155:1' } as unknown as JsonRpcRequest,
{ scope: 'eip155:1' } as unknown as JsonRpcRequest<unknown>,
{ jsonrpc: '2.0', id: 0 },
() => {
//
Expand All @@ -34,7 +34,7 @@ describe('MultichainMiddlewareManager', () => {
multichainMiddlewareManager.removeMiddleware(scope, domain);
const endSpy = jest.fn();
multichainMiddlewareManager.middleware(
{ scope } as unknown as JsonRpcRequest,
{ scope: 'eip155:1' } as unknown as JsonRpcRequest<unknown>,
{ jsonrpc: '2.0', id: 0 },
() => {
//
Expand All @@ -54,7 +54,7 @@ describe('MultichainMiddlewareManager', () => {
multichainMiddlewareManager.removeAllMiddleware();
const endSpy = jest.fn();
multichainMiddlewareManager.middleware(
{ scope } as unknown as JsonRpcRequest,
{ scope: 'eip155:1' } as unknown as JsonRpcRequest<unknown>,
{ jsonrpc: '2.0', id: 0 },
() => {
//
Expand Down
15 changes: 7 additions & 8 deletions app/scripts/lib/multichain-api/MultichainSubscriptionManager.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import EventEmitter from 'events';
import { NetworkController } from '@metamask/network-controller';
import SafeEventEmitter from '@metamask/safe-event-emitter';
import { Hex, parseCaipChainId } from '@metamask/utils';
import { CaipChainId, Hex, parseCaipChainId } from '@metamask/utils';
import { toHex } from '@metamask/controller-utils';
import { ScopeString } from './scope';

export type SubscriptionManager = {
events: EventEmitter;
Expand Down Expand Up @@ -52,7 +51,7 @@ export default class MultichainSubscriptionManager extends SafeEventEmitter {
}

onNotification(
scopeString: ScopeString,
scopeString: CaipChainId,
domain: string,
{ method, params }: SubscriptionNotificationEvent,
) {
Expand All @@ -65,7 +64,7 @@ export default class MultichainSubscriptionManager extends SafeEventEmitter {
});
}

subscribe(scopeString: ScopeString, domain: string) {
subscribe(scopeString: CaipChainId, domain: string) {
let subscriptionManager;
if (this.subscriptionManagerByChain[scopeString]) {
subscriptionManager = this.subscriptionManagerByChain[scopeString];
Expand Down Expand Up @@ -96,7 +95,7 @@ export default class MultichainSubscriptionManager extends SafeEventEmitter {
return subscriptionManager;
}

unsubscribe(scopeString: ScopeString, domain: string) {
unsubscribe(scopeString: CaipChainId, domain: string) {
const subscriptionManager: SubscriptionManager =
this.subscriptionManagerByChain[scopeString];
if (subscriptionManager && this.subscriptionsByChain[scopeString][domain]) {
Expand Down Expand Up @@ -124,13 +123,13 @@ export default class MultichainSubscriptionManager extends SafeEventEmitter {
Object.entries(this.subscriptionsByChain).forEach(
([scopeString, domainObject]) => {
Object.entries(domainObject).forEach(([domain]) => {
this.unsubscribe(scopeString as ScopeString, domain);
this.unsubscribe(scopeString as CaipChainId, domain);
});
},
);
}

unsubscribeScope(scopeString: ScopeString) {
unsubscribeScope(scopeString: CaipChainId) {
Object.entries(this.subscriptionsByChain).forEach(
([_scopeString, domainObject]) => {
if (scopeString === _scopeString) {
Expand All @@ -147,7 +146,7 @@ export default class MultichainSubscriptionManager extends SafeEventEmitter {
([scopeString, domainObject]) => {
Object.entries(domainObject).forEach(([_domain]) => {
if (domain === _domain) {
this.unsubscribe(scopeString as ScopeString, domain);
this.unsubscribe(scopeString as CaipChainId, domain);
}
});
},
Expand Down
3 changes: 3 additions & 0 deletions app/scripts/lib/multichain-api/scope/supported.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {

describe('Scope Support', () => {
describe('isSupportedNotification', () => {
// @ts-expect-error This is missing from the Mocha type definitions
it.each(Object.entries(KnownNotifications))(
'returns true for each %s scope method',
(scopeString: ScopeString, notifications: string[]) => {
Expand All @@ -33,6 +34,7 @@ describe('Scope Support', () => {
});

describe('isSupportedMethod', () => {
// @ts-expect-error This is missing from the Mocha type definitions
it.each(Object.entries(KnownRpcMethods))(
'returns true for each %s scoped method',
(scopeString: ScopeString, methods: string[]) => {
Expand All @@ -48,6 +50,7 @@ describe('Scope Support', () => {
});
});

// @ts-expect-error This is missing from the Mocha type definitions
it.each(Object.entries(KnownWalletNamespaceRpcMethods))(
'returns true for each wallet:%s scoped method',
(scopeString: ScopeString, methods: string[]) => {
Expand Down
4 changes: 3 additions & 1 deletion app/scripts/migrations/131.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,9 @@ describe('migration #131', () => {
'the currently selected network client is %s',
(
_type: string,
NetworkController: Record<string, unknown>,
NetworkController: {
networkConfigurations: Record<string, unknown>;
} & Record<string, unknown>,
chainId: string,
) => {
const baseData = () => ({
Expand Down
4 changes: 4 additions & 0 deletions ui/pages/permissions-connect/connect-page/connect-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ import PermissionsConnectFooter from '../../../components/app/permissions-connec
export type ConnectPageRequest = {
id: string;
origin: string;
permissions?: Record<
string,
{ caveats: { type: string; value: string[] }[] }
>;
};

type ConnectPageProps = {
Expand Down
9 changes: 1 addition & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4177,20 +4177,13 @@ __metadata:
languageName: node
linkType: hard

"@json-schema-tools/traverse@npm:^1.10.4":
"@json-schema-tools/traverse@npm:^1.10.4, @json-schema-tools/traverse@npm:^1.7.5, @json-schema-tools/traverse@npm:^1.7.8":
version: 1.10.4
resolution: "@json-schema-tools/traverse@npm:1.10.4"
checksum: 10/0027bc90df01c5eeee0833e722b7320b53be8b5ce3f4e0e4a6e45713a38e6f88f21aba31e3dd973093ef75cd21a40c07fe8f112da8f49a7919b1c0e44c904d20
languageName: node
linkType: hard

"@json-schema-tools/traverse@npm:^1.7.5, @json-schema-tools/traverse@npm:^1.7.8":
version: 1.10.3
resolution: "@json-schema-tools/traverse@npm:1.10.3"
checksum: 10/690623740d223ea373d8e561dad5c70bf86461bcedc5fc45da01c87bcdf3284bbdbad3006d4a423f8d82e4b2d4580e45f92c0b272f006024fb597d7f01876215
languageName: node
linkType: hard

"@juggle/resize-observer@npm:^3.3.1":
version: 3.4.0
resolution: "@juggle/resize-observer@npm:3.4.0"
Expand Down

0 comments on commit 6c3bc39

Please sign in to comment.