@@ -38,22 +38,14 @@ const TRANSACTION_STATES = {
3838 label: 'Signing Transactions...',
3939 progress: 0.15,
4040 },
41− FUNDING_INVITE: {
42− label: 'Funding Invite Wallet...',
41+ FUNDING: {
42+ label: 'Funding Transactions...',
4343 progress: 0.3,
4444 },
4545 CLAIMING: {
4646 label: 'Claiming Invite...',
4747 progress: 0.55,
4848 },
49− FUNDING_RECIPIENT: {
50− label: 'Funding Recipient Wallet...',
51− progress: 0.65,
52− },
53− CONFIGURING: {
54− label: 'Configuring Point...',
55− progress: 0.85,
56− },
5749 CLEANING: {
5850 label: 'Cleaning Up...',
5951 progress: 0.95,
@@ -108,6 +100,7 @@ async function claimPointFromInvite({
108100 web3,
109101 contracts,
110102 onUpdate,
103+ transferEth,
111104}) {
112105 const askForFunding = (address, minBalance, balance) =>
113106 onUpdate({
@@ -120,61 +113,28 @@ async function claimPointFromInvite({
120113
121114 const inviteAddress = inviteWallet.address;
122115
123− progress(TRANSACTION_STATES.GENERATING);
124−
125− // transfer from invite wallet to new wallet
126− const transferTx = azimuth.ecliptic.transferPoint(
127− contracts,
128− point,
129− wallet.ownership.keys.address
130− );
131− transferTx.gas = 500000; //TODO can maybe be lower?
132−
133− // ping gas tank with txs if needed
134− let inviteNonce = await web3.eth.getTransactionCount(inviteAddress);
135− transferTx.nonce = inviteNonce++;
136− transferTx.gasPrice = 20000000000; //NOTE we pay the premium for faster ux
137− transferTx.from = inviteAddress;
138−
139− progress(TRANSACTION_STATES.SIGNING);
140− // NOTE: using web3.eth.accounts.signTransaction is broken (1.0.0-beta51)
141− const transferStx = new Tx(transferTx);
142− transferStx.sign(inviteWallet.privateKey);
143− const rawTransferStx = hexify(transferStx.serialize());
144− const transferCost = transferTx.gas * transferTx.gasPrice;
145−
146− progress(TRANSACTION_STATES.FUNDING_INVITE);
147−
148− let usedTank = await tank.ensureFundsFor(
149− web3,
150− point,
151− inviteAddress,
152− transferCost,
153− [rawTransferStx],
154− askForFunding,
155− gotFunding
156− );
157−
158− progress(TRANSACTION_STATES.CLAIMING);
116+ //
117+ // generate transactions
118+ //
159119
160− // send transaction
161− await sendAndAwaitConfirm(web3, [Just(transferStx)], usedTank);
120+ progress(TRANSACTION_STATES.GENERATING);
162121
163− //
164− // we're gonna be operating as the new wallet from here on out, so change
165− // the relevant values
166− const newAddress = wallet.ownership.keys.address;
122+ // transfer to invite wallet, so it can configure
123+ //NOTE doing this in the invite wallet instead of the final wallet makes
124+ // failure cases "solvable" by just telling the user to fully retry
167125
168− // configure management proxy
169− const managementTx = azimuth.ecliptic.setManagementProxy(
126+ //TODO no harm done if we already owned it, but should still get a bool arg
127+ // for skipping this, if it isn't too big a burden for callers
128+ let transferTmpTx = azimuth.ecliptic.transferPoint(
170129 contracts,
171130 point,
172− wallet.management.keys.address
131+ inviteAddress,
132+ false
173133 );
174− managementTx.gas = 200000;
175− managementTx.nonce = 0;
134+ transferTmpTx.gas = 500000; //TODO can maybe be lower?
176135
177136 // configure networking public keys
137+
178138 //TODO feels like more of this logic should live in a lib?
179139 const seed = await attemptNetworkSeedDerivation(true, {
180140 walletType: WALLET_TYPES.TICKET,
@@ -201,10 +161,19 @@ async function claimPointFromInvite({
201161 false
202162 );
203163 keysTx.gas = 150000;
204− keysTx.nonce = 1;
205164
206− let txs = [managementTx, keysTx];
165+ // configure management proxy
166+
167+ let managementTx = azimuth.ecliptic.setManagementProxy(
168+ contracts,
169+ point,
170+ wallet.management.keys.address
171+ );
172+ managementTx.gas = 200000;
173+
174+ // set spawn & voting proxies situationally
207175
176+ let txs = [transferTmpTx, keysTx, managementTx];
208177 if (
209178 azimuth.azimuth.getPointSize(point) !== azimuth.azimuth.PointSize.Planet
210179 ) {
@@ -214,7 +183,6 @@ async function claimPointFromInvite({
214183 wallet.spawn.keys.address
215184 );
216185 spawnTx.gas = 200000;
217− spawnTx.nonce = 2;
218186 txs.push(spawnTx);
219187
220188 if (
@@ -226,42 +194,76 @@ async function claimPointFromInvite({
226194 wallet.voting.keys.address
227195 );
228196 votingTx.gas = 200000;
229− votingTx.nonce = 3;
230197 txs.push(votingTx);
231198 }
232199 }
233200
201+ // transfer configured point to user's new wallet
202+
203+ let transferFinalTx = azimuth.ecliptic.transferPoint(
204+ contracts,
205+ point,
206+ wallet.ownership.keys.address,
207+ false
208+ );
209+ transferFinalTx.gas = 500000; //TODO can maybe be lower?
210+ txs.push(transferFinalTx);
211+
212+ //
213+ // finalizing & signing transactions
214+ //
215+
216+ progress(TRANSACTION_STATES.SIGNING);
217+
234218 let totalCost = 0;
219+ let inviteNonce = await web3.eth.getTransactionCount(inviteAddress);
235220 txs = txs.map(tx => {
236− tx.gasPrice = 20000000000;
237− tx.from = newAddress;
221+ tx.from = inviteAddress;
222+ tx.nonce = inviteNonce++;
223+ tx.gasPrice = 20000000000; //NOTE we pay the premium for faster ux
238224 totalCost = totalCost + tx.gasPrice * tx.gas;
239225 return tx;
240226 });
241227
242228 let txPairs = txs.map(tx => {
243229 let stx = new Tx(tx);
244− stx.sign(Buffer.from(wallet.ownership.keys.private, 'hex'));
230+ stx.sign(Buffer.from(inviteWallet.privateKey, 'hex'));
245231 return {
246232 raw: '0x' + stx.serialize().toString('hex'),
247233 signed: stx,
248234 };
249235 });
250236
251− progress(TRANSACTION_STATES.FUNDING_RECIPIENT);
237+ //
238+ // ensuring funding for transactions
239+ //
240+
241+ progress(TRANSACTION_STATES.FUNDING);
252242
253− usedTank = await tank.ensureFundsFor(
243+ const usedTank = await tank.ensureFundsFor(
254244 web3,
255245 point,
256− newAddress,
246+ inviteAddress,
257247 totalCost,
258248 txPairs.map(p => p.raw),
259− askForFunding
249+ askForFunding,
250+ gotFunding
260251 );
252+ console.log('used tank', usedTank);
253+
254+ //
255+ // sending and awaiting transactions
256+ //
261257
262− progress(TRANSACTION_STATES.CONFIGURING);
258+ progress(TRANSACTION_STATES.CLAIMING);
263259
260+ console.log('sending txpairs', txPairs.length);
264261 await sendAndAwaitConfirm(web3, txPairs.map(p => Just(p.signed)), usedTank);
262+ console.log('all done');
263+
264+ //
265+ // move leftover eth
266+ //
265267
266268 progress(TRANSACTION_STATES.CLEANING);
267269
@@ -270,11 +272,11 @@ async function claimPointFromInvite({
270272 const gasPrice = 20000000000;
271273 const gasLimit = 21000;
272274 const sendEthCost = gasPrice * gasLimit;
273− if (balance > sendEthCost) {
275+ if (transferEth && balance > sendEthCost) {
274276 const value = balance - sendEthCost;
275277 console.log('sending', value);
276278 const tx = {
277− to: newAddress,
279+ to: wallet.ownership.keys.address,
278280 value: value,
279281 gasPrice: gasPrice,
280282 gas: gasLimit,