Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/action/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { observe } from 'mobx';
import { toBuffer, parseSat, checkHttpStatus, nap } from '../helper';
import { MIN_PASSWORD_LENGTH, NOTIFICATION_DELAY } from '../config';
import { MIN_PASSWORD_LENGTH, NOTIFICATION_DELAY, RATE_DELAY } from '../config';
import * as log from './log';

class WalletAction {
Expand Down Expand Up @@ -113,7 +113,7 @@ class WalletAction {
this.getBalance(),
this.getChannelBalance(),
this.getNewAddress(),
this.getExchangeRate(),
this.pollExchangeRate(),
]);
}

Expand Down Expand Up @@ -279,6 +279,17 @@ class WalletAction {
}
}

/**
* Poll for the current btc/fiat exchange rate based on the currently selected
* fiat currency every 15 minutes.
* @return {Promise<undefined>}
*/
async pollExchangeRate() {
await this.getExchangeRate();
clearTimeout(this.tPollRate);
this.tPollRate = setTimeout(() => this.pollExchangeRate(), RATE_DELAY);
}

/**
* Fetch a current btc/fiat exchange rate based on the currently selected
* fiat currency and persist the value on disk for the next time the app
Expand Down
1 change: 1 addition & 0 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports.RETRY_DELAY = 3000;
module.exports.LND_INIT_DELAY = 5000;
module.exports.NOTIFICATION_DELAY = 5000;
module.exports.RATE_DELAY = 15 * 60 * 1000;

module.exports.LND_PORT = 10009;
module.exports.LND_PEER_PORT = 10019;
Expand Down
16 changes: 14 additions & 2 deletions test/unit/action/wallet.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import WalletAction from '../../../src/action/wallet';
import NavAction from '../../../src/action/nav';
import NotificationAction from '../../../src/action/notification';
import * as logger from '../../../src/action/log';
import { nap } from '../../../src/helper';
import nock from 'nock';
import 'isomorphic-fetch';

Expand All @@ -23,6 +24,7 @@ describe('Action Wallet Unit Tests', () => {
store = new Store();
require('../../../src/config').RETRY_DELAY = 1;
require('../../../src/config').NOTIFICATION_DELAY = 1;
require('../../../src/config').RATE_DELAY = 1;
grpc = sinon.createStubInstance(GrpcAction);
db = sinon.createStubInstance(AppStorage);
notification = sinon.createStubInstance(NotificationAction);
Expand All @@ -31,6 +33,7 @@ describe('Action Wallet Unit Tests', () => {
});

afterEach(() => {
clearTimeout(wallet.tPollRate);
sandbox.restore();
});

Expand Down Expand Up @@ -106,10 +109,10 @@ describe('Action Wallet Unit Tests', () => {

describe('update()', () => {
it('should refresh balances, exchange rate and address', async () => {
sandbox.stub(wallet, 'getExchangeRate');
sandbox.stub(wallet, 'pollExchangeRate');
await wallet.update();
expect(grpc.sendCommand, 'was called thrice');
expect(wallet.getExchangeRate, 'was called once');
expect(wallet.pollExchangeRate, 'was called once');
});
});

Expand Down Expand Up @@ -324,6 +327,15 @@ describe('Action Wallet Unit Tests', () => {
});
});

describe('pollExchangeRate()', () => {
it('should call getExchangeRate', async () => {
sandbox.stub(wallet, 'getExchangeRate');
await wallet.pollExchangeRate();
await nap(30);
expect(wallet.getExchangeRate.callCount, 'to be greater than', 1);
});
});

describe('getExchangeRate()', () => {
it('should get exchange rate', async () => {
nock('https://blockchain.info')
Expand Down