import React, { Component } from 'react'; import { ActivityIndicator, View, TextInput, KeyboardAvoidingView, Keyboard, TouchableWithoutFeedback, Text } from 'react-native'; import { BlueNavigationStyle, BlueButton } from '../../BlueComponents'; import PropTypes from 'prop-types'; import { BitcoinUnit } from '../../models/bitcoinUnits'; import ReactNativeHapticFeedback from 'react-native-haptic-feedback'; let EV = require('../../events'); let loc = require('../../loc'); export default class LNDCreateInvoice extends Component { static navigationOptions = ({ navigation }) => ({ ...BlueNavigationStyle(navigation, true), title: loc.receive.header, }); constructor(props) { super(props); // fallback to first wallet if it exists const fromWallet = props.navigation.getParam('fromWallet'); this.state = { fromWallet, memo: '', isLoading: false, }; } async createInvoice() { this.setState({ isLoading: true }, async () => { const invoiceRequest = await this.state.fromWallet.addInvoice(this.state.amount, this.state.memo); if (invoiceRequest === null) { ReactNativeHapticFeedback.trigger('notificationError', false); } else { EV(EV.enum.TRANSACTIONS_COUNT_CHANGED); ReactNativeHapticFeedback.trigger('notificationSuccess', false); this.props.navigation.navigate('LNDViewInvoice', { invoice: invoiceRequest, fromWallet: this.state.fromWallet, }); } this.setState({ isLoading: false }); }); } renderCreateButton = () => { return ( {this.state.isLoading ? ( ) : ( 0 && this.state.memo.length > 0)} onPress={() => this.createInvoice()} title={loc.send.details.create} /> )} ); }; render() { if (!this.state.fromWallet) { return ( System error: Source wallet not found (this should never happen) ); } return ( this.setState({ amount: text.replace(',', '').replace('.', '') })} placeholder="0" maxLength={10} editable={!this.state.isLoading} value={this.state.amount} placeholderTextColor="#0f5cc0" style={{ color: '#0f5cc0', fontSize: 36, fontWeight: '600', }} /> {' ' + 'satoshis'} {loc.formatBalance( loc.formatBalanceWithoutSuffix(this.state.amount || 0, BitcoinUnit.BTC) || 0, BitcoinUnit.LOCAL_CURRENCY, )} this.setState({ memo: text })} placeholder={loc.receive.details.label} value={this.state.memo} numberOfLines={1} style={{ flex: 1, marginHorizontal: 8, minHeight: 33 }} editable={!this.state.isLoading} /> {this.renderCreateButton()} ); } } LNDCreateInvoice.propTypes = { navigation: PropTypes.shape({ goBack: PropTypes.function, navigate: PropTypes.func, getParam: PropTypes.func, }), };