Skip to content

Commit

Permalink
Merge branch 'main' into cryptodev2s/add-missing-reset-state-function…
Browse files Browse the repository at this point in the history
…s-assets-controllers
  • Loading branch information
cryptodev-2s authored Oct 31, 2024
2 parents d0b8a4e + f33a4e3 commit 8e4d9c2
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metamask/core-monorepo",
"version": "236.0.0",
"version": "237.0.0",
"private": true,
"description": "Monorepo for packages shared between MetaMask clients",
"repository": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2931,6 +2931,7 @@ async function withController<ReturnValue>(
trackMetaMetricsEvent: jest.fn(),
messenger: buildTokenDetectionControllerMessenger(controllerMessenger),
useAccountsAPI: false,
platform: 'extension',
...options,
});
try {
Expand Down
16 changes: 13 additions & 3 deletions packages/assets-controllers/src/TokenDetectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ export class TokenDetectionController extends StaticIntervalPollingController<To
#accountsAPI = {
isAccountsAPIEnabled: true,
supportedNetworksCache: null as number[] | null,
platform: '' as 'extension' | 'mobile',

async getSupportedNetworks() {
/* istanbul ignore next */
if (!this.isAccountsAPIEnabled) {
Expand Down Expand Up @@ -232,9 +234,13 @@ export class TokenDetectionController extends StaticIntervalPollingController<To
);
}

const result = await fetchMultiChainBalances(address, {
networks: [chainIdNumber],
});
const result = await fetchMultiChainBalances(
address,
{
networks: [chainIdNumber],
},
this.platform,
);

return result.balances;
},
Expand All @@ -250,6 +256,7 @@ export class TokenDetectionController extends StaticIntervalPollingController<To
* @param options.getBalancesInSingleCall - Gets the balances of a list of tokens for the given address.
* @param options.trackMetaMetricsEvent - Sets options for MetaMetrics event tracking.
* @param options.useAccountsAPI - Feature Switch for using the accounts API when detecting tokens (default: true)
* @param options.platform - Indicates whether the platform is extension or mobile
*/
constructor({
interval = DEFAULT_INTERVAL,
Expand All @@ -258,6 +265,7 @@ export class TokenDetectionController extends StaticIntervalPollingController<To
trackMetaMetricsEvent,
messenger,
useAccountsAPI = true,
platform,
}: {
interval?: number;
disabled?: boolean;
Expand All @@ -277,6 +285,7 @@ export class TokenDetectionController extends StaticIntervalPollingController<To
}) => void;
messenger: TokenDetectionControllerMessenger;
useAccountsAPI?: boolean;
platform: 'extension' | 'mobile';
}) {
super({
name: controllerName,
Expand Down Expand Up @@ -315,6 +324,7 @@ export class TokenDetectionController extends StaticIntervalPollingController<To
this.#isUnlocked = isUnlocked;

this.#accountsAPI.isAccountsAPIEnabled = useAccountsAPI;
this.#accountsAPI.platform = platform;

this.#registerEventListeners();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('fetchMultiChainBalances()', () => {
it('should successfully return balances response', async () => {
const mockAPI = createMockAPI().reply(200, MOCK_GET_BALANCES_RESPONSE);

const result = await fetchMultiChainBalances(MOCK_ADDRESS);
const result = await fetchMultiChainBalances(MOCK_ADDRESS, {}, 'extension');
expect(result).toBeDefined();
expect(result).toStrictEqual(MOCK_GET_BALANCES_RESPONSE);
expect(mockAPI.isDone()).toBe(true);
Expand All @@ -59,9 +59,13 @@ describe('fetchMultiChainBalances()', () => {
})
.reply(200, MOCK_GET_BALANCES_RESPONSE);

const result = await fetchMultiChainBalances(MOCK_ADDRESS, {
networks: [1, 10],
});
const result = await fetchMultiChainBalances(
MOCK_ADDRESS,
{
networks: [1, 10],
},
'extension',
);
expect(result).toBeDefined();
expect(result).toStrictEqual(MOCK_GET_BALANCES_RESPONSE);
expect(mockAPI.isDone()).toBe(true);
Expand All @@ -79,7 +83,8 @@ describe('fetchMultiChainBalances()', () => {
const mockAPI = createMockAPI().reply(httpCode);

await expect(
async () => await fetchMultiChainBalances(MOCK_ADDRESS),
async () =>
await fetchMultiChainBalances(MOCK_ADDRESS, {}, 'extension'),
).rejects.toThrow(expect.any(Error));
expect(mockAPI.isDone()).toBe(true);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,21 @@ export async function fetchSupportedNetworks(): Promise<number[]> {
* @param address - address to fetch balances from
* @param options - params to pass down for a more refined search
* @param options.networks - the networks (in decimal) that you want to filter by
* @param platform - indicates whether the platform is extension or mobile
* @returns a Balances Response
*/
export async function fetchMultiChainBalances(
address: string,
options?: { networks?: number[] },
options: { networks?: number[] },
platform: 'extension' | 'mobile',
) {
const url = getBalancesUrl(address, {
networks: options?.networks?.join(),
});
const response: GetBalancesResponse = await handleFetch(url);
const response: GetBalancesResponse = await handleFetch(url, {
headers: {
'x-metamask-clientproduct': `metamask-${platform}`,
},
});
return response;
}
18 changes: 17 additions & 1 deletion packages/transaction-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [38.2.0]

### Added

- Add staking transaction types ([#4874](https://github.com/MetaMask/core/pull/4874))
- `stakingClaim`
- `stakingDeposit`
- `stakingUnstake`

### Changed

- Bump `@metamask/controller-utils` from `^11.4.1` to `^11.4.2` ([#4870](https://github.com/MetaMask/core/pull/4870))
- Bump `@metamask/accounts-controller` from `^18.2.2` to `^18.2.3` ([#4870](https://github.com/MetaMask/core/pull/4870))
- Bump `@metamask/network-controller` from `^22.0.0` to `^22.0.1` ([#4870](https://github.com/MetaMask/core/pull/4870))

## [38.1.0]

### Added
Expand Down Expand Up @@ -1088,7 +1103,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
All changes listed after this point were applied to this package following the monorepo conversion.
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/[email protected]
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/[email protected]
[38.2.0]: https://github.com/MetaMask/core/compare/@metamask/[email protected]...@metamask/[email protected]
[38.1.0]: https://github.com/MetaMask/core/compare/@metamask/[email protected]...@metamask/[email protected]
[38.0.0]: https://github.com/MetaMask/core/compare/@metamask/[email protected]...@metamask/[email protected]
[37.3.0]: https://github.com/MetaMask/core/compare/@metamask/[email protected]...@metamask/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion packages/transaction-controller/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metamask/transaction-controller",
"version": "38.1.0",
"version": "38.2.0",
"description": "Stores transactions alongside their periodically updated statuses and manages interactions such as approval and cancellation",
"keywords": [
"MetaMask",
Expand Down
2 changes: 1 addition & 1 deletion packages/user-operation-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"@metamask/gas-fee-controller": "^22.0.0",
"@metamask/keyring-controller": "^17.3.1",
"@metamask/network-controller": "^22.0.1",
"@metamask/transaction-controller": "^38.1.0",
"@metamask/transaction-controller": "^38.2.0",
"@types/jest": "^27.4.1",
"deepmerge": "^4.2.2",
"jest": "^27.5.1",
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3677,7 +3677,7 @@ __metadata:
languageName: node
linkType: hard

"@metamask/transaction-controller@npm:^38.1.0, @metamask/transaction-controller@workspace:packages/transaction-controller":
"@metamask/transaction-controller@npm:^38.2.0, @metamask/transaction-controller@workspace:packages/transaction-controller":
version: 0.0.0-use.local
resolution: "@metamask/transaction-controller@workspace:packages/transaction-controller"
dependencies:
Expand Down Expand Up @@ -3745,7 +3745,7 @@ __metadata:
"@metamask/polling-controller": "npm:^12.0.1"
"@metamask/rpc-errors": "npm:^7.0.1"
"@metamask/superstruct": "npm:^3.1.0"
"@metamask/transaction-controller": "npm:^38.1.0"
"@metamask/transaction-controller": "npm:^38.2.0"
"@metamask/utils": "npm:^10.0.0"
"@types/jest": "npm:^27.4.1"
bn.js: "npm:^5.2.1"
Expand Down

0 comments on commit 8e4d9c2

Please sign in to comment.