@@ -13,42 +13,65 @@ ElDialog {
1313 title: qsTr (' LNURL Withdraw request' )
1414 iconSource: ' ../../../icons/link.png'
1515
16- property Wallet wallet: Daemon .currentWallet
1716 property RequestDetails requestDetails
1817 property Amount onemsat: Amount { Component .onCompleted : { msatsInt = 1 } }
1918
2019 padding: 0
2120 needsSystemBarPadding: false
2221
23- property var walletCanReceive: Amount {}
22+ property var walletCanReceive: Amount {
23+ onValueChanged: console .log (' wallet can receive ' + msatsStr)
24+ }
2425 property var providerMinWithdrawable: requestDetails .lnurlData [' min_withdrawable_msat' ]
2526 property var providerMaxWithdrawable: requestDetails .lnurlData [' max_withdrawable_msat' ]
2627 property var effectiveMinWithdrawable: onemsat .max (providerMinWithdrawable, onemsat)
27- property var effectiveMaxWithdrawable: onemsat .min (providerMaxWithdrawable, walletCanReceive )
28- property bool insufficientLiquidity: effectiveMinWithdrawable .gt (walletCanReceive )
28+ property var effectiveMaxWithdrawable: onemsat .min (providerMaxWithdrawable, requestDetails . wallet . lightningCanReceive )
29+ property bool insufficientLiquidity: effectiveMinWithdrawable .gt (requestDetails . wallet . lightningCanReceive )
2930 property bool liquidityWarning: providerMaxWithdrawable .gt (walletCanReceive)
31+ property bool fixedAmount: false
3032
31- property bool amountValid: ! dialog .insufficientLiquidity &&
32- amountBtc .textAsSats .gte (dialog .effectiveMinWithdrawable ) &&
33- amountBtc .textAsSats .lte (dialog .effectiveMaxWithdrawable )
33+ property bool amountValid: isValidAmount ()
3434 property bool valid: amountValid
3535
3636 Component .onCompleted : {
37- dialog .walletCanReceive .copyFrom (wallet .lightningCanReceive )
37+ updateLimits ()
38+ }
39+
40+ function isValidAmount () {
41+ return ! dialog .insufficientLiquidity
42+ && amountBtc .textAsSats .gte (dialog .effectiveMinWithdrawable )
43+ && amountBtc .textAsSats .lte (dialog .effectiveMaxWithdrawable )
44+ }
45+
46+ function updateLimits () {
47+ dialog .walletCanReceive .copyFrom (requestDetails .wallet .lightningCanReceive )
48+ dialog .effectiveMaxWithdrawable = onemsat .min (dialog .providerMaxWithdrawable , requestDetails .wallet .lightningCanReceive )
49+ dialog .insufficientLiquidity = dialog .effectiveMinWithdrawable .gt (requestDetails .wallet .lightningCanReceive )
50+ dialog .liquidityWarning = dialog .providerMaxWithdrawable .gt (requestDetails .wallet .lightningCanReceive )
51+ dialog .fixedAmount = dialog .providerMinWithdrawable .eq (dialog .providerMaxWithdrawable )
52+ dialog .amountValid = isValidAmount ()
3853 }
3954
4055 Connections {
4156 // assign walletCanReceive directly to prevent a binding loop
42- target: wallet
57+ target: requestDetails . wallet
4358 function onLightningCanReceiveChanged () {
4459 if (! requestDetails .busy ) {
4560 // don't assign while busy to prevent the view from changing while receiving
4661 // the incoming payment
47- dialog .walletCanReceive .copyFrom (wallet .lightningCanReceive )
62+ console .log (' UPDATING' )
63+ updateLimits ()
4864 }
4965 }
5066 }
5167
68+ Connections {
69+ target: amountBtc
70+ function onValueChanged () {
71+ dialog .amountValid = isValidAmount ()
72+ }
73+ }
74+
5275 ColumnLayout {
5376 width: parent .width
5477
@@ -82,7 +105,7 @@ ElDialog {
82105 Layout .columnSpan : 2
83106 Layout .fillWidth : true
84107 compact: true
85- visible: ! dialog .insufficientLiquidity && dialog . providerMinWithdrawable != dialog .providerMaxWithdrawable
108+ visible: ! dialog .insufficientLiquidity && ! dialog .fixedAmount
86109 text: qsTr (' Amount must be between %1 and %2 %3' )
87110 .arg (Config .formatMilliSats (dialog .effectiveMinWithdrawable ))
88111 .arg (Config .formatMilliSats (dialog .effectiveMaxWithdrawable ))
@@ -133,7 +156,7 @@ ElDialog {
133156 id: amountBtc
134157 Layout .preferredWidth : rootLayout .width / 3
135158 text: Config .formatMilliSatsForEditing (dialog .effectiveMaxWithdrawable )
136- enabled: ! dialog .insufficientLiquidity && ! ( dialog .providerMinWithdrawable . eq ( dialog . providerMaxWithdrawable ))
159+ enabled: ! dialog .insufficientLiquidity && ! dialog .fixedAmount
137160 color: Material .foreground // override gray-out on disabled
138161 fiatfield: amountFiat
139162 msatPrecision: true
@@ -152,7 +175,7 @@ ElDialog {
152175 id: amountFiat
153176 Layout .preferredWidth : rootLayout .width / 3
154177 btcfield: amountBtc
155- enabled: ! dialog .insufficientLiquidity && ! ( dialog .providerMinWithdrawable . eq ( dialog . providerMaxWithdrawable ))
178+ enabled: ! dialog .insufficientLiquidity && ! dialog .fixedAmount
156179 color: Material .foreground
157180 }
158181 Label {
0 commit comments