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

feat: add Solana to the polled exchange rates #4914

Merged
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
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
Loading