mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-03 12:06:21 +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)"
|
urlString = "https://api.yadio.io/json/\(endPointKey)"
|
||||||
case "BitcoinduLiban":
|
case "BitcoinduLiban":
|
||||||
urlString = "https://bitcoinduliban.org/api.php?key=lbpusd"
|
urlString = "https://bitcoinduliban.org/api.php?key=lbpusd"
|
||||||
|
case "Exir":
|
||||||
|
urlString = "https://api.exir.io/v1/ticker?symbol=btc-irt"
|
||||||
default:
|
default:
|
||||||
urlString = "https://api.coindesk.com/v1/bpi/currentprice/\(endPointKey).json"
|
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)
|
latestRateDataStore = WidgetDataStore(rate: String(rateDouble), lastUpdate: lastUpdatedString, rateDouble: rateDouble)
|
||||||
case "BitcoinduLiban":
|
case "BitcoinduLiban":
|
||||||
guard let rateString = json["BTC/LBP"] as? String else { break }
|
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())
|
let lastUpdatedString = ISO8601DateFormatter().string(from: Date())
|
||||||
latestRateDataStore = WidgetDataStore(rate: rateString, lastUpdate: lastUpdatedString, rateDouble: rateDouble)
|
latestRateDataStore = WidgetDataStore(rate: rateString, lastUpdate: lastUpdatedString, rateDouble: rateDouble)
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -4,6 +4,7 @@ export const FiatUnitSource = Object.freeze({
|
||||||
CoinDesk: 'CoinDesk',
|
CoinDesk: 'CoinDesk',
|
||||||
Yadio: 'Yadio',
|
Yadio: 'Yadio',
|
||||||
BitcoinduLiban: 'BitcoinduLiban',
|
BitcoinduLiban: 'BitcoinduLiban',
|
||||||
|
Exir: 'Exir',
|
||||||
});
|
});
|
||||||
|
|
||||||
const RateExtractors = Object.freeze({
|
const RateExtractors = Object.freeze({
|
||||||
|
@ -57,6 +58,24 @@ const RateExtractors = Object.freeze({
|
||||||
let rate = json?.[`BTC/${ticker}`];
|
let rate = json?.[`BTC/${ticker}`];
|
||||||
if (!rate) throw new Error(`Could not update rate for ${ticker}: data is wrong`);
|
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);
|
rate = Number(rate);
|
||||||
if (!(rate >= 0)) throw new Error(`Could not update rate for ${ticker}: data is wrong`);
|
if (!(rate >= 0)) throw new Error(`Could not update rate for ${ticker}: data is wrong`);
|
||||||
return rate;
|
return rate;
|
||||||
|
|
|
@ -113,6 +113,12 @@
|
||||||
"locale": "hi-HN",
|
"locale": "hi-HN",
|
||||||
"source": "CoinDesk"
|
"source": "CoinDesk"
|
||||||
},
|
},
|
||||||
|
"IRR": {
|
||||||
|
"endPointKey": "IRR",
|
||||||
|
"symbol": "﷼",
|
||||||
|
"locale": "fa-IR",
|
||||||
|
"source": "Exir"
|
||||||
|
},
|
||||||
"JPY": {
|
"JPY": {
|
||||||
"endPointKey": "JPY",
|
"endPointKey": "JPY",
|
||||||
"symbol": "¥",
|
"symbol": "¥",
|
||||||
|
|
|
@ -38,7 +38,13 @@ describe('currency', () => {
|
||||||
// disabled, because it throws "Service Temporarily Unavailable" on circleci
|
// disabled, because it throws "Service Temporarily Unavailable" on circleci
|
||||||
// await currency.setPrefferedCurrency(FiatUnit.LBP);
|
// await currency.setPrefferedCurrency(FiatUnit.LBP);
|
||||||
// await currency.startUpdater();
|
// 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);
|
// 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