2018-09-01 01:28:19 +02:00
|
|
|
/* global alert */
|
|
|
|
import React from 'react';
|
2020-06-11 05:54:47 +02:00
|
|
|
import {
|
|
|
|
Text,
|
|
|
|
ActivityIndicator,
|
|
|
|
KeyboardAvoidingView,
|
|
|
|
View,
|
|
|
|
TouchableOpacity,
|
|
|
|
StatusBar,
|
|
|
|
Keyboard,
|
|
|
|
ScrollView,
|
|
|
|
StyleSheet,
|
|
|
|
} from 'react-native';
|
2018-09-01 01:28:19 +02:00
|
|
|
import PropTypes from 'prop-types';
|
2019-01-24 08:36:01 +01:00
|
|
|
import {
|
|
|
|
BlueButton,
|
|
|
|
SafeBlueArea,
|
|
|
|
BlueCard,
|
2019-02-26 02:33:29 +01:00
|
|
|
BlueDismissKeyboardInputAccessory,
|
2019-01-24 08:36:01 +01:00
|
|
|
BlueNavigationStyle,
|
|
|
|
BlueAddressInput,
|
|
|
|
BlueBitcoinAmount,
|
2019-12-28 01:53:34 +01:00
|
|
|
BlueLoading,
|
2019-01-24 08:36:01 +01:00
|
|
|
} from '../../BlueComponents';
|
2020-05-24 12:27:08 +02:00
|
|
|
import { LightningCustodianWallet } from '../../class/wallets/lightning-custodian-wallet';
|
2019-02-26 02:33:29 +01:00
|
|
|
import { BitcoinUnit, Chain } from '../../models/bitcoinUnits';
|
|
|
|
import { Icon } from 'react-native-elements';
|
2019-03-05 02:14:28 +01:00
|
|
|
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
|
2019-09-25 05:42:21 +02:00
|
|
|
import Biometric from '../../class/biometrics';
|
2020-07-20 15:38:46 +02:00
|
|
|
import loc, { formatBalanceWithoutSuffix } from '../../loc';
|
2020-07-15 19:32:59 +02:00
|
|
|
import { BlueCurrentTheme } from '../../components/themes';
|
2020-06-01 14:54:23 +02:00
|
|
|
const BlueApp = require('../../BlueApp');
|
2020-07-01 13:56:52 +02:00
|
|
|
const EV = require('../../blue_modules/events');
|
2020-06-09 16:08:18 +02:00
|
|
|
const currency = require('../../blue_modules/currency');
|
2018-09-01 01:28:19 +02:00
|
|
|
|
2020-05-24 11:17:26 +02:00
|
|
|
const styles = StyleSheet.create({
|
|
|
|
walletSelectRoot: {
|
|
|
|
marginBottom: 16,
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'flex-end',
|
|
|
|
},
|
|
|
|
walletSelectTouch: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center',
|
|
|
|
},
|
|
|
|
walletSelectText: {
|
|
|
|
color: '#9aa0aa',
|
|
|
|
fontSize: 14,
|
|
|
|
marginRight: 8,
|
|
|
|
},
|
|
|
|
walletWrap: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center',
|
|
|
|
marginVertical: 4,
|
|
|
|
},
|
|
|
|
walletWrapTouch: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center',
|
|
|
|
},
|
|
|
|
walletWrapLabel: {
|
2020-07-15 19:32:59 +02:00
|
|
|
color: BlueCurrentTheme.colors.buttonAlternativeTextColor,
|
2020-05-24 11:17:26 +02:00
|
|
|
fontSize: 14,
|
|
|
|
},
|
|
|
|
walletWrapBalance: {
|
2020-07-15 19:32:59 +02:00
|
|
|
color: BlueCurrentTheme.colors.buttonAlternativeTextColor,
|
2020-05-24 11:17:26 +02:00
|
|
|
fontSize: 14,
|
|
|
|
fontWeight: '600',
|
|
|
|
marginLeft: 4,
|
|
|
|
marginRight: 4,
|
|
|
|
},
|
|
|
|
walletWrapSats: {
|
2020-07-15 19:32:59 +02:00
|
|
|
color: BlueCurrentTheme.colors.buttonAlternativeTextColor,
|
2020-05-24 11:17:26 +02:00
|
|
|
fontSize: 11,
|
|
|
|
fontWeight: '600',
|
|
|
|
textAlignVertical: 'bottom',
|
|
|
|
marginTop: 2,
|
|
|
|
},
|
|
|
|
root: {
|
|
|
|
flex: 1,
|
2020-07-15 19:32:59 +02:00
|
|
|
backgroundColor: BlueCurrentTheme.colors.elevated,
|
2020-05-24 11:17:26 +02:00
|
|
|
},
|
|
|
|
scroll: {
|
|
|
|
flex: 1,
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
},
|
|
|
|
scrollMargin: {
|
|
|
|
marginTop: 60,
|
|
|
|
},
|
|
|
|
description: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
marginHorizontal: 20,
|
|
|
|
alignItems: 'center',
|
|
|
|
marginVertical: 0,
|
|
|
|
borderRadius: 4,
|
|
|
|
},
|
|
|
|
descriptionText: {
|
|
|
|
color: '#81868e',
|
|
|
|
fontWeight: '500',
|
|
|
|
fontSize: 14,
|
|
|
|
},
|
|
|
|
expiresIn: {
|
|
|
|
color: '#81868e',
|
|
|
|
fontSize: 12,
|
|
|
|
left: 20,
|
|
|
|
top: 10,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2018-09-01 01:28:19 +02:00
|
|
|
export default class ScanLndInvoice extends React.Component {
|
|
|
|
state = {
|
|
|
|
isLoading: false,
|
2019-01-06 10:30:32 +01:00
|
|
|
isAmountInitiallyEmpty: false,
|
2019-02-26 02:33:29 +01:00
|
|
|
renderWalletSelectionButtonHidden: false,
|
2018-09-01 01:28:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2019-12-28 01:53:34 +01:00
|
|
|
this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this._keyboardDidShow);
|
|
|
|
this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', this._keyboardDidHide);
|
2018-12-29 19:24:51 +01:00
|
|
|
if (!BlueApp.getWallets().some(item => item.type === LightningCustodianWallet.type)) {
|
2019-05-03 14:36:11 +02:00
|
|
|
ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false });
|
2018-12-29 19:24:51 +01:00
|
|
|
alert('Before paying a Lightning invoice, you must first add a Lightning wallet.');
|
2020-05-27 13:12:17 +02:00
|
|
|
props.navigation.dangerouslyGetParent().pop();
|
2018-12-29 19:24:51 +01:00
|
|
|
} else {
|
|
|
|
let fromSecret;
|
2020-05-27 13:12:17 +02:00
|
|
|
if (props.route.params.fromSecret) fromSecret = props.route.params.fromSecret;
|
2018-12-29 19:24:51 +01:00
|
|
|
let fromWallet = {};
|
|
|
|
|
|
|
|
if (!fromSecret) {
|
|
|
|
const lightningWallets = BlueApp.getWallets().filter(item => item.type === LightningCustodianWallet.type);
|
|
|
|
if (lightningWallets.length > 0) {
|
|
|
|
fromSecret = lightningWallets[0].getSecret();
|
2019-01-15 21:18:08 +01:00
|
|
|
console.warn('warning: using ln wallet index 0');
|
2018-12-29 19:24:51 +01:00
|
|
|
}
|
2018-12-24 16:29:33 +01:00
|
|
|
}
|
|
|
|
|
2020-06-01 14:54:23 +02:00
|
|
|
for (const w of BlueApp.getWallets()) {
|
2018-12-29 19:24:51 +01:00
|
|
|
if (w.getSecret() === fromSecret) {
|
|
|
|
fromWallet = w;
|
|
|
|
break;
|
|
|
|
}
|
2018-09-01 01:28:19 +02:00
|
|
|
}
|
|
|
|
|
2018-12-29 19:24:51 +01:00
|
|
|
this.state = {
|
|
|
|
fromWallet,
|
|
|
|
fromSecret,
|
2020-06-09 16:08:18 +02:00
|
|
|
unit: BitcoinUnit.SATS,
|
2018-12-29 19:24:51 +01:00
|
|
|
destination: '',
|
|
|
|
};
|
|
|
|
}
|
2018-12-11 23:52:46 +01:00
|
|
|
}
|
2018-10-23 00:51:30 +02:00
|
|
|
|
2020-01-20 04:33:17 +01:00
|
|
|
static getDerivedStateFromProps(props, state) {
|
2020-05-27 13:12:17 +02:00
|
|
|
if (props.route.params.uri) {
|
|
|
|
let data = props.route.params.uri;
|
2019-01-19 22:18:19 +01:00
|
|
|
// handling BIP21 w/BOLT11 support
|
2020-06-01 14:54:23 +02:00
|
|
|
const ind = data.indexOf('lightning=');
|
2019-01-19 22:18:19 +01:00
|
|
|
if (ind !== -1) {
|
|
|
|
data = data.substring(ind + 10).split('&')[0];
|
|
|
|
}
|
|
|
|
|
2019-01-06 21:21:04 +01:00
|
|
|
data = data.replace('LIGHTNING:', '').replace('lightning:', '');
|
|
|
|
console.log(data);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {LightningCustodianWallet}
|
|
|
|
*/
|
2020-06-01 14:54:23 +02:00
|
|
|
const w = state.fromWallet;
|
2019-01-06 21:21:04 +01:00
|
|
|
let decoded;
|
|
|
|
try {
|
2019-12-26 20:34:35 +01:00
|
|
|
decoded = w.decodeInvoice(data);
|
2018-09-01 01:28:19 +02:00
|
|
|
|
2019-01-06 21:21:04 +01:00
|
|
|
let expiresIn = (decoded.timestamp * 1 + decoded.expiry * 1) * 1000; // ms
|
|
|
|
if (+new Date() > expiresIn) {
|
2020-07-20 15:38:46 +02:00
|
|
|
expiresIn = loc.lnd.expiredLow;
|
2019-01-06 21:21:04 +01:00
|
|
|
} else {
|
|
|
|
expiresIn = Math.round((expiresIn - +new Date()) / (60 * 1000)) + ' min';
|
|
|
|
}
|
|
|
|
Keyboard.dismiss();
|
2020-01-20 04:33:17 +01:00
|
|
|
props.navigation.setParams({ uri: undefined });
|
|
|
|
return {
|
2019-01-06 21:21:04 +01:00
|
|
|
invoice: data,
|
|
|
|
decoded,
|
2020-06-09 16:08:18 +02:00
|
|
|
unit: state.unit,
|
|
|
|
amount: decoded.num_satoshis,
|
2019-01-06 21:21:04 +01:00
|
|
|
expiresIn,
|
|
|
|
destination: data,
|
|
|
|
isAmountInitiallyEmpty: decoded.num_satoshis === '0',
|
|
|
|
isLoading: false,
|
2020-01-20 04:33:17 +01:00
|
|
|
};
|
2019-01-06 21:21:04 +01:00
|
|
|
} catch (Err) {
|
2019-05-03 14:36:11 +02:00
|
|
|
ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false });
|
2020-01-20 04:33:17 +01:00
|
|
|
Keyboard.dismiss();
|
|
|
|
props.navigation.setParams({ uri: undefined });
|
|
|
|
setTimeout(() => alert(Err.message), 10);
|
|
|
|
return { ...state, isLoading: false };
|
2018-09-01 01:28:19 +02:00
|
|
|
}
|
2020-01-20 04:33:17 +01:00
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
this.keyboardDidShowListener.remove();
|
|
|
|
this.keyboardDidHideListener.remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
_keyboardDidShow = () => {
|
|
|
|
this.setState({ renderWalletSelectionButtonHidden: true });
|
|
|
|
};
|
|
|
|
|
|
|
|
_keyboardDidHide = () => {
|
|
|
|
this.setState({ renderWalletSelectionButtonHidden: false });
|
|
|
|
};
|
|
|
|
|
|
|
|
processInvoice = data => {
|
|
|
|
this.props.navigation.setParams({ uri: data });
|
2019-01-24 08:36:01 +01:00
|
|
|
};
|
2018-09-01 01:28:19 +02:00
|
|
|
|
|
|
|
async pay() {
|
2020-06-04 14:17:56 +02:00
|
|
|
if (!('decoded' in this.state)) {
|
2018-10-23 00:51:30 +02:00
|
|
|
return null;
|
|
|
|
}
|
2018-09-01 01:28:19 +02:00
|
|
|
|
2019-09-25 05:42:21 +02:00
|
|
|
const isBiometricsEnabled = await Biometric.isBiometricUseCapableAndEnabled();
|
|
|
|
|
|
|
|
if (isBiometricsEnabled) {
|
|
|
|
if (!(await Biometric.unlockWithBiometrics())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-09 16:08:18 +02:00
|
|
|
let amountSats = this.state.amount;
|
|
|
|
switch (this.state.unit) {
|
|
|
|
case BitcoinUnit.SATS:
|
|
|
|
amountSats = parseInt(amountSats); // nop
|
|
|
|
break;
|
|
|
|
case BitcoinUnit.BTC:
|
|
|
|
amountSats = currency.btcToSatoshi(amountSats);
|
|
|
|
break;
|
|
|
|
case BitcoinUnit.LOCAL_CURRENCY:
|
|
|
|
amountSats = currency.btcToSatoshi(currency.fiatToBTC(amountSats));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-01-05 01:10:59 +01:00
|
|
|
this.setState(
|
|
|
|
{
|
2019-01-06 08:28:23 +01:00
|
|
|
isLoading: true,
|
2019-01-05 01:10:59 +01:00
|
|
|
},
|
|
|
|
async () => {
|
2020-06-01 14:54:23 +02:00
|
|
|
const decoded = this.state.decoded;
|
2018-09-01 01:28:19 +02:00
|
|
|
|
2019-01-05 01:10:59 +01:00
|
|
|
/** @type {LightningCustodianWallet} */
|
2020-06-01 14:54:23 +02:00
|
|
|
const fromWallet = this.state.fromWallet;
|
2018-09-01 01:28:19 +02:00
|
|
|
|
2020-06-01 14:54:23 +02:00
|
|
|
const expiresIn = (decoded.timestamp * 1 + decoded.expiry * 1) * 1000; // ms
|
2019-01-05 01:10:59 +01:00
|
|
|
if (+new Date() > expiresIn) {
|
2019-01-06 08:28:23 +01:00
|
|
|
this.setState({ isLoading: false });
|
2019-05-03 14:36:11 +02:00
|
|
|
ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false });
|
2020-07-20 15:38:46 +02:00
|
|
|
return alert(loc.lnd.errorInvoiceExpired);
|
2019-01-05 01:10:59 +01:00
|
|
|
}
|
2018-09-01 01:28:19 +02:00
|
|
|
|
2019-01-10 17:16:44 +01:00
|
|
|
const currentUserInvoices = fromWallet.user_invoices_raw; // not fetching invoices, as we assume they were loaded previously
|
2019-01-05 01:10:59 +01:00
|
|
|
if (currentUserInvoices.some(invoice => invoice.payment_hash === decoded.payment_hash)) {
|
2019-01-06 08:28:23 +01:00
|
|
|
this.setState({ isLoading: false });
|
2019-05-03 14:36:11 +02:00
|
|
|
ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false });
|
2019-01-05 01:10:59 +01:00
|
|
|
return alert(loc.lnd.sameWalletAsInvoiceError);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2020-06-09 16:08:18 +02:00
|
|
|
await fromWallet.payInvoice(this.state.invoice, amountSats);
|
2019-01-05 01:10:59 +01:00
|
|
|
} catch (Err) {
|
|
|
|
console.log(Err.message);
|
2019-01-06 08:28:23 +01:00
|
|
|
this.setState({ isLoading: false });
|
2019-05-03 14:36:11 +02:00
|
|
|
ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false });
|
2019-02-04 22:09:51 +01:00
|
|
|
return alert(Err.message);
|
2019-01-05 01:10:59 +01:00
|
|
|
}
|
2018-09-01 01:28:19 +02:00
|
|
|
|
2019-01-05 01:10:59 +01:00
|
|
|
EV(EV.enum.REMOTE_TRANSACTIONS_COUNT_CHANGED); // someone should fetch txs
|
2019-02-01 01:59:49 +01:00
|
|
|
this.props.navigation.navigate('Success', {
|
2020-06-09 16:08:18 +02:00
|
|
|
amount: amountSats,
|
2019-02-01 01:59:49 +01:00
|
|
|
amountUnit: BitcoinUnit.SATS,
|
2019-02-01 08:08:37 +01:00
|
|
|
invoiceDescription: this.state.decoded.description,
|
2019-02-01 01:59:49 +01:00
|
|
|
});
|
2019-01-05 01:10:59 +01:00
|
|
|
},
|
|
|
|
);
|
2018-09-01 01:28:19 +02:00
|
|
|
}
|
|
|
|
|
2018-12-24 16:29:33 +01:00
|
|
|
processTextForInvoice = text => {
|
|
|
|
if (text.toLowerCase().startsWith('lnb') || text.toLowerCase().startsWith('lightning:lnb')) {
|
|
|
|
this.processInvoice(text);
|
|
|
|
} else {
|
2018-12-25 17:34:51 +01:00
|
|
|
this.setState({ decoded: undefined, expiresIn: undefined, destination: text });
|
2018-12-24 16:29:33 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-01-06 08:28:23 +01:00
|
|
|
shouldDisablePayButton = () => {
|
|
|
|
if (typeof this.state.decoded !== 'object') {
|
|
|
|
return true;
|
|
|
|
} else {
|
2020-06-09 16:08:18 +02:00
|
|
|
if (!this.state.amount) {
|
2019-01-06 08:28:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2020-06-09 16:08:18 +02:00
|
|
|
return !(this.state.amount > 0);
|
|
|
|
// return this.state.decoded.num_satoshis <= 0 || this.state.isLoading || isNaN(this.state.decoded.num_satoshis);
|
2019-01-06 08:28:23 +01:00
|
|
|
};
|
|
|
|
|
2019-02-26 02:33:29 +01:00
|
|
|
renderWalletSelectionButton = () => {
|
|
|
|
if (this.state.renderWalletSelectionButtonHidden) return;
|
|
|
|
return (
|
2020-05-24 11:17:26 +02:00
|
|
|
<View style={styles.walletSelectRoot}>
|
2019-02-26 02:33:29 +01:00
|
|
|
{!this.state.isLoading && (
|
|
|
|
<TouchableOpacity
|
2020-05-24 11:17:26 +02:00
|
|
|
style={styles.walletSelectTouch}
|
2019-02-26 02:33:29 +01:00
|
|
|
onPress={() =>
|
|
|
|
this.props.navigation.navigate('SelectWallet', { onWalletSelect: this.onWalletSelect, chainType: Chain.OFFCHAIN })
|
|
|
|
}
|
|
|
|
>
|
2020-05-24 11:17:26 +02:00
|
|
|
<Text style={styles.walletSelectText}>{loc.wallets.select_wallet.toLowerCase()}</Text>
|
2019-09-17 21:39:21 +02:00
|
|
|
<Icon name="angle-right" size={18} type="font-awesome" color="#9aa0aa" />
|
2019-02-26 02:33:29 +01:00
|
|
|
</TouchableOpacity>
|
|
|
|
)}
|
2020-05-24 11:17:26 +02:00
|
|
|
<View style={styles.walletWrap}>
|
2019-09-17 21:39:21 +02:00
|
|
|
<TouchableOpacity
|
2020-05-24 11:17:26 +02:00
|
|
|
style={styles.walletWrapTouch}
|
2019-09-17 21:39:21 +02:00
|
|
|
onPress={() =>
|
|
|
|
this.props.navigation.navigate('SelectWallet', { onWalletSelect: this.onWalletSelect, chainType: Chain.OFFCHAIN })
|
|
|
|
}
|
|
|
|
>
|
2020-05-24 11:17:26 +02:00
|
|
|
<Text style={styles.walletWrapLabel}>{this.state.fromWallet.getLabel()}</Text>
|
|
|
|
<Text style={styles.walletWrapBalance}>
|
2020-07-20 15:38:46 +02:00
|
|
|
{formatBalanceWithoutSuffix(this.state.fromWallet.getBalance(), BitcoinUnit.SATS, false)}
|
2019-09-17 21:39:21 +02:00
|
|
|
</Text>
|
2020-05-24 11:17:26 +02:00
|
|
|
<Text style={styles.walletWrapSats}>{BitcoinUnit.SATS}</Text>
|
2019-09-17 21:39:21 +02:00
|
|
|
</TouchableOpacity>
|
2019-02-26 02:33:29 +01:00
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-06-04 15:07:33 +02:00
|
|
|
getFees() {
|
|
|
|
const min = Math.floor(this.state.decoded.num_satoshis * 0.003);
|
|
|
|
const max = Math.floor(this.state.decoded.num_satoshis * 0.01) + 1;
|
|
|
|
return `${min} sat - ${max} sat`;
|
|
|
|
}
|
|
|
|
|
2019-02-26 02:33:29 +01:00
|
|
|
onWalletSelect = wallet => {
|
|
|
|
this.setState({ fromSecret: wallet.getSecret(), fromWallet: wallet }, () => {
|
|
|
|
this.props.navigation.pop();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-06-09 16:08:18 +02:00
|
|
|
async componentDidMount() {
|
|
|
|
console.log('scanLndInvoice did mount');
|
|
|
|
}
|
|
|
|
|
2018-09-01 01:28:19 +02:00
|
|
|
render() {
|
2019-12-28 01:53:34 +01:00
|
|
|
if (!this.state.fromWallet) {
|
|
|
|
return <BlueLoading />;
|
|
|
|
}
|
2020-07-20 15:38:46 +02:00
|
|
|
|
2018-10-23 00:51:30 +02:00
|
|
|
return (
|
2020-05-24 11:17:26 +02:00
|
|
|
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={styles.root}>
|
2020-06-11 05:54:47 +02:00
|
|
|
<StatusBar barStyle="light-content" />
|
2020-05-24 11:17:26 +02:00
|
|
|
<View style={styles.root}>
|
|
|
|
<ScrollView contentContainerStyle={styles.scroll}>
|
2020-04-07 21:17:43 +02:00
|
|
|
<KeyboardAvoidingView enabled behavior="position" keyboardVerticalOffset={20}>
|
2020-05-24 11:17:26 +02:00
|
|
|
<View style={styles.scrollMargin}>
|
2019-09-17 23:26:19 +02:00
|
|
|
<BlueBitcoinAmount
|
|
|
|
pointerEvents={this.state.isAmountInitiallyEmpty ? 'auto' : 'none'}
|
|
|
|
isLoading={this.state.isLoading}
|
2020-06-09 16:08:18 +02:00
|
|
|
amount={this.state.amount}
|
2020-07-20 15:38:46 +02:00
|
|
|
onAmountUnitChange={unit => this.setState({ unit })}
|
2019-09-17 23:26:19 +02:00
|
|
|
onChangeText={text => {
|
2020-06-09 16:08:18 +02:00
|
|
|
this.setState({ amount: text });
|
|
|
|
|
|
|
|
/* if (typeof this.state.decoded === 'object') {
|
2019-09-17 23:26:19 +02:00
|
|
|
text = parseInt(text || 0);
|
2020-06-01 14:54:23 +02:00
|
|
|
const decoded = this.state.decoded;
|
2019-09-17 23:26:19 +02:00
|
|
|
decoded.num_satoshis = text;
|
|
|
|
this.setState({ decoded: decoded });
|
2020-06-09 16:08:18 +02:00
|
|
|
} */
|
2019-09-17 23:26:19 +02:00
|
|
|
}}
|
2020-06-09 16:08:18 +02:00
|
|
|
disabled={
|
|
|
|
typeof this.state.decoded !== 'object' ||
|
|
|
|
this.state.isLoading ||
|
|
|
|
(this.state.decoded && this.state.decoded.num_satoshis > 0)
|
|
|
|
}
|
2019-09-17 23:26:19 +02:00
|
|
|
unit={BitcoinUnit.SATS}
|
|
|
|
inputAccessoryViewID={BlueDismissKeyboardInputAccessory.InputAccessoryViewID}
|
|
|
|
/>
|
|
|
|
</View>
|
2019-10-06 13:40:21 +02:00
|
|
|
|
2019-02-26 02:33:29 +01:00
|
|
|
<BlueCard>
|
|
|
|
<BlueAddressInput
|
|
|
|
onChangeText={text => {
|
2020-01-20 04:33:17 +01:00
|
|
|
text = text.trim();
|
2019-02-26 02:33:29 +01:00
|
|
|
this.processTextForInvoice(text);
|
2019-02-01 01:59:49 +01:00
|
|
|
}}
|
2019-02-26 02:33:29 +01:00
|
|
|
onBarScanned={this.processInvoice}
|
|
|
|
address={this.state.destination}
|
|
|
|
isLoading={this.state.isLoading}
|
|
|
|
placeholder={loc.lnd.placeholder}
|
|
|
|
inputAccessoryViewID={BlueDismissKeyboardInputAccessory.InputAccessoryViewID}
|
2020-05-27 13:12:17 +02:00
|
|
|
launchedBy={this.props.route.name}
|
2019-02-01 01:59:49 +01:00
|
|
|
/>
|
2020-05-24 11:17:26 +02:00
|
|
|
<View style={styles.description}>
|
|
|
|
<Text numberOfLines={0} style={styles.descriptionText}>
|
2020-06-01 14:54:23 +02:00
|
|
|
{'decoded' in this.state && this.state.decoded !== undefined ? this.state.decoded.description : ''}
|
2019-02-26 02:33:29 +01:00
|
|
|
</Text>
|
|
|
|
</View>
|
2020-06-04 15:07:33 +02:00
|
|
|
{this.state.expiresIn !== undefined && (
|
2020-06-03 22:40:16 +02:00
|
|
|
<View>
|
2020-07-20 15:38:46 +02:00
|
|
|
<Text style={styles.expiresIn}>{loc.formatString(loc.lnd.expiresIn, { time: this.state.expiresIn })}</Text>
|
2020-06-04 15:07:33 +02:00
|
|
|
{this.state.decoded && this.state.decoded.num_satoshis > 0 && (
|
2020-07-20 15:38:46 +02:00
|
|
|
<Text style={styles.expiresIn}>{loc.formatString(loc.lnd.potentialFee, { fee: this.getFees() })}</Text>
|
2020-06-04 15:07:33 +02:00
|
|
|
)}
|
|
|
|
</View>
|
|
|
|
)}
|
2019-02-26 02:33:29 +01:00
|
|
|
<BlueCard>
|
|
|
|
{this.state.isLoading ? (
|
|
|
|
<View>
|
|
|
|
<ActivityIndicator />
|
|
|
|
</View>
|
|
|
|
) : (
|
2020-07-20 15:38:46 +02:00
|
|
|
<BlueButton title={loc.lnd.payButton} onPress={() => this.pay()} disabled={this.shouldDisablePayButton()} />
|
2019-02-26 02:33:29 +01:00
|
|
|
)}
|
|
|
|
</BlueCard>
|
|
|
|
</BlueCard>
|
2019-11-21 06:11:50 +01:00
|
|
|
</KeyboardAvoidingView>
|
2019-02-26 02:33:29 +01:00
|
|
|
{this.renderWalletSelectionButton()}
|
2020-04-07 21:17:43 +02:00
|
|
|
</ScrollView>
|
|
|
|
</View>
|
|
|
|
<BlueDismissKeyboardInputAccessory />
|
|
|
|
</SafeBlueArea>
|
2018-10-23 00:51:30 +02:00
|
|
|
);
|
2018-09-01 01:28:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ScanLndInvoice.propTypes = {
|
|
|
|
navigation: PropTypes.shape({
|
2019-02-01 16:28:43 +01:00
|
|
|
goBack: PropTypes.func,
|
|
|
|
navigate: PropTypes.func,
|
2019-02-26 02:33:29 +01:00
|
|
|
pop: PropTypes.func,
|
2020-01-20 04:33:17 +01:00
|
|
|
setParams: PropTypes.func,
|
2020-05-27 13:12:17 +02:00
|
|
|
dangerouslyGetParent: PropTypes.func,
|
|
|
|
}),
|
|
|
|
route: PropTypes.shape({
|
|
|
|
name: PropTypes.string,
|
|
|
|
params: PropTypes.shape({
|
|
|
|
uri: PropTypes.string,
|
|
|
|
fromSecret: PropTypes.string,
|
2018-09-01 01:28:19 +02:00
|
|
|
}),
|
|
|
|
}),
|
2020-04-17 17:23:18 +02:00
|
|
|
};
|
2020-07-15 19:32:59 +02:00
|
|
|
|
|
|
|
ScanLndInvoice.navigationOptions = ({ navigation }) => ({
|
|
|
|
...BlueNavigationStyle(navigation, true),
|
|
|
|
title: loc.send.header,
|
|
|
|
headerLeft: null,
|
|
|
|
});
|