on master help sign in
Add beforeSend prop to StatelessTransaction

If set, will be called prior to funding & sending transaction. If it returns false, this will abort the transaction sending.

commit968321a2e767f91d351c6c53f792dede9be2a594 authorFang <git@fang.io> dateThu 9 May 2019, 21:28 (7 years ago) parent6f3da79
1 file changed+19−2
src/bridge/components/StatelessTransaction.js+19−2
src/bridge/components/StatelessTransaction.js+19−2
@@ -25,6 +25,7 @@ import {
2525
2626const SUBMISSION_STATES = {
2727 PROMPT: 'Send transaction',
28+ PREPARING: 'Preparing...',
2829 FUNDING: 'Finding transaction funding...',
2930 SENDING: 'Sending transaction...'
3031};
@@ -183,14 +184,30 @@ class StatelessTransaction extends React.Component {
183184 const { props, state } = this;
184185 const web3 = props.web3.value;
185186
186− this.setState({ txStatus: SUBMISSION_STATES.FUNDING });
187−
188187 const stx = state.stx.matchWith({
189188 Just: tx => tx.value,
190189 Nothing: () => {
191190 throw BRIDGE_ERROR.MISSING_TXN;
192191 }
193192 });
193+
194+ if (props.beforeSend) {
195+ try {
196+ this.setState({ txStatus: SUBMISSION_STATES.PREPARING });
197+ const res = await props.beforeSend(stx);
198+ if (res === false) throw 'beforeSend disallowed sending';
199+ } catch (e) {
200+ console.log('beforeSend error', e);
201+ this.setState({
202+ txStatus: SUBMISSION_STATES.PROMPT,
203+ txError: Just('Something went wrong!')
204+ });
205+ return;
206+ }
207+ }
208+
209+ this.setState({ txStatus: SUBMISSION_STATES.FUNDING });
210+
194211 const rawTx = hexify(stx.serialize());
195212 const cost = (state.gasLimit * toWei(state.gasPrice, 'gwei'));
196213