on master help sign in
fix: update InviteTicket to correctly execute txs, correct sendMail logic
commitdf46115b705f2dbd2407af629da9aa925a39640c authorMatt Condon (shrugs) <mattgcondon@gmail.com> dateWed 26 Jun 2019, 11:32 (7 years ago) parent2af5239
8 files changed+26−20
src/lib/invite.js+8−5 src/lib/need.js+1−2 src/lib/txn.js+4−1 src/lib/useMailer.js+1 src/store/lib/useInvitesStore.js+1−2 src/views/Invite/InviteEmail.js+9−7 src/views/InviteTicket.js+1−2 src/views/Point/Actions.js+1−1
src/lib/invite.js+8−5
@@ -191,7 +191,7 @@ async function startTransactions(args) {
191191 });
192192
193193 // send transaction
194− await sendAndAwaitConfirm(web3, [rawTransferStx], usedTank);
194+ await sendAndAwaitConfirm(web3, [Just(transferStx)], usedTank);
195195
196196 //
197197 // we're gonna be operating as the new wallet from here on out, so change
@@ -249,10 +249,13 @@ async function startTransactions(args) {
249249 return tx;
250250 });
251251
252− let rawStxs = txs.map(tx => {
252+ let txPairs = txs.map(tx => {
253253 let stx = new Tx(tx);
254254 stx.sign(Buffer.from(realWallet.ownership.keys.private, 'hex'));
255− return '0x' + stx.serialize().toString('hex');
255+ return {
256+ raw: '0x' + stx.serialize().toString('hex'),
257+ signed: stx,
258+ };
256259 });
257260
258261 updateProgress({
@@ -264,7 +267,7 @@ async function startTransactions(args) {
264267 point,
265268 newAddress,
266269 totalCost,
267− rawStxs,
270+ txPairs.map(p => p.raw),
268271 askForFunding
269272 );
270273
@@ -273,7 +276,7 @@ async function startTransactions(args) {
273276 value: TRANSACTION_STATES.CONFIGURING,
274277 });
275278
276− await sendAndAwaitConfirm(web3, rawStxs, usedTank);
279+ await sendAndAwaitConfirm(web3, txPairs.map(p => Just(p.signed)), usedTank);
277280
278281 updateProgress({
279282 type: 'progress',
src/lib/need.js+1−2
@@ -22,8 +22,7 @@ export const wallet = needBuilder(BRIDGE_ERROR.MISSING_WALLET);
2222export const addressFromWallet = obj => wallet(obj).address;
2323export const pointCursor = needBuilder(BRIDGE_ERROR.MISSING_POINT);
2424export const pointCache = needBuilder(BRIDGE_ERROR.MISSING_POINT);
25−export const fromPointCache = (obj, point) => {
26− const cache = pointCache(obj);
25+export const fromPointCache = (cache, point) => {
2726 if (!(point in cache)) {
2827 throw BRIDGE_ERROR.MISSING_POINT;
2928 }
src/lib/txn.js+4−1
@@ -9,6 +9,9 @@ import { ledgerSignTransaction } from './ledger';
99import { trezorSignTransaction } from './trezor';
1010import { WALLET_TYPES, addHexPrefix } from './wallet';
1111
12+const kAverageBlockTimeMs =
13+ process.env.NODE_ENV === 'development' ? 1000 : 13000;
14+
1215const TXN_PURPOSE = {
1316 SET_MANAGEMENT_PROXY: Symbol('SET_MANAGEMENT_PROXY'),
1417 SET_TRANSFER_PROXY: Symbol('SET_TRANSFER_PROXY'),
@@ -194,7 +197,7 @@ const waitForTransactionConfirm = (web3, txHash) => {
194197 console.log('tried, got', receipt);
195198 let confirmed = receipt !== null;
196199 if (confirmed) resolve(receipt.status === true);
197− else setTimeout(checkForConfirm, 13000);
200+ else setTimeout(checkForConfirm, kAverageBlockTimeMs);
198201 };
199202 checkForConfirm();
200203 });
src/lib/useMailer.js+1
@@ -39,6 +39,7 @@ export default function useMailer(emails) {
3939 const hasReceivedCache = useHasReceivedCache(emails);
4040
4141 // prefix to avoid clobbering sendMail import
42+ // also throws if return value is false
4243 const _sendMail = useCallback(async (email, ticket, rawTx) => {
4344 if (kStubMailer) {
4445 console.log(`${email} - ${ticket}`);
src/store/lib/useInvitesStore.js+1−2
@@ -47,13 +47,12 @@ export default function useInvitesStore() {
4747 );
4848 const invitedPointDetails = await Promise.all(
4949 invitedPoints.map(async invitedPoint => {
50− console.log('invitedPoint', invitedPoint, typeof invitedPoint);
5150 const active = await azimuth.azimuth.isActive(
5251 _contracts,
5352 invitedPoint
5453 );
5554 return {
56− point: Number(invitedPoint),
55+ point: invitedPoint,
5756 active,
5857 };
5958 })
src/views/Invite/InviteEmail.js+9−7
@@ -196,7 +196,7 @@ export default function InviteEmail() {
196196 // composing our target list
197197 if (planets.length < inputs.length) {
198198 // resync invites to the cache, since they're out of date
199− syncInvites();
199+ syncInvites(point);
200200
201201 throw new Error(
202202 `Can currently only send ${planets.length} invites. ` +
@@ -315,12 +315,7 @@ export default function InviteEmail() {
315315 }
316316
317317 try {
318− const mailSuccess = await sendMail(
319− invite.email,
320− invite.ticket,
321− invite.rawTx
322− );
323− if (!mailSuccess) throw new Error();
318+ await sendMail(invite.email, invite.ticket, invite.rawTx);
324319 } catch (error) {
325320 console.error(error);
326321 errorCount++;
@@ -396,6 +391,13 @@ export default function InviteEmail() {
396391 }
397392 }, [emails]);
398393
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+
399401 return (
400402 <Grid gap={12}>
401403 <Grid.Item as={Grid} full>
src/views/InviteTicket.js+1−2
@@ -68,8 +68,7 @@ class InviteTicket extends React.Component {
6868 }
6969
7070 navigateLogin() {
71− this.props.history.pop();
72− this.props.history.push(ROUTE_NAMES.NETWORK);
71+ this.props.history.popAndPush(ROUTE_NAMES.LOGIN);
7372 }
7473
7574 handleInviteTicketInput(inviteTicket) {
src/views/Point/Actions.js+1−1
@@ -15,7 +15,7 @@ import { usePointCache } from 'store/pointCache';
1515const isPlanet = point =>
1616 azimuth.getPointSize(point) === azimuth.PointSize.Planet;
1717
18−function Actions(props) {
18+function Actions() {
1919 const history = useHistory();
2020 const { wallet } = useWallet();
2121 const { pointCursor } = usePointCursor();