Skip to content

Commit

Permalink
Merge branch 'main' into remove-provider-config-from-token-list-contr…
Browse files Browse the repository at this point in the history
…oller
  • Loading branch information
mcmire authored Jun 3, 2024
2 parents bbcc8a4 + 076a657 commit c6cd7df
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 71 deletions.
2 changes: 1 addition & 1 deletion packages/accounts-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@ethereumjs/util": "^8.1.0",
"@metamask/base-controller": "^6.0.0",
"@metamask/eth-snap-keyring": "^4.1.1",
"@metamask/keyring-api": "^6.1.1",
"@metamask/keyring-api": "^6.4.0",
"@metamask/snaps-sdk": "^4.2.0",
"@metamask/snaps-utils": "^7.4.0",
"@metamask/utils": "^8.3.0",
Expand Down
21 changes: 13 additions & 8 deletions packages/accounts-controller/src/AccountsController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
BtcAccountType,
BtcMethod,
EthAccountType,
EthErc4337Method,
EthMethod,
} from '@metamask/keyring-api';
import { KeyringTypes } from '@metamask/keyring-controller';
Expand Down Expand Up @@ -46,7 +45,7 @@ const mockGetKeyringForAccount = jest.fn();
const mockGetKeyringByType = jest.fn();
const mockGetAccounts = jest.fn();

