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

deps(approval-controller): eth-rpc-errors -> @metamask/rpc-errors #3

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion packages/approval-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
},
"dependencies": {
"@metamask/base-controller": "^3.2.2",
"@metamask/rpc-errors": "^6.0.0",
"@metamask/utils": "^6.2.0",
"eth-rpc-errors": "^4.0.2",
"immer": "^9.0.6",
"nanoid": "^3.1.31"
},
Expand Down
16 changes: 8 additions & 8 deletions packages/approval-controller/src/ApprovalController.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable jest/expect-expect */

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

import type {
ApprovalControllerActions,
Expand Down Expand Up @@ -652,7 +652,7 @@
approvalController.reject('2', new Error('foo'));
expect(approvalController.getTotalApprovalCount()).toBe(2);

approvalController.clear(new EthereumRpcError(1, 'clear'));
approvalController.clear(new JsonRpcError(1, 'clear'));
expect(approvalController.getTotalApprovalCount()).toBe(0);
});

Expand All @@ -677,7 +677,7 @@
approvalController.reject('2', new Error('foo'));
expect(approvalController.getTotalApprovalCount()).toBe(1);

approvalController.clear(new EthereumRpcError(1, 'clear'));
approvalController.clear(new JsonRpcError(1, 'clear'));
expect(approvalController.getTotalApprovalCount()).toBe(0);
});
});
Expand Down Expand Up @@ -722,13 +722,13 @@
});

it('returns true for existing entry by origin', () => {
approvalController.add({ id: 'foo', origin: 'bar.baz', type: TYPE });

Check warning on line 725 in packages/approval-controller/src/ApprovalController.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

expect(approvalController.has({ origin: 'bar.baz' })).toBe(true);
});

it('returns true for existing entry by origin and type', () => {
approvalController.add({ id: 'foo', origin: 'bar.baz', type: 'myType' });

Check warning on line 731 in packages/approval-controller/src/ApprovalController.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

expect(
approvalController.has({ origin: 'bar.baz', type: 'myType' }),
Expand All @@ -736,25 +736,25 @@
});

it('returns true for existing type', () => {
approvalController.add({ id: 'foo', origin: 'bar.baz', type: 'myType' });

Check warning on line 739 in packages/approval-controller/src/ApprovalController.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

expect(approvalController.has({ type: 'myType' })).toBe(true);
});

it('returns false for non-existing entry by id', () => {
approvalController.add({ id: 'foo', origin: 'bar.baz', type: TYPE });

Check warning on line 745 in packages/approval-controller/src/ApprovalController.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

expect(approvalController.has({ id: 'fizz' })).toBe(false);
});

it('returns false for non-existing entry by origin', () => {
approvalController.add({ id: 'foo', origin: 'bar.baz', type: TYPE });

Check warning on line 751 in packages/approval-controller/src/ApprovalController.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

expect(approvalController.has({ origin: 'fizz.buzz' })).toBe(false);
});

it('returns false for non-existing entry by existing origin and non-existing type', () => {
approvalController.add({ id: 'foo', origin: 'bar.baz', type: TYPE });

Check warning on line 757 in packages/approval-controller/src/ApprovalController.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

expect(
approvalController.has({ origin: 'bar.baz', type: 'myType' }),
Expand All @@ -762,7 +762,7 @@
});

it('returns false for non-existing entry by non-existing origin and existing type', () => {
approvalController.add({ id: 'foo', origin: 'bar.baz', type: 'myType' });

Check warning on line 765 in packages/approval-controller/src/ApprovalController.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

expect(
approvalController.has({ origin: 'fizz.buzz', type: 'myType' }),
Expand All @@ -770,7 +770,7 @@
});

it('returns false for non-existing entry by type', () => {
approvalController.add({ id: 'foo', origin: 'bar.baz', type: 'myType1' });

Check warning on line 773 in packages/approval-controller/src/ApprovalController.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

expect(approvalController.has({ type: 'myType2' })).toBe(false);
});
Expand All @@ -783,7 +783,7 @@
origin: 'bar.baz',
type: 'myType',
});
approvalController.accept('foo', 'success');

Check warning on line 786 in packages/approval-controller/src/ApprovalController.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

const result = await approvalPromise;
expect(result).toBe('success');
Expand All @@ -801,7 +801,7 @@
type: 'myType2',
});

approvalController.accept('foo2', 'success2');

Check warning on line 804 in packages/approval-controller/src/ApprovalController.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

