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

Commit 15da9a4

Browse files
committed
Update exchange rate every 15 minutes
1 parent 352169f commit 15da9a4

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/action/wallet.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class WalletAction {
113113
this.getBalance(),
114114
this.getChannelBalance(),
115115
this.getNewAddress(),
116-
this.getExchangeRate(),
116+
this.pollExchangeRate(),
117117
]);
118118
}
119119

@@ -279,6 +279,18 @@ class WalletAction {
279279
}
280280
}
281281

282+
/**
283+
* Poll for the current btc/fiat exchange rate based on the currently selected
284+
* fiat currency every 15 minutes.
285+
* @return {Promise<undefined>}
286+
*/
287+
async pollExchangeRate() {
288+
// Poll every 15 minutes, starting now.
289+
await this.getExchangeRate();
290+
let interval = 15 * 60 * 1000;
291+
setInterval(() => this.getExchangeRate(), interval);
292+
}
293+
282294
/**
283295
* Fetch a current btc/fiat exchange rate based on the currently selected
284296
* fiat currency and persist the value on disk for the next time the app

test/unit/action/wallet.spec.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ describe('Action Wallet Unit Tests', () => {
106106

107107
describe('update()', () => {
108108
it('should refresh balances, exchange rate and address', async () => {
109-
sandbox.stub(wallet, 'getExchangeRate');
109+
sandbox.stub(wallet, 'pollExchangeRate');
110110
await wallet.update();
111111
expect(grpc.sendCommand, 'was called thrice');
112-
expect(wallet.getExchangeRate, 'was called once');
112+
expect(wallet.pollExchangeRate, 'was called once');
113113
});
114114
});
115115

@@ -324,6 +324,14 @@ describe('Action Wallet Unit Tests', () => {
324324
});
325325
});
326326

327+
describe('pollExchangeRate()', () => {
328+
it('should call getExchangeRate', async () => {
329+
sandbox.stub(wallet, 'getExchangeRate');
330+
await wallet.pollExchangeRate();
331+
expect(wallet.getExchangeRate, 'was called once');
332+
});
333+
});
334+
327335
describe('getExchangeRate()', () => {
328336
it('should get exchange rate', async () => {
329337
nock('https://blockchain.info')

0 commit comments

Comments
 (0)