Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.
Closed
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: 3 additions & 12 deletions src/action/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,8 @@ export const wallet = new WalletAction(store, grpc, db, nav, notify);
export const info = new InfoAction(store, grpc, nav, notify);
export const channel = new ChannelAction(store, grpc, nav, notify);
export const transaction = new TransactionAction(store, grpc, wallet, nav);
export const invoice = new InvoiceAction(
store,
grpc,
transaction,
nav,
notify,
Clipboard
);
export const payment = new PaymentAction(store, grpc, transaction, nav, notify);
export const invoice = new InvoiceAction(store, grpc, nav, notify, Clipboard);
export const payment = new PaymentAction(store, grpc, nav, notify);
export const setting = new SettingAction(store, wallet, db, ipc);

payment.listenForUrl(ipc); // enable incoming url handler
Expand Down Expand Up @@ -98,7 +91,5 @@ observe(store, 'lndReady', () => {
info.getInfo();
wallet.update();
channel.update();
transaction.update();
transaction.subscribeTransactions();
transaction.subscribeInvoices();
transaction.pollUpdate();
});
4 changes: 1 addition & 3 deletions src/action/invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import { PREFIX_URI } from '../config';
import { toSatoshis } from '../helper';

class InvoiceAction {
constructor(store, grpc, transaction, nav, notification, clipboard) {
constructor(store, grpc, nav, notification, clipboard) {
this._store = store;
this._grpc = grpc;
this._transaction = transaction;
this._nav = nav;
this._notification = notification;
this._clipboard = clipboard;
Expand Down Expand Up @@ -70,7 +69,6 @@ class InvoiceAction {
} catch (err) {
this._notification.display({ msg: 'Creating invoice failed!', err });
}
await this._transaction.update();
}

/**
Expand Down
5 changes: 1 addition & 4 deletions src/action/payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ import {
import * as log from './log';

class PaymentAction {
constructor(store, grpc, transaction, nav, notification) {
constructor(store, grpc, nav, notification) {
this._store = store;
this._grpc = grpc;
this._transaction = transaction;
this._nav = nav;
this._notification = notification;
}
Expand Down Expand Up @@ -161,7 +160,6 @@ class PaymentAction {
} catch (err) {
this._notification.display({ msg: 'Sending transaction failed!', err });
}
await this._transaction.update();
}

/**
Expand Down Expand Up @@ -192,7 +190,6 @@ class PaymentAction {
this._nav.goPayLightningConfirm();
this._notification.display({ msg: 'Lightning payment failed!', err });
}
await this._transaction.update();
}
}

Expand Down
17 changes: 15 additions & 2 deletions src/action/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* call the corresponding GRPC apis for listing transactions.
*/

import { RETRY_DELAY } from '../config';
import * as log from './log';
import { parseDate, parseSat, toHex, toHash } from '../helper';

Expand All @@ -21,7 +22,6 @@ class TransactionAction {
*/
init() {
this._nav.goTransactions();
this.update();
}

/**
Expand All @@ -33,7 +33,6 @@ class TransactionAction {
select({ item }) {
this._store.selectedTransaction = item;
this._nav.goTransactionDetail();
this.update();
}

/**
Expand All @@ -51,6 +50,20 @@ class TransactionAction {
]);
}

/**
* Poll the update api to update the transactions and wallet balances.
* @return {Promise<undefined>}
*/
async pollUpdate() {
try {
clearTimeout(this.tPollUpdate);
this.tPollUpdate = setTimeout(() => this.pollUpdate(), RETRY_DELAY);
await this.update();
} catch (err) {
log.error('Polling transaction update failed', err);
}
}

/**
* List the on-chain transactions by calling the respective grpc api and updating
* the transactions array in the global store.
Expand Down
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @fileOverview this file is used to hardcode default settings for the app.
*/

module.exports.RETRY_DELAY = 3000;
module.exports.RETRY_DELAY = 1000;
module.exports.LND_INIT_DELAY = 5000;
module.exports.NOTIFICATION_DELAY = 5000;
module.exports.RATE_DELAY = 15 * 60 * 1000;
Expand Down
11 changes: 2 additions & 9 deletions stories/screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,9 @@ sinon.stub(wallet, 'checkPassword');
sinon.stub(wallet, 'getExchangeRate');
const transaction = new TransactionAction(store, grpc, wallet, nav);
sinon.stub(transaction, 'update');
const invoice = new InvoiceAction(
store,
grpc,
transaction,
nav,
notify,
Clipboard
);
const invoice = new InvoiceAction(store, grpc, nav, notify, Clipboard);
sinon.stub(invoice, 'generateUri');
const payment = new PaymentAction(store, grpc, transaction, nav, notify);
const payment = new PaymentAction(store, grpc, nav, notify);
sinon.stub(payment, 'checkType');
sinon.stub(payment, 'payBitcoin');
sinon.stub(payment, 'payLightning');
Expand Down
8 changes: 4 additions & 4 deletions test/integration/action/action-integration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ describe('Action Integration Tests', function() {
wallet1 = new WalletAction(store1, grpc1, db1, nav1, notify1);
channels1 = new ChannelAction(store1, grpc1, nav1, notify1);
transactions1 = new TransactionAction(store1, grpc1, wallet1, nav1);
invoice1 = new InvoiceAction(store1, grpc1, transactions1, nav1, notify1);
payments1 = new PaymentAction(store1, grpc1, transactions1, nav1, notify1);
invoice1 = new InvoiceAction(store1, grpc1, nav1, notify1);
payments1 = new PaymentAction(store1, grpc1, nav1, notify1);

db2 = sinon.createStubInstance(AppStorage);
nav2 = sinon.createStubInstance(NavAction);
Expand All @@ -165,8 +165,8 @@ describe('Action Integration Tests', function() {
wallet2 = new WalletAction(store2, grpc2, db2, nav2, notify2);
channels2 = new ChannelAction(store2, grpc2, nav2, notify2);
transactions2 = new TransactionAction(store2, grpc2, wallet2, nav2);
invoice2 = new InvoiceAction(store2, grpc2, transactions2, nav2, notify2);
payments2 = new PaymentAction(store2, grpc2, transactions2, nav2, notify2);
invoice2 = new InvoiceAction(store2, grpc2, nav2, notify2);
payments2 = new PaymentAction(store2, grpc2, nav2, notify2);
});

after(async () => {
Expand Down
13 changes: 1 addition & 12 deletions test/unit/action/invoice.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ import { Store } from '../../../src/store';
import NavAction from '../../../src/action/nav';
import GrpcAction from '../../../src/action/grpc';
import InvoiceAction from '../../../src/action/invoice';
import TransactionAction from '../../../src/action/transaction';
import NotificationAction from '../../../src/action/notification';

describe('Action Invoice Unit Tests', () => {
let store;
let nav;
let grpc;
let invoice;
let transaction;
let notification;
let clipboard;

Expand All @@ -22,15 +20,7 @@ describe('Action Invoice Unit Tests', () => {
grpc = sinon.createStubInstance(GrpcAction);
notification = sinon.createStubInstance(NotificationAction);
clipboard = { setString: sinon.stub() };
transaction = sinon.createStubInstance(TransactionAction);
invoice = new InvoiceAction(
store,
grpc,
transaction,
nav,
notification,
clipboard
);
invoice = new InvoiceAction(store, grpc, nav, notification, clipboard);
});

describe('init()', () => {
Expand Down Expand Up @@ -78,7 +68,6 @@ describe('Action Invoice Unit Tests', () => {
expect(store.invoice.encoded, 'to equal', 'some-request');
expect(store.invoice.uri, 'to equal', 'lightning:some-request');
expect(nav.goInvoiceQR, 'was called once');
expect(transaction.update, 'was called once');
});

it('should display notification on error', async () => {
Expand Down
9 changes: 1 addition & 8 deletions test/unit/action/payment.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Store } from '../../../src/store';
import IpcAction from '../../../src/action/ipc';
import GrpcAction from '../../../src/action/grpc';
import PaymentAction from '../../../src/action/payment';
import TransactionAction from '../../../src/action/transaction';
import NotificationAction from '../../../src/action/notification';
import NavAction from '../../../src/action/nav';
import * as logger from '../../../src/action/log';
Expand All @@ -13,7 +12,6 @@ describe('Action Payments Unit Tests', () => {
let store;
let sandbox;
let grpc;
let transaction;
let payment;
let nav;
let notification;
Expand All @@ -27,8 +25,7 @@ describe('Action Payments Unit Tests', () => {
grpc = sinon.createStubInstance(GrpcAction);
notification = sinon.createStubInstance(NotificationAction);
nav = sinon.createStubInstance(NavAction);
transaction = sinon.createStubInstance(TransactionAction);
payment = new PaymentAction(store, grpc, transaction, nav, notification);
payment = new PaymentAction(store, grpc, nav, notification);
});

afterEach(() => {
Expand Down Expand Up @@ -199,14 +196,12 @@ describe('Action Payments Unit Tests', () => {
});
expect(nav.goPayBitcoinDone, 'was called once');
expect(notification.display, 'was not called');
expect(transaction.update, 'was called once');
});

it('should display notification on error', async () => {
grpc.sendCommand.withArgs('sendCoins').rejects();
await payment.payBitcoin();
expect(notification.display, 'was called once');
expect(transaction.update, 'was called once');
});
});

Expand Down Expand Up @@ -237,15 +232,13 @@ describe('Action Payments Unit Tests', () => {
expect(nav.goWait, 'was called once');
expect(nav.goPayLightningDone, 'was called once');
expect(notification.display, 'was not called');
expect(transaction.update, 'was called once');
});

it('should display notification on error', async () => {
paymentsOnStub.withArgs('data').yields({ payment_error: 'Boom!' });
await payment.payLightning({ invoice: 'some-payment' });
expect(nav.goPayLightningConfirm, 'was called once');
expect(notification.display, 'was called once');
expect(transaction.update, 'was called once');
});
});
});
24 changes: 20 additions & 4 deletions test/unit/action/transaction.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import TransactionAction from '../../../src/action/transaction';
import WalletAction from '../../../src/action/wallet';
import NavAction from '../../../src/action/nav';
import * as logger from '../../../src/action/log';
import { nap } from '../../../src/helper';

describe('Action Transactions Unit Tests', () => {
let store;
Expand All @@ -25,24 +26,21 @@ describe('Action Transactions Unit Tests', () => {
});

afterEach(() => {
clearTimeout(transaction.tPollUpdate);
sandbox.restore();
});

describe('init()', () => {
it('should refresh and navigate to list', () => {
sandbox.stub(transaction, 'update');
transaction.init();
expect(transaction.update, 'was called once');
expect(nav.goTransactions, 'was called once');
});
});

describe('select()', () => {
it('should set selectedTransaction', () => {
sandbox.stub(transaction, 'update');
transaction.select({ item: 'some-transaction' });
expect(store.selectedTransaction, 'to equal', 'some-transaction');
expect(transaction.update, 'was called once');
expect(nav.goTransactionDetail, 'was called once');
});
});
Expand All @@ -56,6 +54,24 @@ describe('Action Transactions Unit Tests', () => {
});
});

describe('pollUpdate()', () => {
it('should poll update api several times', async () => {
sandbox.stub(transaction, 'update');
await transaction.pollUpdate();
await nap(30);
expect(transaction.update.callCount, 'to be greater than', 1);
expect(logger.error, 'was not called');
});

it('should handle error in update', async () => {
sandbox.stub(transaction, 'update').rejects(new Error('Boom!'));
await transaction.pollUpdate();
await nap(30);
expect(transaction.update.callCount, 'to be greater than', 1);
expect(logger.error.callCount, 'to be greater than', 1);
});
});

describe('getTransactions()', () => {
it('should set unconfirmed transaction in store', async () => {
grpc.sendCommand.withArgs('getTransactions').resolves({
Expand Down