on master help sign in
chore: reticket: implement error restart & refactor send tx fns
217f1b6Matt Condon (shrugs)
src/lib/invite.js+6−2
@@ -9,7 +9,7 @@ import * as tank from './tank';
9import JSZip from 'jszip';
9import JSZip from 'jszip';
10import saveAs from 'file-saver';
10import saveAs from 'file-saver';
11
11
12−import { hexify, sendAndAwaitConfirm } from './txn';
12+import { hexify, sendTransactionsAndAwaitConfirm } from './txn';
13import { deriveNetworkSeedFromUrbitWallet } from './keys';
13import { deriveNetworkSeedFromUrbitWallet } from './keys';
14import { addHexPrefix } from './wallet';
14import { addHexPrefix } from './wallet';
15import { GAS_LIMITS } from './constants';
15import { GAS_LIMITS } from './constants';
@@ -241,7 +241,11 @@ export async function reticketPointBetweenWallets({
241
241
242 progress(TRANSACTION_STATES.TRANSFERRING);
242 progress(TRANSACTION_STATES.TRANSFERRING);
243
243
244+ await sendTransactionsAndAwaitConfirm(
245+ web3,
244− await sendAndAwaitConfirm(web3, txPairs.map(p => Just(p.signed)), usedTank);
246+ txPairs.map(p => Just(p.signed)),
247+ usedTank
248+ );
245
249
246 //
250 //
247 // move leftover eth
251 // move leftover eth
src/lib/txn.js+9−11
@@ -104,6 +104,8 @@ const signTransaction = async config => {
104 return stx;
104 return stx;
105};
105};
106
106
107+// TODO(shrugs): refactor the hell out of all of these functions
108+// but especially this one
107const sendSignedTransaction = (web3, stx, doubtNonceError, confirmationCb) => {
109const sendSignedTransaction = (web3, stx, doubtNonceError, confirmationCb) => {
108 const txn = stx.matchWith({
110 const txn = stx.matchWith({
109 Just: tx => tx.value,
111 Just: tx => tx.value,
@@ -125,7 +127,9 @@ const sendSignedTransaction = (web3, stx, doubtNonceError, confirmationCb) => {
125 // in on-transactionHash? we don't care (much) about additional
127 // in on-transactionHash? we don't care (much) about additional
126 // confirms anyway.
128 // confirms anyway.
127 .on('confirmation', (confirmationNum, txn) => {
129 .on('confirmation', (confirmationNum, txn) => {
130+ if (confirmationCb) {
128− confirmationCb(txn.transactionHash, confirmationNum + 1);
131+ confirmationCb(txn.transactionHash, confirmationNum + 1);
132+ }
129 resolve(txn.transactionHash);
133 resolve(txn.transactionHash);
130 })
134 })
131 .on('error', err => {
135 .on('error', err => {
@@ -177,15 +181,8 @@ const isTransactionConfirmed = async (web3, txHash) => {
177 return receipt !== null;
181 return receipt !== null;
178};
182};
179
183
180−async function sendAndAwaitConfirm(web3, signedTxs, usedTank) {
184+const sendTransactionsAndAwaitConfirm = async (web3, signedTxs, usedTank) =>
181− await Promise.all(
182− signedTxs.map(tx => {
183− return new Promise((resolve, reject) => {
184− sendSignedTransaction(web3, tx, usedTank, resolve);
185+ Promise.all(signedTxs.map(tx => sendSignedTransaction(web3, tx, usedTank)));
185− });
186− })
187− );
188−}
189
186
190const hexify = val => addHexPrefix(val.toString('hex'));
187const hexify = val => addHexPrefix(val.toString('hex'));
191
188
@@ -201,6 +198,7 @@ const getTxnInfo = async (web3, addr) => {
201 let nonce = await web3.eth.getTransactionCount(addr);
198 let nonce = await web3.eth.getTransactionCount(addr);
202 let chainId = await web3.eth.net.getId();
199 let chainId = await web3.eth.net.getId();
203 let gasPrice = await web3.eth.getGasPrice();
200 let gasPrice = await web3.eth.getGasPrice();
201+
204 return {
202 return {
205 nonce: nonce,
203 nonce: nonce,
206 chainId: chainId,
204 chainId: chainId,
@@ -222,7 +220,7 @@ export {
222 signTransaction,
220 signTransaction,
223 sendSignedTransaction,
221 sendSignedTransaction,
224 waitForTransactionConfirm,
222 waitForTransactionConfirm,
225− sendAndAwaitConfirm,
223+ sendTransactionsAndAwaitConfirm,
226 isTransactionConfirmed,
224 isTransactionConfirmed,
227 getTxnInfo,
225 getTxnInfo,
228 hexify,
226 hexify,
src/views/Admin/Reticket/ReticketExecute.js+9−4
@@ -1,5 +1,5 @@
1import React, { useState, useCallback } from 'react';
1import React, { useState, useCallback } from 'react';
2−import { Just } from 'folktale/maybe';
2+import { Just, Nothing } from 'folktale/maybe';
3import { Grid, H4, Text, ErrorText } from 'indigo-react';
3import { Grid, H4, Text, ErrorText } from 'indigo-react';
4
4
5import { reticketPointBetweenWallets } from 'lib/invite';
5import { reticketPointBetweenWallets } from 'lib/invite';
@@ -19,8 +19,8 @@ import Highlighted from 'components/Highlighted';
19import { WALLET_TYPES } from 'lib/wallet';
19import { WALLET_TYPES } from 'lib/wallet';
20
20
21// TODO: maybe we can merge PassportTransfer here?
21// TODO: maybe we can merge PassportTransfer here?
22−export default function ReticketExecute({ newWallet }) {
22+export default function ReticketExecute({ newWallet, setNewWallet }) {
23− const { popTo, names } = useHistory();
23+ const { popTo, names, reset } = useHistory();
24 const { web3, contracts } = useNetwork();
24 const { web3, contracts } = useNetwork();
25 const { wallet, setWalletType, resetWallet, setUrbitWallet } = useWallet();
25 const { wallet, setWalletType, resetWallet, setUrbitWallet } = useWallet();
26 const { pointCursor } = usePointCursor();
26 const { pointCursor } = usePointCursor();
@@ -51,6 +51,11 @@ export default function ReticketExecute({ newWallet }) {
51 })();
51 })();
52 });
52 });
53
53
54+ const goToRestart = useCallback(() => {
55+ reset();
56+ setNewWallet(Nothing());
57+ }, [reset, setNewWallet]);
58+
54 const loginAndGoHome = useCallback(() => {
59 const loginAndGoHome = useCallback(() => {
55 // set wallet state
60 // set wallet state
56 resetWallet();
61 resetWallet();
@@ -88,7 +93,7 @@ export default function ReticketExecute({ newWallet }) {
88 full
93 full
89 className="mt3"
94 className="mt3"
90 as={RestartButton}
95 as={RestartButton}
91− //TODO onClick={goToRestart}
96+ onClick={goToRestart}
92 />
97 />
93 </>
98 </>
94 );
99 );
src/views/Invite/InviteEmail.js+1−2
@@ -301,8 +301,7 @@ export default function InviteEmail() {
301 const txHash = await sendSignedTransaction(
301 const txHash = await sendSignedTransaction(
302 _web3,
302 _web3,
303 Just(invite.signedTx),
303 Just(invite.signedTx),
304− tankWasUsed,
304+ tankWasUsed
305− () => {}
306 );
305 );
307
306
308 // TODO: waitForTransactionConfirm never rejects
307 // TODO: waitForTransactionConfirm never rejects
src/views/Point.js−1
@@ -4,7 +4,6 @@ import * as need from 'lib/need';
4import { Grid } from 'indigo-react';
4import { Grid } from 'indigo-react';
5
5
6import { usePointCursor } from 'store/pointCursor';
6import { usePointCursor } from 'store/pointCursor';
7−import { usePointCache } from 'store/pointCache';
8import { useHistory } from 'store/history';
7import { useHistory } from 'store/history';
9
8
10import View from 'components/View';
9import View from 'components/View';