@@ -729,9 +729,11 @@ class AppViewModel @Inject constructor(
729729 if (invoice.amountSatoshis > 0uL ) {
730730 val maxSendLightning = walletRepo.balanceState.value.maxSendLightningSats
731731 if (maxSendLightning == 0uL || ! lightningRepo.canSend(invoice.amountSatoshis)) {
732+ val shortfall = invoice.amountSatoshis - maxSendLightning
732733 showAddressValidationError(
733734 titleRes = R .string.other__pay_insufficient_spending,
734- descriptionRes = R .string.other__pay_insufficient_spending_description,
735+ descriptionRes = R .string.other__pay_insufficient_spending_amount_description,
736+ descriptionArgs = mapOf (" amount" to shortfall.toString()),
735737 )
736738 return
737739 }
@@ -762,9 +764,11 @@ class AppViewModel @Inject constructor(
762764 }
763765
764766 if (invoice.amountSatoshis > 0uL && invoice.amountSatoshis > maxSendOnchain) {
767+ val shortfall = invoice.amountSatoshis - maxSendOnchain
765768 showAddressValidationError(
766769 titleRes = R .string.other__pay_insufficient_savings,
767- descriptionRes = R .string.other__pay_insufficient_savings_description,
770+ descriptionRes = R .string.other__pay_insufficient_savings_amount_description,
771+ descriptionArgs = mapOf (" amount" to shortfall.toString()),
768772 )
769773 return
770774 }
@@ -775,12 +779,17 @@ class AppViewModel @Inject constructor(
775779 private fun showAddressValidationError (
776780 @StringRes titleRes : Int ,
777781 @StringRes descriptionRes : Int ,
782+ descriptionArgs : Map <String , String > = emptyMap(),
778783 ) {
779784 _sendUiState .update { it.copy(isAddressInputValid = false ) }
785+ var description = context.getString(descriptionRes)
786+ descriptionArgs.forEach { (key, value) ->
787+ description = description.replace(" {$key }" , value)
788+ }
780789 toast(
781790 type = Toast .ToastType .ERROR ,
782791 title = context.getString(titleRes),
783- description = context.getString(descriptionRes) ,
792+ description = description ,
784793 )
785794 }
786795
@@ -982,7 +991,7 @@ class AppViewModel @Inject constructor(
982991 }
983992 }
984993
985- @Suppress(" LongMethod" )
994+ @Suppress(" LongMethod" , " CyclomaticComplexMethod " )
986995 private suspend fun onScanOnchain (invoice : OnChainInvoice , scanResult : String ) {
987996 // Check network mismatch
988997 val addressNetwork = NetworkValidationHelper .getAddressNetwork(invoice.address)
@@ -1047,6 +1056,17 @@ class AppViewModel @Inject constructor(
10471056 return
10481057 }
10491058
1059+ // Check on-chain balance before proceeding to amount screen
1060+ val maxSendOnchain = walletRepo.balanceState.value.maxSendOnchainSats
1061+ if (maxSendOnchain == 0uL ) {
1062+ toast(
1063+ type = Toast .ToastType .ERROR ,
1064+ title = context.getString(R .string.other__pay_insufficient_savings),
1065+ description = context.getString(R .string.other__pay_insufficient_savings_description),
1066+ )
1067+ return
1068+ }
1069+
10501070 Logger .info(
10511071 when (invoice.amountSatoshis > 0u ) {
10521072 true -> " Found amount in invoice, proceeding to edit amount"
@@ -1076,10 +1096,13 @@ class AppViewModel @Inject constructor(
10761096 if (quickPayHandled) return
10771097
10781098 if (! lightningRepo.canSend(invoice.amountSatoshis)) {
1099+ val maxSendLightning = walletRepo.balanceState.value.maxSendLightningSats
1100+ val shortfall = invoice.amountSatoshis - maxSendLightning
10791101 toast(
10801102 type = Toast .ToastType .ERROR ,
1081- title = context.getString(R .string.wallet__error_insufficient_funds_title),
1082- description = context.getString(R .string.wallet__error_insufficient_funds_msg)
1103+ title = context.getString(R .string.other__pay_insufficient_spending),
1104+ description = context.getString(R .string.other__pay_insufficient_spending_amount_description)
1105+ .replace(" {amount}" , shortfall.toString()),
10831106 )
10841107 return
10851108 }
0 commit comments