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

Commit 93619eb

Browse files
Add parameter to customize Wait screen copy.
1 parent 18c81b9 commit 93619eb

File tree

13 files changed

+75
-35
lines changed

13 files changed

+75
-35
lines changed

src/action/index-mobile.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ export const ipc = sinon.createStubInstance(IpcAction); // STUB DURING DEVELOPME
4949
export const log = new LogAction(store, ipc, false);
5050
export const nav = new NavAction(store, NavigationActions, StackActions);
5151
export const notify = new NotificationAction(store, nav);
52-
export const wallet = new WalletAction(store, grpc, db, nav, notify);
52+
export const payment = new PaymentAction(store, grpc, nav, notify, Clipboard);
53+
export const wallet = new WalletAction(store, grpc, db, nav, notify, payment);
5354
export const info = new InfoAction(store, grpc, nav, notify);
5455
export const transaction = new TransactionAction(store, grpc, nav, notify);
5556
export const channel = new ChannelAction(store, grpc, nav, notify);
5657
export const invoice = new InvoiceAction(store, grpc, nav, notify, Clipboard);
57-
export const payment = new PaymentAction(store, grpc, nav, notify, Clipboard);
5858
export const setting = new SettingAction(store, wallet, db, ipc);
5959
export const auth = new AuthAction(
6060
store,

src/action/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ export const log = new LogAction(store, ipc);
3535
export const nav = new NavAction(store);
3636
export const grpc = new GrpcAction(store, ipc);
3737
export const notify = new NotificationAction(store, nav);
38-
export const wallet = new WalletAction(store, grpc, db, nav, notify);
38+
export const payment = new PaymentAction(store, grpc, nav, notify, Clipboard);
39+
export const wallet = new WalletAction(store, grpc, db, nav, notify, payment);
3940
export const info = new InfoAction(store, grpc, nav, notify);
4041
export const transaction = new TransactionAction(store, grpc, nav, notify);
4142
export const channel = new ChannelAction(store, grpc, nav, notify);
4243
export const invoice = new InvoiceAction(store, grpc, nav, notify, Clipboard);
43-
export const payment = new PaymentAction(store, grpc, nav, notify, Clipboard);
4444
export const setting = new SettingAction(store, wallet, db, ipc);
4545
export const autopilot = new AtplAction(store, grpc, db, notify);
4646

src/action/payment.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ class PaymentAction {
259259
msg: 'Sending transaction timed out!',
260260
});
261261
}, PAYMENT_TIMEOUT);
262-
this._nav.goWait();
262+
this.initWaitScreen({ copy: 'Sending payment...' });
263263
try {
264264
await this._sendPayment();
265265
this._nav.goPayBitcoinDone();
@@ -295,7 +295,7 @@ class PaymentAction {
295295
this._nav.goPaymentFailed();
296296
}, PAYMENT_TIMEOUT);
297297
try {
298-
this._nav.goWait();
298+
this.initWaitScreen({ copy: 'Sending payment...' });
299299
const invoice = this._store.payment.address;
300300
const stream = this._grpc.sendStreamCommand('sendPayment');
301301
await new Promise((resolve, reject) => {
@@ -319,6 +319,17 @@ class PaymentAction {
319319
clearTimeout(timeout);
320320
}
321321
}
322+
323+
/**
324+
* Initialize the Wait screen with copy appropriate for what the user is
325+
* waiting on.
326+
* @param {string} copy Copy to display.
327+
* @return {undefined}
328+
*/
329+
initWaitScreen({ copy = 'Loading network...' }) {
330+
this._store.waitScreenCopy = copy;
331+
this._nav.goWait();
332+
}
322333
}
323334

324335
export default PaymentAction;

src/action/wallet.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ import { when } from 'mobx';
1414
import * as log from './log';
1515

1616
class WalletAction {
17-
constructor(store, grpc, db, nav, notification) {
17+
constructor(store, grpc, db, nav, notification, payment) {
1818
this._store = store;
1919
this._grpc = grpc;
2020
this._db = db;
2121
this._nav = nav;
2222
this._notification = notification;
23+
this._payment = payment;
2324
}
2425

2526
//
@@ -245,7 +246,7 @@ class WalletAction {
245246
this.initResetPassword();
246247
return this._notification.display({ msg: errorMsg });
247248
}
248-
this._nav.goWait();
249+
this._payment.initWaitScreen({ copy: 'Updating password...' });
249250
await this.resetPassword({
250251
currentPassword: password,
251252
newPassword: newPassword,
@@ -394,7 +395,7 @@ class WalletAction {
394395
*/
395396
async unlockWallet({ walletPassword }) {
396397
try {
397-
this._nav.goWait();
398+
this._payment.initWaitScreen({});
398399
await this._grpc.sendUnlockerCommand('UnlockWallet', {
399400
walletPassword: toBuffer(walletPassword),
400401
recoveryWindow: this._store.settings.restoring ? 250 : 0,
@@ -463,7 +464,7 @@ class WalletAction {
463464
if (this._store.walletAddress) {
464465
this._nav.goNewAddress();
465466
} else {
466-
this._nav.goWait();
467+
this._payment.initWaitScreen({});
467468
when(() => this._store.walletAddress, () => this._nav.goNewAddress());
468469
}
469470
}

src/store.js

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export class Store {
8585
notifications: [],
8686
unseenNtfnCount: 0,
8787
logs: '',
88+
waitScreenCopy: 'Loading network...',
8889

8990
// Persistent data
9091
settings: {

src/view/main-mobile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const Password = () => <PinView store={store} auth={auth} />;
9595

9696
const LoaderSyncing = () => <LoaderSyncingView store={store} />;
9797

98-
const Wait = () => <WaitView />;
98+
const Wait = () => <WaitView store={store} />;
9999

100100
const Home = () => (
101101
<HomeView

src/view/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class MainView extends Component {
9999
<NewAddress store={store} invoice={invoice} info={info} />
100100
)}
101101
{route === 'LoaderSyncing' && <LoaderSyncing store={store} />}
102-
{route === 'Wait' && <Wait />}
102+
{route === 'Wait' && <Wait store={store} />}
103103
{route === 'Home' && (
104104
<Home
105105
store={store}

src/view/wait-mobile.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import { StyleSheet, ActivityIndicator } from 'react-native';
3+
import PropTypes from 'prop-types';
34
import Background from '../component/background';
45
import MainContent from '../component/main-content';
56
import Text from '../component/text';
@@ -19,17 +20,21 @@ const styles = StyleSheet.create({
1920
},
2021
});
2122

22-
const WaitView = () => (
23+
const WaitView = ({ store }) => (
2324
<Background color={color.blackDark}>
2425
<MainContent style={styles.content}>
2526
<ActivityIndicator
2627
size="large"
2728
color={color.lightPurple}
2829
style={styles.spinner}
2930
/>
30-
<Text style={styles.copy}>Loading network...</Text>
31+
<Text style={styles.copy}>{store.waitScreenCopy}</Text>
3132
</MainContent>
3233
</Background>
3334
);
3435

36+
WaitView.propTypes = {
37+
store: PropTypes.object.isRequired,
38+
};
39+
3540
export default WaitView;

src/view/wait.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import { StyleSheet } from 'react-native';
3+
import PropTypes from 'prop-types';
34
import Background from '../component/background';
45
import MainContent from '../component/main-content';
56
import { color } from '../component/style';
@@ -11,12 +12,16 @@ const styles = StyleSheet.create({
1112
},
1213
});
1314

14-
const WaitView = () => (
15+
const WaitView = ({ store }) => (
1516
<Background color={color.blackDark}>
1617
<MainContent style={styles.content}>
17-
<ContinuousLoadNetworkSpinner msg="Loading network..." />
18+
<ContinuousLoadNetworkSpinner msg={store.waitScreenCopy} />
1819
</MainContent>
1920
</Background>
2021
);
2122

23+
WaitView.propTypes = {
24+
store: PropTypes.object.isRequired,
25+
};
26+
2227
export default WaitView;

stories/screen-story.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,13 @@ const ipc = sinon.createStubInstance(IpcAction);
9292
const grpc = sinon.createStubInstance(GrpcAction);
9393
const info = sinon.createStubInstance(InfoAction);
9494
const notify = sinon.createStubInstance(NotificationAction);
95-
const wallet = new WalletAction(store, grpc, db, nav, notify);
95+
const payment = new PaymentAction(store, grpc, nav, notify);
96+
sinon.stub(payment, 'checkType');
97+
sinon.stub(payment, 'payBitcoin');
98+
sinon.stub(payment, 'toggleMax');
99+
sinon.stub(payment, 'payLightning');
100+
sinon.stub(payment, 'initPayBitcoinConfirm');
101+
const wallet = new WalletAction(store, grpc, db, nav, notify, payment);
96102
const setting = new SettingAction(store, wallet, db, ipc);
97103
const autopilot = sinon.createStubInstance(AtplAction);
98104
sinon.stub(wallet, 'update');
@@ -104,12 +110,6 @@ const transaction = new TransactionAction(store, grpc, nav, notify);
104110
sinon.stub(transaction, 'update');
105111
const invoice = new InvoiceAction(store, grpc, nav, notify, Clipboard);
106112
sinon.stub(invoice, 'generateUri');
107-
const payment = new PaymentAction(store, grpc, nav, notify);
108-
sinon.stub(payment, 'checkType');
109-
sinon.stub(payment, 'payBitcoin');
110-
sinon.stub(payment, 'toggleMax');
111-
sinon.stub(payment, 'payLightning');
112-
sinon.stub(payment, 'initPayBitcoinConfirm');
113113
const channel = new ChannelAction(store, grpc, nav, notify);
114114
sinon.stub(channel, 'update');
115115
sinon.stub(channel, 'connectAndOpen');
@@ -178,8 +178,8 @@ storiesOf('Screens', module)
178178
.add('Loader - Syncing Chain (Mobile)', () => (
179179
<LoaderSyncingMobile store={store} />
180180
))
181-
.add('Wait', () => <Wait />)
182-
.add('Wait (Mobile)', () => <WaitMobile />)
181+
.add('Wait', () => <Wait store={store} />)
182+
.add('Wait (Mobile)', () => <WaitMobile store={store} />)
183183
.add('Home', () => (
184184
<Home
185185
store={store}

test/integration/action/action-integration.spec.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,11 @@ describe('Action Integration Tests', function() {
162162
ipc1 = new IpcAction(ipcRendererStub1);
163163
grpc1 = new GrpcAction(store1, ipc1);
164164
info1 = new InfoAction(store1, grpc1, nav1, notify1);
165-
wallet1 = new WalletAction(store1, grpc1, db1, nav1, notify1);
165+
payments1 = new PaymentAction(store1, grpc1, nav1, notify1);
166+
wallet1 = new WalletAction(store1, grpc1, db1, nav1, notify1, payments1);
166167
transactions1 = new TransactionAction(store1, grpc1, nav1, notify1);
167168
channels1 = new ChannelAction(store1, grpc1, nav1, notify1);
168169
invoice1 = new InvoiceAction(store1, grpc1, nav1, notify1);
169-
payments1 = new PaymentAction(store1, grpc1, nav1, notify1);
170170
autopilot1 = new AtplAction(store1, grpc1, db1, notify1);
171171

172172
db2 = sinon.createStubInstance(AppStorage);
@@ -175,11 +175,11 @@ describe('Action Integration Tests', function() {
175175
ipc2 = new IpcAction(ipcRendererStub2);
176176
grpc2 = new GrpcAction(store2, ipc2);
177177
info2 = new InfoAction(store2, grpc2, nav2, notify2);
178-
wallet2 = new WalletAction(store2, grpc2, db2, nav2, notify2);
178+
payments2 = new PaymentAction(store2, grpc2, nav2, notify2);
179+
wallet2 = new WalletAction(store2, grpc2, db2, nav2, notify2, payments2);
179180
transactions2 = new TransactionAction(store2, grpc2, nav2, notify2);
180181
channels2 = new ChannelAction(store2, grpc2, nav2, notify2);
181182
invoice2 = new InvoiceAction(store2, grpc2, nav2, notify2);
182-
payments2 = new PaymentAction(store2, grpc2, nav2, notify2);
183183
autopilot2 = new AtplAction(store2, grpc2, db2, notify2);
184184

185185
sandbox.stub(autopilot1, 'updateNodeScores').resolves(true);

test/unit/action/payment.spec.js

+14
Original file line numberDiff line numberDiff line change
@@ -453,4 +453,18 @@ describe('Action Payments Unit Tests', () => {
453453
expect(nav.goPayLightningDone, 'was not called');
454454
});
455455
});
456+
457+
describe('initWaitScreen', () => {
458+
it('should set the wait screen copy and go to wait page', () => {
459+
const testCopy = 'foobar';
460+
payment.initWaitScreen({ copy: testCopy });
461+
expect(store.waitScreenCopy, 'to be', testCopy);
462+
});
463+
464+
it('should set default copy if not specified', () => {
465+
const defaultCopy = 'Loading network...';
466+
payment.initWaitScreen({});
467+
expect(store.waitScreenCopy, 'to be', defaultCopy);
468+
});
469+
});
456470
});

test/unit/action/wallet.spec.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import WalletAction from '../../../src/action/wallet';
55
import NavAction from '../../../src/action/nav';
66
import NavActionMobile from '../../../src/action/nav-mobile';
77
import NotificationAction from '../../../src/action/notification';
8+
import PaymentAction from '../../../src/action/payment';
89
import * as logger from '../../../src/action/log';
910
import nock from 'nock';
1011
import 'isomorphic-fetch';
@@ -18,6 +19,7 @@ describe('Action Wallet Unit Tests', () => {
1819
let wallet;
1920
let nav;
2021
let notification;
22+
let payment;
2123

2224
beforeEach(() => {
2325
sandbox = sinon.createSandbox({});
@@ -30,7 +32,8 @@ describe('Action Wallet Unit Tests', () => {
3032
db = sinon.createStubInstance(AppStorage);
3133
notification = sinon.createStubInstance(NotificationAction);
3234
nav = sinon.createStubInstance(NavAction);
33-
wallet = new WalletAction(store, grpc, db, nav, notification);
35+
payment = sinon.createStubInstance(PaymentAction);
36+
wallet = new WalletAction(store, grpc, db, nav, notification, payment);
3437
});
3538

3639
afterEach(() => {
@@ -325,7 +328,7 @@ describe('Action Wallet Unit Tests', () => {
325328

326329
it('should navigate to seed intro on mobile', () => {
327330
nav = sinon.createStubInstance(NavActionMobile);
328-
wallet = new WalletAction(store, grpc, db, nav, notification);
331+
wallet = new WalletAction(store, grpc, db, nav, notification, payment);
329332
wallet.initSeed();
330333
expect(nav.goSeedIntro, 'was called once');
331334
});
@@ -437,15 +440,15 @@ describe('Action Wallet Unit Tests', () => {
437440
store.walletAddress = 'non-null-addr';
438441
wallet.initInitialDeposit();
439442
expect(nav.goNewAddress, 'was called once');
440-
expect(nav.goWait, 'was not called');
443+
expect(payment.initWaitScreen, 'was not called');
441444
});
442445

443446
it('should stay on wait screen until address is non-null', async () => {
444447
store.walletAddress = null;
445448
wallet.initInitialDeposit();
446449
expect(nav.goNewAddress, 'was not called');
447450
store.walletAddress = 'non-null-addr';
448-
expect(nav.goWait, 'was called once');
451+
expect(payment.initWaitScreen, 'was called once');
449452
expect(nav.goNewAddress, 'was called once');
450453
});
451454
});
@@ -510,7 +513,7 @@ describe('Action Wallet Unit Tests', () => {
510513
expect(grpc.sendUnlockerCommand, 'was called with', 'UnlockWallet', {
511514
walletPassword: Buffer.from('baz', 'utf8'),
512515
});
513-
expect(nav.goWait, 'was called once');
516+
expect(payment.initWaitScreen, 'was called once');
514517
expect(nav.goHome, 'was not called');
515518
store.lndReady = true;
516519
store.walletAddress = 'some-address';
@@ -525,7 +528,7 @@ describe('Action Wallet Unit Tests', () => {
525528
.rejects(new Error('Boom!'));
526529
await wallet.unlockWallet({ walletPassword: 'baz' });
527530
expect(notification.display, 'was called once');
528-
expect(nav.goWait, 'was called once');
531+
expect(payment.initWaitScreen, 'was called once');
529532
expect(store.walletUnlocked, 'to be', false);
530533
expect(store.wallet.password, 'to be', '');
531534
expect(nav.goPassword, 'was called once');

0 commit comments

Comments
 (0)