@@ -1,9 +1,8 @@
1−import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
1+import { useCallback, useEffect, useMemo, useState } from 'react';
2import * as azimuth from 'azimuth-js';
2import * as azimuth from 'azimuth-js';
3import * as need from 'lib/need';
3import * as need from 'lib/need';
4import SecureLS from 'secure-ls';
4import SecureLS from 'secure-ls';
6−import { Invite } from 'lib/types/Invite';
8 deriveNetworkSeedFromUrbitWallet,
7 deriveNetworkSeedFromUrbitWallet,
9 attemptNetworkSeedDerivation,
8 attemptNetworkSeedDerivation,
@@ -13,24 +12,17 @@ import { useNetwork } from 'store/network';
13import { usePointCursor } from 'store/pointCursor';
12import { usePointCursor } from 'store/pointCursor';
14import { EMPTY_POINT, useRollerStore } from 'store/rollerStore';
13import { EMPTY_POINT, useRollerStore } from 'store/rollerStore';
15import { useWallet } from 'store/wallet';
14import { useWallet } from 'store/wallet';
20−} from 'store/storage/roller';
21import { usePointCache } from 'store/pointCache';
15import { usePointCache } from 'store/pointCache';
23import { getUpdatedPointMessage, isPlanet, toL1Details } from './utils/point';
17import { getUpdatedPointMessage, isPlanet, toL1Details } from './utils/point';
24import { convertToInt } from './convertToInt';
18import { convertToInt } from './convertToInt';
25import { isDevelopment, isMainnet, isRopsten } from './flags';
19import { isDevelopment, isMainnet, isRopsten } from './flags';
27− generateInviteWallet,
29 submitL2Transaction,
21 submitL2Transaction,
30 registerProxyAddress,
22 registerProxyAddress,
31 isL2Spawn,
23 isL2Spawn,
32} from './utils/roller';
24} from './utils/roller';
33−import { POINT_DOMINIONS, ROLLER_HOSTS, TEN_SECONDS } from './constants';
25+import { ROLLER_HOSTS, TEN_SECONDS } from './constants';
@@ -39,7 +31,6 @@ import {
39 RollerRPCAPI,
31 RollerRPCAPI,
41 EthAddress,
33 EthAddress,
43} from '@urbit/roller-api';
34} from '@urbit/roller-api';
45import Point, { PointField, Points } from './types/Point';
36import Point, { PointField, Points } from './types/Point';
@@ -60,18 +51,6 @@ interface UpdateParams {
60 intervalTime?: number;
51 intervalTime?: number;
63−const inviteTemplate = (
75export default function useRoller() {
54export default function useRoller() {
@@ -89,22 +68,16 @@ export default function useRoller() {
93 nextQuotaTime,
71 nextQuotaTime,
95 setNextBatchTime,
72 setNextBatchTime,
96 setNextQuotaTime,
73 setNextQuotaTime,
97 setPendingTransactions,
74 setPendingTransactions,
99− setInviteGeneratingNum,
101 setModalText,
75 setModalText,
102 setPoints,
76 setPoints,
103 updatePoint,
77 updatePoint,
104 storePendingL1Txn,
78 storePendingL1Txn,
105 deletePendingL1Txn,
79 deletePendingL1Txn,
106 } = useRollerStore();
80 } = useRollerStore();
107− const generatingInvites = useRef(false);
108 const [config, setConfig] = useState<Config | null>(null);
81 const [config, setConfig] = useState<Config | null>(null);
110 const options: Options = useMemo(() => {
83 const options: Options = useMemo(() => {
@@ -344,247 +317,6 @@ export default function useRoller() {
347− const generateInviteInfo = async (planet: number, _authToken: string) => {
348− const { ticket, inviteWallet } = await generateInviteWallet(
353− return inviteTemplate(planet, ticket, inviteWallet.ownership.keys.address);
356− const getInvites = useCallback(async () => {
357− if (generatingInvites.current) {
361− generatingInvites.current = true;
363− setInvitesLoading(true);
364− const curPoint: number = Number(need.point(pointCursor));
365− const _authToken = authToken.getOrElse(null);
366− const _contracts = contracts.getOrElse(null);
368− if (_authToken && _contracts) {
369− const spawnedPoints = point.isL2Spawn
370− ? await api.getSpawned(curPoint)
373− const newPending = await api.getPendingByShip(curPoint);
374− setPendingTransactions(newPending);
375− const pendingSpawns = getPendingSpawns(newPending);
377− const availablePoints = await azimuth.azimuth.getUnspawnedChildren(
382− const outgoingPoints = pointList
384− ({ value, isPlanet }) => isPlanet && availablePoints.includes(value)
386− .map(({ value }) => value);
388− const invitePlanets = spawnedPoints
390− outgoingPoints.filter((p: number) => !spawnedPoints.includes(p))
392− .filter((p: number) => !pendingSpawns.has(p))
395− setInvites(curPoint, []);
397− const newInvites: Invite[] = [];
398− // Iterate over all of the stored invites, generating wallet info as necessary
399− const storedInvites = getStoredInvites(ls);
401− for (let i = 0; i < invitePlanets.length; i++) {
402− setInviteGeneratingNum(i + 1);
403− const planet = invitePlanets[i];
404− const storedInvite = storedInvites[planet];
406− storedInvite || (await generateInviteInfo(planet, _authToken));
408− // TODO: check if the invite point's owner still matches the deterministic wallet address
409− const planetInfo = await api.getPoint(planet);
410− setStoredInvite(ls, invite);
413− invite.owner.toLowerCase() ===
414− planetInfo.ownership?.owner?.address &&
415− planetInfo.dominion === POINT_DOMINIONS.L2
417− addInvite(curPoint, invite);
418− newInvites.push(invite);
422− setStoredInvite(ls, invite);
426− setInvitesLoading(false);
430− console.warn('ERROR GETTING INVITES', error);
433− generatingInvites.current = false;
445− setInviteGeneratingNum,
446− setPendingTransactions,
449− const generateInviteCodes = useCallback(
450− async (numInvites: number) => {
451− const _point = need.point(pointCursor);
452− const _contracts = contracts.getOrElse(null);
453− const _web3 = web3.getOrElse(null);
454− const _wallet = wallet.getOrElse(null);
455− const _authToken = authToken.getOrElse(null);
456− const _details = getDetails(_point);
458− if (!_contracts || !_web3 || !_wallet || !_authToken || !_details) {
459− // not using need because we want a custom error
460− throw new Error('Internal Error: Missing Contracts/Web3/Wallet');
463− // TODO: remove when UI disables management proxy from spawning invites
464− // if (Just.hasInstance(authMnemonic)) {
466− // "Auth key Error: A management mnemonic can't create invite codes"
469− let planets: UnspawnedPoints = await api.getUnspawned(_point);
471− const pendingTxs = await api.getPendingByShip(_point);
473− const pendingSpawns = getPendingSpawns(pendingTxs);
475− planets = planets.filter((point: number) => !pendingSpawns.has(point));
477− const invites: Invite[] = [];
479− const proxy = point.getSpawnProxy();
481− if (proxy === undefined)
482− throw new Error("Error: Address doesn't match proxy");
484− const nonce = await api.getNonce({
489− for (let i = 0; i < numInvites && planets[i]; i++) {
490− setInviteGeneratingNum(i + 1);
491− const planet = planets[i];
492− const nonceInc = i + nonce;
494− const { ticket, inviteWallet } = await generateInviteWallet(
499− await submitL2Transaction({
501− address: _wallet.address,
506− pointToSpawn: planet,
513− const networkSeed = await deriveNetworkSeedFromUrbitWallet(
517− await submitL2Transaction({
524− type: 'configureKeys',
530− await registerProxyAddress(
537− inviteWallet.management.keys.address,
543− await submitL2Transaction({
548− type: 'transferPoint',
550− address: inviteWallet.ownership.keys.address,
560− owner: inviteWallet.ownership.keys.address,
564− setStoredInvites(ls, invites);
565− console.log('getting invites from code generation');
568− `Your invite${invites.length > 1 ? 's have' : ' has'} been generated!`
584− setInviteGeneratingNum,
588 const getPoints = useCallback(
320 const getPoints = useCallback(
589 async (proxy: Proxy, address: EthAddress) => {
321 async (proxy: Proxy, address: EthAddress) => {
590 const points: Ship[] =
322 const points: Ship[] =
@@ -1049,9 +781,7 @@ export default function useRoller() {
1049 checkForUpdates,
781 checkForUpdates,
1051 configureNetworkKeys,
783 configureNetworkKeys,
1052− generateInviteCodes,
1053 getAndUpdatePoint,
784 getAndUpdatePoint,
1055 getPoints,
785 getPoints,
1056 getPointsDetails,
786 getPointsDetails,
1057 getPendingTransactions,
787 getPendingTransactions,