const EOA_METHODS = [
const ETH_EOA_METHODS = [
EthMethod.PersonalSign,
EthMethod.Sign,
EthMethod.SignTransaction,
Expand All @@ -55,11 +54,17 @@ const EOA_METHODS = [
EthMethod.SignTypedDataV4,
] as const;

const ETH_ERC_4337_METHODS = [
EthMethod.PatchUserOperation,
EthMethod.PrepareUserOperation,
EthMethod.SignUserOperation,
] as const;

const mockAccount: InternalAccount = {
id: 'mock-id',
address: '0x123',
options: {},
methods: [...EOA_METHODS],
methods: [...ETH_EOA_METHODS],
type: EthAccountType.Eoa,
metadata: {
name: 'Account 1',
Expand All @@ -73,7 +78,7 @@ const mockAccount2: InternalAccount = {
id: 'mock-id2',
address: '0x1234',
options: {},
methods: [...EOA_METHODS],
methods: [...ETH_EOA_METHODS],
type: EthAccountType.Eoa,
metadata: {
name: 'Account 2',
Expand All @@ -87,7 +92,7 @@ const mockAccount3: InternalAccount = {
id: 'mock-id3',
address: '0x3333',
options: {},
methods: [...EOA_METHODS],
methods: [...ETH_EOA_METHODS],
type: EthAccountType.Eoa,
metadata: {
name: '',
Expand All @@ -106,7 +111,7 @@ const mockAccount4: InternalAccount = {
id: 'mock-id4',
address: '0x4444',
options: {},
methods: [...EOA_METHODS],
methods: [...ETH_EOA_METHODS],
type: EthAccountType.Eoa,
metadata: {
name: 'Custom Name',
Expand Down Expand Up @@ -183,8 +188,8 @@ function createExpectedInternalAccount({
lastSelected?: number;
}): InternalAccount {
const accountTypeToMethods = {
[`${EthAccountType.Eoa}`]: [...Object.values(EthMethod)],
[`${EthAccountType.Erc4337}`]: [...Object.values(EthErc4337Method)],
[`${EthAccountType.Eoa}`]: [...Object.values(ETH_EOA_METHODS)],
[`${EthAccountType.Erc4337}`]: [...Object.values(ETH_ERC_4337_METHODS)],
[`${BtcAccountType.P2wpkh}`]: [...Object.values(BtcMethod)],
};

Expand Down
7 changes: 3 additions & 4 deletions packages/accounts-controller/src/tests/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
BtcAccountType,
BtcMethod,
EthAccountType,
EthErc4337Method,
EthMethod,
} from '@metamask/keyring-api';
import { KeyringTypes } from '@metamask/keyring-controller';
Expand Down Expand Up @@ -50,9 +49,9 @@ export const createMockInternalAccount = ({
break;
case EthAccountType.Erc4337:
methods = [
EthErc4337Method.PatchUserOperation,
EthErc4337Method.PrepareUserOperation,
EthErc4337Method.SignUserOperation,
EthMethod.PatchUserOperation,
EthMethod.PrepareUserOperation,
EthMethod.SignUserOperation,
];
break;
case BtcAccountType.P2wpkh:
Expand Down
2 changes: 1 addition & 1 deletion packages/assets-controllers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"devDependencies": {
"@metamask/auto-changelog": "^3.4.4",
"@metamask/ethjs-provider-http": "^0.3.0",
"@metamask/keyring-api": "^6.1.1",
"@metamask/keyring-api": "^6.4.0",
"@types/jest": "^27.4.1",
"@types/lodash": "^4.14.191",
"@types/node": "^16.18.54",
Expand Down
3 changes: 1 addition & 2 deletions packages/assets-controllers/src/AccountTrackerController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,8 @@ export class AccountTrackerController extends StaticIntervalPollingControllerV1<
[chainId]: accountsForChain,
},
});
} catch (err) {
} finally {
releaseLock();
throw err;
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,59 @@ describe('CodefiTokenPricesServiceV2', () => {
});
});

it('should correctly handle null market data for a token address', async () => {
nock('https://price.api.cx.metamask.io')
.get('/v2/chains/1/spot-prices')
.query({
tokenAddresses:
'0x0000000000000000000000000000000000000000,0xAAA,0xBBB,0xCCC',
vsCurrency: 'ETH',
includeMarketData: 'true',
})
.reply(200, {
'0x0000000000000000000000000000000000000000': {
price: 14,
currency: 'ETH',
},
'0xaaa': null, // Simulating API returning null for market data
'0xbbb': {
price: 33689.98134554716,
currency: 'ETH',
},
'0xccc': {
price: 148.1344197578456,
currency: 'ETH',
},
});

const result = await new CodefiTokenPricesServiceV2().fetchTokenPrices({
chainId: '0x1',
tokenAddresses: ['0xAAA', '0xBBB', '0xCCC'],
currency: 'ETH',
});

expect(result).toStrictEqual({
'0x0000000000000000000000000000000000000000': {
tokenAddress: '0x0000000000000000000000000000000000000000',
value: 14,
currency: 'ETH',
price: 14,
},
'0xBBB': {
tokenAddress: '0xBBB',
value: 33689.98134554716,
currency: 'ETH',
price: 33689.98134554716,
},
'0xCCC': {
tokenAddress: '0xCCC',
value: 148.1344197578456,
currency: 'ETH',
price: 148.1344197578456,
},
});
});

it('throws if the request fails consistently', async () => {
nock('https://price.api.cx.metamask.io')
.get('/v2/chains/1/spot-prices')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ export class CodefiTokenPricesServiceV2

const marketData = addressCryptoDataMap[lowercasedTokenAddress];

if (marketData === undefined) {
if (!marketData) {
return obj;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/chain-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"dependencies": {
"@metamask/base-controller": "^6.0.0",
"@metamask/chain-api": "^0.0.1",
"@metamask/keyring-api": "^6.1.1",
"@metamask/keyring-api": "^6.4.0",
"@metamask/snaps-controllers": "^8.1.1",
"@metamask/snaps-sdk": "^4.2.0",
"@metamask/snaps-utils": "^7.4.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 @@ -48,7 +48,7 @@
"@metamask/eth-hd-keyring": "^7.0.1",
"@metamask/eth-sig-util": "^7.0.1",
"@metamask/eth-simple-keyring": "^6.0.1",
"@metamask/keyring-api": "^6.1.1",
"@metamask/keyring-api": "^6.4.0",
"@metamask/message-manager": "^10.0.0",
"@metamask/utils": "^8.3.0",
"async-mutex": "^0.5.0",
Expand Down
Loading

0 comments on commit c6cd7df

Please sign in to comment.