Cancel propagated TX (#5899)

* lgtm

* linting

* Slight shortening
This commit is contained in:
Craig O'Connor 2017-06-23 02:32:19 -06:00 committed by Gav Wood
parent 796482c129
commit 614a80bd23
3 changed files with 42 additions and 2 deletions

View File

@ -47,7 +47,8 @@ class TxRow extends Component {
className: PropTypes.string, className: PropTypes.string,
cancelTransaction: PropTypes.func, cancelTransaction: PropTypes.func,
editTransaction: PropTypes.func, editTransaction: PropTypes.func,
historic: PropTypes.bool historic: PropTypes.bool,
killTransaction: PropTypes.func
}; };
static defaultProps = { static defaultProps = {
@ -368,8 +369,21 @@ class TxRow extends Component {
return 'pending'; return 'pending';
} }
killTx = () => {
const { killTransaction, tx } = this.props;
killTransaction(this, tx);
}
cancelTx = () => { cancelTx = () => {
const { cancelTransaction, tx } = this.props; const { cancelTransaction, tx } = this.props;
const pendingStatus = this.getCondition();
const isPending = pendingStatus === 'pending';
if (isPending) {
this.killTx();
return;
}
cancelTransaction(this, tx); cancelTransaction(this, tx);
} }

View File

@ -15,6 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
import { action, observable } from 'mobx'; import { action, observable } from 'mobx';
import BigNumber from 'bignumber.js';
export default class Store { export default class Store {
@observable blocks = {}; @observable blocks = {};
@ -125,6 +126,30 @@ export default class Store {
}); });
} }
killTransaction = (txComponent, tx) => {
const { hash, gasPrice, from } = tx;
this._api.parity
.removeTransaction(hash)
.then(() => {
return this._api.parity.postTransaction({
from: from,
to: from, // set to owner
gas: new BigNumber(21000), // set default gas
gasPrice: gasPrice.times(1.25), // must be a minimum of 10% growth to be recognized as a replacement by miners (incentive)
value: new BigNumber(0), // zero out the value
condition: null, // ensure to post this instantly
data: '0x'
});
})
.then(() => {
tx.Component.setState({ canceled: true });
})
.catch((err) => {
this._onNewError({ message: err });
});
}
editTransaction = (txComponent, tx) => { editTransaction = (txComponent, tx) => {
const { hash, gas, gasPrice, to, from, value, input, condition } = tx; const { hash, gas, gasPrice, to, from, value, input, condition } = tx;

View File

@ -60,7 +60,7 @@ class TxList extends Component {
renderRows () { renderRows () {
const { address, netVersion, blockNumber } = this.props; const { address, netVersion, blockNumber } = this.props;
const { editTransaction, cancelTransaction } = this.store; const { editTransaction, cancelTransaction, killTransaction } = this.store;
return this.store.sortedHashes.map((txhash) => { return this.store.sortedHashes.map((txhash) => {
const tx = this.store.transactions[txhash]; const tx = this.store.transactions[txhash];
@ -77,6 +77,7 @@ class TxList extends Component {
netVersion={ netVersion } netVersion={ netVersion }
editTransaction={ editTransaction } editTransaction={ editTransaction }
cancelTransaction={ cancelTransaction } cancelTransaction={ cancelTransaction }
killTransaction={ killTransaction }
/> />
); );
}); });