on master help sign in
chore: reticket: implement error restart & refactor send tx fns
commit217f1b6ed834ed49023e0cee74767a3198e19d20 authorMatt Condon (shrugs) <mattgcondon@gmail.com> dateTue 9 Jul 2019, 14:12 (7 years ago) parentd1230bb
5 files changed+25−20
src/lib/invite.js+6−2 src/lib/txn.js+9−11 src/views/Admin/Reticket/ReticketExecute.js+9−4 src/views/Invite/InviteEmail.js+1−2 src/views/Point.js−1
src/lib/invite.js+6−2
@@ -9,7 +9,7 @@ import * as tank from './tank';
99import JSZip from 'jszip';
1010import saveAs from 'file-saver';
1111
12−import { hexify, sendAndAwaitConfirm } from './txn';
12+import { hexify, sendTransactionsAndAwaitConfirm } from './txn';
1313import { deriveNetworkSeedFromUrbitWallet } from './keys';
1414import { addHexPrefix } from './wallet';
1515import { GAS_LIMITS } from './constants';
@@ -241,7 +241,11 @@ export async function reticketPointBetweenWallets({
241241
242242 progress(TRANSACTION_STATES.TRANSFERRING);
243243
244− await sendAndAwaitConfirm(web3, txPairs.map(p => Just(p.signed)), usedTank);
244+ await sendTransactionsAndAwaitConfirm(
245+ web3,
246+ txPairs.map(p => Just(p.signed)),
247+ usedTank
248+ );
245249
246250 //
247251 // move leftover eth
src/lib/txn.js+9−11
@@ -104,6 +104,8 @@ const signTransaction = async config => {
104104 return stx;
105105};
106106
107+// TODO(shrugs): refactor the hell out of all of these functions
108+// but especially this one
107109const sendSignedTransaction = (web3, stx, doubtNonceError, confirmationCb) => {
108110 const txn = stx.matchWith({
109111 Just: tx => tx.value,
@@ -125,7 +127,9 @@ const sendSignedTransaction = (web3, stx, doubtNonceError, confirmationCb) => {
125127 // in on-transactionHash? we don't care (much) about additional
126128 // confirms anyway.
127129 .on('confirmation', (confirmationNum, txn) => {
128− confirmationCb(txn.transactionHash, confirmationNum + 1);
130+ if (confirmationCb) {
131+ confirmationCb(txn.transactionHash, confirmationNum + 1);
132+ }
129133 resolve(txn.transactionHash);
130134 })
131135 .on('error', err => {
@@ -177,15 +181,8 @@ const isTransactionConfirmed = async (web3, txHash) => {
177181 return receipt !== null;
178182};
179183
180−async function sendAndAwaitConfirm(web3, signedTxs, usedTank) {
181− await Promise.all(
182− signedTxs.map(tx => {
183− return new Promise((resolve, reject) => {
184− sendSignedTransaction(web3, tx, usedTank, resolve);
185− });
186− })
187− );
188−}
184+const sendTransactionsAndAwaitConfirm = async (web3, signedTxs, usedTank) =>
185+ Promise.all(signedTxs.map(tx => sendSignedTransaction(web3, tx, usedTank)));
189186
190187const hexify = val => addHexPrefix(val.toString('hex'));
191188
@@ -201,6 +198,7 @@ const getTxnInfo = async (web3, addr) => {
201198 let nonce = await web3.eth.getTransactionCount(addr);
202199 let chainId = await web3.eth.net.getId();
203200 let gasPrice = await web3.eth.getGasPrice();
201+
204202 return {
205203 nonce: nonce,
206204 chainId: chainId,
@@ -222,7 +220,7 @@ export {
222220 signTransaction,
223221 sendSignedTransaction,
224222 waitForTransactionConfirm,
225− sendAndAwaitConfirm,
223+ sendTransactionsAndAwaitConfirm,
226224 isTransactionConfirmed,
227225 getTxnInfo,
228226 hexify,
src/views/Admin/Reticket/ReticketExecute.js+9−4
@@ -1,5 +1,5 @@
11import React, { useState, useCallback } from 'react';
2−import { Just } from 'folktale/maybe';
2+import { Just, Nothing } from 'folktale/maybe';
33import { Grid, H4, Text, ErrorText } from 'indigo-react';
44
55import { reticketPointBetweenWallets } from 'lib/invite';
@@ -19,8 +19,8 @@ import Highlighted from 'components/Highlighted';
1919import { WALLET_TYPES } from 'lib/wallet';
2020
2121// TODO: maybe we can merge PassportTransfer here?
22−export default function ReticketExecute({ newWallet }) {
23− const { popTo, names } = useHistory();
22+export default function ReticketExecute({ newWallet, setNewWallet }) {
23+ const { popTo, names, reset } = useHistory();
2424 const { web3, contracts } = useNetwork();
2525 const { wallet, setWalletType, resetWallet, setUrbitWallet } = useWallet();
2626 const { pointCursor } = usePointCursor();
@@ -51,6 +51,11 @@ export default function ReticketExecute({ newWallet }) {
5151 })();
5252 });
5353
54+ const goToRestart = useCallback(() => {
55+ reset();
56+ setNewWallet(Nothing());
57+ }, [reset, setNewWallet]);
58+
5459 const loginAndGoHome = useCallback(() => {
5560 // set wallet state
5661 resetWallet();
@@ -88,7 +93,7 @@ export default function ReticketExecute({ newWallet }) {
8893 full
8994 className="mt3"
9095 as={RestartButton}
91− //TODO onClick={goToRestart}
96+ onClick={goToRestart}
9297 />
9398 </>
9499 );
src/views/Invite/InviteEmail.js+1−2
@@ -301,8 +301,7 @@ export default function InviteEmail() {
301301 const txHash = await sendSignedTransaction(
302302 _web3,
303303 Just(invite.signedTx),
304− tankWasUsed,
305− () => {}
304+ tankWasUsed
306305 );
307306
308307 // TODO: waitForTransactionConfirm never rejects
src/views/Point.js−1
@@ -4,7 +4,6 @@ import * as need from 'lib/need';
44import { Grid } from 'indigo-react';
55
66import { usePointCursor } from 'store/pointCursor';
7−import { usePointCache } from 'store/pointCache';
87import { useHistory } from 'store/history';
98
109import View from 'components/View';