@@ -26,6 +26,7 @@ import SentryPermission from './screens/SentryPermission';
26
26
import UnknownTokens from './screens/UnknownTokens' ;
27
27
import Signin from './screens/Signin' ;
28
28
import LockedWallet from './screens/LockedWallet' ;
29
+ import ChooseWallet from './screens/ChooseWallet' ;
29
30
import NewWallet from './screens/NewWallet' ;
30
31
import WalletType from './screens/WalletType' ;
31
32
import SoftwareWalletWarning from './screens/SoftwareWalletWarning' ;
@@ -45,8 +46,9 @@ import RequestErrorModal from './components/RequestError';
45
46
import { GlobalModalContext , MODAL_TYPES } from './components/GlobalModal' ;
46
47
import createRequestInstance from './api/axiosInstance' ;
47
48
import hathorLib from '@hathor/wallet-lib' ;
48
- import { IPC_RENDERER } from './constants' ;
49
49
import AllAddresses from './screens/AllAddresses' ;
50
+ import AddressList from './screens/AddressList' ;
51
+ import { IPC_RENDERER , LEDGER_ENABLED } from './constants' ;
50
52
import NFTList from './screens/NFTList' ;
51
53
import { resetNavigateTo , updateLedgerClosed } from './actions/index' ;
52
54
import { WALLET_STATUS } from './sagas/wallet' ;
@@ -80,7 +82,17 @@ function Root() {
80
82
useEffect ( ( ) => {
81
83
if ( ledgerClosed ) {
82
84
LOCAL_STORE . lock ( ) ;
83
- navigate ( '/locked/' ) ;
85
+ wallet . removeHardwareWalletFromStorage ( ) ;
86
+
87
+ // If there are other wallets, go to screen to choose wallet
88
+ const firstWallet = wallet . getFirstWalletPrefix ( ) ;
89
+ if ( firstWallet ) {
90
+ wallet . setWalletPrefix ( firstWallet ) ;
91
+ navigate ( '/choose_wallet' ) ;
92
+ } else {
93
+ wallet . setWalletPrefix ( null ) ;
94
+ navigate ( '/wallet_type/' ) ;
95
+ }
84
96
}
85
97
} , [ ledgerClosed ] ) ;
86
98
@@ -91,6 +103,22 @@ function Root() {
91
103
* - Ledger event handlers
92
104
*/
93
105
useEffect ( ( ) => {
106
+ // When Ledger device loses connection or the app is closed
107
+ if ( this . props . ledgerClosed && ! prevProps . ledgerClosed ) {
108
+ wallet . removeHardwareWalletFromStorage ( ) ;
109
+
110
+ // If there are other wallets, go to screen to choose wallet
111
+ const firstWallet = wallet . getFirstWalletPrefix ( ) ;
112
+ if ( firstWallet ) {
113
+ wallet . setWalletPrefix ( firstWallet ) ;
114
+ this . props . history . push ( '/choose_wallet' ) ;
115
+ } else {
116
+ wallet . setWalletPrefix ( null ) ;
117
+ this . props . history . push ( '/wallet_type/' ) ;
118
+ }
119
+ }
120
+
121
+ // ---
94
122
// Detect a previous instalation and migrate
95
123
storageUtils . migratePreviousLocalStorage ( ) ;
96
124
@@ -215,6 +243,7 @@ function Root() {
215
243
< Route path = "/signin" element = { < StartedComponent children = { < Signin /> } loaded = { false } /> } />
216
244
< Route path = "/hardware_wallet" element = { < StartedComponent children = { < StartHardwareWallet /> } loaded = { false } /> } />
217
245
< Route path = "/locked" element = { < DefaultComponent children = { < LockedWallet /> } /> } />
246
+ < Route path = "/choose_wallet" element = { < DefaultComponent children = { < ChooseWallet /> } /> } />
218
247
< Route path = "/welcome" element = { < Welcome /> } />
219
248
< Route path = "/loading_addresses" element = { < LoadingAddresses /> } />
220
249
< Route path = "/permission" element = { < SentryPermission /> } />
@@ -233,7 +262,7 @@ function LoadedWalletComponent({ children }) {
233
262
234
263
// If was closed and is loaded we need to redirect to locked screen
235
264
if ( ( ! isServerScreen ) && ( LOCAL_STORE . wasClosed ( ) || LOCAL_STORE . isLocked ( ) ) && ( ! LOCAL_STORE . isHardwareWallet ( ) ) ) {
236
- return < Navigate to = { '/locked /' } /> ;
265
+ return < Redirect to = { { pathname : '/choose_wallet /' } } /> ;
237
266
}
238
267
239
268
// We allow server screen to be shown from locked screen to allow the user to
@@ -303,18 +332,29 @@ function StartedComponent({children, loaded: routeRequiresWalletToBeLoaded}) {
303
332
const isServerScreen = location . pathname === '/server' ;
304
333
// Wallet is locked, go to locked screen
305
334
if ( LOCAL_STORE . isLocked ( ) && ! isServerScreen && ! LOCAL_STORE . isHardwareWallet ( ) ) {
306
- return < Navigate to = { '/locked/' } replace /> ;
335
+ return < Redirect to = { { pathname : '/choose_wallet/' } } /> ;
307
336
}
308
337
309
338
// Route requires the wallet to be loaded, render it
310
339
if ( routeRequiresWalletToBeLoaded || isServerScreen ) {
311
340
return < LoadedWalletComponent children = { children } /> ;
312
341
}
313
342
343
+ // XXX: Wallet reseted?
344
+ const firstWallet = wallet . getFirstWalletPrefix ( ) ;
345
+ if ( firstWallet && LOCAL_STORE . prefix === '' ) {
346
+ return < Redirect to = { { pathname : '/choose_wallet/' } } /> ;
347
+ }
348
+
314
349
// Route does not require wallet to be loaded. Redirect to wallet "home" screen
315
350
return < Navigate to = "/wallet/" replace /> ;
316
351
}
317
352
353
+ const firstWallet = wallet . getFirstWalletPrefix ( ) ;
354
+ if ( firstWallet && hathorLib . storage . store . prefix === '' ) {
355
+ return < Redirect to = { { pathname : '/choose_wallet/' } } /> ;
356
+ }
357
+
318
358
// Wallet is not loaded, but it is still loading addresses. Go to the loading screen
319
359
if ( loadingAddresses ) {
320
360
const location = useLocation ( ) ;
@@ -378,7 +418,13 @@ function DefaultComponent({ children }) {
378
418
LOCAL_STORE . isHardwareWallet ( ) ) {
379
419
// This will redirect the page to Wallet Type screen
380
420
LOCAL_STORE . cleanWallet ( ) ;
381
- return < Navigate to = { '/wallet_type/' } /> ;
421
+ wallet . removeHardwareWalletFromStorage ( ) ;
422
+ hathorLib . wallet . unlock ( ) ;
423
+ const firstWallet = wallet . getFirstWalletPrefix ( ) ;
424
+ if ( firstWallet ) {
425
+ return < Redirect to = { { pathname : '/choose_wallet/' } } /> ;
426
+ }
427
+ return < Redirect to = { { pathname : '/wallet_type/' } } /> ;
382
428
}
383
429
384
430
// Render the navigation top bar, the component and the error handling modal
0 commit comments