diff --git a/src/component/modalTipView/index.js b/src/component/modalTipView/index.js new file mode 100644 index 0000000..7eaf6e6 --- /dev/null +++ b/src/component/modalTipView/index.js @@ -0,0 +1,18 @@ +import { connect } from 'react-redux'; +import { doSendTip, doToast, selectBalance } from 'lbry-redux'; +import ModalTipView from './view'; + +const select = state => ({ + balance: selectBalance(state), +}); + +const perform = dispatch => ({ + notify: data => dispatch(doToast(data)), + sendTip: (amount, claimId, isSupport, successCallback, errorCallback) => + dispatch(doSendTip(amount, claimId, isSupport, successCallback, errorCallback)), +}); + +export default connect( + select, + perform +)(ModalTipView); diff --git a/src/component/modalTipView/view.js b/src/component/modalTipView/view.js new file mode 100644 index 0000000..301a225 --- /dev/null +++ b/src/component/modalTipView/view.js @@ -0,0 +1,139 @@ +import React from 'react'; +import { ActivityIndicator, Alert, Text, TextInput, TouchableOpacity, View } from 'react-native'; +import { formatCredits } from 'lbry-redux'; +import modalStyle from 'styles/modal'; +import modalTipStyle from 'styles/modalTip'; +import Button from 'component/button'; +import Colors from 'styles/colors'; +import Constants from 'constants'; // eslint-disable-line node/no-deprecated-api +import Icon from 'react-native-vector-icons/FontAwesome5'; +import Link from 'component/link'; + +export default class ModalTipView extends React.PureComponent { + state = { + creditsInputFocused: false, + sendTipStarted: false, + tipAmount: null, + }; + + handleSendTip = () => { + const { claim, balance, notify, onSendTipFailed, onSendTipSuccessful, sendTip } = this.props; + const { tipAmount } = this.state; + + if (tipAmount > balance) { + notify({ + message: 'Insufficient credits', + }); + return; + } + + const amount = parseInt(tipAmount, 10); + const message = + amount === 1 + ? __('Are you sure you want to tip %amount% credit', { amount }) + : __('Are you sure you want to tip %amount% credits', { amount }); + + Alert.alert( + __('Send tip'), + message, + [ + { text: __('No') }, + { + text: __('Yes'), + onPress: () => { + this.setState({ sendTipStarted: true }, () => + sendTip( + tipAmount, + claim.claim_id, + false, + () => { + // success + this.setState({ tipAmount: null, sendTipStarted: false }); + if (onSendTipSuccessful) onSendTipSuccessful(); + }, + () => { + // error + if (onSendTipFailed) onSendTipFailed(); + } + ) + ); + }, + }, + ], + { cancelable: true } + ); + }; + + render() { + const { balance, channelName, contentName, onCancelPress, onOverlayPress } = this.props; + const canSendTip = this.state.tipAmount > 0; + + return ( + + + + + {channelName ? __('Send a tip to %channel%', { channel: channelName }) : __('Send a tip')} + + + + + (this.tipAmountInput = ref)} + onChangeText={value => this.setState({ tipAmount: value })} + underlineColorAndroid={Colors.NextLbryGreen} + keyboardType={'numeric'} + onFocus={() => this.setState({ creditsInputFocused: true })} + onBlur={() => this.setState({ creditsInputFocused: false })} + placeholder={'0'} + value={this.state.tipAmount} + selectTextOnFocus + style={modalTipStyle.tipAmountInput} + /> + LBC + + {this.state.creditsInputFocused && } + {this.state.creditsInputFocused && ( + {formatCredits(parseFloat(balance), 1, true)} + )} + + + {this.state.sendTipStarted && } + + + + + {__( + 'This will appear as a tip for %content%, which will boost its ability to be discovered while active.', + { content: contentName } + )} + + + + + + { + if (onCancelPress) onCancelPress(); + }} + /> +