Skip to content

Commit

Permalink
Provide method for updating useLedgerLive setting
Browse files Browse the repository at this point in the history
  • Loading branch information
darkwing committed Feb 17, 2021
1 parent d70554f commit 6d7b974
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6d7b974

Please sign in to comment.