mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-02-22 23:08:07 +01:00
FIX: min/max in lndCreateInvoice
This commit is contained in:
parent
5c75627c84
commit
f1b6ac5f0b
3 changed files with 32 additions and 19 deletions
|
@ -75,7 +75,7 @@ class AmountInput extends Component {
|
|||
*/
|
||||
onAmountUnitChange(previousUnit, newUnit) {
|
||||
const amount = this.props.amount || 0;
|
||||
console.log('was:', amount, previousUnit, '; converting to', newUnit);
|
||||
const log = `${amount}(${previousUnit}) ->`;
|
||||
let sats = 0;
|
||||
switch (previousUnit) {
|
||||
case BitcoinUnit.BTC:
|
||||
|
@ -92,10 +92,9 @@ class AmountInput extends Component {
|
|||
// cache hit! we reuse old value that supposedly doesnt have rounding errors
|
||||
sats = AmountInput.conversionCache[amount + previousUnit];
|
||||
}
|
||||
console.log('so, in sats its', sats);
|
||||
|
||||
const newInputValue = formatBalancePlain(sats, newUnit, false);
|
||||
console.log('and in', newUnit, 'its', newInputValue);
|
||||
console.log(`${log} ${sats}(sats) -> ${newInputValue}(${newUnit})`);
|
||||
|
||||
if (newUnit === BitcoinUnit.LOCAL_CURRENCY && previousUnit === BitcoinUnit.SATS) {
|
||||
// we cache conversion, so when we will need reverse conversion there wont be a rounding error
|
||||
|
|
|
@ -182,7 +182,11 @@
|
|||
"details_label": "Description",
|
||||
"details_setAmount": "Receive with amount",
|
||||
"details_share": "Share",
|
||||
"header": "Receive"
|
||||
"header": "Receive",
|
||||
"maxSats": "Maximum amount is {max} sats",
|
||||
"maxSatsFull": "Maximum amount is {max} sats or {currency}",
|
||||
"minSats": "Minimal amount is {min} sats",
|
||||
"minSatsFull": "Minimal amount is {min} sats or {currency}"
|
||||
},
|
||||
"send": {
|
||||
"provided_address_is_invoice": "This address appears to be for a Lightning invoice. Please, go to your Lightning wallet in order to make a payment for this invoice.",
|
||||
|
|
|
@ -23,7 +23,7 @@ import navigationStyle from '../../components/navigationStyle';
|
|||
import AmountInput from '../../components/AmountInput';
|
||||
import * as NavigationService from '../../NavigationService';
|
||||
import { BitcoinUnit, Chain } from '../../models/bitcoinUnits';
|
||||
import loc, { formatBalanceWithoutSuffix, formatBalancePlain } from '../../loc';
|
||||
import loc, { formatBalance, formatBalanceWithoutSuffix, formatBalancePlain } from '../../loc';
|
||||
import Lnurl from '../../class/lnurl';
|
||||
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
||||
import Notifications from '../../blue_modules/notifications';
|
||||
|
@ -45,6 +45,7 @@ const LNDCreateInvoice = () => {
|
|||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [description, setDescription] = useState('');
|
||||
const [lnurlParams, setLNURLParams] = useState();
|
||||
|
||||
const styleHooks = StyleSheet.create({
|
||||
scanRoot: {
|
||||
backgroundColor: colors.scanLabel,
|
||||
|
@ -162,6 +163,28 @@ const LNDCreateInvoice = () => {
|
|||
break;
|
||||
}
|
||||
|
||||
if (lnurlParams) {
|
||||
const { min, max } = lnurlParams;
|
||||
if (invoiceAmount < min || invoiceAmount > min) {
|
||||
let text;
|
||||
if (invoiceAmount < min) {
|
||||
text =
|
||||
unit === BitcoinUnit.SATS
|
||||
? loc.formatString(loc.receive.minSats, { min })
|
||||
: loc.formatString(loc.receive.minSatsFull, { min, currency: formatBalance(min, unit) });
|
||||
} else {
|
||||
text =
|
||||
unit === BitcoinUnit.SATS
|
||||
? loc.formatString(loc.receive.maxSats, { max })
|
||||
: loc.formatString(loc.receive.maxSatsFull, { max, currency: formatBalance(max, unit) });
|
||||
}
|
||||
ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false });
|
||||
alert(text);
|
||||
setIsLoading(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const invoiceRequest = await wallet.current.addInvoice(invoiceAmount, description);
|
||||
ReactNativeHapticFeedback.trigger('notificationSuccess', { ignoreAndroidSystemSettings: false });
|
||||
|
||||
|
@ -395,20 +418,7 @@ const LNDCreateInvoice = () => {
|
|||
isLoading={isLoading}
|
||||
amount={amount}
|
||||
onAmountUnitChange={setUnit}
|
||||
onChangeText={text => {
|
||||
if (lnurlParams) {
|
||||
// in this case we prevent the user from changing the amount to < min or > max
|
||||
const { min, max } = lnurlParams;
|
||||
const nextAmount = parseInt(text);
|
||||
if (nextAmount < min) {
|
||||
text = min.toString();
|
||||
} else if (nextAmount > max) {
|
||||
text = max.toString();
|
||||
}
|
||||
}
|
||||
|
||||
setAmount(text);
|
||||
}}
|
||||
onChangeText={setAmount}
|
||||
disabled={isLoading || (lnurlParams && lnurlParams.fixed)}
|
||||
unit={unit}
|
||||
inputAccessoryViewID={BlueDismissKeyboardInputAccessory.InputAccessoryViewID}
|
||||
|
|
Loading…
Add table
Reference in a new issue