@@ -73,6 +73,8 @@ export default function SendForm() {
7373 amountIsAboveMaxLimit,
7474 amountIsBelowMinLimit,
7575 lnSwapsAllowed,
76+ minSwapAllowed,
77+ maxSwapAllowed,
7678 utxoTxsAllowed,
7779 validArkToBtc,
7880 validLnSwap,
@@ -260,6 +262,17 @@ export default function SendForm() {
260262 }
261263 const satoshis = getInvoiceSatoshis ( lowerCaseData )
262264 if ( ! satoshis ) return setError ( 'Invoice must have amount defined' )
265+ // Check swap limits proactively
266+ if ( ! lnSwapsAllowed ( ) ) {
267+ setError ( 'Lightning sends are currently unavailable' )
268+ } else if ( satoshis < minSwapAllowed ( ) ) {
269+ setError ( `Minimum Lightning send is ${ minSwapAllowed ( ) } sats` )
270+ } else {
271+ const maxSwap = maxSwapAllowed ( )
272+ if ( maxSwap > 0 && satoshis > maxSwap ) {
273+ setError ( `Maximum Lightning send is ${ maxSwap } sats` )
274+ }
275+ }
263276 setState ( { ...base , invoice : lowerCaseData , satoshis } )
264277 setAmountIsReadOnly ( true )
265278 setAmount ( satoshis )
@@ -432,6 +445,22 @@ export default function SendForm() {
432445 }
433446 const satoshis = sendInfo . satoshis ?? 0
434447 const isLightningSend = Boolean ( sendInfo . invoice )
448+
449+ // Set error for Lightning limit violations
450+ if ( isLightningSend && satoshis > 0 ) {
451+ if ( ! lnSwapsAllowed ( ) ) {
452+ setError ( 'Lightning sends are currently unavailable' )
453+ } else {
454+ const minSwap = minSwapAllowed ( )
455+ const maxSwap = maxSwapAllowed ( )
456+ if ( minSwap > 0 && satoshis < minSwap ) {
457+ setError ( `Minimum Lightning send is ${ minSwap } sats` )
458+ } else if ( maxSwap > 0 && satoshis > maxSwap ) {
459+ setError ( `Maximum Lightning send is ${ maxSwap } sats` )
460+ }
461+ }
462+ }
463+
435464 setLabel (
436465 satoshis > liquidBalance
437466 ? 'Insufficient funds'
@@ -441,15 +470,11 @@ export default function SendForm() {
441470 ? 'Amount above LNURL max limit'
442471 : satoshis && satoshis < 1
443472 ? 'Amount below 1 satoshi'
444- : isLightningSend && ! lnSwapsAllowed ( )
445- ? 'Lightning swaps not enabled'
446- : isLightningSend && ! validLnSwap ( satoshis )
447- ? 'Amount outside Lightning swap limits'
448- : amountIsAboveMaxLimit ( satoshis )
449- ? 'Amount above max limit'
450- : satoshis && amountIsBelowMinLimit ( satoshis )
451- ? 'Amount below min limit'
452- : 'Continue' ,
473+ : amountIsAboveMaxLimit ( satoshis )
474+ ? 'Amount above max limit'
475+ : satoshis && amountIsBelowMinLimit ( satoshis )
476+ ? 'Amount below min limit'
477+ : 'Continue' ,
453478 )
454479 } , [ sendInfo . satoshis , sendInfo . assets , sendInfo . invoice , liquidBalance , selectedAsset ] )
455480
@@ -470,8 +495,11 @@ export default function SendForm() {
470495 if ( ! sendInfo . address && ! sendInfo . arkAddress && ! sendInfo . invoice ) return
471496 if ( sendInfo . arkAddress || sendInfo . pendingSwap ) return navigate ( Pages . SendDetails )
472497 if ( sendInfo . invoice ) {
473- if ( ! lnSwapsAllowed ( ) ) return handleError ( 'Lightning swaps not enabled' )
474- if ( ! validLnSwap ( sendInfo . satoshis ?? 0 ) ) return handleError ( 'Amount outside Lightning swap limits' )
498+ if ( ! lnSwapsAllowed ( ) ) return handleError ( 'Lightning sends are currently unavailable' )
499+ const invoiceSats = sendInfo . satoshis ?? 0
500+ if ( invoiceSats < minSwapAllowed ( ) ) return handleError ( `Minimum Lightning send is ${ minSwapAllowed ( ) } sats` )
501+ const maxSwap = maxSwapAllowed ( )
502+ if ( maxSwap > 0 && invoiceSats > maxSwap ) return handleError ( `Maximum Lightning send is ${ maxSwap } sats` )
475503 createSubmarineSwap ( sendInfo . invoice )
476504 . then ( ( pendingSwap ) => {
477505 if ( ! pendingSwap ) return handleError ( 'Unable to create swap' )
@@ -595,17 +623,21 @@ export default function SendForm() {
595623 setState ( { ...sendInfo , arkAddress : arkResponse . address , invoice : undefined } )
596624 } else {
597625 // Fallback to Lightning invoice
598- if ( ! lnSwapsAllowed ( ) ) return handleError ( 'Lightning swaps not enabled' )
599- if ( ! validLnSwap ( satoshis ) ) return handleError ( 'Amount outside Lightning swap limits' )
626+ if ( ! lnSwapsAllowed ( ) ) return handleError ( 'Lightning sends are currently unavailable' )
627+ if ( satoshis < minSwapAllowed ( ) ) return handleError ( `Minimum Lightning send is ${ minSwapAllowed ( ) } sats` )
628+ const maxSwap = maxSwapAllowed ( )
629+ if ( maxSwap > 0 && satoshis > maxSwap ) return handleError ( `Maximum Lightning send is ${ maxSwap } sats` )
600630 const amountForInvoice = deductFromAmount ? satoshis - calcSubmarineSwapFee ( satoshis ) : satoshis
601631 if ( amountForInvoice < 1 ) return handleError ( 'Amount too low to cover fees' )
602632 const invoice = await fetchInvoice ( sendInfo . lnUrl , amountForInvoice , '' )
603633 setState ( { ...sendInfo , invoice, arkAddress : undefined } )
604634 }
605635 } else {
606636 if ( sendInfo . invoice ) {
607- if ( ! lnSwapsAllowed ( ) ) return handleError ( 'Lightning swaps not enabled' )
608- if ( ! validLnSwap ( satoshis ) ) return handleError ( 'Amount outside Lightning swap limits' )
637+ if ( ! lnSwapsAllowed ( ) ) return handleError ( 'Lightning sends are currently unavailable' )
638+ if ( satoshis < minSwapAllowed ( ) ) return handleError ( `Minimum Lightning send is ${ minSwapAllowed ( ) } sats` )
639+ const maxSwap = maxSwapAllowed ( )
640+ if ( maxSwap > 0 && satoshis > maxSwap ) return handleError ( `Maximum Lightning send is ${ maxSwap } sats` )
609641 }
610642 setState ( { ...sendInfo , satoshis } )
611643 }
0 commit comments