Poll channels to keep home screen up to date

parent 279b9bf2
......@@ -3,7 +3,7 @@
* call the corresponding GRPC apis for channel management.
*/
import { toSatoshis } from '../helper';
import { toSatoshis, poll } from '../helper';
import * as log from './log';
class ChannelAction {
......@@ -58,7 +58,6 @@ class ChannelAction {
*/
init() {
this._nav.goChannels();
this.update();
}
/**
......@@ -70,7 +69,6 @@ class ChannelAction {
select({ item }) {
this._store.selectedChannel = item;
this._nav.goChannelDetail();
this.update();
}
/**
......@@ -87,6 +85,14 @@ class ChannelAction {
]);
}
/**
* Poll the channels in the background since there is no streaming grpc api
* @return {Promise<undefined>}
*/
async pollChannels() {
await poll(() => this.update());
}
//
// Generic channel actions
//
......
......@@ -100,7 +100,7 @@ when(
wallet.getNewAddress();
wallet.pollBalances();
wallet.pollExchangeRate();
channel.update();
channel.pollChannels();
transaction.update();
info.pollInfo();
}
......
......@@ -91,7 +91,7 @@ when(
wallet.getNewAddress();
wallet.pollBalances();
wallet.pollExchangeRate();
channel.update();
channel.pollChannels();
transaction.update();
transaction.subscribeTransactions();
transaction.subscribeInvoices();
......
......@@ -59,21 +59,17 @@ describe('Action Channels Unit Tests', () => {
});
describe('init()', () => {
it('should update channels and navigate to list', () => {
sandbox.stub(channel, 'update');
it('should navigate to list', () => {
channel.init();
expect(channel.update, 'was called once');
expect(nav.goChannels, 'was called once');
});
});
describe('select()', () => {
it('should set selectedChannel', () => {
sandbox.stub(channel, 'update');
const item = 'some-channel';
channel.select({ item });
expect(store.selectedChannel, 'to equal', 'some-channel');
expect(channel.update, 'was called once');
expect(nav.goChannelDetail, 'was called once');
});
});
......@@ -85,6 +81,15 @@ describe('Action Channels Unit Tests', () => {
});
});
describe('pollChannels()', () => {
it('should poll all channels', async () => {
sandbox.stub(channel, 'update');
channel.update.onSecondCall().resolves(true);
await channel.pollChannels();
expect(channel.update, 'was called twice');
});
});
describe('getChannels()', () => {
it('should list open channels', async () => {
grpc.sendCommand.withArgs('listChannels').resolves({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment