Skip to content

Commit f53d5f5

Browse files
authored
Switch sendTransaction to use ledger UI (#5496)
1 parent 6a4bcc1 commit f53d5f5

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

ironfish-cli/src/ui/ledger.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,16 @@ export async function sendTransactionWithLedger(
131131
confirm: boolean,
132132
logger?: Logger,
133133
): Promise<void> {
134-
const ledger = new LedgerSingleSigner(logger)
135-
136-
try {
137-
await ledger.connect()
138-
} catch (e) {
139-
if (e instanceof Error) {
140-
Errors.error(e.message)
141-
} else {
142-
throw e
143-
}
144-
}
134+
const ledgerApp = new LedgerSingleSigner(logger)
145135

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

149-
const ledgerPublicKey = await ledger.getPublicAddress()
139+
const ledgerPublicKey = await ledger({
140+
ledger: ledgerApp,
141+
message: 'Get Public Address',
142+
action: () => ledgerApp.getPublicAddress(),
143+
})
150144

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

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

166-
const signature = (await ledger.sign(unsignedTransaction)).toString('hex')
160+
const signature = await ledger({
161+
ledger: ledgerApp,
162+
message: 'Sign Transaction',
163+
approval: true,
164+
action: () => ledgerApp.sign(unsignedTransaction),
165+
})
167166

168-
ux.stdout(`\nSignature: ${signature}`)
167+
ux.stdout(`\nSignature: ${signature.toString('hex')}`)
169168

170169
const addSignatureResponse = await client.wallet.addSignature({
171170
unsignedTransaction,
172-
signature,
171+
signature: signature.toString('hex'),
173172
})
174173

175174
const signedTransaction = addSignatureResponse.content.transaction

0 commit comments

Comments
 (0)