diff --git a/views/Send.tsx b/views/Send.tsx index ebce3144b..950498c8e 100644 --- a/views/Send.tsx +++ b/views/Send.tsx @@ -95,6 +95,8 @@ interface SendState { contactName: string; contacts: Contact[]; clearOnBackPress: boolean; + feeOption: string; + maxFeePercent: string; } @inject( @@ -148,13 +150,16 @@ export default class Send extends React.Component { loading: false, contactName, contacts: [], - clearOnBackPress + clearOnBackPress, + feeOption: 'fixed', + maxFeePercent: '5.0' }; } async UNSAFE_componentWillMount() { const { SettingsStore } = this.props; - const { settings } = SettingsStore; + const { getSettings } = SettingsStore; + const settings = await getSettings(); if (settings.privacy && settings.privacy.clipboard) { const clipboard = await Clipboard.getString(); @@ -166,6 +171,11 @@ export default class Send extends React.Component { } if (this.listener && this.listener.stop) this.listener.stop(); + + this.setState({ + feeLimitSat: settings?.payments?.defaultFeeFixed || '100', + maxFeePercent: settings?.payments?.defaultFeePercentage || '5.0' + }); } UNSAFE_componentWillReceiveProps(nextProps: any) { @@ -386,18 +396,26 @@ export default class Send extends React.Component { navigation.navigate('SendingOnChain'); }; - sendKeySendPayment = (satAmount: string | number) => { + sendKeySendPayment = ( + satAmount: string | number, + percentAmount?: string | number + ) => { const { TransactionsStore, SettingsStore, navigation } = this.props; const { implementation } = SettingsStore; const { destination, maxParts, maxShardAmt, - feeLimitSat, message, - enableAtomicMultiPathPayment + enableAtomicMultiPathPayment, + feeOption } = this.state; + const feeLimitSat = + feeOption == 'percent' && percentAmount + ? percentAmount.toString() + : this.state.feeLimitSat; + let streamingCall; if (enableAtomicMultiPathPayment) { streamingCall = TransactionsStore.sendPayment({ @@ -569,7 +587,9 @@ export default class Send extends React.Component { clipboard, loading, contactName, - contacts + contacts, + feeOption, + maxFeePercent } = this.state; const { confirmedBlockchainBalance, @@ -591,6 +611,19 @@ export default class Send extends React.Component { (contact: Contact) => contact.isFavourite ); + const isLnd: boolean = BackendUtils.isLNDBased(); + const isCLightning: boolean = implementation === 'c-lightning-REST'; + + // handle fee percents that use commas + const maxFeePercentFormatted = maxFeePercent.replace(/,/g, '.'); + + const percentAmount = satAmount + ? ( + Number(satAmount) * + (Number(maxFeePercentFormatted) / 100) + ).toFixed() + : 0; + return (
{ }} /> - {BackendUtils.supportsAMP() && ( + + {`${localeString( + 'views.Send.message' + )} (${localeString('general.optional')})`} + + + this.setState({ + message: text + }) + } + /> + + {isLnd && ( + <> + + {localeString( + 'views.PaymentRequest.feeLimit' + )} + + + + + + + + + this.setState({ + feeLimitSat: text + }) + } + onPressIn={() => + this.setState({ + feeOption: 'fixed' + }) + } + /> + + {localeString('general.sats')} + + + this.setState({ + maxFeePercent: text + }) + } + onPressIn={() => + this.setState({ + feeOption: 'percent' + }) + } + /> + + {'%'} + + + + )} + + {isCLightning && ( { }) } /> - - {`${localeString( - 'views.Send.message' - )} (${localeString( - 'general.optional' - )})`} - - - this.setState({ - message: text - }) - } - /> + + )} + + {BackendUtils.supportsAMP() && ( + { : themeColor('background') }} onPress={() => - this.sendKeySendPayment(satAmount) + this.sendKeySendPayment( + satAmount, + percentAmount + ) } disabled={lightningBalance === 0} />