Skip to content

Commit a179a95

Browse files
author
Nathan James
committed
mac ledger fix
1 parent aa4676d commit a179a95

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

package-lock.json

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/models/hardware/LedgerWallet.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export const LEDGER_PATHS = {
2626
[Blockchains.EOSIO]:"44'/194'/0'/0/0",
2727
}
2828

29+
const cache = {};
30+
2931
export default class LedgerWallet {
3032

3133
constructor(blockchain){
@@ -34,7 +36,8 @@ export default class LedgerWallet {
3436
}
3537

3638
static typeToInterface(blockchain){
37-
return new LedgerWallet(blockchain);
39+
if(!cache.hasOwnProperty(blockchain)) cache[blockchain] = new LedgerWallet(blockchain);
40+
return cache[blockchain];
3841
};
3942

4043
async init(){
@@ -54,6 +57,7 @@ export default class LedgerWallet {
5457
if(store.state.hardware.subscriber)
5558
await store.state.hardware.subscriber.unsubscribe();
5659
store.dispatch(Actions.SET_HARDWARE, null);
60+
delete cache[this.blockchain];
5761
}
5862
}
5963
store.dispatch(Actions.SET_HARDWARE, hardware);
@@ -68,9 +72,10 @@ export default class LedgerWallet {
6872
async add(device){
6973
const {path} = device;
7074

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)});
7276
store.dispatch(Actions.SET_HARDWARE, clone);
7377

78+
7479
this.api = new LedgerAPI(store.state.hardware.transport, this.blockchain);
7580
this.getPublicKey = this.api.getPublicKey;
7681
this.sign = this.api.signTransaction;
@@ -235,6 +240,7 @@ class LedgerAPI {
235240
'exclamation-triangle',
236241
'Okay'
237242
));
243+
delete cache[this.blockchain];
238244
return false;
239245
})
240246
}

0 commit comments

Comments
 (0)