on master help sign in
Merge pull request #210 from urbit/mino-more-fixes

Mino more fixes

commita017d40833de7003cac0d0cc79b98eda01683e4d authorFang <Fang-@users.noreply.github.com> dateFri 26 Jul 2019, 16:02 (7 years ago) parent261ea40fb24632
15 files changed+105−89
package-lock.json+5−4 package.json+1−1 src/components/Passport.js+2−2 src/lib/child.js+3−1 src/lib/inviteMail.js+2−2 src/lib/lib.js+2−1 src/lib/txn.js+2−2 src/lib/useMailer.js+2−2 src/lib/usePermissionsForPoint.js+60−61 src/lib/validators.js+10 src/lib/wallet.js+1−1 src/views/Invite/InviteEmail.js+2 src/views/IssueChild.js+8−8 src/views/Login/Ticket.js+4−3 src/views/Points.js+1−1
package-lock.json+5−4
@@ -2658,12 +2658,13 @@
26582658 }
26592659 },
26602660 "azimuth-js": {
2661− "version": "0.15.0",
2662− "resolved": "https://registry.npmjs.org/azimuth-js/-/azimuth-js-0.15.0.tgz",
2663− "integrity": "sha512-U/700d/94vvjDXpfXVPhrmYna3EX4aVRfkAdG21+k54LJTEozKAQySTPiuOpNsn9kEjaAp3sHR+C9glxm+5NEg==",
2661+ "version": "0.15.1",
2662+ "resolved": "https://registry.npmjs.org/azimuth-js/-/azimuth-js-0.15.1.tgz",
2663+ "integrity": "sha512-EEjDPlv4LQcgF5xhRQg2o81IrcVCu+3K87AI/NVRl37rcQyTCrCzjfeafOTqUQ8PvQXk+wf0Vrtrc+80yJju4g==",
26642664 "requires": {
26652665 "azimuth-solidity": "1.2.0",
2666− "ethereumjs-util": "^5.2.0"
2666+ "ethereumjs-util": "^5.2.0",
2667+ "urbit-ob": "^4.0.1"
26672668 }
26682669 },
26692670 "azimuth-solidity": {
package.json+1−1
@@ -19,7 +19,7 @@
1919 "@ledgerhq/hw-transport-u2f": "^4.61.0",
2020 "PaperCollateralRenderer": "github:urbit/PaperCollateralRenderer",
2121 "async-retry": "^1.2.3",
22− "azimuth-js": "^0.15.0",
22+ "azimuth-js": "^0.15.1",
2323 "azimuth-solidity": "^1.2.0",
2424 "bip32": "^1.0.2",
2525 "bip39": "^2.5.0",
src/components/Passport.js+2−2
@@ -30,7 +30,7 @@ const VISIBLE_ADDRESS_CHAR_COUNT = 20;
3030const EMPTY_ADDRESS = times(VISIBLE_ADDRESS_CHAR_COUNT, () => '<').join('');
3131const ADDRESS_BUFFER_CHARS = times(40, () => '<').join('');
3232
33−const INVERTED_COLORWAY = ['#000', '#fff', '#000'];
33+const INVERTED_COLORWAY = ['#fff', '#000'];
3434
3535const buildKeyType = permissions => {
3636 if (permissions.isOwner) {
@@ -142,7 +142,7 @@ Passport.Mini = function MiniPassport({ point, className, inverted, ...rest }) {
142142 patp={name}
143143 size={64}
144144 margin={0}
145− colorway={inverted ? INVERTED_COLORWAY : undefined}
145+ colors={inverted ? INVERTED_COLORWAY : undefined}
146146 />
147147 </Grid.Item>
148148 <Grid.Item as={Flex} cols={[4, 13]} col justify="between">
src/lib/child.js+3−1
@@ -5,10 +5,12 @@ const MAX_GALAXY = MIN_STAR - 1;
55const MAX_STAR = MIN_PLANET - 1;
66
77const randomStarName = galaxy =>
8+ // ( random in range 0x1 .. 0xff ) * 0x100 + 0x??
89 (Math.floor(Math.random() * MAX_GALAXY) + 1) * MIN_STAR + galaxy;
910
1011const randomPlanetName = star =>
11− (Math.floor(Math.random() * MAX_STAR) + 1) * (MAX_STAR + 1) + star;
12+ // ( random in range 0x1 .. 0xffff ) * 0x10000 + 0x????
13+ (Math.floor(Math.random() * MAX_STAR) + 1) * MIN_PLANET + star;
1214
1315const getSpawnCandidate = point =>
1416 point >= MIN_GALAXY && point < MIN_STAR
src/lib/inviteMail.js+2−2
@@ -30,8 +30,8 @@ async function hasReceived(recipient) {
3030 return res.hasReceived;
3131}
3232
33−function sendMail(recipient, ticket, tx) {
34− return sendRequest('/send-ticket', { recipient, ticket, tx });
33+function sendMail(recipient, ticket, sender, tx) {
34+ return sendRequest('/send-ticket', { recipient, ticket, sender, tx });
3535}
3636
3737export { hasReceived, sendMail };
src/lib/lib.js+2−1
@@ -1,4 +1,5 @@
11import * as ob from 'urbit-ob';
2+import patp2dec from './patp2dec';
23
34const compose = (...fs) =>
45 fs.reduceRight((pF, nF) => (...args) => nF(pF(...args)), v => v);
@@ -18,7 +19,7 @@ const fill = (n, v) => Array.from(Array(n), () => v);
1819const isValidGalaxy = name => {
1920 let point;
2021 try {
21− point = parseInt(ob.patp2dec(name), 10);
22+ point = patp2dec(name);
2223 } catch (err) {
2324 return false;
2425 }
src/lib/txn.js+2−2
@@ -1,4 +1,3 @@
1−import * as ob from 'urbit-ob';
21import Tx from 'ethereumjs-tx';
32import { toWei, fromWei, toHex } from 'web3-utils';
43import retry from 'async-retry';
@@ -8,6 +7,7 @@ import { ledgerSignTransaction } from './ledger';
87import { trezorSignTransaction } from './trezor';
98import { WALLET_TYPES, addHexPrefix } from './wallet';
109import { CHECK_BLOCK_EVERY_MS } from './constants';
10+import patp2dec from './patp2dec';
1111
1212const RETRY_OPTIONS = {
1313 retries: 99999,
@@ -177,7 +177,7 @@ const getTxnInfo = async (web3, addr) => {
177177// TODO(shrugs): deprecate, unifiy with other callsites
178178const canDecodePatp = p => {
179179 try {
180− ob.patp2dec(p);
180+ patp2dec(p);
181181 return true;
182182 } catch (_) {
183183 return false;
src/lib/useMailer.js+2−2
@@ -40,13 +40,13 @@ export default function useMailer(emails) {
4040
4141 // prefix to avoid clobbering sendMail import
4242 // also throws if return value is false
43− const _sendMail = useCallback(async (email, ticket, rawTx) => {
43+ const _sendMail = useCallback(async (email, ticket, sender, rawTx) => {
4444 if (STUB_MAILER) {
4545 console.log(`${email} - ${ticket}`);
4646 return true;
4747 }
4848
49− return await sendMail(email, ticket, rawTx);
49+ return await sendMail(email, ticket, sender, rawTx);
5050 }, []);
5151
5252 return { ...hasReceivedCache, sendMail: _sendMail };
src/lib/usePermissionsForPoint.js+60−61
@@ -8,9 +8,7 @@ import * as need from 'lib/need';
88import { eqAddr, isZeroAddress } from './wallet';
99
1010const NULL_PERMISSIONS = {
11− isPlanet: false,
12− isStar: false,
13− isGalaxy: false,
11+ isActive: false,
1412 //
1513 isOwner: false,
1614 isActiveOwner: false,
@@ -40,69 +38,70 @@ export default function usePermissionsForPoint(address, point) {
4038 const { getDetails } = usePointCache();
4139 const { contracts } = useNetwork();
4240
43− return getDetails(point).matchWith({
44− Nothing: () => NULL_PERMISSIONS,
45− Just: ({ value: details }) => {
46− const _contracts = need.contracts(contracts);
41+ const pointSize = azimuth.getPointSize(point);
42+ const isPlanet = pointSize === azimuth.PointSize.Planet;
43+ const isStar = pointSize === azimuth.PointSize.Star;
44+ const isGalaxy = pointSize === azimuth.PointSize.Galaxy;
45+ const isParent = isStar || isGalaxy;
46+ const staticPermissions = { isPlanet, isStar, isGalaxy, isParent };
4747
48− const pointSize = azimuth.getPointSize(point);
49− const isPlanet = pointSize === azimuth.PointSize.Planet;
50− const isStar = pointSize === azimuth.PointSize.Star;
51− const isGalaxy = pointSize === azimuth.PointSize.Galaxy;
52− const isParent = isStar || isGalaxy;
48+ return {
49+ ...staticPermissions,
50+ ...getDetails(point).matchWith({
51+ Nothing: () => NULL_PERMISSIONS,
52+ Just: ({ value: details }) => {
53+ const _contracts = need.contracts(contracts);
5354
54− const isActive = details.active;
55+ const isActive = details.active;
5556
56− const isOwner = eqAddr(address, details.owner);
57− const isActiveOwner = isOwner && isActive;
58− const isManagementProxy = eqAddr(address, details.managementProxy);
59− const isSpawnProxy = eqAddr(address, details.spawnProxy);
60− const isVotingProxy = eqAddr(address, details.votingProxy);
61− const isTransferProxy = eqAddr(address, details.transferProxy);
57+ const isOwner = eqAddr(address, details.owner);
58+ const isActiveOwner = isOwner && isActive;
59+ const isManagementProxy = eqAddr(address, details.managementProxy);
60+ const isSpawnProxy = eqAddr(address, details.spawnProxy);
61+ const isVotingProxy = eqAddr(address, details.votingProxy);
62+ const isTransferProxy = eqAddr(address, details.transferProxy);
6263
63− const isManagementProxySet = !isZeroAddress(details.managementProxy);
64− const isSpawnProxySet = !isZeroAddress(details.spawnProxy);
65− const isVotingProxySet = !isZeroAddress(details.votingProxy);
66− const isTransferProxySet = !isZeroAddress(details.transferProxy);
64+ const isManagementProxySet = !isZeroAddress(details.managementProxy);
65+ const isSpawnProxySet = !isZeroAddress(details.spawnProxy);
66+ const isVotingProxySet = !isZeroAddress(details.votingProxy);
67+ const isTransferProxySet = !isZeroAddress(details.transferProxy);
6768
68− const canManage = isOwner || isManagementProxy;
69− const canTransfer = isOwner || isTransferProxy;
70− const canSpawn =
71− isParent && (isOwner || isSpawnProxy) && details.keyRevisionNumber > 0;
72− const canVote = isGalaxy && isActive && (isOwner || isVotingProxy);
69+ const canManage = isOwner || isManagementProxy;
70+ const canTransfer = isOwner || isTransferProxy;
71+ const canSpawn =
72+ isParent &&
73+ (isOwner || isSpawnProxy) &&
74+ details.keyRevisionNumber > 0;
75+ const canVote = isGalaxy && isActive && (isOwner || isVotingProxy);
7376
74− const spawnIsDelegatedSending = eqAddr(
75− _contracts.delegatedSending.address,
76− details.spawnProxy
77− );
77+ const spawnIsDelegatedSending = eqAddr(
78+ _contracts.delegatedSending.address,
79+ details.spawnProxy
80+ );
7881
79− return {
80− isPlanet,
81− isStar,
82− isGalaxy,
83− isParent,
84− //
85− isActive,
86− //
87− isOwner,
88− isActiveOwner,
89− isManagementProxy,
90− isSpawnProxy,
91− isVotingProxy,
92− isTransferProxy,
93− //
94− isManagementProxySet,
95− isSpawnProxySet,
96− isVotingProxySet,
97− isTransferProxySet,
98− //
99− canManage,
100− canTransfer,
101− canSpawn,
102− canVote,
103− //
104− spawnIsDelegatedSending,
105− };
106− },
107− });
82+ return {
83+ isActive,
84+ //
85+ isOwner,
86+ isActiveOwner,
87+ isManagementProxy,
88+ isSpawnProxy,
89+ isVotingProxy,
90+ isTransferProxy,
91+ //
92+ isManagementProxySet,
93+ isSpawnProxySet,
94+ isVotingProxySet,
95+ isTransferProxySet,
96+ //
97+ canManage,
98+ canTransfer,
99+ canSpawn,
100+ canVote,
101+ //
102+ spawnIsDelegatedSending,
103+ };
104+ },
105+ }),
106+ };
108107}
src/lib/validators.js+10
@@ -252,6 +252,16 @@ export const validateInSet = (set, error) => m =>
252252 error,
253253 });
254254
255+export const validateNameInNumberSet = (set, error) => m =>
256+ simpleValidatorWrapper({
257+ prevMessage: m,
258+ validator: p => {
259+ const num = patp2dec(p);
260+ return set.has(num);
261+ },
262+ error,
263+ });
264+
255265export const validatePatpByteLength = byteLength => {
256266 return validateLength(patpStringLength(byteLength));
257267};
src/lib/wallet.js+1−1
@@ -104,4 +104,4 @@ export const walletFromMnemonic = (mnemonic, hdpath, passphrase) => {
104104};
105105
106106export const abbreviateAddress = address =>
107− `${address.slice(0, 4)}…${address.slice(-4)}`;
107+ `${address.slice(0, 6)}…${address.slice(-4)}`;
src/views/Invite/InviteEmail.js+2
@@ -1,5 +1,6 @@
11import React, { useCallback, useEffect, useMemo, useState } from 'react';
22import cn from 'classnames';
3+import * as ob from 'urbit-ob';
34import * as azimuth from 'azimuth-js';
45import {
56 Grid,
@@ -340,6 +341,7 @@ export default function InviteEmail() {
340341 const success = await sendMail(
341342 invite.email,
342343 invite.ticket,
344+ ob.patp(point),
343345 invite.rawTx
344346 );
345347 if (!success) throw new Error('Failed to send mail');
src/views/IssueChild.js+8−8
@@ -21,7 +21,7 @@ import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
2121import View from 'components/View';
2222import useLifecycle from 'lib/useLifecycle';
2323import { usePointCursor } from 'store/pointCursor';
24−import { validateInSet } from 'lib/validators';
24+import { validateNameInNumberSet } from 'lib/validators';
2525import { getSpawnCandidate } from 'lib/child';
2626
2727function useIssueChild() {
@@ -54,9 +54,9 @@ export default function IssueChild() {
5454 const { pointCursor } = usePointCursor();
5555
5656 const _contracts = need.contracts(contracts);
57− const _point = need.point(pointCursor);
57+ const _point = parseInt(need.point(pointCursor), 10);
5858
59− const [availablePointNames, setAvailablePointNames] = useState(Nothing());
59+ const [availablePoints, setAvailablePoints] = useState(Nothing());
6060
6161 const candidates = useMemo(() => {
6262 const getCandidate = () => ob.patp(getSpawnCandidate(_point));
@@ -75,12 +75,12 @@ export default function IssueChild() {
7575
7676 const validators = useMemo(
7777 () => [
78− validateInSet(
79− availablePointNames.getOrElse(new Set()),
78+ validateNameInNumberSet(
79+ availablePoints.getOrElse(new Set()),
8080 'This point cannot be spawned.'
8181 ),
8282 ],
83− [availablePointNames]
83+ [availablePoints]
8484 );
8585 const [
8686 pointNameInput,
@@ -91,7 +91,7 @@ export default function IssueChild() {
9191 disabled: inputsLocked,
9292 autoFocus: true,
9393 validators,
94− error: availablePointNames.matchWith({
94+ error: availablePoints.matchWith({
9595 Nothing: () => 'Loading availability...',
9696 Just: () => undefined,
9797 }),
@@ -124,7 +124,7 @@ export default function IssueChild() {
124124 return;
125125 }
126126
127− setAvailablePointNames(Just(new Set(availablePoints.map(ob.patp))));
127+ setAvailablePoints(Just(new Set(availablePoints)));
128128 })();
129129
130130 return () => (mounted = false);
src/views/Login/Ticket.js+4−3
@@ -20,6 +20,7 @@ import * as need from 'lib/need';
2020import { WALLET_TYPES, urbitWalletFromTicket } from 'lib/wallet';
2121import useImpliedPoint from 'lib/useImpliedPoint';
2222import useLoginView from 'lib/useLoginView';
23+import patp2dec from 'lib/patp2dec';
2324
2425export default function Ticket({ className }) {
2526 useLoginView(WALLET_TYPES.TICKET);
@@ -100,7 +101,7 @@ export default function Ticket({ className }) {
100101 }
101102
102103 const _contracts = need.contracts(contracts);
103− const point = ob.patp2dec(pointName);
104+ const point = patp2dec(pointName);
104105 const urbitWallet = await urbitWalletFromTicket(ticket, point, passphrase);
105106 const [isOwner, isTransferProxy] = await Promise.all([
106107 azimuth.azimuth.isOwner(
@@ -123,7 +124,7 @@ export default function Ticket({ className }) {
123124 }
124125
125126 setUrbitWallet(Just(urbitWallet));
126− setPointCursor(Just(ob.patp2dec(pointName)));
127+ setPointCursor(Just(point));
127128 setDeriving(false);
128129 }, [
129130 pointName,
@@ -142,7 +143,7 @@ export default function Ticket({ className }) {
142143
143144 try {
144145 const ticket = kg.combine([s1, s2, s3]);
145− const point = ob.patp2dec(pointName);
146+ const point = patp2dec(pointName);
146147 const uhdw = await urbitWalletFromTicket(ticket, point, passphrase);
147148 setUrbitWallet(Just(uhdw));
148149 } catch (_) {
src/views/Points.js+1−1
@@ -109,7 +109,7 @@ export default function Points() {
109109 );
110110
111111 const multipassPoints = [
112− ...ownedPoints,
112+ ...ownedPoints.filter(p => !outgoingPoints.includes(p)),
113113 ...managingPoints,
114114 ...votingPoints,
115115 ...spawningPoints,