diff --git a/components/AmountInput.js b/components/AmountInput.js index 500862e75..2e629d259 100644 --- a/components/AmountInput.js +++ b/components/AmountInput.js @@ -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 diff --git a/loc/en.json b/loc/en.json index 72041aa04..d6872bad6 100644 --- a/loc/en.json +++ b/loc/en.json @@ -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.", diff --git a/screen/lnd/lndCreateInvoice.js b/screen/lnd/lndCreateInvoice.js index ee2da2709..84b99d3cd 100644 --- a/screen/lnd/lndCreateInvoice.js +++ b/screen/lnd/lndCreateInvoice.js @@ -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}