on master help sign in
fix: update InviteTicket to correctly execute txs, correct sendMail logic
df46115Matt Condon (shrugs)
src/lib/invite.js+8−5
@@ -191,7 +191,7 @@ async function startTransactions(args) {
191 });
191 });
192
192
193 // send transaction
193 // send transaction
194− await sendAndAwaitConfirm(web3, [rawTransferStx], usedTank);
194+ await sendAndAwaitConfirm(web3, [Just(transferStx)], usedTank);
195
195
196 //
196 //
197 // we're gonna be operating as the new wallet from here on out, so change
197 // we're gonna be operating as the new wallet from here on out, so change
@@ -249,10 +249,13 @@ async function startTransactions(args) {
249 return tx;
249 return tx;
250 });
250 });
251
251
252− let rawStxs = txs.map(tx => {
252+ let txPairs = txs.map(tx => {
253 let stx = new Tx(tx);
253 let stx = new Tx(tx);
254 stx.sign(Buffer.from(realWallet.ownership.keys.private, 'hex'));
254 stx.sign(Buffer.from(realWallet.ownership.keys.private, 'hex'));
255+ return {
255− return '0x' + stx.serialize().toString('hex');
256+ raw: '0x' + stx.serialize().toString('hex'),
257+ signed: stx,
258+ };
256 });
259 });
257
260
258 updateProgress({
261 updateProgress({
@@ -264,7 +267,7 @@ async function startTransactions(args) {
264 point,
267 point,
265 newAddress,
268 newAddress,
266 totalCost,
269 totalCost,
267− rawStxs,
270+ txPairs.map(p => p.raw),
268 askForFunding
271 askForFunding
269 );
272 );
270
273
@@ -273,7 +276,7 @@ async function startTransactions(args) {
273 value: TRANSACTION_STATES.CONFIGURING,
276 value: TRANSACTION_STATES.CONFIGURING,
274 });
277 });
275
278
276− await sendAndAwaitConfirm(web3, rawStxs, usedTank);
279+ await sendAndAwaitConfirm(web3, txPairs.map(p => Just(p.signed)), usedTank);
277
280
278 updateProgress({
281 updateProgress({
279 type: 'progress',
282 type: 'progress',
src/lib/need.js+1−2
@@ -22,8 +22,7 @@ export const wallet = needBuilder(BRIDGE_ERROR.MISSING_WALLET);
22export const addressFromWallet = obj => wallet(obj).address;
22export const addressFromWallet = obj => wallet(obj).address;
23export const pointCursor = needBuilder(BRIDGE_ERROR.MISSING_POINT);
23export const pointCursor = needBuilder(BRIDGE_ERROR.MISSING_POINT);
24export const pointCache = needBuilder(BRIDGE_ERROR.MISSING_POINT);
24export const pointCache = needBuilder(BRIDGE_ERROR.MISSING_POINT);
25−export const fromPointCache = (obj, point) => {
25+export const fromPointCache = (cache, point) => {
26− const cache = pointCache(obj);
27 if (!(point in cache)) {
26 if (!(point in cache)) {
28 throw BRIDGE_ERROR.MISSING_POINT;
27 throw BRIDGE_ERROR.MISSING_POINT;
29 }
28 }
src/lib/txn.js+4−1
@@ -9,6 +9,9 @@ import { ledgerSignTransaction } from './ledger';
9import { trezorSignTransaction } from './trezor';
9import { trezorSignTransaction } from './trezor';
10import { WALLET_TYPES, addHexPrefix } from './wallet';
10import { WALLET_TYPES, addHexPrefix } from './wallet';
11
11
12+const kAverageBlockTimeMs =
13+ process.env.NODE_ENV === 'development' ? 1000 : 13000;
14+
12const TXN_PURPOSE = {
15const TXN_PURPOSE = {
13 SET_MANAGEMENT_PROXY: Symbol('SET_MANAGEMENT_PROXY'),
16 SET_MANAGEMENT_PROXY: Symbol('SET_MANAGEMENT_PROXY'),
14 SET_TRANSFER_PROXY: Symbol('SET_TRANSFER_PROXY'),
17 SET_TRANSFER_PROXY: Symbol('SET_TRANSFER_PROXY'),
@@ -194,7 +197,7 @@ const waitForTransactionConfirm = (web3, txHash) => {
194 console.log('tried, got', receipt);
197 console.log('tried, got', receipt);
195 let confirmed = receipt !== null;
198 let confirmed = receipt !== null;
196 if (confirmed) resolve(receipt.status === true);
199 if (confirmed) resolve(receipt.status === true);
197− else setTimeout(checkForConfirm, 13000);
200+ else setTimeout(checkForConfirm, kAverageBlockTimeMs);
198 };
201 };
199 checkForConfirm();
202 checkForConfirm();
200 });
203 });
src/lib/useMailer.js+1
@@ -39,6 +39,7 @@ export default function useMailer(emails) {
39 const hasReceivedCache = useHasReceivedCache(emails);
39 const hasReceivedCache = useHasReceivedCache(emails);
40
40
41 // prefix to avoid clobbering sendMail import
41 // prefix to avoid clobbering sendMail import
42+ // also throws if return value is false
42 const _sendMail = useCallback(async (email, ticket, rawTx) => {
43 const _sendMail = useCallback(async (email, ticket, rawTx) => {
43 if (kStubMailer) {
44 if (kStubMailer) {
44 console.log(`${email} - ${ticket}`);
45 console.log(`${email} - ${ticket}`);
src/store/lib/useInvitesStore.js+1−2
@@ -47,13 +47,12 @@ export default function useInvitesStore() {
47 );
47 );
48 const invitedPointDetails = await Promise.all(
48 const invitedPointDetails = await Promise.all(
49 invitedPoints.map(async invitedPoint => {
49 invitedPoints.map(async invitedPoint => {
50− console.log('invitedPoint', invitedPoint, typeof invitedPoint);
51 const active = await azimuth.azimuth.isActive(
50 const active = await azimuth.azimuth.isActive(
52 _contracts,
51 _contracts,
53 invitedPoint
52 invitedPoint
54 );
53 );
55 return {
54 return {
56− point: Number(invitedPoint),
55+ point: invitedPoint,
57 active,
56 active,
58 };
57 };
59 })
58 })
src/views/Invite/InviteEmail.js+9−7
@@ -196,7 +196,7 @@ export default function InviteEmail() {
196 // composing our target list
196 // composing our target list
197 if (planets.length < inputs.length) {
197 if (planets.length < inputs.length) {
198 // resync invites to the cache, since they're out of date
198 // resync invites to the cache, since they're out of date
199− syncInvites();
199+ syncInvites(point);
200
200
201 throw new Error(
201 throw new Error(
202 `Can currently only send ${planets.length} invites. ` +
202 `Can currently only send ${planets.length} invites. ` +
@@ -315,12 +315,7 @@ export default function InviteEmail() {
315 }
315 }
316
316
317 try {
317 try {
318− const mailSuccess = await sendMail(
319− invite.email,
320− invite.ticket,
318+ await sendMail(invite.email, invite.ticket, invite.rawTx);
321− invite.rawTx
322− );
323− if (!mailSuccess) throw new Error();
324 } catch (error) {
319 } catch (error) {
325 console.error(error);
320 console.error(error);
326 errorCount++;
321 errorCount++;
@@ -396,6 +391,13 @@ export default function InviteEmail() {
396 }
391 }
397 }, [emails]);
392 }, [emails]);
398
393
394+ // when we transition to done, sync invites because we just sent some
395+ useEffect(() => {
396+ if (isDone) {
397+ syncInvites(point);
398+ }
399+ }, [isDone, syncInvites, point]);
400+
399 return (
401 return (
400 <Grid gap={12}>
402 <Grid gap={12}>
401 <Grid.Item as={Grid} full>
403 <Grid.Item as={Grid} full>
src/views/InviteTicket.js+1−2
@@ -68,8 +68,7 @@ class InviteTicket extends React.Component {
68 }
68 }
69
69
70 navigateLogin() {
70 navigateLogin() {
71− this.props.history.pop();
71+ this.props.history.popAndPush(ROUTE_NAMES.LOGIN);
72− this.props.history.push(ROUTE_NAMES.NETWORK);
73 }
72 }
74
73
75 handleInviteTicketInput(inviteTicket) {
74 handleInviteTicketInput(inviteTicket) {
src/views/Point/Actions.js+1−1
@@ -15,7 +15,7 @@ import { usePointCache } from 'store/pointCache';
15const isPlanet = point =>
15const isPlanet = point =>
16 azimuth.getPointSize(point) === azimuth.PointSize.Planet;
16 azimuth.getPointSize(point) === azimuth.PointSize.Planet;
17
17
18−function Actions(props) {
18+function Actions() {
19 const history = useHistory();
19 const history = useHistory();
20 const { wallet } = useWallet();
20 const { wallet } = useWallet();
21 const { pointCursor } = usePointCursor();
21 const { pointCursor } = usePointCursor();