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

Multichain: Lint #27745

Merged
merged 3 commits into from
Oct 9, 2024
Merged
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
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
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