mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-02-22 23:08:07 +01:00
FIX: change faulty exchange rate API
This commit is contained in:
parent
49dcf04b8d
commit
38a8a02459
2 changed files with 26 additions and 4 deletions
|
@ -6,6 +6,7 @@ export const FiatUnitSource = {
|
||||||
YadioConvert: 'YadioConvert',
|
YadioConvert: 'YadioConvert',
|
||||||
Exir: 'Exir',
|
Exir: 'Exir',
|
||||||
wazirx: 'wazirx',
|
wazirx: 'wazirx',
|
||||||
|
Bitstamp: 'Bitstamp',
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
const RateExtractors = {
|
const RateExtractors = {
|
||||||
|
@ -25,6 +26,27 @@ const RateExtractors = {
|
||||||
return rate;
|
return rate;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Bitstamp: async (ticker: string): Promise<number> => {
|
||||||
|
let json;
|
||||||
|
try {
|
||||||
|
const res = await fetch(`https://www.bitstamp.net/api/v2/ticker/btc${ticker.toLowerCase()}`);
|
||||||
|
json = await res.json();
|
||||||
|
} catch (e: any) {
|
||||||
|
throw new Error(`Could not update rate from Bitstamp for ${ticker}: ${e.message}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(json)) {
|
||||||
|
throw new Error(`Unsupported ticker for Bitstamp: ${ticker}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
let rate = +json?.last;
|
||||||
|
if (!rate) throw new Error(`Could not update rate from Bitstamp for ${ticker}: data is wrong`);
|
||||||
|
|
||||||
|
rate = Number(rate);
|
||||||
|
if (!(rate >= 0)) throw new Error(`Could not update rate from Bitstamp for ${ticker}: data is wrong`);
|
||||||
|
return rate;
|
||||||
|
},
|
||||||
|
|
||||||
Yadio: async (ticker: string): Promise<number> => {
|
Yadio: async (ticker: string): Promise<number> => {
|
||||||
let json;
|
let json;
|
||||||
try {
|
try {
|
||||||
|
@ -95,7 +117,7 @@ type FiatUnit = {
|
||||||
endPointKey: string;
|
endPointKey: string;
|
||||||
symbol: string;
|
symbol: string;
|
||||||
locale: string;
|
locale: string;
|
||||||
source: 'CoinDesk' | 'Yadio' | 'Exir' | 'wazirx';
|
source: 'CoinDesk' | 'Yadio' | 'Exir' | 'wazirx' | 'Bitstamp';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
export const FiatUnit = untypedFiatUnit as FiatUnit;
|
export const FiatUnit = untypedFiatUnit as FiatUnit;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"USD": {
|
"USD": {
|
||||||
"endPointKey": "USD",
|
"endPointKey": "USD",
|
||||||
"locale": "en-US",
|
"locale": "en-US",
|
||||||
"source": "CoinDesk",
|
"source": "Bitstamp",
|
||||||
"symbol": "$"
|
"symbol": "$"
|
||||||
},
|
},
|
||||||
"AED": {
|
"AED": {
|
||||||
|
@ -92,13 +92,13 @@
|
||||||
"EUR": {
|
"EUR": {
|
||||||
"endPointKey": "EUR",
|
"endPointKey": "EUR",
|
||||||
"locale": "en-IE",
|
"locale": "en-IE",
|
||||||
"source": "CoinDesk",
|
"source": "Bitstamp",
|
||||||
"symbol": "€"
|
"symbol": "€"
|
||||||
},
|
},
|
||||||
"GBP": {
|
"GBP": {
|
||||||
"endPointKey": "GBP",
|
"endPointKey": "GBP",
|
||||||
"locale": "en-GB",
|
"locale": "en-GB",
|
||||||
"source": "CoinDesk",
|
"source": "Bitstamp",
|
||||||
"symbol": "£"
|
"symbol": "£"
|
||||||
},
|
},
|
||||||
"HRK": {
|
"HRK": {
|
||||||
|
|
Loading…
Add table
Reference in a new issue