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

fix: currency data type #4741

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -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: {
Expand All @@ -142,7 +142,7 @@ describe('RatesController', () => {
expect(ratesPreUpdate).toStrictEqual({
btc: {
conversionDate: 0,
conversionRate: '0',
conversionRate: 0,
},
});

Expand Down Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const defaultState = {
rates: {
[Cryptocurrency.Btc]: {
conversionDate: 0,
conversionRate: '0',
conversionRate: 0,
},
},
cryptocurrencies: [Cryptocurrency.Btc],
Expand Down Expand Up @@ -119,7 +119,7 @@ export class RatesController extends BaseController<
const { fiatCurrency, cryptocurrencies } = this.state;
const response: Record<
Cryptocurrency,
Record<string, string>
Record<string, number>
> = await this.#fetchMultiExchangeRate(
fiatCurrency,
cryptocurrencies,
Expand Down
4 changes: 2 additions & 2 deletions packages/assets-controllers/src/RatesController/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import type {
* The `conversionDate` is a Unix timestamp (number) indicating when the conversion rate was last updated.
gantunesr marked this conversation as resolved.
Show resolved Hide resolved
*/
export type Rate = {
conversionRate: string;
conversionRate: number;
conversionDate: number;
usdConversionRate?: string;
usdConversionRate?: number;
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export async function fetchMultiExchangeRate(
fiatCurrency: string,
cryptocurrencies: string[],
includeUSDRate: boolean,
): Promise<Record<string, Record<string, string>>> {
): Promise<Record<string, Record<string, number>>> {
const url = getMultiPricingURL(
Object.values(cryptocurrencies).join(','),
fiatCurrency,
Expand All @@ -148,10 +148,10 @@ export async function fetchMultiExchangeRate(
const response = await handleFetch(url);
handleErrorResponse(response);

const rates: Record<string, Record<string, string>> = {};
const rates: Record<string, Record<string, number>> = {};
for (const [cryptocurrency, values] of Object.entries(response) as [
string,
Record<string, string>,
Record<string, number>,
][]) {
rates[cryptocurrency.toLowerCase()] = {
[fiatCurrency.toLowerCase()]: values[fiatCurrency.toUpperCase()],
Expand Down
Loading