Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions src/app/common/utils/psbt.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Psbt, Transaction } from "bitcoinjs-lib";
import { Psbt, Transaction } from 'bitcoinjs-lib'

import { WalletProvider } from "../../../utils/wallet/wallet_provider";

const SIGN_PSBT_NOT_COMPATIBLE_WALLETS = ["OneKey", "DYNAMIC"];
import { WalletProvider } from '../../../utils/wallet/wallet_provider'

export type SignPsbtTransaction = (psbtHex: string) => Promise<Transaction>;

Expand All @@ -11,19 +9,25 @@ export type SignPsbtTransaction = (psbtHex: string) => Promise<Transaction>;
// the signed transaction in hex
export const signPsbtTransaction = (wallet: WalletProvider) => {
return async (psbtHex: string) => {
const signedHex = await wallet.signPsbt(psbtHex);
const providerName = await wallet.getWalletProviderName();
if (SIGN_PSBT_NOT_COMPATIBLE_WALLETS.includes(providerName)) {
try {
// Try to parse the signedHex as PSBT to see if it follows the new implementation
return Psbt.fromHex(signedHex).extractTransaction();
} catch {
// If parsing fails, it's the old version implementation
return Transaction.fromHex(signedHex);
}

let signedHex: string

// @ts-ignore
if (('connector' in wallet) && (wallet.connector?.name == 'OneKey')) {
const provider = window['$onekey'].btcwallet
signedHex = await provider.signPsbt(psbtHex)
} else {
signedHex = await wallet.signPsbt(psbtHex)
}

// For compatible wallets, directly extract the transaction from the signed PSBT
return Psbt.fromHex(signedHex).extractTransaction();
};
};
try {
// Try to parse the signedHex as PSBT to see if it follows the new implementation
return Psbt.fromHex(signedHex).extractTransaction()
} catch (error) {
console.log('failed to sign:', error)

// If parsing fails, it's the old version implementation
return Transaction.fromHex(signedHex)
}
}
}
6 changes: 4 additions & 2 deletions src/utils/delegations/signWithdrawalTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,12 @@ export const signWithdrawalTx = async (
withdrawPsbtTxResult.fee,
);

emitBroadcastEvent();
// TODO: uncomment back
// emitBroadcastEvent();

// Broadcast withdrawal transaction
await pushTx(withdrawalTxHex);
// await pushTx(withdrawalTxHex);

Comment thread
DaBors marked this conversation as resolved.

return { withdrawalTxHex, delegation };
};