Skip to content

Commit

Permalink
Refactored consideredUtxo for forward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
amitx13 committed Aug 11, 2024
1 parent 2eb60bc commit 8c8198e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/components/Send/SendForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
isValidNumCollaborators,
} from './helpers'
import { AccountBalanceSummary } from '../../context/BalanceSummary'
import { WalletInfo, CurrentWallet, Utxos } from '../../context/WalletContext'
import { WalletInfo, CurrentWallet } from '../../context/WalletContext'
import { useSettings } from '../../context/SettingsContext'
import styles from './SendForm.module.css'
import { TxFeeInputField, validateTxFee } from '../settings/TxFeeInputField'
Expand Down Expand Up @@ -214,7 +214,7 @@ export interface SendFormValues {
txFee?: TxFee
isCoinJoin: boolean
numCollaborators?: number
consideredUtxos?: Utxos
consideredUtxos?: string[]
}

interface InnerSendFormProps {
Expand Down
22 changes: 14 additions & 8 deletions src/components/Send/SourceJarSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,28 @@ export const SourceJarSelector = ({

if (res.length !== 0) {
setIsUtxosLoading(true)
await reloadCurrentWalletInfo.reloadUtxos({ signal: abortCtrl.signal })
const allUtxosData = await reloadCurrentWalletInfo.reloadUtxos({ signal: abortCtrl.signal })
if (allUtxosData) {
const selectedUtxos = allUtxosData.utxos
.filter((utxo) => utxo.mixdepth === field.value && !utxo.frozen)
.map((utxo) => utxo.utxo)
form.setFieldValue(consideredUtxos.name, selectedUtxos, true)
}
} else {
if (walletInfo) {
const selectedUtxos = walletInfo.utxosByJar[field.value]
.filter((utxo) => !utxo.frozen)
.map((utxo) => utxo.utxo)
form.setFieldValue(consideredUtxos.name, selectedUtxos, true)
}
}

setShowUtxos(undefined)
} catch (err: any) {
if (!abortCtrl.signal.aborted) {
setAlert({ variant: 'danger', message: err.message, dismissible: true })
}
} finally {
setIsUtxosLoading(false)
if (walletInfo) {
const selectedUtxos = walletInfo.utxosByJar[field.value].filter((utxo) => {
return !utxo.frozen
})
form.setFieldValue(consideredUtxos.name, selectedUtxos, true)
}
}
}, [frozenUtxos, unFrozenUtxos, wallet, reloadCurrentWalletInfo, consideredUtxos, form, field, walletInfo])

Expand Down
14 changes: 11 additions & 3 deletions src/components/Send/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -542,9 +542,17 @@ export default function Send({ wallet }: SendProps) {
feeConfigValues: { ...feeConfigValues, tx_fees: showConfirmSendModal.txFee },
}}
>
{showConfirmSendModal.amount!.isSweep && showConfirmSendModal.consideredUtxos && (
<ReviewConsideredUtxos utxos={showConfirmSendModal.consideredUtxos} />
)}
{showConfirmSendModal.amount?.isSweep &&
showConfirmSendModal.consideredUtxos &&
walletInfo &&
showConfirmSendModal.sourceJarIndex !== undefined &&
(() => {
const selectedUtxosList = showConfirmSendModal.consideredUtxos
const utxoList = walletInfo.utxosByJar[showConfirmSendModal.sourceJarIndex].filter((utxo) =>
selectedUtxosList.some((selectedUtxos) => selectedUtxos === utxo.utxo),
)
return <ReviewConsideredUtxos utxos={utxoList} />
})()}
</PaymentConfirmModal>
)}
</div>
Expand Down

0 comments on commit 8c8198e

Please sign in to comment.