Skip to content

Commit b725015

Browse files
legobeatMajorLift
authored andcommitted
deps(approval-controller): move to @metamask/rpc-errors (#1743)
## Explanation This replaces obsolete `eth-rpc-errors` with `@metamask/rpc-errors` in `@metamask/approval-controller`. This should be coupled with #1639 and can be merged before or after. ## References #### Broken out from - #1731 #### Blocking - #1724 #### Related - #1690 ## Changelog ### `@metamask/approval-controller` - **Changed**: Replaced `eth-rpc-errors` with `@metamask/rpc-errors` ### `@metamask/controller-utils` - **Fixed**: Removed unused dependency `eth-rpc-errors` ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've highlighted breaking changes using the "BREAKING" category above as appropriate
1 parent 8d99162 commit b725015

File tree

5 files changed

+17
-19
lines changed

5 files changed

+17
-19
lines changed

packages/approval-controller/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
},
3131
"dependencies": {
3232
"@metamask/base-controller": "^3.2.2",
33+
"@metamask/rpc-errors": "^6.0.0",
3334
"@metamask/utils": "^8.1.0",
34-
"eth-rpc-errors": "^4.0.2",
3535
"immer": "^9.0.6",
3636
"nanoid": "^3.1.31"
3737
},

packages/approval-controller/src/ApprovalController.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable jest/expect-expect */
22

33
import { ControllerMessenger } from '@metamask/base-controller';
4-
import { errorCodes, EthereumRpcError } from 'eth-rpc-errors';
4+
import { errorCodes, JsonRpcError } from '@metamask/rpc-errors';
55

