Skip to content

Commit

Permalink
Fix ledger parse transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
serg-plusplus committed Aug 23, 2022
1 parent 11481ef commit ee46117
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
9 changes: 5 additions & 4 deletions src/app/components/screens/approvals/Transaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
FeeSuggestions,
AccountSource,
TxAction,
TxSignature,
} from "core/types";
import {
approveItem,
Expand Down Expand Up @@ -367,7 +368,7 @@ const ApproveTransaction: FC<ApproveTransactionProps> = ({ 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 }) => {
Expand All @@ -393,14 +394,14 @@ const ApproveTransaction: FC<ApproveTransactionProps> = ({ 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 ??
Expand Down
15 changes: 7 additions & 8 deletions src/core/back/approve/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function processApprove(
{
approved,
rawTx,
signedRawTx,
signature,
signedMessage,
accountAddresses,
overriddenChainId,
Expand Down Expand Up @@ -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"
Expand Down
8 changes: 7 additions & 1 deletion src/core/types/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export type ActivitySource =
export interface ApprovalResult {
approved: boolean;
rawTx?: string;
signedRawTx?: string;
signature?: TxSignature;
signedMessage?: string;
accountAddresses?: string[];
overriddenChainId?: number;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ee46117

Please sign in to comment.