on master help sign in
refactor: tiny refactor for converting point names into points before deriving wallets
ca6ebb8Matt Condon (shrugs)
src/lib/invite.js+5−7
@@ -99,8 +99,6 @@ export async function reticketPointBetweenWallets({
99 const gotFunding = () => onUpdate({ type: 'gotFunding' });
99 const gotFunding = () => onUpdate({ type: 'gotFunding' });
100 const progress = state => onUpdate({ type: 'progress', state });
100 const progress = state => onUpdate({ type: 'progress', state });
101
101
102− const inviteAddress = fromWallet.address;
103−
104 //
102 //
105 // generate transactions
103 // generate transactions
106 //
104 //
@@ -117,7 +115,7 @@ export async function reticketPointBetweenWallets({
117 const transferTmpTx = azimuth.ecliptic.transferPoint(
115 const transferTmpTx = azimuth.ecliptic.transferPoint(
118 contracts,
116 contracts,
119 point,
117 point,
120− inviteAddress,
118+ fromWallet.address,
121 false
119 false
122 );
120 );
123 transferTmpTx.gas = GAS_LIMITS.TRANSFER;
121 transferTmpTx.gas = GAS_LIMITS.TRANSFER;
@@ -201,9 +199,9 @@ export async function reticketPointBetweenWallets({
201 progress(TRANSACTION_STATES.SIGNING);
199 progress(TRANSACTION_STATES.SIGNING);
202
200
203 let totalCost = 0;
201 let totalCost = 0;
204− let inviteNonce = await web3.eth.getTransactionCount(inviteAddress);
202+ let inviteNonce = await web3.eth.getTransactionCount(fromWallet.address);
205 txs = txs.map(tx => {
203 txs = txs.map(tx => {
206− tx.from = inviteAddress;
204+ tx.from = fromWallet.address;
207 tx.nonce = inviteNonce++;
205 tx.nonce = inviteNonce++;
208 tx.gasPrice = 20000000000; //NOTE we pay the premium for faster ux
206 tx.gasPrice = 20000000000; //NOTE we pay the premium for faster ux
209 totalCost = totalCost + tx.gasPrice * tx.gas;
207 totalCost = totalCost + tx.gasPrice * tx.gas;
@@ -228,7 +226,7 @@ export async function reticketPointBetweenWallets({
228 const usedTank = await tank.ensureFundsFor(
226 const usedTank = await tank.ensureFundsFor(
229 web3,
227 web3,
230 point,
228 point,
231− inviteAddress,
229+ fromWallet.address,
232 totalCost,
230 totalCost,
233 txPairs.map(p => p.raw),
231 txPairs.map(p => p.raw),
234 askForFunding,
232 askForFunding,
@@ -254,7 +252,7 @@ export async function reticketPointBetweenWallets({
254 progress(TRANSACTION_STATES.CLEANING);
252 progress(TRANSACTION_STATES.CLEANING);
255
253
256 // if non-trivial eth left in invite wallet, transfer to new ownership
254 // if non-trivial eth left in invite wallet, transfer to new ownership
257− let balance = await web3.eth.getBalance(inviteAddress);
255+ let balance = await web3.eth.getBalance(fromWallet.address);
258 const gasPrice = 20000000000;
256 const gasPrice = 20000000000;
259 const gasLimit = 21000;
257 const gasLimit = 21000;
260 const sendEthCost = gasPrice * gasLimit;
258 const sendEthCost = gasPrice * gasLimit;
src/lib/wallet.js−18
@@ -74,11 +74,6 @@ export const eqAddr = (addr0, addr1) =>
74 toChecksumAddress(addr0) === toChecksumAddress(addr1);
74 toChecksumAddress(addr0) === toChecksumAddress(addr1);
75
75
76export const urbitWalletFromTicket = async (ticket, point, passphrase) => {
76export const urbitWalletFromTicket = async (ticket, point, passphrase) => {
77− if (typeof point === 'string') {
78− //TODO why not in kg?
79− point = ob.patp2dec(point);
80− }
81−
82 return await kg.generateWallet({
77 return await kg.generateWallet({
83 ticket: ticket,
78 ticket: ticket,
84 ship: point,
79 ship: point,
@@ -86,19 +81,6 @@ export const urbitWalletFromTicket = async (ticket, point, passphrase) => {
86 });
81 });
87};
82};
88
83
89−export const ownershipWalletFromTicket = async (ticket, point, passphrase) => {
90− if (typeof point === 'string') {
91− //TODO why not in kg?
92− point = ob.patp2dec(point);
93− }
94−
95− return await kg.generateOwnershipWallet({
96− ticket,
97− ship: point,
98− passphrase,
99− });
100−};
101−
102export const walletFromMnemonic = (mnemonic, hdpath, passphrase) => {
84export const walletFromMnemonic = (mnemonic, hdpath, passphrase) => {
103 const seed = bip39.validateMnemonic(mnemonic)
85 const seed = bip39.validateMnemonic(mnemonic)
104 ? Just(bip39.mnemonicToSeed(mnemonic, passphrase))
86 ? Just(bip39.mnemonicToSeed(mnemonic, passphrase))
src/lib/walletgen.js+1
@@ -71,6 +71,7 @@ export const generateOwnershipWallet = (ship, ticket) =>
71// so we always use ~zod as the wallet point.
71// so we always use ~zod as the wallet point.
72export const generateTemporaryOwnershipWallet = ticket =>
72export const generateTemporaryOwnershipWallet = ticket =>
73 generateOwnershipWallet(ZOD, ticket);
73 generateOwnershipWallet(ZOD, ticket);
74+
74export const generateTemporaryTicketAndWallet = async point => {
75export const generateTemporaryTicketAndWallet = async point => {
75 const ticket = await makeTicket(point);
76 const ticket = await makeTicket(point);
76 const owner = await generateOwnershipWallet(ZOD, ticket);
77 const owner = await generateOwnershipWallet(ZOD, ticket);
src/views/Login/Ticket.js+6−9
@@ -94,21 +94,17 @@ export default function Ticket({ className }) {
94 }
94 }
95
95
96 const _contracts = need.contracts(contracts);
96 const _contracts = need.contracts(contracts);
97− const pointNumber = ob.patp2dec(pointName);
97+ const point = ob.patp2dec(pointName);
98− const urbitWallet = await urbitWalletFromTicket(
98+ const urbitWallet = await urbitWalletFromTicket(ticket, point, passphrase);
99− ticket,
100− pointName,
101− passphrase
102− );
103 const [isOwner, isTransferProxy] = await Promise.all([
99 const [isOwner, isTransferProxy] = await Promise.all([
104 azimuth.azimuth.isOwner(
100 azimuth.azimuth.isOwner(
105 _contracts,
101 _contracts,
106− pointNumber,
102+ point,
107 urbitWallet.ownership.keys.address
103 urbitWallet.ownership.keys.address
108 ),
104 ),
109 azimuth.azimuth.isTransferProxy(
105 azimuth.azimuth.isTransferProxy(
110 _contracts,
106 _contracts,
111− pointNumber,
107+ point,
112 urbitWallet.ownership.keys.address
108 urbitWallet.ownership.keys.address
113 ),
109 ),
114 ]);
110 ]);
@@ -140,7 +136,8 @@ export default function Ticket({ className }) {
140
136
141 try {
137 try {
142 const ticket = kg.combine([s1, s2, s3]);
138 const ticket = kg.combine([s1, s2, s3]);
139+ const point = ob.patp2dec(pointName);
143− const uhdw = await urbitWalletFromTicket(ticket, pointName, passphrase);
140+ const uhdw = await urbitWalletFromTicket(ticket, point, passphrase);
144 setUrbitWallet(Just(uhdw));
141 setUrbitWallet(Just(uhdw));
145 } catch (_) {
142 } catch (_) {
146 // do nothing
143 // do nothing