Skip to content

Commit

Permalink
fix(send): show warning on missing fee config values
Browse files Browse the repository at this point in the history
  • Loading branch information
theborakompanioni committed Oct 10, 2023
1 parent 11ee5b4 commit b42de4c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
34 changes: 22 additions & 12 deletions src/components/Send/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,13 @@ export default function Send({ wallet }: SendProps) {
const [paymentSuccessfulInfoAlert, setPaymentSuccessfulInfoAlert] = useState<SimpleAlert>()

const isOperationDisabled = useMemo(
() => isCoinjoinInProgress || isMakerRunning || isRescanningInProgress || waitForUtxosToBeSpent.length > 0,
[isCoinjoinInProgress, isMakerRunning, isRescanningInProgress, waitForUtxosToBeSpent],
() =>
!feeConfigValues ||
isCoinjoinInProgress ||
isMakerRunning ||
isRescanningInProgress ||
waitForUtxosToBeSpent.length > 0,
[feeConfigValues, isCoinjoinInProgress, isMakerRunning, isRescanningInProgress, waitForUtxosToBeSpent],
)
const [isInitializing, setIsInitializing] = useState(!isOperationDisabled)
const isLoading = useMemo(
Expand Down Expand Up @@ -255,7 +260,7 @@ export default function Send({ wallet }: SendProps) {
setAlert(undefined)
setIsInitializing(true)

// reloading service info is important, is it must be known as soon as possible
// reloading service info is important, as it must be known as soon as possible
// if the operation is even allowed, i.e. if no other service is running
const loadingServiceInfo = reloadServiceInfo({ signal: abortCtrl.signal }).catch((err) => {
if (abortCtrl.signal.aborted) return
Expand Down Expand Up @@ -315,18 +320,17 @@ export default function Send({ wallet }: SendProps) {
[walletInfo, destination],
)

const sendPayment = async (
sourceJarIndex: JarIndex,
destination: Api.BitcoinAddress,
amount_sats: Api.AmountSats,
) => {
const sendPayment = async (sourceJarIndex: JarIndex, destination: Api.BitcoinAddress, amountSats: Api.AmountSats) => {
setAlert(undefined)
setPaymentSuccessfulInfoAlert(undefined)
setIsSending(true)

let success = false
try {
const res = await Api.postDirectSend({ ...wallet }, { mixdepth: sourceJarIndex, destination, amount_sats })
const res = await Api.postDirectSend(
{ ...wallet },
{ mixdepth: sourceJarIndex, amount_sats: amountSats, destination },
)

if (res.ok) {
// TODO: add type for json response
Expand Down Expand Up @@ -366,7 +370,7 @@ export default function Send({ wallet }: SendProps) {
const startCoinjoin = async (
sourceJarIndex: JarIndex,
destination: Api.BitcoinAddress,
amount_sats: Api.AmountSats,
amountSats: Api.AmountSats,
counterparties: number,
) => {
setAlert(undefined)
Expand All @@ -378,8 +382,8 @@ export default function Send({ wallet }: SendProps) {
{ ...wallet },
{
mixdepth: sourceJarIndex,
amount_sats: amountSats,
destination,
amount_sats,
counterparties,
},
)
Expand Down Expand Up @@ -433,6 +437,7 @@ export default function Send({ wallet }: SendProps) {

const abortCtrl = new AbortController()
return Api.getTakerStop({ ...wallet, signal: abortCtrl.signal }).catch((err) => {
if (abortCtrl.signal.aborted) return
setAlert({ variant: 'danger', message: err.message })
})
}
Expand Down Expand Up @@ -621,6 +626,11 @@ export default function Send({ wallet }: SendProps) {
)}
</>
</rb.Fade>
{!isLoading && !feeConfigValues && (
<rb.Alert className="slashed-zeroes" variant="danger">
{t('send.taker_error_message_max_fees_config_missing')}
</rb.Alert>
)}
{alert && (
<rb.Alert className="slashed-zeroes" variant={alert.variant}>
{alert.message}
Expand Down Expand Up @@ -832,7 +842,7 @@ export default function Send({ wallet }: SendProps) {
</rb.Form.Control.Feedback>
{isSweep && <>{frozenOrLockedWarning}</>}
</rb.Form.Group>
<Accordion title={t('send.sending_options')}>
<Accordion title={t('send.sending_options')} disabled={isOperationDisabled}>
<rb.Form.Group controlId="isCoinjoin" className="mb-3">
<ToggleSwitch
label={t('send.toggle_coinjoin')}
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/Fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export const useFeeConfigValues = (): [FeeValues | undefined, () => void] => {
loadFeeConfigValues(abortCtrl.signal)
.then((val) => setValues(val))
.catch((e) => {
if (abortCtrl.signal.aborted) return

console.log('Unable lo load fee config: ', e)
setValues(undefined)
})
Expand Down

0 comments on commit b42de4c

Please sign in to comment.