diff --git a/index.js b/index.js index d9259a8..98a2d39 100644 --- a/index.js +++ b/index.js @@ -32,6 +32,7 @@ class LedgerBridgeKeyring extends EventEmitter { this.iframe = null this.network = 'mainnet' this.implementFullBIP44 = false + this.useLedgerLive = false this.deserialize(opts) this._setupIframe() } @@ -48,14 +49,13 @@ class LedgerBridgeKeyring extends EventEmitter { deserialize (opts = {}) { this.hdPath = opts.hdPath || hdPathString - - const bridgeUrl = new URL(opts.bridgeUrl || BRIDGE_URL); - bridgeUrl.search = new URLSearchParams({ useLedgerLive: !!opts.useLedgerLive }) - this.bridgeUrl = bridgeUrl.toString() - + this.bridgeUrl = opts.bridgeUrl || BRIDGE_URL this.accounts = opts.accounts || [] this.accountIndexes = opts.accountIndexes || {} this.implementFullBIP44 = opts.implementFullBIP44 || false + this.useLedgerLive = opts.useLedgerLive || false + + console.log("[LedgerBridgeKeyring] useLedgerLive initialized with: ", opts.useLedgerLive); if (this._isBIP44()) { // Remove accounts that don't have corresponding account indexes @@ -160,6 +160,11 @@ class LedgerBridgeKeyring extends EventEmitter { this._sendMessage({ action: 'ledger-close-bridge' }, () => this.forgetDevice()) } + updateTransportMethod(useLedgerLive = false) { + console.log("[LedgerBridgeKeyring] Sending message to iFrame to update Ledger Live preference to: ", useLedgerLive) + this._sendMessage({ action: 'ledger-update-transport', params: { useLedgerLive } }) + } + // tx is an instance of the ethereumjs-transaction class. signTransaction (address, tx) { return new Promise((resolve, reject) => { @@ -278,6 +283,7 @@ class LedgerBridgeKeyring extends EventEmitter { _setupIframe () { this.iframe = document.createElement('iframe') + this.iframe.onload = () => { this.updateTransportMethod(this.useLedgerLive) } this.iframe.src = this.bridgeUrl this.iframe.allow = 'usb' document.head.appendChild(this.iframe)