diff --git a/src/components/fb/SpendFidelityBondModal.tsx b/src/components/fb/SpendFidelityBondModal.tsx index b3ad30ad..6194939a 100644 --- a/src/components/fb/SpendFidelityBondModal.tsx +++ b/src/components/fb/SpendFidelityBondModal.tsx @@ -67,10 +67,15 @@ const spendUtxosWithDirectSend = async ( request: UtxoDirectSendRequest, hooks: UtxoDirectSendHook, ) => { + if (request.utxos.length === 0) { + // this is a programming error (no translation needed) + throw new Error('Precondition failed: No UTXO(s) provided.') + } + const utxosFromSameJar = request.utxos.every((it) => it.mixdepth === request.sourceJarIndex) - if (!utxosFromSameJar || request.utxos.length === 0) { + if (!utxosFromSameJar) { // this is a programming error (no translation needed) - throw new Error('Precondition failed: UTXOs must be from the same jar') + throw new Error('Precondition failed: UTXOs must be from the same jar.') } const spendableUtxoIds = request.utxos.map((it) => it.utxo) @@ -84,6 +89,10 @@ const spendUtxosWithDirectSend = async ( const utxosToSpend = utxosFromSourceJar.filter((it) => spendableUtxoIds.includes(it.utxo)) + if (spendableUtxoIds.length !== utxosToSpend.length) { + throw new Error('Precondition failed: Specified UTXO(s) cannot be used for this payment.') + } + const utxosToFreeze = utxosFromSourceJar .filter((it) => !it.frozen) .filter((it) => !spendableUtxoIds.includes(it.utxo)) @@ -236,10 +245,12 @@ const RenewFidelityBondModal = ({ const [lockDate, setLockDate] = useState() const [timelockedAddress, setTimelockedAddress] = useState() + const [isLoadingTimelockedAddress, setIsLoadingTimelockAddress] = useState(false) + const [timelockedAddressAlert, setTimelockedAddressAlert] = useState() const [parentMustReload, setParentMustReload] = useState(false) const [isSending, setIsSending] = useState(false) - const [isLoadingTimelockedAddress, setIsLoadingTimelockAddress] = useState(false) + const isLoading = useMemo(() => isSending || waitForUtxosToBeSpent.length > 0, [isSending, waitForUtxosToBeSpent]) const [showConfirmSendModal, setShowConfirmSendModal] = useState(false) @@ -292,7 +303,7 @@ const RenewFidelityBondModal = ({ const abortCtrl = new AbortController() setIsLoadingTimelockAddress(true) - setAlert(undefined) + setTimelockedAddressAlert(undefined) const timer = setTimeout( () => @@ -304,8 +315,9 @@ const RenewFidelityBondModal = ({ }) .catch((err) => { if (abortCtrl.signal.aborted) return - setAlert({ variant: 'danger', message: err.message }) setIsLoadingTimelockAddress(false) + setTimelockedAddress(undefined) + setTimelockedAddressAlert({ variant: 'danger', message: err.message }) }), 250, ) @@ -364,28 +376,36 @@ const RenewFidelityBondModal = ({ onChange={onSelectedDateChanged} /> - <> -
-
- } - successText={} - value={timelockedAddress || ''} +
+
+ {timelockedAddressAlert ? ( + setTimelockedAddressAlert(undefined)} /> -
-
{t('earn.fidelity_bond.review_inputs.label_address')}
- {!isLoading && !isLoadingTimelockedAddress ? ( -
{timelockedAddress}
- ) : ( - - - - )} -
-
+ ) : ( + <> + } + successText={} + value={timelockedAddress || ''} + /> +
+
{t('earn.fidelity_bond.review_inputs.label_address')}
+ {!isLoading && !isLoadingTimelockedAddress ? ( +
{timelockedAddress || '...'}
+ ) : ( + + + + )} +
+ + )}
- +
) }, [ @@ -394,6 +414,7 @@ const RenewFidelityBondModal = ({ yearsRange, timelockedAddress, isLoadingTimelockedAddress, + timelockedAddressAlert, txInfo, onSelectedDateChanged, t,