diff --git a/packages/assets-controllers/src/RatesController/RatesController.test.ts b/packages/assets-controllers/src/RatesController/RatesController.test.ts index 12277764f5..bf9d0fc193 100644 --- a/packages/assets-controllers/src/RatesController/RatesController.test.ts +++ b/packages/assets-controllers/src/RatesController/RatesController.test.ts @@ -119,7 +119,7 @@ describe('RatesController', () => { const publishActionSpy = jest.spyOn(messenger, 'publish'); jest.spyOn(global.Date, 'now').mockImplementation(() => getStubbedDate()); - const mockRateValue = '57715.42'; + const mockRateValue = 57715.42; const fetchExchangeRateStub = jest.fn(() => { return Promise.resolve({ btc: { @@ -142,7 +142,7 @@ describe('RatesController', () => { expect(ratesPreUpdate).toStrictEqual({ btc: { conversionDate: 0, - conversionRate: '0', + conversionRate: 0, }, }); @@ -177,12 +177,12 @@ describe('RatesController', () => { it('starts the polling process with custom values', async () => { jest.spyOn(global.Date, 'now').mockImplementation(() => getStubbedDate()); - const mockBtcUsdRateValue = '62235.48'; - const mockSolUsdRateValue = '148.41'; - const mockStrkUsdRateValue = '1.248'; - const mockBtcEurRateValue = '57715.42'; - const mockSolEurRateValue = '137.68'; - const mockStrkEurRateValue = '1.157'; + const mockBtcUsdRateValue = 62235.48; + const mockSolUsdRateValue = 148.41; + const mockStrkUsdRateValue = 1.248; + const mockBtcEurRateValue = 57715.42; + const mockSolEurRateValue = 137.68; + const mockStrkEurRateValue = 1.157; const fetchExchangeRateStub = jest.fn(() => { return Promise.resolve({ btc: { diff --git a/packages/assets-controllers/src/RatesController/RatesController.ts b/packages/assets-controllers/src/RatesController/RatesController.ts index 461e471d57..7abed73eed 100644 --- a/packages/assets-controllers/src/RatesController/RatesController.ts +++ b/packages/assets-controllers/src/RatesController/RatesController.ts @@ -29,7 +29,7 @@ const defaultState = { rates: { [Cryptocurrency.Btc]: { conversionDate: 0, - conversionRate: '0', + conversionRate: 0, }, }, cryptocurrencies: [Cryptocurrency.Btc], @@ -119,7 +119,7 @@ export class RatesController extends BaseController< const { fiatCurrency, cryptocurrencies } = this.state; const response: Record< Cryptocurrency, - Record + Record > = await this.#fetchMultiExchangeRate( fiatCurrency, cryptocurrencies, diff --git a/packages/assets-controllers/src/RatesController/types.ts b/packages/assets-controllers/src/RatesController/types.ts index 7a422aaef2..83f7e8ccc9 100644 --- a/packages/assets-controllers/src/RatesController/types.ts +++ b/packages/assets-controllers/src/RatesController/types.ts @@ -12,17 +12,17 @@ import type { /** * Represents the conversion rates from one currency to others, including the conversion date. - * The `conversionRate` field is a string that maps a cryptocurrency code (e.g., "BTC") to its - * conversion rate. For this field we use string as the data type to avoid potential rounding - * errors and precision loss. - * The `usdConversionRate` provides the conversion rate to USD as a string, or `null` if the - * conversion rate to USD is not available. We also use string for the same reason as stated before. - * The `conversionDate` is a Unix timestamp (number) indicating when the conversion rate was last updated. + * The `conversionRate` field is a `number` that maps a cryptocurrency code (e.g., "BTC") to its + * conversion rate. Precision lost is not relevant in this case since the value is only used for UI + * purposes, once we start to use it for operations, there should be the proper checks. + * The `usdConversionRate` provides the conversion rate to USD as a `number`, or `null` if the + * conversion rate to USD is not available. + * The `conversionDate` is a Unix timestamp (`number`) indicating when the conversion rate was last updated. */ export type Rate = { - conversionRate: string; + conversionRate: number; conversionDate: number; - usdConversionRate?: string; + usdConversionRate?: number; }; /** diff --git a/packages/assets-controllers/src/crypto-compare-service/crypto-compare.ts b/packages/assets-controllers/src/crypto-compare-service/crypto-compare.ts index 4d92d3af6a..0d62e0bea5 100644 --- a/packages/assets-controllers/src/crypto-compare-service/crypto-compare.ts +++ b/packages/assets-controllers/src/crypto-compare-service/crypto-compare.ts @@ -139,7 +139,7 @@ export async function fetchMultiExchangeRate( fiatCurrency: string, cryptocurrencies: string[], includeUSDRate: boolean, -): Promise>> { +): Promise>> { const url = getMultiPricingURL( Object.values(cryptocurrencies).join(','), fiatCurrency, @@ -148,10 +148,10 @@ export async function fetchMultiExchangeRate( const response = await handleFetch(url); handleErrorResponse(response); - const rates: Record> = {}; + const rates: Record> = {}; for (const [cryptocurrency, values] of Object.entries(response) as [ string, - Record, + Record, ][]) { rates[cryptocurrency.toLowerCase()] = { [fiatCurrency.toLowerCase()]: values[fiatCurrency.toUpperCase()],