Skip to content

Commit

Permalink
chore: simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuditi committed Oct 26, 2023
1 parent 1b4f3c3 commit 16bd676
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions packages/shared/src/lib/core/ledger/classes/ledger.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,15 @@ export class Ledger {
() => ledgerApiBridge.makeRequest(LedgerApiMethod.SignMessage, messageHex, bip32Path),
'signed-message'
)
if (transactionSignature) {
const { r, v, s } = transactionSignature

const { r, v, s } = transactionSignature
if (r && v && s) {
const vBig = BigInt(v)
const rBuffer = Buffer.from(r, 'hex')
const sBuffer = Buffer.from(s, 'hex')
return toRpcSig(vBig, rBuffer, sBuffer)
} else {
throw new Error(localize('error.ledger.rejected'))
}
}

Expand All @@ -157,22 +160,16 @@ export class Ledger {

callback()

let receivedResponse = false
let returnValue: R | undefined = undefined

Platform.onEvent(responseEvent, (value) => {
receivedResponse = true
returnValue = <R>value
})

for (let count = 0; count < iterationCount; count++) {
if (receivedResponse) {
if (returnValue) {
Platform.removeListenersForEvent(responseEvent)
if (returnValue && Object.keys(returnValue).length !== 0) {
return returnValue
} else {
return Promise.reject('error.ledger.rejected')
}
return returnValue
}
await sleep(pollingInterval)
}
Expand Down

0 comments on commit 16bd676

Please sign in to comment.