@@ -26,6 +26,8 @@ export const LEDGER_PATHS = {
26
26
[ Blockchains . EOSIO ] :"44'/194'/0'/0/0" ,
27
27
}
28
28
29
+ const cache = { } ;
30
+
29
31
export default class LedgerWallet {
30
32
31
33
constructor ( blockchain ) {
@@ -34,7 +36,8 @@ export default class LedgerWallet {
34
36
}
35
37
36
38
static typeToInterface ( blockchain ) {
37
- return new LedgerWallet ( blockchain ) ;
39
+ if ( ! cache . hasOwnProperty ( blockchain ) ) cache [ blockchain ] = new LedgerWallet ( blockchain ) ;
40
+ return cache [ blockchain ] ;
38
41
} ;
39
42
40
43
async init ( ) {
@@ -54,6 +57,7 @@ export default class LedgerWallet {
54
57
if ( store . state . hardware . subscriber )
55
58
await store . state . hardware . subscriber . unsubscribe ( ) ;
56
59
store . dispatch ( Actions . SET_HARDWARE , null ) ;
60
+ delete cache [ this . blockchain ] ;
57
61
}
58
62
}
59
63
store . dispatch ( Actions . SET_HARDWARE , hardware ) ;
@@ -68,9 +72,10 @@ export default class LedgerWallet {
68
72
async add ( device ) {
69
73
const { path} = device ;
70
74
71
- const clone = Object . assign ( store . state . hardware , { transport : await Transport . open ( path ) } ) ;
75
+ const clone = Object . assign ( store . state . hardware , { transport :await Transport . open ( path ) } ) ;
72
76
store . dispatch ( Actions . SET_HARDWARE , clone ) ;
73
77
78
+
74
79
this . api = new LedgerAPI ( store . state . hardware . transport , this . blockchain ) ;
75
80
this . getPublicKey = this . api . getPublicKey ;
76
81
this . sign = this . api . signTransaction ;
@@ -235,6 +240,7 @@ class LedgerAPI {
235
240
'exclamation-triangle' ,
236
241
'Okay'
237
242
) ) ;
243
+ delete cache [ this . blockchain ] ;
238
244
return false ;
239
245
} )
240
246
}
0 commit comments