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

Commit 1223f06

Browse files
authored
Merge pull request #533 from lightninglabs/wait-on-wallet-addr
Wait for wallet address to be set before naving to NewAddress screen
2 parents 6ae9e66 + 5a2f8e5 commit 1223f06

File tree

5 files changed

+46
-6
lines changed

5 files changed

+46
-6
lines changed

src/action/wallet.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* call the corresponding GRPC apis for updating wallet balances.
44
*/
55

6-
import { observe } from 'mobx';
6+
import { observe, when } from 'mobx';
77
import { toBuffer, parseSat, checkHttpStatus, nap } from '../helper';
88
import { MIN_PASSWORD_LENGTH, NOTIFICATION_DELAY, RATE_DELAY } from '../config';
99
import * as log from './log';
@@ -261,6 +261,26 @@ class WalletAction {
261261
}
262262
}
263263

264+
/**
265+
* Ensure that the wallet address is non-null before navigating to the
266+
* NewAddress view during onboarding.
267+
* This is necessary because the wallet address may be null if neutrino
268+
* has not started syncing by the time the user finishes verifying
269+
* their seed.
270+
* @return {undefined}
271+
*/
272+
initInitialDeposit() {
273+
if (this._store.walletAddress) {
274+
this._nav.goNewAddress();
275+
} else {
276+
this._nav.goWait();
277+
when(
278+
() => typeof this._store.walletAddress === 'string',
279+
() => this._nav.goNewAddress()
280+
);
281+
}
282+
}
283+
264284
/**
265285
* Fetch a new on-chain bitcoin address which can be used to fund the wallet
266286
* or receive an on-chain transaction from another user.

src/view/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class MainView extends Component {
6060
{route === 'SeedVerify' && (
6161
<SeedVerify store={store} nav={nav} wallet={wallet} />
6262
)}
63-
{route === 'SeedSuccess' && <SeedSuccess nav={nav} />}
63+
{route === 'SeedSuccess' && <SeedSuccess wallet={wallet} />}
6464
{route === 'SetPassword' && (
6565
<SetPassword store={store} wallet={wallet} />
6666
)}

src/view/seed-success.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const styles = StyleSheet.create({
2424
},
2525
});
2626

27-
const SeedSuccessView = ({ nav }) => (
27+
const SeedSuccessView = ({ wallet }) => (
2828
<Background image="purple-gradient-bg">
2929
<MainContent>
3030
<View style={styles.wrapper}>
@@ -36,13 +36,15 @@ const SeedSuccessView = ({ nav }) => (
3636
}
3737
</CopyText>
3838
</View>
39-
<GlasButton onPress={() => nav.goNewAddress()}>Add some coin</GlasButton>
39+
<GlasButton onPress={() => wallet.initInitialDeposit()}>
40+
Add some coin
41+
</GlasButton>
4042
</MainContent>
4143
</Background>
4244
);
4345

4446
SeedSuccessView.propTypes = {
45-
nav: PropTypes.object.isRequired,
47+
wallet: PropTypes.object.isRequired,
4648
};
4749

4850
export default SeedSuccessView;

stories/screen.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ storiesOf('Screens', module)
9595
.add('Restore Wallet', () => (
9696
<RestoreWallet store={store} nav={nav} wallet={wallet} />
9797
))
98-
.add('Seed Success', () => <SeedSuccess nav={nav} />)
98+
.add('Seed Success', () => <SeedSuccess wallet={wallet} />)
9999
.add('Set Password', () => <SetPassword store={store} wallet={wallet} />)
100100
.add('Password', () => <Password store={store} wallet={wallet} />)
101101
.add('New Address', () => (

test/unit/action/wallet.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,24 @@ describe('Action Wallet Unit Tests', () => {
221221
});
222222
});
223223

224+
describe('initInitialDeposit()', () => {
225+
it('should navigate to new address screen if address is non-null', () => {
226+
store.walletAddress = 'non-null-addr';
227+
wallet.initInitialDeposit();
228+
expect(nav.goNewAddress, 'was called once');
229+
expect(nav.goWait, 'was not called');
230+
});
231+
232+
it('should stay on wait screen until address is non-null', async () => {
233+
store.walletAddress = null;
234+
wallet.initInitialDeposit();
235+
expect(nav.goNewAddress, 'was not called');
236+
store.walletAddress = 'non-null-addr';
237+
expect(nav.goWait, 'was called once');
238+
expect(nav.goNewAddress, 'was called once');
239+
});
240+
});
241+
224242
describe('checkPassword()', () => {
225243
beforeEach(() => {
226244
sandbox.stub(wallet, 'unlockWallet');

0 commit comments

Comments
 (0)