diff --git a/src/app/common/transactions/bitcoin/fees/calculate-max-bitcoin-spend.ts b/src/app/common/transactions/bitcoin/fees/calculate-max-bitcoin-spend.ts index 1f806b4f623..2dc025d02c9 100644 --- a/src/app/common/transactions/bitcoin/fees/calculate-max-bitcoin-spend.ts +++ b/src/app/common/transactions/bitcoin/fees/calculate-max-bitcoin-spend.ts @@ -38,6 +38,7 @@ export function calculateMaxBitcoinSpend({ utxos: filteredUtxos, feeRate: currentFeeRate, recipients: [{ address, amount: createMoney(0, 'BTC') }], + isSendMax: true, }); return { diff --git a/src/app/common/transactions/bitcoin/utils.ts b/src/app/common/transactions/bitcoin/utils.ts index b77344f4061..89cee5e6b89 100644 --- a/src/app/common/transactions/bitcoin/utils.ts +++ b/src/app/common/transactions/bitcoin/utils.ts @@ -123,20 +123,25 @@ export function getBitcoinTxValue(address: string, transaction?: BitcoinTx) { return ''; } +interface GetSpendableAmountArgs { + utxos: UtxoResponseItem[]; + feeRate: number; + recipients: TransferRecipient[]; + isSendMax?: boolean; +} + export function getSpendableAmount({ utxos, feeRate, recipients, -}: { - utxos: UtxoResponseItem[]; - feeRate: number; - recipients: TransferRecipient[]; -}) { + isSendMax, +}: GetSpendableAmountArgs) { const balance = utxos.map(utxo => utxo.value).reduce((prevVal, curVal) => prevVal + curVal, 0); const size = getSizeInfo({ inputLength: utxos.length, recipients, + isSendMax, }); const fee = Math.ceil(size.txVBytes * feeRate); const bigNumberBalance = BigNumber(balance); @@ -169,6 +174,11 @@ export function getSizeInfo(payload: { const outputTypesCount = getTxOutputsLengthByPaymentType(); + // If no outputs, e.g. when recipient is not provided, set default output to p2wpkh + if (Object.values(outputTypesCount).length === 0) { + outputTypesCount[AddressType.p2wpkh] = 1; + } + // Add a change address if not sending max (defaults to p2wpkh) if (!isSendMax) { outputTypesCount[AddressType.p2wpkh] = (outputTypesCount[AddressType.p2wpkh] || 0) + 1; diff --git a/src/app/pages/send/send-crypto-asset-form/components/recipient-accounts-dialog/account-list-item.tsx b/src/app/pages/send/send-crypto-asset-form/components/recipient-accounts-dialog/account-list-item.tsx index ea910bf3fe6..aeb31c79e8d 100644 --- a/src/app/pages/send/send-crypto-asset-form/components/recipient-accounts-dialog/account-list-item.tsx +++ b/src/app/pages/send/send-crypto-asset-form/components/recipient-accounts-dialog/account-list-item.tsx @@ -19,7 +19,7 @@ interface AccountListItemProps { onClose(): void; } export const AccountListItem = memo(({ index, stacksAccount, onClose }: AccountListItemProps) => { - const { setFieldValue, values, setFieldTouched } = useFormikContext< + const { setFieldValue, values } = useFormikContext< BitcoinSendFormValues | StacksSendFormValues >(); const stacksAddress = stacksAccount?.address || ''; @@ -30,7 +30,6 @@ export const AccountListItem = memo(({ index, stacksAccount, onClose }: AccountL const onSelectAccount = () => { const isBitcoin = values.symbol === 'BTC'; void setFieldValue('recipient', isBitcoin ? bitcoinAddress : stacksAddress, false); - void setFieldTouched('recipient', false); onClose(); };