66
import type {
77
ApprovalControllerActions,
@@ -652,7 +652,7 @@ describe('approval controller', () => {
652652
approvalController.reject('2', new Error('foo'));
653653
expect(approvalController.getTotalApprovalCount()).toBe(2);
654654

655-
approvalController.clear(new EthereumRpcError(1, 'clear'));
655+
approvalController.clear(new JsonRpcError(1, 'clear'));
656656
expect(approvalController.getTotalApprovalCount()).toBe(0);
657657
});
658658

@@ -677,7 +677,7 @@ describe('approval controller', () => {
677677
approvalController.reject('2', new Error('foo'));
678678
expect(approvalController.getTotalApprovalCount()).toBe(1);
679679

680-
approvalController.clear(new EthereumRpcError(1, 'clear'));
680+
approvalController.clear(new JsonRpcError(1, 'clear'));
681681
expect(approvalController.getTotalApprovalCount()).toBe(0);
682682
});
683683
});
@@ -1042,7 +1042,7 @@ describe('approval controller', () => {
10421042
describe('clear', () => {
10431043
it('does nothing if state is already empty', () => {
10441044
expect(() =>
1045-
approvalController.clear(new EthereumRpcError(1, 'clear')),
1045+
approvalController.clear(new JsonRpcError(1, 'clear')),
10461046
).not.toThrow();
10471047
});
10481048

@@ -1057,7 +1057,7 @@ describe('approval controller', () => {
10571057
.add({ id: 'foo3', origin: 'fizz.buzz', type: 'myType' })
10581058
.catch((_error) => undefined);
10591059

1060-
approvalController.clear(new EthereumRpcError(1, 'clear'));
1060+
approvalController.clear(new JsonRpcError(1, 'clear'));
10611061

10621062
expect(
10631063
approvalController.state[PENDING_APPROVALS_STORE_KEY],
@@ -1072,16 +1072,16 @@ describe('approval controller', () => {
10721072
type: 'myType',
10731073
});
10741074

1075-
approvalController.clear(new EthereumRpcError(1000, 'foo'));
1075+
approvalController.clear(new JsonRpcError(1000, 'foo'));
10761076
await expect(rejectPromise).rejects.toThrow(
1077-
new EthereumRpcError(1000, 'foo'),
1077+
new JsonRpcError(1000, 'foo'),
10781078
);
10791079
});
10801080

10811081
it('does not clear approval flows', async () => {
10821082
approvalController.startFlow();
10831083

1084-
approvalController.clear(new EthereumRpcError(1, 'clear'));
1084+
approvalController.clear(new JsonRpcError(1, 'clear'));
10851085

10861086
expect(approvalController.state[APPROVAL_FLOWS_STORE_KEY]).toHaveLength(
10871087
1,

packages/approval-controller/src/ApprovalController.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { RestrictedControllerMessenger } from '@metamask/base-controller';
22
import { BaseControllerV2 } from '@metamask/base-controller';
3+
import type { JsonRpcError, DataWithOptionalCause } from '@metamask/rpc-errors';
4+
import { rpcErrors } from '@metamask/rpc-errors';
35
import type { Json, OptionalField } from '@metamask/utils';
4-
import type { EthereumRpcError } from 'eth-rpc-errors';
5-
import { ethErrors } from 'eth-rpc-errors';
66
import type { Patch } from 'immer';
77
import { nanoid } from 'nanoid';
88

@@ -256,7 +256,7 @@ export type GetApprovalsState = {
256256

257257
export type ClearApprovalRequests = {
258258
type: `${typeof controllerName}:clearRequests`;
259-
handler: (error: EthereumRpcError<unknown>) => void;
259+
handler: (error: JsonRpcError<DataWithOptionalCause>) => void;
260260
};
261261

262262
export type AddApprovalRequest = {
@@ -719,10 +719,10 @@ export class ApprovalController extends BaseControllerV2<
719719
/**
720720
* Rejects and deletes all approval requests.
721721
*
722-
* @param rejectionError - The EthereumRpcError to reject the approval
722+
* @param rejectionError - The JsonRpcError to reject the approval
723723
* requests with.
724724
*/
725-
clear(rejectionError: EthereumRpcError<unknown>): void {
725+
clear(rejectionError: JsonRpcError<DataWithOptionalCause>): void {
726726
for (const id of this.#approvals.keys()) {
727727
this.reject(id, rejectionError);
728728
}
@@ -878,7 +878,7 @@ export class ApprovalController extends BaseControllerV2<
878878
!this.#typesExcludedFromRateLimiting.includes(type) &&
879879
this.has({ origin, type })
880880
) {
881-
throw ethErrors.rpc.resourceUnavailable(
881+
throw rpcErrors.resourceUnavailable(
882882
getAlreadyPendingMessage(origin, type),
883883
);
884884
}
@@ -937,7 +937,7 @@ export class ApprovalController extends BaseControllerV2<
937937
}
938938

939939
if (errorMessage) {
940-
throw ethErrors.rpc.internal(errorMessage);
940+
throw rpcErrors.internal(errorMessage);
941941
}
942942
}
943943

packages/controller-utils/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"@metamask/utils": "^8.1.0",
3434
"@spruceid/siwe-parser": "1.1.3",
3535
"eth-ens-namehash": "^2.0.8",
36-
"eth-rpc-errors": "^4.0.2",
3736
"ethereumjs-util": "^7.0.10",
3837
"ethjs-unit": "^0.1.6",
3938
"fast-deep-equal": "^3.1.3"

yarn.lock

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,10 +1369,10 @@ __metadata:
13691369
dependencies:
13701370
"@metamask/auto-changelog": ^3.1.0
13711371
"@metamask/base-controller": ^3.2.2
1372+
"@metamask/rpc-errors": ^6.0.0
13721373
"@metamask/utils": ^8.1.0
13731374
"@types/jest": ^27.4.1
13741375
deepmerge: ^4.2.2
1375-
eth-rpc-errors: ^4.0.2
13761376
immer: ^9.0.6
13771377
jest: ^27.5.1
13781378
nanoid: ^3.1.31
@@ -1506,7 +1506,6 @@ __metadata:
15061506
"@types/jest": ^27.4.1
15071507
deepmerge: ^4.2.2
15081508
eth-ens-namehash: ^2.0.8
1509-
eth-rpc-errors: ^4.0.2
15101509
ethereumjs-util: ^7.0.10
15111510
ethjs-unit: ^0.1.6
15121511
fast-deep-equal: ^3.1.3

0 commit comments

Comments
 (0)