2019-07-14 12:40:31 +01:00
|
|
|
import React from 'react';
|
2020-09-14 13:49:08 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2020-05-24 12:17:26 +03:00
|
|
|
import { ActivityIndicator, View, ScrollView, StyleSheet } from 'react-native';
|
2020-12-25 19:09:53 +03:00
|
|
|
import navigationStyle from '../../components/navigationStyle';
|
|
|
|
import { BlueSpacing20, SafeBlueArea, BlueText } from '../../BlueComponents';
|
2019-07-14 12:40:31 +01:00
|
|
|
import { HDSegwitBech32Transaction, HDSegwitBech32Wallet } from '../../class';
|
|
|
|
import CPFP from './CPFP';
|
2020-07-20 16:38:46 +03:00
|
|
|
import loc from '../../loc';
|
2020-10-24 13:20:59 -04:00
|
|
|
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
2021-10-04 02:02:33 -04:00
|
|
|
import alert from '../../components/Alert';
|
2019-07-14 12:40:31 +01:00
|
|
|
|
2020-05-24 12:17:26 +03:00
|
|
|
const styles = StyleSheet.create({
|
|
|
|
root: {
|
|
|
|
flex: 1,
|
|
|
|
paddingTop: 16,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2019-07-14 12:40:31 +01:00
|
|
|
export default class RBFBumpFee extends CPFP {
|
2020-10-24 13:20:59 -04:00
|
|
|
static contextType = BlueStorageContext;
|
|
|
|
|
2019-07-14 12:40:31 +01:00
|
|
|
async componentDidMount() {
|
|
|
|
console.log('transactions/RBFBumpFee - componentDidMount');
|
|
|
|
this.setState({
|
|
|
|
isLoading: true,
|
|
|
|
newFeeRate: '',
|
|
|
|
nonReplaceable: false,
|
|
|
|
});
|
|
|
|
await this.checkPossibilityOfRBFBumpFee();
|
|
|
|
}
|
|
|
|
|
|
|
|
async checkPossibilityOfRBFBumpFee() {
|
|
|
|
if (this.state.wallet.type !== HDSegwitBech32Wallet.type) {
|
|
|
|
return this.setState({ nonReplaceable: true, isLoading: false });
|
|
|
|
}
|
|
|
|
|
2020-06-01 15:54:23 +03:00
|
|
|
const tx = new HDSegwitBech32Transaction(null, this.state.txid, this.state.wallet);
|
2019-07-14 12:40:31 +01:00
|
|
|
if ((await tx.isOurTransaction()) && (await tx.getRemoteConfirmationsNum()) === 0 && (await tx.isSequenceReplaceable())) {
|
2020-06-01 15:54:23 +03:00
|
|
|
const info = await tx.getInfo();
|
2019-07-14 12:40:31 +01:00
|
|
|
return this.setState({ nonReplaceable: false, feeRate: info.feeRate + 1, isLoading: false, tx });
|
|
|
|
// 1 sat makes a lot of difference, since sometimes because of rounding created tx's fee might be insufficient
|
|
|
|
} else {
|
|
|
|
return this.setState({ nonReplaceable: true, isLoading: false });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async createTransaction() {
|
|
|
|
const newFeeRate = parseInt(this.state.newFeeRate);
|
|
|
|
if (newFeeRate > this.state.feeRate) {
|
|
|
|
/** @type {HDSegwitBech32Transaction} */
|
|
|
|
const tx = this.state.tx;
|
|
|
|
this.setState({ isLoading: true });
|
|
|
|
try {
|
2020-06-01 15:54:23 +03:00
|
|
|
const { tx: newTx } = await tx.createRBFbumpFee(newFeeRate);
|
2019-07-14 12:40:31 +01:00
|
|
|
this.setState({ stage: 2, txhex: newTx.toHex(), newTxid: newTx.getId() });
|
|
|
|
this.setState({ isLoading: false });
|
|
|
|
} catch (_) {
|
|
|
|
this.setState({ isLoading: false });
|
2020-07-20 16:38:46 +03:00
|
|
|
alert(loc.errors.error + ': ' + _.message);
|
2019-07-14 12:40:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onSuccessBroadcast() {
|
|
|
|
// porting memo from old tx:
|
2020-10-24 13:20:59 -04:00
|
|
|
if (this.context.txMetadata[this.state.txid]) {
|
|
|
|
this.context.txMetadata[this.state.newTxid] = this.context.txMetadata[this.state.txid];
|
2019-07-14 12:40:31 +01:00
|
|
|
}
|
2020-12-02 00:45:56 -05:00
|
|
|
this.context.sleep(4000).then(() => this.context.fetchAndSaveWalletTransactions(this.state.wallet.getID()));
|
2020-11-22 02:41:59 -05:00
|
|
|
this.props.navigation.navigate('Success', { onDonePressed: () => this.props.navigation.popToTop(), amount: undefined });
|
2019-07-14 12:40:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
if (this.state.isLoading) {
|
|
|
|
return (
|
2020-05-24 12:17:26 +03:00
|
|
|
<View style={styles.root}>
|
2019-07-14 12:40:31 +01:00
|
|
|
<ActivityIndicator />
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.state.stage === 2) {
|
|
|
|
return this.renderStage2();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.state.nonReplaceable) {
|
|
|
|
return (
|
2020-05-24 12:17:26 +03:00
|
|
|
<SafeBlueArea style={styles.root}>
|
2019-07-14 12:40:31 +01:00
|
|
|
<BlueSpacing20 />
|
|
|
|
<BlueSpacing20 />
|
|
|
|
<BlueSpacing20 />
|
|
|
|
<BlueSpacing20 />
|
|
|
|
<BlueSpacing20 />
|
|
|
|
|
2020-07-20 16:38:46 +03:00
|
|
|
<BlueText h4>{loc.transactions.cpfp_no_bump}</BlueText>
|
2019-07-14 12:40:31 +01:00
|
|
|
</SafeBlueArea>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-05-15 12:41:57 +02:00
|
|
|
return (
|
2020-05-24 12:17:26 +03:00
|
|
|
<SafeBlueArea style={styles.root}>
|
2020-07-20 16:38:46 +03:00
|
|
|
<ScrollView>{this.renderStage1(loc.transactions.rbf_explain)}</ScrollView>
|
2020-05-15 13:07:08 +02:00
|
|
|
</SafeBlueArea>
|
|
|
|
);
|
2019-07-14 12:40:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RBFBumpFee.propTypes = {
|
|
|
|
navigation: PropTypes.shape({
|
|
|
|
popToTop: PropTypes.func,
|
|
|
|
navigate: PropTypes.func,
|
|
|
|
state: PropTypes.shape({
|
|
|
|
params: PropTypes.shape({
|
|
|
|
txid: PropTypes.string,
|
|
|
|
wallet: PropTypes.object,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
};
|
2021-02-15 11:03:54 +03:00
|
|
|
RBFBumpFee.navigationOptions = navigationStyle({}, opts => ({ ...opts, title: loc.transactions.rbf_title }));
|