Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit d2c60cc

Browse files
committed
Use new exchange rate api
1 parent 415e00c commit d2c60cc

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

src/action/wallet.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,12 @@ class WalletAction {
504504
async getExchangeRate() {
505505
try {
506506
const fiat = this._store.settings.fiat;
507-
const uri = `https://blockchain.info/tobtc?currency=${fiat}&value=1`;
507+
const uri =
508+
'https://nodes.lightning.computer/fiat/v1/btc-exchange-rates.json';
508509
const response = checkHttpStatus(await fetch(uri));
509-
this._store.settings.exchangeRate[fiat] = Number(await response.text());
510+
const tickers = (await response.json()).tickers;
511+
const rate = tickers.find(t => t.ticker.toLowerCase() === fiat).rate;
512+
this._store.settings.exchangeRate[fiat] = 100 / rate;
510513
this._db.save();
511514
} catch (err) {
512515
log.error('Getting exchange rate failed', err);

test/unit/action/wallet.spec.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -597,20 +597,38 @@ describe('Action Wallet Unit Tests', () => {
597597
});
598598

599599
describe('getExchangeRate()', () => {
600+
const json = `{
601+
"tickers": [
602+
{
603+
"date": "2019-04-04T03:30:05.000Z",
604+
"rate": 443302,
605+
"ticker": "EUR"
606+
},
607+
{
608+
"date": "2019-04-04T03:30:05.000Z",
609+
"rate": 378294,
610+
"ticker": "GBP"
611+
},
612+
{
613+
"date": "2019-04-04T03:30:05.000Z",
614+
"rate": 498467,
615+
"ticker": "USD"
616+
}
617+
]
618+
}`;
619+
600620
it('should get exchange rate', async () => {
601-
nock('https://blockchain.info')
602-
.get('/tobtc')
603-
.query({ currency: 'usd', value: 1 })
604-
.reply(200, '0.00011536');
621+
nock('https://nodes.lightning.computer')
622+
.get('/fiat/v1/btc-exchange-rates.json')
623+
.reply(200, json);
605624
await wallet.getExchangeRate();
606-
expect(store.settings.exchangeRate.usd, 'to be', 0.00011536);
625+
expect(store.settings.exchangeRate.usd, 'to be', 0.000200615085853226);
607626
expect(db.save, 'was called once');
608627
});
609628

610629
it('should display notification on error', async () => {
611-
nock('https://blockchain.info')
612-
.get('/tobtc')
613-
.query({ currency: 'usd', value: 1 })
630+
nock('https://nodes.lightning.computer')
631+
.get('/fiat/v1/btc-exchange-rates.json')
614632
.reply(500, 'Boom!');
615633
await wallet.getExchangeRate();
616634
expect(store.settings.exchangeRate.usd, 'to be', undefined);

0 commit comments

Comments
 (0)