on master help sign in
Add beforeSend prop to StatelessTransaction
968321aFang
src/bridge/components/StatelessTransaction.js+19−2
@@ -25,6 +25,7 @@ import {
25
25
26const SUBMISSION_STATES = {
26const SUBMISSION_STATES = {
27 PROMPT: 'Send transaction',
27 PROMPT: 'Send transaction',
28+ PREPARING: 'Preparing...',
28 FUNDING: 'Finding transaction funding...',
29 FUNDING: 'Finding transaction funding...',
29 SENDING: 'Sending transaction...'
30 SENDING: 'Sending transaction...'
30};
31};
@@ -183,14 +184,30 @@ class StatelessTransaction extends React.Component {
183 const { props, state } = this;
184 const { props, state } = this;
184 const web3 = props.web3.value;
185 const web3 = props.web3.value;
185
186
186− this.setState({ txStatus: SUBMISSION_STATES.FUNDING });
187−
188 const stx = state.stx.matchWith({
187 const stx = state.stx.matchWith({
189 Just: tx => tx.value,
188 Just: tx => tx.value,
190 Nothing: () => {
189 Nothing: () => {
191 throw BRIDGE_ERROR.MISSING_TXN;
190 throw BRIDGE_ERROR.MISSING_TXN;
192 }
191 }
193 });
192 });
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+
194 const rawTx = hexify(stx.serialize());
211 const rawTx = hexify(stx.serialize());
195 const cost = (state.gasLimit * toWei(state.gasPrice, 'gwei'));
212 const cost = (state.gasLimit * toWei(state.gasPrice, 'gwei'));
196
213