mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2024-11-19 18:00:17 +01:00
Merge pull request #6604 from BlueWallet/fix-exchange-rate
FIX: use exchange rate for USD, GBP & EUR from Kraken public API
This commit is contained in:
commit
0fc46bbb2d
@ -4,6 +4,7 @@ export const FiatUnitSource = {
|
||||
Coinbase: 'Coinbase',
|
||||
CoinDesk: 'CoinDesk',
|
||||
CoinGecko: 'CoinGecko',
|
||||
Kraken: 'Kraken',
|
||||
Yadio: 'Yadio',
|
||||
YadioConvert: 'YadioConvert',
|
||||
Exir: 'Exir',
|
||||
@ -75,6 +76,23 @@ const RateExtractors = {
|
||||
if (!(rate >= 0)) throw new Error(`Could not update rate from Bitstamp for ${ticker}: data is wrong`);
|
||||
return rate;
|
||||
},
|
||||
Kraken: async (ticker: string): Promise<number> => {
|
||||
let json;
|
||||
try {
|
||||
const res = await fetch(`https://api.kraken.com/0/public/Ticker?pair=XXBTZ${ticker.toUpperCase()}`);
|
||||
json = await res.json();
|
||||
} catch (e: any) {
|
||||
throw new Error(`Could not update rate from Kraken for ${ticker}: ${e.message}`);
|
||||
}
|
||||
|
||||
let rate = json?.result?.[`XXBTZ${ticker.toUpperCase()}`]?.c?.[0];
|
||||
|
||||
if (!rate) throw new Error(`Could not update rate from Kraken for ${ticker}: data is wrong`);
|
||||
|
||||
rate = Number(rate);
|
||||
if (!(rate >= 0)) throw new Error(`Could not update rate from Kraken for ${ticker}: data is wrong`);
|
||||
return rate;
|
||||
},
|
||||
BNR: async (): Promise<number> => {
|
||||
try {
|
||||
const response = await fetch('https://www.bnr.ro/nbrfxrates.xml');
|
||||
@ -168,7 +186,7 @@ export type TFiatUnit = {
|
||||
endPointKey: string;
|
||||
symbol: string;
|
||||
locale: string;
|
||||
source: 'CoinDesk' | 'Yadio' | 'Exir' | 'wazirx' | 'Bitstamp';
|
||||
source: 'CoinDesk' | 'Yadio' | 'Exir' | 'wazirx' | 'Bitstamp' | 'Kraken';
|
||||
};
|
||||
|
||||
export type TFiatUnits = {
|
||||
|
@ -2,7 +2,7 @@
|
||||
"USD": {
|
||||
"endPointKey": "USD",
|
||||
"locale": "en-US",
|
||||
"source": "CoinGecko",
|
||||
"source": "Kraken",
|
||||
"symbol": "$"
|
||||
},
|
||||
"AED": {
|
||||
@ -92,13 +92,13 @@
|
||||
"EUR": {
|
||||
"endPointKey": "EUR",
|
||||
"locale": "en-IE",
|
||||
"source": "CoinGecko",
|
||||
"source": "Kraken",
|
||||
"symbol": "€"
|
||||
},
|
||||
"GBP": {
|
||||
"endPointKey": "GBP",
|
||||
"locale": "en-GB",
|
||||
"source": "CoinGecko",
|
||||
"source": "Kraken",
|
||||
"symbol": "£"
|
||||
},
|
||||
"HRK": {
|
||||
|
Loading…
Reference in New Issue
Block a user