let result = await approvalPromise2;
expect(result).toBe('success2');
Expand Down Expand Up @@ -1042,7 +1042,7 @@
describe('clear', () => {
it('does nothing if state is already empty', () => {
expect(() =>
approvalController.clear(new EthereumRpcError(1, 'clear')),
approvalController.clear(new JsonRpcError(1, 'clear')),
).not.toThrow();
});

Expand All @@ -1057,7 +1057,7 @@
.add({ id: 'foo3', origin: 'fizz.buzz', type: 'myType' })
.catch((_error) => undefined);

approvalController.clear(new EthereumRpcError(1, 'clear'));
approvalController.clear(new JsonRpcError(1, 'clear'));

expect(
approvalController.state[PENDING_APPROVALS_STORE_KEY],
Expand All @@ -1072,16 +1072,16 @@
type: 'myType',
});

approvalController.clear(new EthereumRpcError(1000, 'foo'));
approvalController.clear(new JsonRpcError(1000, 'foo'));
await expect(rejectPromise).rejects.toThrow(
new EthereumRpcError(1000, 'foo'),
new JsonRpcError(1000, 'foo'),
);
});

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

approvalController.clear(new EthereumRpcError(1, 'clear'));
approvalController.clear(new JsonRpcError(1, 'clear'));

expect(approvalController.state[APPROVAL_FLOWS_STORE_KEY]).toHaveLength(
1,
Expand Down
14 changes: 7 additions & 7 deletions packages/approval-controller/src/ApprovalController.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { RestrictedControllerMessenger } from '@metamask/base-controller';
import { BaseControllerV2 } from '@metamask/base-controller';
import type { JsonRpcError, DataWithOptionalCause } from '@metamask/rpc-errors';
import { rpcErrors } from '@metamask/rpc-errors';
import type { Json, OptionalField } from '@metamask/utils';
import type { EthereumRpcError } from 'eth-rpc-errors';
import { ethErrors } from 'eth-rpc-errors';
import type { Patch } from 'immer';
import { nanoid } from 'nanoid';

Expand Down Expand Up @@ -256,7 +256,7 @@ export type GetApprovalsState = {

export type ClearApprovalRequests = {
type: `${typeof controllerName}:clearRequests`;
handler: (error: EthereumRpcError<unknown>) => void;
handler: (error: JsonRpcError<DataWithOptionalCause>) => void;
};

export type AddApprovalRequest = {
Expand Down Expand Up @@ -719,10 +719,10 @@ export class ApprovalController extends BaseControllerV2<
/**
* Rejects and deletes all approval requests.
*
* @param rejectionError - The EthereumRpcError to reject the approval
* @param rejectionError - The JsonRpcError to reject the approval
* requests with.
*/
clear(rejectionError: EthereumRpcError<unknown>): void {
clear(rejectionError: JsonRpcError<DataWithOptionalCause>): void {
for (const id of this.#approvals.keys()) {
this.reject(id, rejectionError);
}
Expand Down Expand Up @@ -878,7 +878,7 @@ export class ApprovalController extends BaseControllerV2<
!this.#typesExcludedFromRateLimiting.includes(type) &&
this.has({ origin, type })
) {
throw ethErrors.rpc.resourceUnavailable(
throw rpcErrors.resourceUnavailable(
getAlreadyPendingMessage(origin, type),
);
}
Expand Down Expand Up @@ -937,7 +937,7 @@ export class ApprovalController extends BaseControllerV2<
}

if (errorMessage) {
throw ethErrors.rpc.internal(errorMessage);
throw rpcErrors.internal(errorMessage);
}
}

Expand Down
1 change: 0 additions & 1 deletion packages/controller-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"@metamask/utils": "^6.2.0",
"@spruceid/siwe-parser": "1.1.3",
"eth-ens-namehash": "^2.0.8",
"eth-rpc-errors": "^4.0.2",
"ethereumjs-util": "^7.0.10",
"ethjs-unit": "^0.1.6",
"fast-deep-equal": "^3.1.3"
Expand Down
3 changes: 1 addition & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1369,10 +1369,10 @@ __metadata:
dependencies:
"@metamask/auto-changelog": ^3.1.0
"@metamask/base-controller": ^3.2.2
"@metamask/rpc-errors": ^6.0.0
"@metamask/utils": ^6.2.0
"@types/jest": ^27.4.1
deepmerge: ^4.2.2
eth-rpc-errors: ^4.0.2
immer: ^9.0.6
jest: ^27.5.1
nanoid: ^3.1.31
Expand Down Expand Up @@ -1506,7 +1506,6 @@ __metadata:
"@types/jest": ^27.4.1
deepmerge: ^4.2.2
eth-ens-namehash: ^2.0.8
eth-rpc-errors: ^4.0.2
ethereumjs-util: ^7.0.10
ethjs-unit: ^0.1.6
fast-deep-equal: ^3.1.3
Expand Down