Skip to content

Commit

Permalink
Merge branch 'main' into caip-multichain
Browse files Browse the repository at this point in the history
  • Loading branch information
adonesky1 authored Nov 13, 2024
2 parents d0865d4 + 6859854 commit 30e6842
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 18 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": "245.0.0",
"version": "247.0.0",
"private": true,
"description": "Monorepo for packages shared between MetaMask clients",
"repository": {
Expand Down
16 changes: 15 additions & 1 deletion packages/assets-controllers/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [43.1.1]

### Changed

- Fix a bug in `TokensController.addTokens` where tokens could be added from the wrong chain. ([#4924](https://github.com/MetaMask/core/pull/4924))

## [43.1.0]

### Added

- Add Solana to the polled exchange rates ([#4914](https://github.com/MetaMask/core/pull/4914))

## [43.0.0]

### Added
Expand Down Expand Up @@ -1204,7 +1216,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Use Ethers for AssetsContractController ([#845](https://github.com/MetaMask/core/pull/845))
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/[email protected]
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/[email protected]
[43.1.1]: https://github.com/MetaMask/core/compare/@metamask/[email protected]...@metamask/[email protected]
[43.1.0]: https://github.com/MetaMask/core/compare/@metamask/[email protected]...@metamask/[email protected]
[43.0.0]: https://github.com/MetaMask/core/compare/@metamask/[email protected]...@metamask/[email protected]
[42.0.0]: https://github.com/MetaMask/core/compare/@metamask/[email protected]...@metamask/[email protected]
[41.0.0]: https://github.com/MetaMask/core/compare/@metamask/[email protected]...@metamask/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion packages/assets-controllers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metamask/assets-controllers",
"version": "43.0.0",
"version": "43.1.1",
"description": "Controllers which manage interactions involving ERC-20, ERC-721, and ERC-1155 tokens (including NFTs)",
"keywords": [
"MetaMask",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,14 @@ describe('RatesController', () => {
const { fiatCurrency, rates, cryptocurrencies } = ratesController.state;
expect(ratesController).toBeDefined();
expect(fiatCurrency).toBe('usd');
expect(Object.keys(rates)).toStrictEqual([Cryptocurrency.Btc]);
expect(cryptocurrencies).toStrictEqual([Cryptocurrency.Btc]);
expect(Object.keys(rates)).toStrictEqual([
Cryptocurrency.Btc,
Cryptocurrency.Solana,
]);
expect(cryptocurrencies).toStrictEqual([
Cryptocurrency.Btc,
Cryptocurrency.Solana,
]);
});
});

Expand All @@ -119,11 +125,16 @@ describe('RatesController', () => {
const publishActionSpy = jest.spyOn(messenger, 'publish');

jest.spyOn(global.Date, 'now').mockImplementation(() => getStubbedDate());
const mockRateValue = 57715.42;
const mockBtcRateValue = 57715.42;
const mockSolRateValue = 200.48;

const fetchExchangeRateStub = jest.fn(() => {
return Promise.resolve({
btc: {
eur: mockRateValue,
eur: mockBtcRateValue,
},
sol: {
eur: mockSolRateValue,
},
});
});
Expand All @@ -144,6 +155,10 @@ describe('RatesController', () => {
conversionDate: 0,
conversionRate: 0,
},
sol: {
conversionDate: 0,
conversionRate: 0,
},
});

await ratesController.start();
Expand All @@ -163,7 +178,11 @@ describe('RatesController', () => {
expect(ratesPosUpdate).toStrictEqual({
btc: {
conversionDate: MOCK_TIMESTAMP,
conversionRate: mockRateValue,
conversionRate: mockBtcRateValue,
},
sol: {
conversionDate: MOCK_TIMESTAMP,
conversionRate: mockSolRateValue,
},
});

Expand Down Expand Up @@ -326,7 +345,10 @@ describe('RatesController', () => {

const cryptocurrencyListPreUpdate =
ratesController.getCryptocurrencyList();
expect(cryptocurrencyListPreUpdate).toStrictEqual([Cryptocurrency.Btc]);
expect(cryptocurrencyListPreUpdate).toStrictEqual([
Cryptocurrency.Btc,
Cryptocurrency.Solana,
]);
// Just to make sure we're updating to something else than the default list
expect(cryptocurrencyListPreUpdate).not.toStrictEqual(
mockCryptocurrencyList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@ import type {

export const name = 'RatesController';

/**
* Supported cryptocurrencies that can be used as a base currency. The value needs to be compatible
* with CryptoCompare's API which is the default source for the rates.
*
* See: https://min-api.cryptocompare.com/documentation?key=Price&cat=multipleSymbolsPriceEndpoint
*/
export enum Cryptocurrency {
Btc = 'btc',
Solana = 'sol',
}

const DEFAULT_INTERVAL = 180000;
Expand All @@ -31,8 +38,12 @@ const defaultState = {
conversionDate: 0,
conversionRate: 0,
},
[Cryptocurrency.Solana]: {
conversionDate: 0,
conversionRate: 0,
},
},
cryptocurrencies: [Cryptocurrency.Btc],
cryptocurrencies: [Cryptocurrency.Btc, Cryptocurrency.Solana],
};

export class RatesController extends BaseController<
Expand Down
16 changes: 8 additions & 8 deletions packages/assets-controllers/src/TokensController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,16 +462,16 @@ export class TokensController extends BaseController<
*/
async addTokens(tokensToImport: Token[], networkClientId?: NetworkClientId) {
const releaseLock = await this.#mutex.acquire();
const { ignoredTokens, allDetectedTokens } = this.state;
const { allTokens, ignoredTokens, allDetectedTokens } = this.state;
const importedTokensMap: { [key: string]: true } = {};
// Used later to dedupe imported tokens
const newTokensMap = Object.values(tokensToImport).reduce(
(output, token) => {
output[token.address] = token;
return output;
},
{} as { [address: string]: Token },
);
const newTokensMap = [
...(allTokens[this.#chainId]?.[this.#getSelectedAccount().address] || []),
...tokensToImport,
].reduce((output, token) => {
output[token.address] = token;
return output;
}, {} as { [address: string]: Token });
try {
tokensToImport.forEach((tokenToAdd) => {
const { address, symbol, decimals, image, aggregators, name } =
Expand Down

0 comments on commit 30e6842

Please sign in to comment.