Add more fiat currencies using fx rates from FreeCurrencyAPI

This commit is contained in:
natsoni
2024-03-07 10:48:32 +01:00
parent bfaddfc345
commit f121d16544
7 changed files with 727 additions and 38 deletions

View File

@@ -268,4 +268,134 @@ export const fiatCurrencies = {
code: 'USD',
indexed: true,
},
BGN: {
name: 'Bulgarian Lev',
code: 'BGN',
indexed: true,
},
BRL: {
name: 'Brazilian Real',
code: 'BRL',
indexed: true,
},
CNY: {
name: 'Chinese Yuan',
code: 'CNY',
indexed: true,
},
CZK: {
name: 'Czech Koruna',
code: 'CZK',
indexed: true,
},
DKK: {
name: 'Danish Krone',
code: 'DKK',
indexed: true,
},
HKD: {
name: 'Hong Kong Dollar',
code: 'HKD',
indexed: true,
},
HRK: {
name: 'Croatian Kuna',
code: 'HRK',
indexed: true,
},
HUF: {
name: 'Hungarian Forint',
code: 'HUF',
indexed: true,
},
IDR: {
name: 'Indonesian Rupiah',
code: 'IDR',
indexed: true,
},
ILS: {
name: 'Israeli Shekel',
code: 'ILS',
indexed: true,
},
INR: {
name: 'Indian Rupee',
code: 'INR',
indexed: true,
},
ISK: {
name: 'Icelandic Krona',
code: 'ISK',
indexed: true,
},
KRW: {
name: 'South Korean Won',
code: 'KRW',
indexed: true,
},
MXN: {
name: 'Mexican Peso',
code: 'MXN',
indexed: true,
},
MYR: {
name: 'Malaysian Ringgit',
code: 'MYR',
indexed: true,
},
NOK: {
name: 'Norwegian Krone',
code: 'NOK',
indexed: true,
},
NZD: {
name: 'New Zealand Dollar',
code: 'NZD',
indexed: true,
},
PHP: {
name: 'Philippine Peso',
code: 'PHP',
indexed: true,
},
PLN: {
name: 'Polish Zloty',
code: 'PLN',
indexed: true,
},
RON: {
name: 'Romanian Leu',
code: 'RON',
indexed: true,
},
RUB: {
name: 'Russian Ruble',
code: 'RUB',
indexed: true,
},
SEK: {
name: 'Swedish Krona',
code: 'SEK',
indexed: true,
},
SGD: {
name: 'Singapore Dollar',
code: 'SGD',
indexed: true,
},
THB: {
name: 'Thai Baht',
code: 'THB',
indexed: true,
},
TRY: {
name: 'Turkish Lira',
code: 'TRY',
indexed: true,
},
ZAR: {
name: 'South African Rand',
code: 'ZAR',
indexed: true,
},
};

View File

