Skip to content

Commit

Permalink
Merge branch 'main' into deps-metamask-utils-8
Browse files Browse the repository at this point in the history
  • Loading branch information
MajorLift authored Sep 27, 2023
2 parents 1b63bfa + 978ffa1 commit 7aee973
Show file tree
Hide file tree
Showing 37 changed files with 252 additions and 119 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"rimraf": "^3.0.2",
"simple-git-hooks": "^2.8.0",
"ts-node": "^10.9.1",
"typescript": "~4.6.3",
"typescript": "~4.8.4",
"which": "^3.0.0"
},
"packageManager": "[email protected]",
Expand Down
2 changes: 1 addition & 1 deletion packages/accounts-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"ts-jest": "^27.1.4",
"typedoc": "^0.23.15",
"typedoc-plugin-missing-exports": "^0.23.0",
"typescript": "~4.6.3"
"typescript": "~4.8.4"
},
"peerDependencies": {
"@metamask/keyring-controller": "^8.0.0"
Expand Down
5 changes: 4 additions & 1 deletion packages/accounts-controller/src/AccountsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,10 @@ export class AccountsController extends BaseControllerV2<
currentState.internalAccounts.selectedAccount = account.id;
});

this.messagingSystem.publish(`${this.name}:selectedAccountChange`, account);
this.messagingSystem.publish(
'AccountsController:selectedAccountChange',
account,
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/address-book-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"ts-jest": "^27.1.4",
"typedoc": "^0.23.15",
"typedoc-plugin-missing-exports": "^0.23.0",
"typescript": "~4.6.3"
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/announcement-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"ts-jest": "^27.1.4",
"typedoc": "^0.23.15",
"typedoc-plugin-missing-exports": "^0.23.0",
"typescript": "~4.6.3"
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/approval-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"ts-jest": "^27.1.4",
"typedoc": "^0.23.15",
"typedoc-plugin-missing-exports": "^0.23.0",
"typescript": "~4.6.3"
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
Expand Down
29 changes: 23 additions & 6 deletions packages/approval-controller/src/ApprovalController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,8 @@ describe('approval controller', () => {

describe('get', () => {
it('gets entry', () => {
// We only want to test the stored entity in the controller state hence disabling floating promises here.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
approvalController.add({
id: 'foo',
origin: 'bar.baz',
Expand All @@ -481,7 +483,13 @@ describe('approval controller', () => {
});

it('returns undefined for non-existing entry', () => {
approvalController.add({ id: 'foo', origin: 'bar.baz', type: 'type' });
// We only want to test the stored entity in the controller state hence disabling floating promises here.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
approvalController.add({
id: 'foo',
origin: 'bar.baz',
type: 'type',
});

expect(approvalController.get('fizz')).toBeUndefined();

Expand All @@ -495,8 +503,9 @@ describe('approval controller', () => {
let addWithCatch: (args: any) => void;

beforeEach(() => {
addWithCatch = (args: any) =>
addWithCatch = (args: any) => {
approvalController.add(args).catch(() => undefined);
};
});

it('validates input', () => {
Expand Down Expand Up @@ -627,8 +636,9 @@ describe('approval controller', () => {
it('gets the total approval count', () => {
expect(approvalController.getTotalApprovalCount()).toBe(0);

const addWithCatch = (args: any) =>
const addWithCatch = (args: any) => {
approvalController.add(args).catch(() => undefined);
};

addWithCatch({ id: '1', origin: 'origin1', type: 'type0' });
expect(approvalController.getTotalApprovalCount()).toBe(1);
Expand All @@ -654,8 +664,9 @@ describe('approval controller', () => {
});
expect(approvalController.getTotalApprovalCount()).toBe(0);

const addWithCatch = (args: any) =>
const addWithCatch = (args: any) => {
approvalController.add(args).catch(() => undefined);
};

addWithCatch({ id: '1', origin: 'origin1', type: 'type0' });
expect(approvalController.getTotalApprovalCount()).toBe(1);
Expand Down Expand Up @@ -698,8 +709,14 @@ describe('approval controller', () => {
).toThrow(getInvalidHasTypeError());
});

it('returns true for existing entry by id', () => {
approvalController.add({ id: 'foo', origin: 'bar.baz', type: TYPE });
it('returns true for existing entry by id', async () => {
// We only want to check the stored entity is exist in the state hence disabling floating promises here.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
approvalController.add({
id: 'foo',
origin: 'bar.baz',
type: TYPE,
});

expect(approvalController.has({ id: 'foo' })).toBe(true);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/assets-controllers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@metamask/metamask-eth-abis": "3.0.0",
"@metamask/network-controller": "^13.0.0",
"@metamask/preferences-controller": "^4.4.1",
"@metamask/rpc-errors": "^5.1.1",
"@metamask/rpc-errors": "^6.0.0",
"@metamask/utils": "^8.1.0",
"@types/uuid": "^8.3.0",
"async-mutex": "^0.2.6",
Expand All @@ -64,7 +64,7 @@
"ts-jest": "^27.1.4",
"typedoc": "^0.23.15",
"typedoc-plugin-missing-exports": "^0.23.0",
"typescript": "~4.6.3"
"typescript": "~4.8.4"
},
"peerDependencies": {
"@metamask/approval-controller": "^3.5.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/base-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"ts-jest": "^27.1.4",
"typedoc": "^0.23.15",
"typedoc-plugin-missing-exports": "^0.23.0",
"typescript": "~4.6.3"
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/composable-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"ts-jest": "^27.1.4",
"typedoc": "^0.23.15",
"typedoc-plugin-missing-exports": "^0.23.0",
"typescript": "~4.6.3"
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/controller-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"ts-jest": "^27.1.4",
"typedoc": "^0.23.15",
"typedoc-plugin-missing-exports": "^0.23.0",
"typescript": "~4.6.3"
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/ens-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"ts-jest": "^27.1.4",
"typedoc": "^0.23.15",
"typedoc-plugin-missing-exports": "^0.23.0",
"typescript": "~4.6.3"
"typescript": "~4.8.4"
},
"peerDependencies": {
"@metamask/network-controller": "^13.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/gas-fee-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"ts-jest": "^27.1.4",
"typedoc": "^0.23.15",
"typedoc-plugin-missing-exports": "^0.23.0",
"typescript": "~4.6.3"
"typescript": "~4.8.4"
},
"peerDependencies": {
"@metamask/network-controller": "^13.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/keyring-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"ts-jest": "^27.1.4",
"typedoc": "^0.23.15",
"typedoc-plugin-missing-exports": "^0.23.0",
"typescript": "~4.6.3",
"typescript": "~4.8.4",
"uuid": "^8.3.2"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/logging-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"ts-jest": "^27.1.4",
"typedoc": "^0.23.15",
"typedoc-plugin-missing-exports": "^0.23.0",
"typescript": "~4.6.3"
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/message-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"ts-jest": "^27.1.4",
"typedoc": "^0.23.15",
"typedoc-plugin-missing-exports": "^0.23.0",
"typescript": "~4.6.3"
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/name-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"ts-jest": "^27.1.4",
"typedoc": "^0.23.15",
"typedoc-plugin-missing-exports": "^0.23.0",
"typescript": "~4.6.3"
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
Expand Down
8 changes: 6 additions & 2 deletions packages/name-controller/src/providers/etherscan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
NameProviderResult,
} from '../types';
import { NameType } from '../types';
import { handleFetch } from '../util';
import { handleFetch, assertIsError } from '../util';

const ID = 'etherscan';
const LABEL = 'Etherscan (Verified Contract Name)';
Expand Down Expand Up @@ -134,7 +134,10 @@ export class EtherscanNameProvider implements NameProvider {
}
}

async #sendRequest(url: string) {
async #sendRequest(url: string): Promise<{
responseData?: EtherscanGetSourceCodeResponse;
error?: Error;
}> {
try {
log('Sending request', url);

Expand All @@ -144,6 +147,7 @@ export class EtherscanNameProvider implements NameProvider {

return { responseData };
} catch (error) {
assertIsError(error);
return { error };
} finally {
this.#lastRequestTime = Date.now();
Expand Down
16 changes: 16 additions & 0 deletions packages/name-controller/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,19 @@ export async function successfulFetch(request: string, options?: RequestInit) {
}
return response;
}

/**
* Assert that a value is an error. If it's not an error, throw an
* error that wraps the given value.
*
* TODO: Migrate this to @metamask/utils
*
* @param error - The value that we expect to be an error.
* @throws Throws an error wrapping the given value if it's not an error.
*/
export function assertIsError(error: unknown): asserts error is Error {
if (error instanceof Error) {
return;
}
throw new Error(`Invalid error of type '${typeof error}'`);
}
14 changes: 13 additions & 1 deletion packages/name-controller/src/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { graphQL } from './util';
import { assertIsError, graphQL } from './util';

describe('Utils', () => {
describe('graphQL', () => {
Expand Down Expand Up @@ -51,4 +51,16 @@ describe('Utils', () => {
);
});
});

describe('assertIsError', () => {
it('does not throw if given an error', () => {
expect(() => assertIsError(new Error('test'))).not.toThrow();
});

it('throws if passed something that is not an error', () => {
expect(() => assertIsError('test')).toThrow(
`Invalid error of type 'string'`,
);
});
});
});
2 changes: 1 addition & 1 deletion packages/network-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"ts-jest": "^27.1.4",
"typedoc": "^0.23.15",
"typedoc-plugin-missing-exports": "^0.23.0",
"typescript": "~4.6.3"
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/notification-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"ts-jest": "^27.1.4",
"typedoc": "^0.23.15",
"typedoc-plugin-missing-exports": "^0.23.0",
"typescript": "~4.6.3"
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/permission-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"ts-jest": "^27.1.4",
"typedoc": "^0.23.15",
"typedoc-plugin-missing-exports": "^0.23.0",
"typescript": "~4.6.3"
"typescript": "~4.8.4"
},
"peerDependencies": {
"@metamask/approval-controller": "^3.5.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/phishing-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"ts-jest": "^27.1.4",
"typedoc": "^0.23.15",
"typedoc-plugin-missing-exports": "^0.23.0",
"typescript": "~4.6.3"
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/polling-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"ts-jest": "^27.1.4",
"typedoc": "^0.23.15",
"typedoc-plugin-missing-exports": "^0.23.0",
"typescript": "~4.6.3"
"typescript": "~4.8.4"
},
"peerDependencies": {
"@metamask/network-controller": "^13.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/preferences-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"ts-jest": "^27.1.4",
"typedoc": "^0.23.15",
"typedoc-plugin-missing-exports": "^0.23.0",
"typescript": "~4.6.3"
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/rate-limit-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"ts-jest": "^27.1.4",
"typedoc": "^0.23.15",
"typedoc-plugin-missing-exports": "^0.23.0",
"typescript": "~4.6.3"
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/selected-network-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"ts-jest": "^27.1.4",
"typedoc": "^0.23.15",
"typedoc-plugin-missing-exports": "^0.23.0",
"typescript": "~4.6.3"
"typescript": "~4.8.4"
},
"peerDependencies": {
"@metamask/network-controller": "^13.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/signature-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"ts-jest": "^27.1.4",
"typedoc": "^0.23.15",
"typedoc-plugin-missing-exports": "^0.23.0",
"typescript": "~4.6.3"
"typescript": "~4.8.4"
},
"peerDependencies": {
"@metamask/approval-controller": "^3.5.1",
Expand Down
Loading

0 comments on commit 7aee973

Please sign in to comment.