Skip to content

Commit

Permalink
fix: show correct amount for nonWitnessUtxo, ref #5113
Browse files Browse the repository at this point in the history
  • Loading branch information
pete-watters committed May 9, 2024
1 parent 5d9895f commit d239e56
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import * as btc from '@scure/btc-signer';

import { getPsbtTxInputs, getPsbtTxOutputs } from '@shared/crypto/bitcoin/bitcoin.utils';
import {
getBitcoinInputValue,
getPsbtTxInputs,
getPsbtTxOutputs,
} from '@shared/crypto/bitcoin/bitcoin.utils';
import { isDefined } from '@shared/utils';

import { useLedgerTxSigningContext } from '@app/features/ledger/generic-flows/tx-signing/ledger-sign-tx.context';
import { ApproveLedgerOperationLayout } from '@app/features/ledger/generic-steps/approve-ledger-operation/approve-ledger-operation.layout';
Expand All @@ -20,7 +25,7 @@ export function ApproveSignLedgerBitcoinTx() {
[
...getPsbtTxInputs(context.transaction as unknown as btc.Transaction).map((input, i) => [
`Input ${i + 1}`,
input.witnessUtxo?.amount?.toString() + ' sats',
getBitcoinInputValue(isDefined(input.index) ? input.index : 0, input) + ' sats',
]),
...getPsbtTxOutputs(context.transaction as unknown as btc.Transaction).map(
(output, i) => [`Output ${i + 1}`, output.amount?.toString() + ' sats']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
getNativeSegwitAccountDerivationPath,
} from '@shared/crypto/bitcoin/p2wpkh-address-gen';
import { BitcoinInputSigningConfig } from '@shared/crypto/bitcoin/signer-config';
import { reverseBytes } from '@shared/utils';
import { isDefined, reverseBytes } from '@shared/utils';

import { mnemonicToRootNode } from '@app/common/keychain/keychain';
import { useBitcoinClient } from '@app/store/common/api-clients.hooks';
Expand Down Expand Up @@ -148,9 +148,12 @@ export function useUpdateLedgerSpecificNativeSegwitUtxoHexForAdddressIndexZero()
)
);
inputSigningConfig.forEach(({ index }) => {
tx.updateInput(index, {
nonWitnessUtxo: Buffer.from(inputsTxHex[index], 'hex'),
});
// don't update nonWitnessUtxo if it already exists
if (!tx.data.inputs.map(input => isDefined(input.nonWitnessUtxo))) {
tx.updateInput(index, {
nonWitnessUtxo: Buffer.from(inputsTxHex[index], 'hex'),
});
}
});
};
}
Expand Down

0 comments on commit d239e56

Please sign in to comment.