2019-01-06 08:42:53 +01:00
|
|
|
/* global alert */
|
2018-12-25 17:34:51 +01:00
|
|
|
import React, { Component } from 'react';
|
2019-08-04 21:34:17 +02:00
|
|
|
import {
|
|
|
|
ActivityIndicator,
|
|
|
|
View,
|
|
|
|
TextInput,
|
|
|
|
KeyboardAvoidingView,
|
|
|
|
Keyboard,
|
2020-06-11 05:54:47 +02:00
|
|
|
StatusBar,
|
2019-08-04 21:34:17 +02:00
|
|
|
TouchableWithoutFeedback,
|
|
|
|
TouchableOpacity,
|
|
|
|
Text,
|
2020-05-24 11:17:26 +02:00
|
|
|
StyleSheet,
|
2020-07-15 19:32:59 +02:00
|
|
|
Image,
|
2019-08-04 21:34:17 +02:00
|
|
|
} from 'react-native';
|
2019-12-25 04:35:47 +01:00
|
|
|
import {
|
|
|
|
BlueNavigationStyle,
|
|
|
|
BlueButton,
|
|
|
|
BlueBitcoinAmount,
|
|
|
|
BlueDismissKeyboardInputAccessory,
|
|
|
|
BlueAlertWalletExportReminder,
|
|
|
|
} from '../../BlueComponents';
|
2020-05-24 12:27:08 +02:00
|
|
|
import { LightningCustodianWallet } from '../../class/wallets/lightning-custodian-wallet';
|
2018-12-25 17:34:51 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2019-07-28 19:22:58 +02:00
|
|
|
import bech32 from 'bech32';
|
2020-01-19 22:00:25 +01:00
|
|
|
import { BitcoinUnit, Chain } from '../../models/bitcoinUnits';
|
2020-06-19 02:24:26 +02:00
|
|
|
import * as NavigationService from '../../NavigationService';
|
2018-12-25 17:34:51 +01:00
|
|
|
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
|
2019-12-13 06:28:01 +01:00
|
|
|
import { Icon } from 'react-native-elements';
|
2020-07-15 19:32:59 +02:00
|
|
|
import { BlueCurrentTheme } from '../../components/themes';
|
2020-06-09 16:08:18 +02:00
|
|
|
const currency = require('../../blue_modules/currency');
|
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-01 14:54:23 +02:00
|
|
|
const loc = require('../../loc');
|
2020-07-18 21:33:43 +02:00
|
|
|
const notifications = require('../../blue_modules/notifications');
|
2018-12-25 17:34:51 +01:00
|
|
|
|
2020-05-24 11:17:26 +02:00
|
|
|
const styles = StyleSheet.create({
|
|
|
|
createButton: {
|
|
|
|
marginHorizontal: 56,
|
|
|
|
marginVertical: 16,
|
|
|
|
minHeight: 45,
|
|
|
|
alignContent: 'center',
|
|
|
|
},
|
|
|
|
scanRoot: {
|
|
|
|
height: 36,
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'space-between',
|
2020-07-15 19:32:59 +02:00
|
|
|
backgroundColor: BlueCurrentTheme.colors.scanLabel,
|
2020-05-24 11:17:26 +02:00
|
|
|
borderRadius: 4,
|
|
|
|
paddingVertical: 4,
|
|
|
|
paddingHorizontal: 8,
|
|
|
|
marginHorizontal: 4,
|
|
|
|
},
|
|
|
|
scanClick: {
|
|
|
|
marginLeft: 4,
|
2020-07-15 19:32:59 +02:00
|
|
|
color: BlueCurrentTheme.colors.inverseForegroundColor,
|
2020-05-24 11:17:26 +02:00
|
|
|
},
|
|
|
|
walletRoot: {
|
|
|
|
marginBottom: 16,
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
|
|
|
},
|
|
|
|
walletChooseWrap: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center',
|
|
|
|
},
|
|
|
|
walletChooseText: {
|
|
|
|
color: '#9aa0aa',
|
|
|
|
fontSize: 14,
|
|
|
|
marginRight: 8,
|
|
|
|
},
|
|
|
|
walletNameWrap: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center',
|
|
|
|
marginVertical: 4,
|
|
|
|
},
|
|
|
|
walletNameTouch: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center',
|
|
|
|
},
|
|
|
|
walletNameText: {
|
2020-07-15 19:32:59 +02:00
|
|
|
color: BlueCurrentTheme.colors.buttonAlternativeTextColor,
|
2020-05-24 11:17:26 +02:00
|
|
|
fontSize: 14,
|
|
|
|
},
|
|
|
|
walletNameBalance: {
|
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: 8,
|
|
|
|
marginRight: 4,
|
|
|
|
},
|
|
|
|
walletNameSats: {
|
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,
|
|
|
|
},
|
|
|
|
error: {
|
|
|
|
flex: 1,
|
|
|
|
paddingTop: 20,
|
|
|
|
},
|
|
|
|
root: {
|
|
|
|
flex: 1,
|
|
|
|
justifyContent: 'space-between',
|
2020-07-15 19:32:59 +02:00
|
|
|
backgroundColor: BlueCurrentTheme.colors.elevated,
|
2020-05-24 11:17:26 +02:00
|
|
|
},
|
|
|
|
amount: {
|
|
|
|
flex: 1,
|
2020-07-15 19:32:59 +02:00
|
|
|
backgroundColor: BlueCurrentTheme.colors.elevated,
|
2020-05-24 11:17:26 +02:00
|
|
|
},
|
|
|
|
fiat: {
|
|
|
|
flexDirection: 'row',
|
2020-07-15 19:32:59 +02:00
|
|
|
borderColor: BlueCurrentTheme.colors.formBorder,
|
|
|
|
borderBottomColor: BlueCurrentTheme.colors.formBorder,
|
2020-05-24 11:17:26 +02:00
|
|
|
borderWidth: 1.0,
|
|
|
|
borderBottomWidth: 0.5,
|
2020-07-15 19:32:59 +02:00
|
|
|
backgroundColor: BlueCurrentTheme.colors.inputBackgroundColor,
|
2020-05-24 11:17:26 +02:00
|
|
|
minHeight: 44,
|
|
|
|
height: 44,
|
|
|
|
marginHorizontal: 20,
|
|
|
|
alignItems: 'center',
|
|
|
|
marginVertical: 8,
|
|
|
|
borderRadius: 4,
|
|
|
|
},
|
|
|
|
fiat2: {
|
|
|
|
flex: 1,
|
|
|
|
marginHorizontal: 8,
|
|
|
|
minHeight: 33,
|
2020-06-11 05:54:47 +02:00
|
|
|
color: '#81868e',
|
2020-05-24 11:17:26 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2018-12-25 17:34:51 +01:00
|
|
|
export default class LNDCreateInvoice extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2020-01-19 22:00:25 +01:00
|
|
|
this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this._keyboardDidShow);
|
|
|
|
this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', this._keyboardDidHide);
|
2020-06-09 16:08:18 +02:00
|
|
|
/** @type LightningCustodianWallet */
|
2019-09-03 22:44:57 +02:00
|
|
|
let fromWallet;
|
2020-05-27 13:12:17 +02:00
|
|
|
if (props.route.params.fromWallet) fromWallet = props.route.params.fromWallet;
|
2019-09-03 22:44:57 +02:00
|
|
|
|
2018-12-25 17:34:51 +01:00
|
|
|
// fallback to first wallet if it exists
|
2019-09-03 22:44:57 +02:00
|
|
|
if (!fromWallet) {
|
|
|
|
const lightningWallets = BlueApp.getWallets().filter(item => item.type === LightningCustodianWallet.type);
|
|
|
|
if (lightningWallets.length > 0) {
|
|
|
|
fromWallet = lightningWallets[0];
|
|
|
|
console.warn('warning: using ln wallet index 0');
|
|
|
|
}
|
|
|
|
}
|
2018-12-25 17:34:51 +01:00
|
|
|
|
|
|
|
this.state = {
|
|
|
|
fromWallet,
|
2019-07-28 19:22:58 +02:00
|
|
|
amount: '',
|
2020-06-09 16:08:18 +02:00
|
|
|
unit: fromWallet.preferredBalanceUnit,
|
2019-01-06 08:42:53 +01:00
|
|
|
description: '',
|
2019-07-28 19:22:58 +02:00
|
|
|
lnurl: '',
|
|
|
|
lnurlParams: null,
|
2019-12-25 04:35:47 +01:00
|
|
|
isLoading: true,
|
2020-01-19 22:00:25 +01:00
|
|
|
renderWalletSelectionButtonHidden: false,
|
2018-12-25 17:34:51 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-12-25 04:35:47 +01:00
|
|
|
renderReceiveDetails = async () => {
|
|
|
|
this.state.fromWallet.setUserHasSavedExport(true);
|
|
|
|
await BlueApp.saveToDisk();
|
2020-05-27 13:12:17 +02:00
|
|
|
if (this.props.route.params.uri) {
|
|
|
|
this.processLnurl(this.props.route.params.uri);
|
2019-09-03 22:44:57 +02:00
|
|
|
}
|
2019-12-25 04:35:47 +01:00
|
|
|
this.setState({ isLoading: false });
|
|
|
|
};
|
|
|
|
|
|
|
|
componentDidMount() {
|
2020-06-09 16:08:18 +02:00
|
|
|
console.log('lnd/lndCreateInvoice mounted');
|
2019-12-25 04:35:47 +01:00
|
|
|
if (this.state.fromWallet.getUserHasSavedExport()) {
|
|
|
|
this.renderReceiveDetails();
|
|
|
|
} else {
|
|
|
|
BlueAlertWalletExportReminder({
|
|
|
|
onSuccess: this.renderReceiveDetails,
|
|
|
|
onFailure: () => {
|
2020-05-27 13:12:17 +02:00
|
|
|
this.props.navigation.dangerouslyGetParent().pop();
|
2019-12-25 04:35:47 +01:00
|
|
|
this.props.navigation.navigate('WalletExport', {
|
2020-03-12 18:26:05 +01:00
|
|
|
wallet: this.state.fromWallet,
|
2019-12-25 04:35:47 +01:00
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2019-09-03 22:44:57 +02:00
|
|
|
}
|
|
|
|
|
2020-01-19 22:00:25 +01:00
|
|
|
componentWillUnmount() {
|
|
|
|
this.keyboardDidShowListener.remove();
|
|
|
|
this.keyboardDidHideListener.remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
_keyboardDidShow = () => {
|
|
|
|
this.setState({ renderWalletSelectionButtonHidden: true });
|
|
|
|
};
|
|
|
|
|
|
|
|
_keyboardDidHide = () => {
|
|
|
|
this.setState({ renderWalletSelectionButtonHidden: false });
|
|
|
|
};
|
|
|
|
|
2018-12-25 17:34:51 +01:00
|
|
|
async createInvoice() {
|
|
|
|
this.setState({ isLoading: true }, async () => {
|
2019-01-06 08:42:53 +01:00
|
|
|
try {
|
2020-06-09 16:08:18 +02:00
|
|
|
this.setState({ isLoading: false });
|
|
|
|
let amount = this.state.amount;
|
|
|
|
switch (this.state.unit) {
|
|
|
|
case BitcoinUnit.SATS:
|
|
|
|
amount = parseInt(amount); // basically nop
|
|
|
|
break;
|
|
|
|
case BitcoinUnit.BTC:
|
|
|
|
amount = currency.btcToSatoshi(amount);
|
|
|
|
break;
|
|
|
|
case BitcoinUnit.LOCAL_CURRENCY:
|
|
|
|
// trying to fetch cached sat equivalent for this fiat amount
|
|
|
|
amount = BlueBitcoinAmount.getCachedSatoshis(amount) || currency.btcToSatoshi(currency.fiatToBTC(amount));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
const invoiceRequest = await this.state.fromWallet.addInvoice(amount, this.state.description);
|
2018-12-27 07:12:19 +01:00
|
|
|
EV(EV.enum.TRANSACTIONS_COUNT_CHANGED);
|
2019-05-03 14:36:11 +02:00
|
|
|
ReactNativeHapticFeedback.trigger('notificationSuccess', { ignoreAndroidSystemSettings: false });
|
2019-07-28 19:22:58 +02:00
|
|
|
|
2020-07-18 21:33:43 +02:00
|
|
|
// lets decode payreq and subscribe groundcontrol so we can receive push notification when our invoice is paid
|
|
|
|
/** @type LightningCustodianWallet */
|
|
|
|
const fromWallet = this.state.fromWallet;
|
|
|
|
const decoded = await fromWallet.decodeInvoice(invoiceRequest);
|
|
|
|
await notifications.tryToObtainPermissions();
|
|
|
|
notifications.majorTomToGroundControl([], [decoded.payment_hash]);
|
|
|
|
|
2019-07-28 19:22:58 +02:00
|
|
|
// send to lnurl-withdraw callback url if that exists
|
|
|
|
if (this.state.lnurlParams) {
|
2020-06-01 14:54:23 +02:00
|
|
|
const { callback, k1 } = this.state.lnurlParams;
|
|
|
|
const callbackUrl = callback + (callback.indexOf('?') !== -1 ? '&' : '?') + 'k1=' + k1 + '&pr=' + invoiceRequest;
|
|
|
|
const resp = await fetch(callbackUrl, { method: 'GET' });
|
2019-07-28 19:22:58 +02:00
|
|
|
if (resp.status >= 300) {
|
2020-06-01 14:54:23 +02:00
|
|
|
const text = await resp.text();
|
2019-07-28 19:22:58 +02:00
|
|
|
throw new Error(text);
|
|
|
|
}
|
2020-06-01 14:54:23 +02:00
|
|
|
const reply = await resp.json();
|
2019-07-28 19:22:58 +02:00
|
|
|
if (reply.status === 'ERROR') {
|
|
|
|
throw new Error('Reply from server: ' + reply.reason);
|
|
|
|
}
|
|
|
|
}
|
2019-08-24 23:11:47 +02:00
|
|
|
await BlueApp.saveToDisk();
|
2018-12-25 17:34:51 +01:00
|
|
|
this.props.navigation.navigate('LNDViewInvoice', {
|
|
|
|
invoice: invoiceRequest,
|
2018-12-28 00:33:39 +01:00
|
|
|
fromWallet: this.state.fromWallet,
|
2019-01-14 07:55:55 +01:00
|
|
|
isModal: true,
|
2018-12-25 17:34:51 +01:00
|
|
|
});
|
2019-07-28 19:22:58 +02:00
|
|
|
} catch (Err) {
|
|
|
|
ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false });
|
|
|
|
this.setState({ isLoading: false });
|
|
|
|
alert(Err.message);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
processLnurl = data => {
|
|
|
|
this.setState({ isLoading: true }, async () => {
|
|
|
|
if (!this.state.fromWallet) {
|
2019-05-03 14:36:11 +02:00
|
|
|
ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false });
|
2019-07-28 19:22:58 +02:00
|
|
|
alert('Before paying a Lightning invoice, you must first add a Lightning wallet.');
|
|
|
|
return this.props.navigation.goBack();
|
|
|
|
}
|
|
|
|
|
|
|
|
// handling fallback lnurl
|
2020-06-01 14:54:23 +02:00
|
|
|
const ind = data.indexOf('lightning=');
|
2019-07-28 19:22:58 +02:00
|
|
|
if (ind !== -1) {
|
|
|
|
data = data.substring(ind + 10).split('&')[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
data = data.replace('LIGHTNING:', '').replace('lightning:', '');
|
|
|
|
console.log(data);
|
|
|
|
|
|
|
|
// decoding the lnurl
|
2020-06-01 14:54:23 +02:00
|
|
|
const decoded = bech32.decode(data, 1500);
|
|
|
|
const url = Buffer.from(bech32.fromWords(decoded.words)).toString();
|
2019-07-28 19:22:58 +02:00
|
|
|
|
|
|
|
// calling the url
|
|
|
|
try {
|
2020-06-01 14:54:23 +02:00
|
|
|
const resp = await fetch(url, { method: 'GET' });
|
2019-07-28 19:22:58 +02:00
|
|
|
if (resp.status >= 300) {
|
2019-08-04 21:34:17 +02:00
|
|
|
throw new Error('Bad response from server');
|
2019-07-28 19:22:58 +02:00
|
|
|
}
|
2020-06-01 14:54:23 +02:00
|
|
|
const reply = await resp.json();
|
2019-07-28 19:22:58 +02:00
|
|
|
if (reply.status === 'ERROR') {
|
|
|
|
throw new Error('Reply from server: ' + reply.reason);
|
|
|
|
}
|
|
|
|
|
2019-07-28 21:12:42 +02:00
|
|
|
if (reply.tag !== 'withdrawRequest') {
|
|
|
|
throw new Error('Unsupported lnurl');
|
|
|
|
}
|
|
|
|
|
2020-06-15 15:45:06 +02:00
|
|
|
// amount that comes from lnurl is always in sats
|
|
|
|
let amount = (reply.maxWithdrawable / 1000).toString();
|
2020-06-25 17:39:48 +02:00
|
|
|
const sats = amount;
|
2020-06-15 15:45:06 +02:00
|
|
|
switch (this.state.unit) {
|
|
|
|
case BitcoinUnit.SATS:
|
|
|
|
// nop
|
|
|
|
break;
|
|
|
|
case BitcoinUnit.BTC:
|
|
|
|
amount = currency.satoshiToBTC(amount);
|
|
|
|
break;
|
|
|
|
case BitcoinUnit.LOCAL_CURRENCY:
|
|
|
|
amount = loc.formatBalancePlain(amount, BitcoinUnit.LOCAL_CURRENCY);
|
2020-06-25 17:39:48 +02:00
|
|
|
BlueBitcoinAmount.setCachedSatoshis(amount, sats);
|
2020-06-15 15:45:06 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-07-28 19:22:58 +02:00
|
|
|
// setting the invoice creating screen with the parameters
|
|
|
|
this.setState({
|
|
|
|
isLoading: false,
|
2019-08-03 03:37:18 +02:00
|
|
|
lnurlParams: {
|
|
|
|
k1: reply.k1,
|
|
|
|
callback: reply.callback,
|
|
|
|
fixed: reply.minWithdrawable === reply.maxWithdrawable,
|
2019-08-03 14:27:09 +02:00
|
|
|
min: (reply.minWithdrawable || 0) / 1000,
|
2019-08-04 21:34:17 +02:00
|
|
|
max: reply.maxWithdrawable / 1000,
|
2019-08-03 03:37:18 +02:00
|
|
|
},
|
2020-06-15 15:45:06 +02:00
|
|
|
amount,
|
2019-07-28 19:22:58 +02:00
|
|
|
description: reply.defaultDescription,
|
|
|
|
});
|
|
|
|
} catch (Err) {
|
|
|
|
Keyboard.dismiss();
|
2019-01-06 08:42:53 +01:00
|
|
|
this.setState({ isLoading: false });
|
2019-07-28 19:22:58 +02:00
|
|
|
ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false });
|
|
|
|
alert(Err.message);
|
2018-12-25 17:34:51 +01:00
|
|
|
}
|
|
|
|
});
|
2019-08-04 21:34:17 +02:00
|
|
|
};
|
2018-12-25 17:34:51 +01:00
|
|
|
|
|
|
|
renderCreateButton = () => {
|
|
|
|
return (
|
2020-05-24 11:17:26 +02:00
|
|
|
<View style={styles.createButton}>
|
2018-12-25 17:34:51 +01:00
|
|
|
{this.state.isLoading ? (
|
|
|
|
<ActivityIndicator />
|
|
|
|
) : (
|
2019-11-11 10:23:29 +01:00
|
|
|
<BlueButton disabled={!(this.state.amount > 0)} onPress={() => this.createInvoice()} title={loc.send.details.create} />
|
2018-12-25 17:34:51 +01:00
|
|
|
)}
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2019-08-03 05:10:50 +02:00
|
|
|
renderScanClickable = () => {
|
2019-07-28 19:22:58 +02:00
|
|
|
return (
|
2019-12-13 06:28:01 +01:00
|
|
|
<TouchableOpacity
|
|
|
|
disabled={this.state.isLoading}
|
|
|
|
onPress={() => {
|
2020-05-31 05:34:58 +02:00
|
|
|
NavigationService.navigate('ScanQRCodeRoot', {
|
|
|
|
screen: 'ScanQRCode',
|
|
|
|
params: {
|
|
|
|
onBarScanned: this.processLnurl,
|
|
|
|
launchedBy: this.props.route.name,
|
|
|
|
},
|
2020-02-27 16:38:13 +01:00
|
|
|
});
|
2019-12-13 06:28:01 +01:00
|
|
|
Keyboard.dismiss();
|
|
|
|
}}
|
2020-05-24 11:17:26 +02:00
|
|
|
style={styles.scanRoot}
|
2019-12-13 06:28:01 +01:00
|
|
|
>
|
2020-07-15 19:32:59 +02:00
|
|
|
<Image style={{}} source={require('../../img/scan-white.png')} />
|
2020-05-24 11:17:26 +02:00
|
|
|
<Text style={styles.scanClick}>{loc.send.details.scan}</Text>
|
2019-12-13 06:28:01 +01:00
|
|
|
</TouchableOpacity>
|
2019-07-28 19:22:58 +02:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-01-19 22:00:25 +01:00
|
|
|
renderWalletSelectionButton = () => {
|
|
|
|
if (this.state.renderWalletSelectionButtonHidden) return;
|
|
|
|
return (
|
2020-05-24 11:17:26 +02:00
|
|
|
<View style={styles.walletRoot}>
|
2020-01-19 22:00:25 +01:00
|
|
|
{!this.state.isLoading && (
|
|
|
|
<TouchableOpacity
|
2020-05-24 11:17:26 +02:00
|
|
|
style={styles.walletChooseWrap}
|
2020-01-19 22:00:25 +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.walletChooseText}>{loc.wallets.select_wallet.toLowerCase()}</Text>
|
2020-01-19 22:00:25 +01:00
|
|
|
<Icon name="angle-right" size={18} type="font-awesome" color="#9aa0aa" />
|
|
|
|
</TouchableOpacity>
|
|
|
|
)}
|
2020-05-24 11:17:26 +02:00
|
|
|
<View style={styles.walletNameWrap}>
|
2020-01-19 22:00:25 +01:00
|
|
|
<TouchableOpacity
|
2020-05-24 11:17:26 +02:00
|
|
|
style={styles.walletNameTouch}
|
2020-01-19 22:00:25 +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.walletNameText}>{this.state.fromWallet.getLabel()}</Text>
|
|
|
|
<Text style={styles.walletNameBalance}>
|
2020-01-19 22:00:25 +01:00
|
|
|
{loc.formatBalanceWithoutSuffix(this.state.fromWallet.getBalance(), BitcoinUnit.SATS, false)}
|
|
|
|
</Text>
|
2020-05-24 11:17:26 +02:00
|
|
|
<Text style={styles.walletNameSats}>{BitcoinUnit.SATS}</Text>
|
2020-01-19 22:00:25 +01:00
|
|
|
</TouchableOpacity>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
onWalletSelect = wallet => {
|
|
|
|
this.setState({ fromWallet: wallet }, () => this.props.navigation.pop());
|
|
|
|
};
|
|
|
|
|
2018-12-25 17:34:51 +01:00
|
|
|
render() {
|
|
|
|
if (!this.state.fromWallet) {
|
|
|
|
return (
|
2020-05-24 11:17:26 +02:00
|
|
|
<View style={styles.error}>
|
2018-12-25 17:34:51 +01:00
|
|
|
<Text>System error: Source wallet not found (this should never happen)</Text>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false}>
|
2020-05-24 11:17:26 +02:00
|
|
|
<View 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.amount}>
|
2018-12-25 17:34:51 +01:00
|
|
|
<KeyboardAvoidingView behavior="position">
|
2019-01-06 08:42:53 +01:00
|
|
|
<BlueBitcoinAmount
|
|
|
|
isLoading={this.state.isLoading}
|
|
|
|
amount={this.state.amount}
|
2020-06-09 16:08:18 +02:00
|
|
|
onAmountUnitChange={unit => {
|
|
|
|
this.setState({ unit });
|
|
|
|
}}
|
2019-01-06 08:42:53 +01:00
|
|
|
onChangeText={text => {
|
2019-08-03 03:37:18 +02:00
|
|
|
if (this.state.lnurlParams) {
|
|
|
|
// in this case we prevent the user from changing the amount to < min or > max
|
2020-06-01 14:54:23 +02:00
|
|
|
const { min, max } = this.state.lnurlParams;
|
|
|
|
const nextAmount = parseInt(text);
|
2019-08-03 03:37:18 +02:00
|
|
|
if (nextAmount < min) {
|
2019-08-04 21:34:17 +02:00
|
|
|
text = min.toString();
|
2019-08-03 03:37:18 +02:00
|
|
|
} else if (nextAmount > max) {
|
2019-08-04 21:34:17 +02:00
|
|
|
text = max.toString();
|
2019-08-03 03:37:18 +02:00
|
|
|
}
|
2019-07-28 19:22:58 +02:00
|
|
|
}
|
2019-08-03 03:37:18 +02:00
|
|
|
|
2019-01-06 08:42:53 +01:00
|
|
|
this.setState({ amount: text });
|
|
|
|
}}
|
2019-08-03 03:37:18 +02:00
|
|
|
disabled={this.state.isLoading || (this.state.lnurlParams && this.state.lnurlParams.fixed)}
|
2020-06-09 16:08:18 +02:00
|
|
|
unit={this.state.unit}
|
2019-02-17 10:23:12 +01:00
|
|
|
inputAccessoryViewID={BlueDismissKeyboardInputAccessory.InputAccessoryViewID}
|
2019-01-06 08:42:53 +01:00
|
|
|
/>
|
2020-05-24 11:17:26 +02:00
|
|
|
<View style={styles.fiat}>
|
2018-12-25 17:34:51 +01:00
|
|
|
<TextInput
|
2019-01-06 08:42:53 +01:00
|
|
|
onChangeText={text => this.setState({ description: text })}
|
2019-01-01 01:41:15 +01:00
|
|
|
placeholder={loc.receive.details.label}
|
2019-01-06 08:42:53 +01:00
|
|
|
value={this.state.description}
|
2018-12-25 17:34:51 +01:00
|
|
|
numberOfLines={1}
|
2020-06-09 18:34:29 +02:00
|
|
|
placeholderTextColor="#81868e"
|
2020-05-24 11:17:26 +02:00
|
|
|
style={styles.fiat2}
|
2018-12-25 17:34:51 +01:00
|
|
|
editable={!this.state.isLoading}
|
2019-02-09 21:46:43 +01:00
|
|
|
onSubmitEditing={Keyboard.dismiss}
|
2019-02-17 10:23:12 +01:00
|
|
|
inputAccessoryViewID={BlueDismissKeyboardInputAccessory.InputAccessoryViewID}
|
2018-12-25 17:34:51 +01:00
|
|
|
/>
|
2019-12-13 06:28:01 +01:00
|
|
|
{this.state.lnurlParams ? null : this.renderScanClickable()}
|
2018-12-25 17:34:51 +01:00
|
|
|
</View>
|
2019-02-17 10:23:12 +01:00
|
|
|
<BlueDismissKeyboardInputAccessory />
|
2018-12-25 17:34:51 +01:00
|
|
|
{this.renderCreateButton()}
|
|
|
|
</KeyboardAvoidingView>
|
|
|
|
</View>
|
2020-01-19 22:00:25 +01:00
|
|
|
{this.renderWalletSelectionButton()}
|
2018-12-25 17:34:51 +01:00
|
|
|
</View>
|
|
|
|
</TouchableWithoutFeedback>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LNDCreateInvoice.propTypes = {
|
|
|
|
navigation: PropTypes.shape({
|
2019-02-01 16:28:43 +01:00
|
|
|
goBack: PropTypes.func,
|
2020-05-27 13:12:17 +02:00
|
|
|
dangerouslyGetParent: PropTypes.func,
|
2018-12-25 17:34:51 +01:00
|
|
|
navigate: PropTypes.func,
|
2020-01-19 22:00:25 +01:00
|
|
|
pop: PropTypes.func,
|
2020-05-27 13:12:17 +02:00
|
|
|
}),
|
|
|
|
route: PropTypes.shape({
|
|
|
|
name: PropTypes.string,
|
|
|
|
params: PropTypes.shape({
|
|
|
|
uri: PropTypes.string,
|
|
|
|
fromWallet: PropTypes.shape({}),
|
2019-09-11 01:53:48 +02:00
|
|
|
}),
|
2018-12-25 17:34:51 +01:00
|
|
|
}),
|
|
|
|
};
|
2020-07-15 19:32:59 +02:00
|
|
|
LNDCreateInvoice.navigationOptions = ({ navigation }) => ({
|
|
|
|
...BlueNavigationStyle(navigation, true),
|
|
|
|
headerTitle: loc.receive.header,
|
|
|
|
headerLeft: null,
|
|
|
|
});
|