@@ -35,6 +35,11 @@ export class FiatSelectorComponent implements OnInit {
this.stateService.fiatCurrency$.subscribe((fiat) => {
this.fiatForm.get('fiat')?.setValue(fiat);
});
if (!this.stateService.env.ADDITIONAL_CURRENCIES) {
this.currencies = this.currencies.filter((currency: any) => {
return ['AUD', 'CAD', 'EUR', 'JPY', 'GBP', 'CHF', 'USD'].includes(currency[0]);
});
}
}
changeFiat() {

View File

@@ -13,6 +13,32 @@ export interface ApiPrice {
CHF: number,
AUD: number,
JPY: number,
BGN?: number,
BRL?: number,
CNY?: number,
CZK?: number,
DKK?: number,
HKD?: number,
HRK?: number,
HUF?: number,
IDR?: number,
ILS?: number,
INR?: number,
ISK?: number,
KRW?: number,
MXN?: number,
MYR?: number,
NOK?: number,
NZD?: number,
PHP?: number,
PLN?: number,
RON?: number,
RUB?: number,
SEK?: number,
SGD?: number,
THB?: number,
TRY?: number,
ZAR?: number,
}
export interface ExchangeRates {
USDEUR: number,
@@ -21,6 +47,32 @@ export interface ExchangeRates {
USDCHF: number,
USDAUD: number,
USDJPY: number,
USDBGN?: number,
USDBRL?: number,
USDCNY?: number,
USDCZK?: number,
USDDKK?: number,
USDHKD?: number,
USDHRK?: number,
USDHUF?: number,
USDIDR?: number,
USDILS?: number,
USDINR?: number,
USDISK?: number,
USDKRW?: number,
USDMXN?: number,
USDMYR?: number,
USDNOK?: number,
USDNZD?: number,
USDPHP?: number,
USDPLN?: number,
USDRON?: number,
USDRUB?: number,
USDSEK?: number,
USDSGD?: number,
USDTHB?: number,
USDTRY?: number,
USDZAR?: number,
}
export interface Conversion {
prices: ApiPrice[],
@@ -60,10 +112,19 @@ export class PriceService {
getEmptyPrice(): Price {
return {
price: {
price: this.stateService.env.ADDITIONAL_CURRENCIES ? {
USD: 0, EUR: 0, GBP: 0, CAD: 0, CHF: 0, AUD: 0, JPY: 0, BGN: 0, BRL: 0, CNY: 0, CZK: 0, DKK: 0, HKD: 0, HRK: 0, HUF: 0, IDR: 0,
ILS: 0, INR: 0, ISK: 0, KRW: 0, MXN: 0, MYR: 0, NOK: 0, NZD: 0, PHP: 0, PLN: 0, RON: 0, RUB: 0, SEK: 0, SGD: 0, THB: 0, TRY: 0,
ZAR: 0
} :
{
USD: 0, EUR: 0, GBP: 0, CAD: 0, CHF: 0, AUD: 0, JPY: 0,
},
exchangeRates: {
exchangeRates: this.stateService.env.ADDITIONAL_CURRENCIES ? {
USDEUR: 0, USDGBP: 0, USDCAD: 0, USDCHF: 0, USDAUD: 0, USDJPY: 0, USDBGN: 0, USDBRL: 0, USDCNY: 0, USDCZK: 0, USDDKK: 0, USDHKD: 0,
USDHRK: 0, USDHUF: 0, USDIDR: 0, USDILS: 0, USDINR: 0, USDISK: 0, USDKRW: 0, USDMXN: 0, USDMYR: 0, USDNOK: 0, USDNZD: 0, USDPHP: 0,
USDPLN: 0, USDRON: 0, USDRUB: 0, USDSEK: 0, USDSGD: 0, USDTHB: 0, USDTRY: 0, USDZAR: 0
} : {
USDEUR: 0, USDGBP: 0, USDCAD: 0, USDCHF: 0, USDAUD: 0, USDJPY: 0,
},
};
@@ -92,7 +153,17 @@ export class PriceService {
return undefined;
}
return {
price: {
price: this.stateService.env.ADDITIONAL_CURRENCIES ? {
USD: conversion.prices[0].USD, EUR: conversion.prices[0].EUR, GBP: conversion.prices[0].GBP, CAD: conversion.prices[0].CAD,
CHF: conversion.prices[0].CHF, AUD: conversion.prices[0].AUD, JPY: conversion.prices[0].JPY, BGN: conversion.prices[0].BGN,
BRL: conversion.prices[0].BRL, CNY: conversion.prices[0].CNY, CZK: conversion.prices[0].CZK, DKK: conversion.prices[0].DKK,
HKD: conversion.prices[0].HKD, HRK: conversion.prices[0].HRK, HUF: conversion.prices[0].HUF, IDR: conversion.prices[0].IDR,
ILS: conversion.prices[0].ILS, INR: conversion.prices[0].INR, ISK: conversion.prices[0].ISK, KRW: conversion.prices[0].KRW,
MXN: conversion.prices[0].MXN, MYR: conversion.prices[0].MYR, NOK: conversion.prices[0].NOK, NZD: conversion.prices[0].NZD,
PHP: conversion.prices[0].PHP, PLN: conversion.prices[0].PLN, RON: conversion.prices[0].RON, RUB: conversion.prices[0].RUB,
SEK: conversion.prices[0].SEK, SGD: conversion.prices[0].SGD, THB: conversion.prices[0].THB, TRY: conversion.prices[0].TRY,
ZAR: conversion.prices[0].ZAR
} : {
USD: conversion.prices[0].USD, EUR: conversion.prices[0].EUR, GBP: conversion.prices[0].GBP, CAD: conversion.prices[0].CAD,
CHF: conversion.prices[0].CHF, AUD: conversion.prices[0].AUD, JPY: conversion.prices[0].JPY
},
@@ -122,9 +193,15 @@ export class PriceService {
exchangeRates: conversion.exchangeRates,
};
for (const price of conversion.prices) {
historicalPrice.prices[price.time] = {
USD: price.USD, EUR: price.EUR, GBP: price.GBP, CAD: price.CAD,
CHF: price.CHF, AUD: price.AUD, JPY: price.JPY
historicalPrice.prices[price.time] = this.stateService.env.ADDITIONAL_CURRENCIES ? {
USD: price.USD, EUR: price.EUR, GBP: price.GBP, CAD: price.CAD, CHF: price.CHF, AUD: price.AUD,
JPY: price.JPY, BGN: price.BGN, BRL: price.BRL, CNY: price.CNY, CZK: price.CZK, DKK: price.DKK,
HKD: price.HKD, HRK: price.HRK, HUF: price.HUF, IDR: price.IDR, ILS: price.ILS, INR: price.INR,
ISK: price.ISK, KRW: price.KRW, MXN: price.MXN, MYR: price.MYR, NOK: price.NOK, NZD: price.NZD,
PHP: price.PHP, PLN: price.PLN, RON: price.RON, RUB: price.RUB, SEK: price.SEK, SGD: price.SGD,
THB: price.THB, TRY: price.TRY, ZAR: price.ZAR
} : {
USD: price.USD, EUR: price.EUR, GBP: price.GBP, CAD: price.CAD, CHF: price.CHF, AUD: price.AUD, JPY: price.JPY
};
}