mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-03 03:59:10 +01:00
ADD: IRR currency
This commit is contained in:
parent
cbe95236e9
commit
cd135c95e3
4 changed files with 40 additions and 2 deletions
|
@ -31,6 +31,8 @@ class WidgetAPI {
|
|||
urlString = "https://api.yadio.io/json/\(endPointKey)"
|
||||
case "BitcoinduLiban":
|
||||
urlString = "https://bitcoinduliban.org/api.php?key=lbpusd"
|
||||
case "Exir":
|
||||
urlString = "https://api.exir.io/v1/ticker?symbol=btc-irt"
|
||||
default:
|
||||
urlString = "https://api.coindesk.com/v1/bpi/currentprice/\(endPointKey).json"
|
||||
}
|
||||
|
@ -59,7 +61,12 @@ class WidgetAPI {
|
|||
latestRateDataStore = WidgetDataStore(rate: String(rateDouble), lastUpdate: lastUpdatedString, rateDouble: rateDouble)
|
||||
case "BitcoinduLiban":
|
||||
guard let rateString = json["BTC/LBP"] as? String else { break }
|
||||
guard let rateDouble = Double(rateString) else {return}
|
||||
guard let rateDouble = Double(rateString) else { break }
|
||||
let lastUpdatedString = ISO8601DateFormatter().string(from: Date())
|
||||
latestRateDataStore = WidgetDataStore(rate: rateString, lastUpdate: lastUpdatedString, rateDouble: rateDouble)
|
||||
case "Exir":
|
||||
guard let rateDouble = json["last"] as? Double else { break }
|
||||
let rateString = String(rateDouble)
|
||||
let lastUpdatedString = ISO8601DateFormatter().string(from: Date())
|
||||
latestRateDataStore = WidgetDataStore(rate: rateString, lastUpdate: lastUpdatedString, rateDouble: rateDouble)
|
||||
default:
|
||||
|
|
|
@ -4,6 +4,7 @@ export const FiatUnitSource = Object.freeze({
|
|||
CoinDesk: 'CoinDesk',
|
||||
Yadio: 'Yadio',
|
||||
BitcoinduLiban: 'BitcoinduLiban',
|
||||
Exir: 'Exir',
|
||||
});
|
||||
|
||||
const RateExtractors = Object.freeze({
|
||||
|
@ -57,6 +58,24 @@ const RateExtractors = Object.freeze({
|
|||
let rate = json?.[`BTC/${ticker}`];
|
||||
if (!rate) throw new Error(`Could not update rate for ${ticker}: data is wrong`);
|
||||
|
||||
rate = Number(rate);
|
||||
if (!(rate >= 0)) throw new Error(`Could not update rate for ${ticker}: data is wrong`);
|
||||
return rate;
|
||||
},
|
||||
Exir: async ticker => {
|
||||
const api = new Frisbee({ baseURI: 'https://api.exir.io' });
|
||||
const res = await api.get('/v1/ticker?symbol=btc-irt');
|
||||
if (res.err) throw new Error(`Could not update rate for ${ticker}: ${res.err}`);
|
||||
|
||||
let json;
|
||||
try {
|
||||
json = typeof res.body === 'string' ? JSON.parse(res.body) : res.body;
|
||||
} catch (e) {
|
||||
throw new Error(`Could not update rate for ${ticker}: ${e.message}`);
|
||||
}
|
||||
let rate = json?.last;
|
||||
if (!rate) throw new Error(`Could not update rate for ${ticker}: data is wrong`);
|
||||
|
||||
rate = Number(rate);
|
||||
if (!(rate >= 0)) throw new Error(`Could not update rate for ${ticker}: data is wrong`);
|
||||
return rate;
|
||||
|
|
|
@ -113,6 +113,12 @@
|
|||
"locale": "hi-HN",
|
||||
"source": "CoinDesk"
|
||||
},
|
||||
"IRR": {
|
||||
"endPointKey": "IRR",
|
||||
"symbol": "﷼",
|
||||
"locale": "fa-IR",
|
||||
"source": "Exir"
|
||||
},
|
||||
"JPY": {
|
||||
"endPointKey": "JPY",
|
||||
"symbol": "¥",
|
||||
|
|
|
@ -38,7 +38,13 @@ describe('currency', () => {
|
|||
// disabled, because it throws "Service Temporarily Unavailable" on circleci
|
||||
// await currency.setPrefferedCurrency(FiatUnit.LBP);
|
||||
// await currency.startUpdater();
|
||||
// cur = JSON.parse(await AsyncStorage.getItem(AppStorage.EXCHANGE_RATES));
|
||||
// cur = JSON.parse(await AsyncStorage.getItem(currency.EXCHANGE_RATES));
|
||||
// assert.ok(cur.BTC_LBP > 0);
|
||||
|
||||
// test Exir rate source
|
||||
await currency.setPrefferedCurrency(FiatUnit.IRR);
|
||||
await currency.startUpdater();
|
||||
cur = JSON.parse(await AsyncStorage.getItem(currency.EXCHANGE_RATES));
|
||||
assert.ok(cur.BTC_IRR > 0);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue