Skip to content

Commit

Permalink
Switch sendTransaction to use ledger UI (#5496)
Browse files Browse the repository at this point in the history
  • Loading branch information
NullSoldier authored Oct 7, 2024
1 parent 6a4bcc1 commit f53d5f5
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions ironfish-cli/src/ui/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,16 @@ export async function sendTransactionWithLedger(
confirm: boolean,
logger?: Logger,
): Promise<void> {
const ledger = new LedgerSingleSigner(logger)

try {
await ledger.connect()
} catch (e) {
if (e instanceof Error) {
Errors.error(e.message)
} else {
throw e
}
}
const ledgerApp = new LedgerSingleSigner(logger)

const publicKey = (await client.wallet.getAccountPublicKey({ account: from })).content
.publicKey

const ledgerPublicKey = await ledger.getPublicAddress()
const ledgerPublicKey = await ledger({
ledger: ledgerApp,
message: 'Get Public Address',
action: () => ledgerApp.getPublicAddress(),
})

if (publicKey !== ledgerPublicKey) {
Errors.error(
Expand All @@ -163,13 +157,18 @@ export async function sendTransactionWithLedger(

ux.stdout('Please confirm the transaction on your Ledger device')

const signature = (await ledger.sign(unsignedTransaction)).toString('hex')
const signature = await ledger({
ledger: ledgerApp,
message: 'Sign Transaction',
approval: true,
action: () => ledgerApp.sign(unsignedTransaction),
})

ux.stdout(`\nSignature: ${signature}`)
ux.stdout(`\nSignature: ${signature.toString('hex')}`)

const addSignatureResponse = await client.wallet.addSignature({
unsignedTransaction,
signature,
signature: signature.toString('hex'),
})

const signedTransaction = addSignatureResponse.content.transaction
Expand Down

0 comments on commit f53d5f5

Please sign in to comment.