on master help sign in
inviter: display and recover deterministic invites
commitbe56aee53529cbdf35f65ef1ac9b0b262cecba85 authorLiam Fitzgerald <liam@urizen.co> dateWed 8 Apr 2020, 12:49 (7 years ago) parent673ee7d
5 files changed+63−48
src/store/lib/usePointStore.js+6−1 src/views/Invite/Cohort.js+54−44 src/views/Login/Ledger.js+1−1 src/views/Login/Metamask.js+1−1 src/views/Login/Trezor.js+1−1
src/store/lib/usePointStore.js+6−1
@@ -25,7 +25,12 @@ export default function usePointStore() {
2525 );
2626
2727 // sync all of the on-chain info required to display a foreign point
28− const syncForeignPoint = useCallback(async point => {}, []);
28+ const syncForeignPoint = useCallback(
29+ async point => {
30+ syncDetails(point);
31+ },
32+ [syncDetails]
33+ );
2934
3035 // sync all of the on-chain info required for a point that the user owns
3136 const syncOwnedPoint = useCallback(
src/views/Invite/Cohort.js+54−44
@@ -3,6 +3,7 @@ import { Grid, Flex, Button } from 'indigo-react';
33import * as ob from 'urbit-ob';
44import { Just, Nothing } from 'folktale/maybe';
55import cn from 'classnames';
6+import { delegatedSending } from 'azimuth-js';
67
78import { usePointCursor } from 'store/pointCursor';
89import { usePointCache } from 'store/pointCache';
@@ -27,6 +28,7 @@ import Inviter from 'views/Invite/Inviter';
2728import { ReactComponent as SearchIcon } from 'assets/search.svg';
2829import CopyButton from 'components/CopyButton';
2930import { useSyncForeignPoints } from 'lib/useSyncPoints';
31+import { useNetwork } from 'store/network';
3032
3133function SearchInput({ className, value, onChange }) {
3234 return (
@@ -164,10 +166,14 @@ function CohortMemberExpanded({ point, className, ...rest }) {
164166 const { sentInvites, acceptedInvites } = useInvites(point);
165167 const { getDetails } = usePointCache();
166168 const { authToken } = useWallet();
167− const details = getDetails(point).getOrElse({});
168− const { active } = details;
169+ const { contracts } = useNetwork();
170+ const details = getDetails(point);
171+ const { active } = details.getOrElse({});
169172 const patp = useMemo(() => ob.patp(point), [point]);
170− const colors = !active ? ['#ee892b', '#FFFFFF'] : ['#000000', '#FFFFFF'];
173+ const colors = useMemo(
174+ () => (!active ? ['#ee892b', '#FFFFFF'] : ['#000000', '#FFFFFF']),
175+ [active]
176+ );
171177
172178 const [code, setCode] = useState(Nothing());
173179 const [codeVisible, setCodeVisible] = useState(false);
@@ -175,20 +181,35 @@ function CohortMemberExpanded({ point, className, ...rest }) {
175181 useEffect(() => {
176182 const fetchWallet = async () => {
177183 const _authToken = authToken.getOrElse(null);
178− if (!_authToken || active) {
184+ const _details = details.getOrElse(null);
185+ const _contracts = contracts.getOrElse(null);
186+ if (
187+ !_authToken ||
188+ !_details ||
189+ _details.active ||
190+ !_contracts ||
191+ !codeVisible
192+ ) {
193+ setCode(Nothing());
179194 return;
180195 }
181− const ticket = await wg.makeDeterministicTicket(point, _authToken);
182− setCode(Just(ticket));
196+ const { ticket, owner } = await wg.generateTemporaryDeterministicWallet(
197+ point,
198+ _authToken
199+ );
200+
201+ if (owner.keys.address !== _details.transferProxy) {
202+ setCode(Just(null));
203+ } else {
204+ setCode(Just(ticket));
205+ }
183206 };
184207 fetchWallet();
185− }, [authToken, point, active]);
208+ }, [codeVisible]);
186209
187− const DetailText = useCallback(
188− () =>
189− !active ? 'Pending' : <> {matchBlinky(sentInvites)} points invited </>,
190− [active, sentInvites]
191− );
210+ useEffect(() => {
211+ setCodeVisible(false);
212+ }, [point]);
192213
193214 return (
194215 <Grid justify="between" className={cn('b1 b-gray2', className)} {...rest}>
@@ -209,20 +230,27 @@ function CohortMemberExpanded({ point, className, ...rest }) {
209230 col>
210231 Invite Code
211232 </Grid.Item>
212− <Grid.Item
213− cols={[4, 10]}
214− className="mb-auto mt1 f6 gray4"
215− as={Flex}
216− col
217− onClick={() => setCodeVisible(r => !r)}>
218− {hideIf(!codeVisible, matchBlinky(code))}
233+ <Grid.Item cols={[4, 10]} className="mb-auto mt1 f6 gray4">
234+ {(code.getOrElse(true) === null &&
235+ 'This invite code cannot be recovered') ||
236+ hideIf(!codeVisible, matchBlinky(code))}
219237 </Grid.Item>
220− <Grid.Item
221− className="mh-auto f6"
222− cols={[10, 13]}
223− as={CopyButton}
224− text={code.getOrElse('')}
225− />
238+ {!codeVisible && (
239+ <Grid.Item
240+ cols={[10, 13]}
241+ className="mh-auto f6 underline pointer"
242+ onClick={() => setCodeVisible(true)}>
243+ Show
244+ </Grid.Item>
245+ )}
246+ {codeVisible && code.getOrElse('') !== null && (
247+ <Grid.Item
248+ className="mh-auto f6 t-right"
249+ cols={[10, 13]}
250+ as={CopyButton}
251+ text={code.getOrElse('')}
252+ />
253+ )}
226254 </>
227255 )}
228256
@@ -244,22 +272,6 @@ function CohortMemberExpanded({ point, className, ...rest }) {
244272 </Grid.Item>
245273 </>
246274 )}
247−
248− {/* <Flex.Item>Invite Code</Flex.Item> */}
249− {/* <Flex.Item>{matchBlinky(code)}</Flex.Item> */}
250− {/* <span className="pointer underline">Get Invite code </span> */}
251− {/* <br /> */}
252− {/* {resend && <span>{matchBlinky(code)}</span>} */}
253− {/* </Grid.Item> */}
254− {/* {resend && ( */}
255− {/* <Grid.Item cols={[5, 13]} rows={[2, 3]} className="mv-auto"></Grid.Item> */}
256− {/* )} */}
257− {/* <Grid.Item justify="evenly" as={Flex} col className="mono f6 ph4"> */}
258− {/* <Flex.Item>{patp}</Flex.Item> */}
259− {/* <Flex.Item className="gray4"> */}
260− {/* <DetailText /> */}
261− {/* </Flex.Item> */}
262− {/* </Grid.Item> */}
263275 </Grid>
264276 );
265277}
@@ -293,9 +305,7 @@ export default function InviteCohort() {
293305
294306 const [selectedInvite, _setSelectedInvite] = useState();
295307
296− useEffect(() => {
297− Promise.all(_acceptedPoints.map(i => syncDetails(i)));
298− }, [_acceptedPoints, syncDetails]);
308+ useSyncForeignPoints([..._acceptedPoints, ..._pendingPoints]);
299309
300310 const setSelectedInvite = useCallback(
301311 p => _setSelectedInvite(old => (old === p ? null : p)),
src/views/Login/Ledger.js+1−1
@@ -78,7 +78,7 @@ export default function Ledger({ className, goHome }) {
7878 walletHdPath: addHdPrefix(values.hdpath),
7979 });
8080
81− setAuthToken(authToken);
81+ setAuthToken(Just(authToken));
8282 setWallet(Just(hd));
8383 setWalletHdPath(addHdPrefix(values.hdpath));
8484 } catch (error) {
src/views/Login/Metamask.js+1−1
@@ -33,7 +33,7 @@ export default function Metamask({ className, goHome }) {
3333 web3: _web3,
3434 });
3535
36− setAuthToken(authToken);
36+ setAuthToken(Just(authToken));
3737 setWallet(Just(wallet));
3838 setWalletType(WALLET_TYPES.METAMASK);
3939 } catch (e) {
src/views/Login/Trezor.js+1−1
@@ -74,7 +74,7 @@ export default function Trezor({ className, goHome }) {
7474 walletHdPath: values.hdPath,
7575 });
7676
77− setAuthToken(authToken);
77+ setAuthToken(Just(authToken));
7878 setWallet(Just(hd));
7979 setWalletHdPath(values.hdPath);
8080 },