From ee4611733c56012c5d1c5d0ca3b891066aebbbfa Mon Sep 17 00:00:00 2001 From: pas1ko Date: Tue, 23 Aug 2022 22:06:31 +0100 Subject: [PATCH] Fix ledger parse transaction --- .../components/screens/approvals/Transaction.tsx | 9 +++++---- src/core/back/approve/index.ts | 15 +++++++-------- src/core/types/activity.ts | 8 +++++++- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/app/components/screens/approvals/Transaction.tsx b/src/app/components/screens/approvals/Transaction.tsx index 8e72a7e00..30683b383 100644 --- a/src/app/components/screens/approvals/Transaction.tsx +++ b/src/app/components/screens/approvals/Transaction.tsx @@ -22,6 +22,7 @@ import { FeeSuggestions, AccountSource, TxAction, + TxSignature, } from "core/types"; import { approveItem, @@ -367,7 +368,7 @@ const ApproveTransaction: FC = ({ approval }) => { if (account.source !== AccountSource.Ledger) { await approveItem(approval.id, { approved, rawTx }); } else { - let signedRawTx: string | undefined; + let signature: TxSignature | undefined; let ledgerError: any; await withLedger(async ({ ledgerEth }) => { @@ -393,14 +394,14 @@ const ApproveTransaction: FC = ({ approval }) => { ); } - signedRawTx = serializeTransaction(finalTx, formattedSig); + signature = formattedSig; } catch (err) { ledgerError = err; } }); - if (signedRawTx) { - await approveItem(approval.id, { approved, signedRawTx }); + if (signature) { + await approveItem(approval.id, { approved, rawTx, signature }); } else { throw ( ledgerError ?? diff --git a/src/core/back/approve/index.ts b/src/core/back/approve/index.ts index 4d3d6df1b..60ec72090 100644 --- a/src/core/back/approve/index.ts +++ b/src/core/back/approve/index.ts @@ -36,7 +36,7 @@ export async function processApprove( { approved, rawTx, - signedRawTx, + signature, signedMessage, accountAddresses, overriddenChainId, @@ -100,21 +100,20 @@ export async function processApprove( txParams, rpcReply, }) => { - assert(rawTx || signedRawTx, "Transaction not provided"); + assert(rawTx, "Transaction not provided"); - const tx = parseTxSafe(rawTx ?? signedRawTx!); + const tx = parseTxSafe(rawTx); validateTxOrigin(tx, txParams); - if (!signedRawTx) { + if (!signature) { accountAddress = ethers.utils.getAddress(accountAddress); const account = getAccountSafe(accountAddress); - const signature = await vault.sign(account.uuid, keccak256(rawTx!)); - signedRawTx = serializeTransaction(tx, signature); - } else { - rawTx = serializeTransaction(tx); + signature = await vault.sign(account.uuid, keccak256(rawTx!)); } + const signedRawTx = serializeTransaction(tx, signature); + if ( process.env.NODE_ENV === "development" && process.env.VIGVAM_DEV_BLOCK_TX_SEND === "true" diff --git a/src/core/types/activity.ts b/src/core/types/activity.ts index 5692f8e0d..b9044c4eb 100644 --- a/src/core/types/activity.ts +++ b/src/core/types/activity.ts @@ -41,7 +41,7 @@ export type ActivitySource = export interface ApprovalResult { approved: boolean; rawTx?: string; - signedRawTx?: string; + signature?: TxSignature; signedMessage?: string; accountAddresses?: string[]; overriddenChainId?: number; @@ -122,6 +122,12 @@ export type TxParams = { maxFeePerGas?: string; }; +export type TxSignature = { + v: number; + r: string; + s: string; +}; + export type TxReceipt = { blockHash: string; blockNumber: string;