@@ -13,8 +13,7 @@ ElDialog {
1313 title: qsTr (' LNURL Withdraw request' )
1414 iconSource: ' ../../../icons/link.png'
1515
16- property var wallet: Daemon .currentWallet // type: Wallet
17- property var requestDetails // type: RequestDetails
16+ property var requestDetails
1817 property var onemsat: Amount { Component .onCompleted : { msatsInt = 1 } }
1918
2019 padding: 0
@@ -24,31 +23,53 @@ ElDialog {
2423 property var providerMinWithdrawable: requestDetails .lnurlData [' min_withdrawable_msat' ]
2524 property var providerMaxWithdrawable: requestDetails .lnurlData [' max_withdrawable_msat' ]
2625 property var effectiveMinWithdrawable: onemsat .max (providerMinWithdrawable, onemsat)
27- property var effectiveMaxWithdrawable: onemsat .min (providerMaxWithdrawable, walletCanReceive )
28- property bool insufficientLiquidity: effectiveMinWithdrawable .gt (walletCanReceive )
26+ property var effectiveMaxWithdrawable: onemsat .min (providerMaxWithdrawable, requestDetails . wallet . lightningCanReceive )
27+ property bool insufficientLiquidity: effectiveMinWithdrawable .gt (requestDetails . wallet . lightningCanReceive )
2928 property bool liquidityWarning: providerMaxWithdrawable .gt (walletCanReceive)
29+ property bool fixedAmount: false
3030
31- property bool amountValid: ! dialog .insufficientLiquidity &&
32- amountBtc .textAsSats .gte (dialog .effectiveMinWithdrawable ) &&
33- amountBtc .textAsSats .lte (dialog .effectiveMaxWithdrawable )
31+ property bool amountValid: isValidAmount ()
3432 property bool valid: amountValid
3533
3634 Component .onCompleted : {
37- dialog .walletCanReceive .copyFrom (wallet .lightningCanReceive )
35+ updateLimits ()
36+ }
37+
38+ function isValidAmount () {
39+ return ! dialog .insufficientLiquidity
40+ && amountBtc .textAsSats .gte (dialog .effectiveMinWithdrawable )
41+ && amountBtc .textAsSats .lte (dialog .effectiveMaxWithdrawable )
42+ }
43+
44+ function updateLimits () {
45+ dialog .walletCanReceive .copyFrom (requestDetails .wallet .lightningCanReceive )
46+ dialog .effectiveMaxWithdrawable = onemsat .min (dialog .providerMaxWithdrawable , requestDetails .wallet .lightningCanReceive )
47+ dialog .insufficientLiquidity = dialog .effectiveMinWithdrawable .gt (requestDetails .wallet .lightningCanReceive )
48+ dialog .liquidityWarning = dialog .providerMaxWithdrawable .gt (requestDetails .wallet .lightningCanReceive )
49+ dialog .fixedAmount = dialog .providerMinWithdrawable .eq (dialog .providerMaxWithdrawable )
50+ dialog .amountValid = isValidAmount ()
3851 }
3952
4053 Connections {
4154 // assign walletCanReceive directly to prevent a binding loop
42- target: wallet
55+ target: requestDetails . wallet
4356 function onLightningCanReceiveChanged () {
4457 if (! requestDetails .busy ) {
4558 // don't assign while busy to prevent the view from changing while receiving
4659 // the incoming payment
47- dialog .walletCanReceive .copyFrom (wallet .lightningCanReceive )
60+ console .log (' UPDATING' )
61+ updateLimits ()
4862 }
4963 }
5064 }
5165
66+ Connections {
67+ target: amountBtc
68+ function onValueChanged () {
69+ dialog .amountValid = isValidAmount ()
70+ }
71+ }
72+
5273 ColumnLayout {
5374 width: parent .width
5475 spacing: 0
@@ -84,7 +105,7 @@ ElDialog {
84105 Layout .columnSpan : 2
85106 Layout .fillWidth : true
86107 compact: true
87- visible: ! dialog .insufficientLiquidity && dialog . providerMinWithdrawable != dialog .providerMaxWithdrawable
108+ visible: ! dialog .insufficientLiquidity && ! dialog .fixedAmount
88109 text: qsTr (' Amount must be between %1 and %2 %3' )
89110 .arg (Config .formatMilliSats (dialog .effectiveMinWithdrawable ))
90111 .arg (Config .formatMilliSats (dialog .effectiveMaxWithdrawable ))
@@ -137,7 +158,7 @@ ElDialog {
137158 id: amountBtc
138159 Layout .preferredWidth : rootLayout .width / 3
139160 text: Config .formatMilliSatsForEditing (dialog .effectiveMaxWithdrawable )
140- enabled: ! dialog .insufficientLiquidity && ! ( dialog .providerMinWithdrawable . eq ( dialog . providerMaxWithdrawable ))
161+ enabled: ! dialog .insufficientLiquidity && ! dialog .fixedAmount
141162 color: Material .foreground // override gray-out on disabled
142163 fiatfield: amountFiat
143164 msatPrecision: true
@@ -156,7 +177,7 @@ ElDialog {
156177 id: amountFiat
157178 Layout .preferredWidth : rootLayout .width / 3
158179 btcfield: amountBtc
159- enabled: ! dialog .insufficientLiquidity && ! ( dialog .providerMinWithdrawable . eq ( dialog . providerMaxWithdrawable ))
180+ enabled: ! dialog .insufficientLiquidity && ! dialog .fixedAmount
160181 color: Material .foreground
161182 }
162183 Label {
0 commit comments