Skip to content

Commit 306c5ff

Browse files
committed
refactor(keyring-api): fix new eslint errors
1 parent badeaeb commit 306c5ff

17 files changed

+43
-51
lines changed

packages/keyring-api/src/KeyringClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export type Sender = {
3535
};
3636

3737
export class KeyringClient implements Keyring {
38-
#sender: Sender;
38+
readonly #sender: Sender;
3939

4040
/**
4141
* Create a new instance of `KeyringClient`.

packages/keyring-api/src/KeyringSnapRpcClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import { KeyringClient } from './KeyringClient';
1010
* to a snap through the snap JSON-RPC API.
1111
*/
1212
export class SnapRpcSender implements Sender {
13-
#origin: string;
13+
readonly #origin: string;
1414

15-
#provider: MetaMaskInpageProvider;
15+
readonly #provider: MetaMaskInpageProvider;
1616

1717
/**
1818
* Create a new instance of `SnapRpcSender`.

packages/keyring-api/src/api/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ export * from './account';
22
export * from './balance';
33
export * from './caip';
44
export * from './export';
5-
export * from './keyring';
5+
export type * from './keyring';
66
export * from './request';
77
export * from './response';
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import type { BtcP2wpkhAccount } from './types';
12
import type { KeyringAccount } from '../api';
23
import type { Extends } from '../utils';
34
import { expectTrue } from '../utils';
4-
import type { BtcP2wpkhAccount } from './types';
55

66
// `BtcP2wpkhAccount` extends `KeyringAccount`
77
expectTrue<Extends<BtcP2wpkhAccount, KeyringAccount>>();

packages/keyring-api/src/eth/erc4337/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { EthAddressStruct, EthBytesStruct, EthUint256Struct } from '../types';
66

77
/**
88
* Struct of a UserOperation as defined by ERC-4337.
9+
*
910
* @see https://eips.ethereum.org/EIPS/eip-4337#definitions
1011
*/
1112
export const EthUserOperationStruct = object({

packages/keyring-api/src/eth/types.test-d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { expectAssignable, expectNotAssignable } from 'tsd';
22

3+
import type { EthEoaAccount, EthErc4337Account } from './types';
4+
import { EthMethod } from './types';
35
import type { KeyringAccount } from '../api';
46
import { EthAccountType } from '../api';
57
import type { Extends } from '../utils';
68
import { expectTrue } from '../utils';
7-
import type { EthEoaAccount, EthErc4337Account } from './types';
8-
import { EthMethod } from './types';
99

1010
const id = '606a7759-b0fb-48e4-9874-bab62ff8e7eb';
1111
const address = '0x000';

packages/keyring-api/src/eth/utils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { BtcAccountType, EthAccountType } from '../api';
21
import { isEvmAccountType } from './utils';
2+
import { BtcAccountType, EthAccountType } from '../api';
33

44
describe('isEvmAccountType', () => {
55
it.each([

packages/keyring-api/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export * from './api';
22
export * from './btc';
3-
export * from './contexts';
3+
export type * from './contexts';
44
export * from './eth';
55
export * from './events';
66
export * from './internal';

packages/keyring-api/src/internal/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from '@metamask/superstruct';
1010
import { JsonStruct } from '@metamask/utils';
1111

12+
import { KeyringRpcMethod } from './rpc';
1213
import {
1314
BalanceStruct,
1415
CaipAssetTypeStruct,
@@ -19,7 +20,6 @@ import {
1920
} from '../api';
2021
import { object } from '../superstruct';
2122
import { UuidStruct } from '../utils';
22-
import { KeyringRpcMethod } from './rpc';
2323

2424
const CommonHeader = {
2525
jsonrpc: literal('2.0'),
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from './EthKeyring';
1+
export type * from './EthKeyring';

packages/keyring-api/src/internal/events.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { is } from '@metamask/superstruct';
22

3-
import { EthAccountType } from '../api';
4-
import { KeyringEvent } from '../events';
53
import {
64
AccountCreatedEventStruct,
75
AccountDeletedEventStruct,
86
AccountUpdatedEventStruct,
97
RequestApprovedEventStruct,
108
RequestRejectedEventStruct,
119
} from './events';
10+
import { EthAccountType } from '../api';
11+
import { KeyringEvent } from '../events';
1212

1313
describe('events', () => {
1414
describe('AccountCreatedEventStruct', () => {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export * from './api';
2-
export * from './eth';
2+
export type * from './eth';
33
export * from './events';
44
export * from './rpc';
55
export * from './types';

packages/keyring-api/src/internal/types.ts

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,20 @@ export const InternalAccountMetadataStruct = object({
2727
}),
2828
});
2929

30-
/**
31-
* Creates an `InternalAccount` from an existing account `superstruct` object.
32-
*
33-
* @param accountStruct - An account `superstruct` object.
34-
* @returns The `InternalAccount` associated to `accountStruct`.
35-
*/
36-
function asInternalAccountStruct<Account, AccountSchema>(
37-
accountStruct: Struct<Account, AccountSchema>,
38-
) {
39-
return object({
40-
...accountStruct.schema,
41-
...InternalAccountMetadataStruct.schema,
42-
});
43-
}
44-
45-
export const InternalEthEoaAccountStruct =
46-
asInternalAccountStruct(EthEoaAccountStruct);
30+
export const InternalEthEoaAccountStruct = object({
31+
...EthEoaAccountStruct.schema,
32+
...InternalAccountMetadataStruct.schema,
33+
});
4734

48-
export const InternalEthErc4337AccountStruct = asInternalAccountStruct(
49-
EthErc4337AccountStruct,
50-
);
35+
export const InternalEthErc4337AccountStruct = object({
36+
...EthErc4337AccountStruct.schema,
37+
...InternalAccountMetadataStruct.schema,
38+
});
5139

52-
export const InternalBtcP2wpkhAccountStruct = asInternalAccountStruct(
53-
BtcP2wpkhAccountStruct,
54-
);
40+
export const InternalBtcP2wpkhAccountStruct = object({
41+
...BtcP2wpkhAccountStruct.schema,
42+
...InternalAccountMetadataStruct.schema,
43+
});
5544

5645
export type InternalEthEoaAccount = Infer<typeof InternalEthEoaAccountStruct>;
5746

packages/keyring-api/src/rpc-handler.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,22 @@ async function dispatchRequest(
4747
assert(request, JsonRpcRequestStruct);
4848

4949
switch (request.method) {
50-
case KeyringRpcMethod.ListAccounts: {
50+
case `${KeyringRpcMethod.ListAccounts}`: {
5151
assert(request, ListAccountsRequestStruct);
5252
return keyring.listAccounts();
5353
}
5454

55-
case KeyringRpcMethod.GetAccount: {
55+
case `${KeyringRpcMethod.GetAccount}`: {
5656
assert(request, GetAccountRequestStruct);
5757
return keyring.getAccount(request.params.id);
5858
}
5959

60-
case KeyringRpcMethod.CreateAccount: {
60+
case `${KeyringRpcMethod.CreateAccount}`: {
6161
assert(request, CreateAccountRequestStruct);
6262
return keyring.createAccount(request.params.options);
6363
}
6464

65-
case KeyringRpcMethod.GetAccountBalances: {
65+
case `${KeyringRpcMethod.GetAccountBalances}`: {
6666
if (keyring.getAccountBalances === undefined) {
6767
throw new MethodNotSupportedError(request.method);
6868
}
@@ -73,62 +73,62 @@ async function dispatchRequest(
7373
);
7474
}
7575

76-
case KeyringRpcMethod.FilterAccountChains: {
76+
case `${KeyringRpcMethod.FilterAccountChains}`: {
7777
assert(request, FilterAccountChainsStruct);
7878
return keyring.filterAccountChains(
7979
request.params.id,
8080
request.params.chains,
8181
);
8282
}
8383

84-
case KeyringRpcMethod.UpdateAccount: {
84+
case `${KeyringRpcMethod.UpdateAccount}`: {
8585
assert(request, UpdateAccountRequestStruct);
8686
return keyring.updateAccount(request.params.account);
8787
}
8888

89-
case KeyringRpcMethod.DeleteAccount: {
89+
case `${KeyringRpcMethod.DeleteAccount}`: {
9090
assert(request, DeleteAccountRequestStruct);
9191
return keyring.deleteAccount(request.params.id);
9292
}
9393

94-
case KeyringRpcMethod.ExportAccount: {
94+
case `${KeyringRpcMethod.ExportAccount}`: {
9595
if (keyring.exportAccount === undefined) {
9696
throw new MethodNotSupportedError(request.method);
9797
}
9898
assert(request, ExportAccountRequestStruct);
9999
return keyring.exportAccount(request.params.id);
100100
}
101101

102-
case KeyringRpcMethod.ListRequests: {
102+
case `${KeyringRpcMethod.ListRequests}`: {
103103
if (keyring.listRequests === undefined) {
104104
throw new MethodNotSupportedError(request.method);
105105
}
106106
assert(request, ListRequestsRequestStruct);
107107
return keyring.listRequests();
108108
}
109109

110-
case KeyringRpcMethod.GetRequest: {
110+
case `${KeyringRpcMethod.GetRequest}`: {
111111
if (keyring.getRequest === undefined) {
112112
throw new MethodNotSupportedError(request.method);
113113
}
114114
assert(request, GetRequestRequestStruct);
115115
return keyring.getRequest(request.params.id);
116116
}
117117

118-
case KeyringRpcMethod.SubmitRequest: {
118+
case `${KeyringRpcMethod.SubmitRequest}`: {
119119
assert(request, SubmitRequestRequestStruct);
120120
return keyring.submitRequest(request.params);
121121
}
122122

123-
case KeyringRpcMethod.ApproveRequest: {
123+
case `${KeyringRpcMethod.ApproveRequest}`: {
124124
if (keyring.approveRequest === undefined) {
125125
throw new MethodNotSupportedError(request.method);
126126
}
127127
assert(request, ApproveRequestRequestStruct);
128128
return keyring.approveRequest(request.params.id, request.params.data);
129129
}
130130

131-
case KeyringRpcMethod.RejectRequest: {
131+
case `${KeyringRpcMethod.RejectRequest}`: {
132132
if (keyring.rejectRequest === undefined) {
133133
throw new MethodNotSupportedError(request.method);
134134
}

packages/keyring-api/src/superstruct.test-d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { expectAssignable, expectNotAssignable } from 'tsd';
44

55
import { exactOptional, object } from '.';
66

7+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
78
const exactOptionalObject = object({
89
a: number(),
910
b: optional(string()),

packages/keyring-api/src/superstruct.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {
1414
Simplify,
1515
} from '@metamask/superstruct';
1616

17+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1718
declare const ExactOptionalSymbol: unique symbol;
1819

1920
export type ExactOptionalTag = {

packages/keyring-api/src/utils/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const UrlStruct = define<string>('Url', (value: unknown) => {
2020
try {
2121
const url = new URL(value as string);
2222
return url.protocol === 'http:' || url.protocol === 'https:';
23-
} catch (_) {
23+
} catch {
2424
return false;
2525
}
2626
});

0 commit comments

Comments
 (0)