on master help sign in
Fixing roller timer display, csv download, and show invite
4f027eaWill Galebach
src/lib/useRoller.ts+7−3
@@ -313,7 +313,9 @@ export default function useRoller() {
313 getDetails
313 getDetails
314 ).filter((p: number) => isPlanet(p) && availablePoints.includes(p));
314 ).filter((p: number) => isPlanet(p) && availablePoints.includes(p));
315
315
316− const invitePlanets = spawnedPoints.concat(outgoingPoints);
316+ const invitePlanets = spawnedPoints.concat(
317+ outgoingPoints.filter((p: number) => !spawnedPoints.includes(p))
318+ );
317
319
318 if (isDevelopment) {
320 if (isDevelopment) {
319 console.log('INVITED PLANETS', invitePlanets);
321 console.log('INVITED PLANETS', invitePlanets);
@@ -406,8 +408,10 @@ export default function useRoller() {
406 setPendingTransactions(newPending);
408 setPendingTransactions(newPending);
407 setInvitePoints(
409 setInvitePoints(
408 invitePoints
410 invitePoints
409− .concat(outgoingPoints)
411+ .concat(
412+ outgoingPoints.filter((p: number) => !invitePoints.includes(p))
413+ )
410− .filter(p => !pendingSpawns.has(p))
414+ .filter((p: number) => !pendingSpawns.has(p))
411 );
415 );
412 }
416 }
413 } catch (e) {
417 } catch (e) {
src/lib/utils/invite.ts+1−1
@@ -31,4 +31,4 @@ export const generateCsvLine = (ind: number, ticket: string, planet: number) =>
31 )},${planet},${ticket}\n`;
31 )},${planet},${ticket}\n`;
32
32
33export const generateCsvName = (defaultName: string, point: number) =>
33export const generateCsvName = (defaultName: string, point: number) =>
34− `${ob.patp(point).slice(1)}_${defaultName}`;
34+ `${point ? ob.patp(point).slice(1) : 'bridge'}_${defaultName}`;
src/lib/utils/roller.ts+1−1
@@ -30,7 +30,7 @@ export const hasPoint = (point: number) => (invite: Invite) =>
30 invite.planet === point;
30 invite.planet === point;
31
31
32export const getTimeToNextBatch = (nextBatch: number, now: number) => {
32export const getTimeToNextBatch = (nextBatch: number, now: number) => {
33− const toNext = nextBatch - now;
33+ const toNext = Math.max(nextBatch - now, 0);
34 const hours = Math.floor(toNext / HOUR);
34 const hours = Math.floor(toNext / HOUR);
35 const minutes = Math.floor((toNext - hours * HOUR) / MINUTE);
35 const minutes = Math.floor((toNext - hours * HOUR) / MINUTE);
36 const seconds = Math.floor(
36 const seconds = Math.floor(
src/store/storage/roller.ts+1−1
@@ -15,7 +15,7 @@ export const getStoredInvites = (ls: SecureLS): Invites => {
15export const setStoredInvites = (ls: SecureLS, newInvites: Invite[]) => {
15export const setStoredInvites = (ls: SecureLS, newInvites: Invite[]) => {
16 let invites: Invites = {};
16 let invites: Invites = {};
17 try {
17 try {
18− invites = ls.get(INVITES_KEY);
18+ invites = ls.get(INVITES_KEY) || {};
19 } catch (e) {}
19 } catch (e) {}
20
20
21 newInvites.forEach(invite => {
21 newInvites.forEach(invite => {
src/views/Invite/Cohort.tsx+31−11
@@ -75,7 +75,7 @@ export default function InviteCohort() {
75 const { contracts }: any = useNetwork();
75 const { contracts }: any = useNetwork();
76 const { syncControlledPoints }: any = usePointCache();
76 const { syncControlledPoints }: any = usePointCache();
77
77
78− const point = Just(pointCursor)
78+ const point = pointCursor.getOrElse(null);
79 const _contracts = need.contracts(contracts);
79 const _contracts = need.contracts(contracts);
80
80
81 const [numInvites, setNumInvites] = useState(
81 const [numInvites, setNumInvites] = useState(
@@ -83,13 +83,25 @@ export default function InviteCohort() {
83 );
83 );
84 const [showInviteForm, setShowInviteForm] = useState(false);
84 const [showInviteForm, setShowInviteForm] = useState(false);
85 const [loading, setLoading] = useState(false);
85 const [loading, setLoading] = useState(false);
86− const [error, setError] = useState('');
87 const [downloadingCsv, setDownloadingCsv] = useState(false);
86 const [downloadingCsv, setDownloadingCsv] = useState(false);
87+ const [error, setError] = useState('');
88 const [l1Invite, setL1Invite] = useState<L1Invite | null>(null);
88 const [l1Invite, setL1Invite] = useState<L1Invite | null>(null);
89 const [page, setPage] = useState(0);
89 const [page, setPage] = useState(0);
90
90
91 const { construct, unconstruct, completed, bind } = useIssueChild();
91 const { construct, unconstruct, completed, bind } = useIssueChild();
92
92
93+ const onClickShowInvite = useCallback(
94+ (planet: number) => {
95+ setLoading(true);
96+ // Put this in a timeout to let the UI update
97+ setTimeout(async () => {
98+ await showInvite(planet);
99+ setLoading(false);
100+ }, 50);
101+ },
102+ [setLoading, showInvite]
103+ );
104+
93 useEffect(() => {
105 useEffect(() => {
94 if (invitePoints.length > 0) {
106 if (invitePoints.length > 0) {
95 getInvites(currentL2);
107 getInvites(currentL2);
@@ -101,7 +113,7 @@ export default function InviteCohort() {
101 const _authToken = authToken.getOrElse(null);
113 const _authToken = authToken.getOrElse(null);
102
114
103 const setUpInvite = async () => {
115 const setUpInvite = async () => {
104− setLoading(true);
116+ setDownloadingCsv(true);
105 const possiblePoints = await azimuth.azimuth.getUnspawnedChildren(
117 const possiblePoints = await azimuth.azimuth.getUnspawnedChildren(
106 _contracts,
118 _contracts,
107 point
119 point
@@ -132,7 +144,7 @@ export default function InviteCohort() {
132 setError('No available planets');
144 setError('No available planets');
133 }
145 }
134
146
135− setLoading(false);
147+ setDownloadingCsv(false);
136 };
148 };
137
149
138 if (!currentL2 && _contracts && point && _authToken && showInviteForm) {
150 if (!currentL2 && _contracts && point && _authToken && showInviteForm) {
@@ -154,7 +166,12 @@ export default function InviteCohort() {
154 useEffect(() => {
166 useEffect(() => {
155 const storedInvites = getStoredInvites(ls);
167 const storedInvites = getStoredInvites(ls);
156
168
169+ if (
170+ !currentL2 ||
171+ !completed ||
172+ !l1Invite ||
157− if (!completed || !l1Invite || storedInvites[l1Invite.planet]) {
173+ storedInvites[l1Invite.planet]
174+ ) {
158 return;
175 return;
159 }
176 }
160
177
@@ -164,7 +181,7 @@ export default function InviteCohort() {
164 setL1Invite(null);
181 setL1Invite(null);
165 unconstruct();
182 unconstruct();
166 pop();
183 pop();
167− }, [completed]); // eslint-disable-line react-hooks/exhaustive-deps
184+ }, [completed, currentL2]); // eslint-disable-line react-hooks/exhaustive-deps
168
185
169 const invitesToDisplay = invites.slice(
186 const invitesToDisplay = invites.slice(
170 page * INVITES_PER_PAGE,
187 page * INVITES_PER_PAGE,
@@ -198,7 +215,7 @@ export default function InviteCohort() {
198
215
199 const downloadCsv = useCallback(() => {
216 const downloadCsv = useCallback(() => {
200 const generateAndDownload = async () => {
217 const generateAndDownload = async () => {
201− setDownloadingCsv(true);
218+ setLoading(true);
202 const invites = await getInvites(currentL2, true);
219 const invites = await getInvites(currentL2, true);
203 if (invites) {
220 if (invites) {
204 const csv = invites.reduce(
221 const csv = invites.reduce(
@@ -218,14 +235,14 @@ export default function InviteCohort() {
218 } else {
235 } else {
219 setError('There was an error creating the CSV');
236 setError('There was an error creating the CSV');
220 }
237 }
221− setDownloadingCsv(false);
238+ setLoading(false);
222 setInviteGeneratingNum(0);
239 setInviteGeneratingNum(0);
223 };
240 };
224 generateAndDownload();
241 generateAndDownload();
225 }, [
242 }, [
226 getInvites,
243 getInvites,
227 setError,
244 setError,
228− setDownloadingCsv,
245+ setLoading,
229 setInviteGeneratingNum,
246 setInviteGeneratingNum,
230 currentL2,
247 currentL2,
231 point,
248 point,
@@ -261,7 +278,7 @@ export default function InviteCohort() {
261 ) : (
278 ) : (
262 <Button2
279 <Button2
263 className="secondary"
280 className="secondary"
264− onClick={() => showInvite(invite.planet)}>
281+ onClick={() => onClickShowInvite(invite.planet)}>
265 Show Invite
282 Show Invite
266 </Button2>
283 </Button2>
267 )}
284 )}
@@ -437,7 +454,10 @@ export default function InviteCohort() {
437 Add More
454 Add More
438 </Button>
455 </Button>
439 )}
456 )}
457+ <LoadingOverlay
440− <LoadingOverlay loading={downloadingCsv} text={downloadingCsvText} />
458+ loading={downloadingCsv || loading}
459+ text={downloadingCsv ? downloadingCsvText : undefined}
460+ />
441 </View>
461 </View>
442 );
462 );
443}
463}
src/views/Login/LoginSelector.tsx+8
@@ -15,6 +15,7 @@ import { MetamaskWallet } from 'lib/metamask';
15import { getAuthToken } from 'lib/authToken';
15import { getAuthToken } from 'lib/authToken';
16import * as need from 'lib/need';
16import * as need from 'lib/need';
17import { useWalletConnect } from 'lib/useWalletConnect';
17import { useWalletConnect } from 'lib/useWalletConnect';
18+import useLoginView from 'lib/useLoginView';
18
19
19import Window from 'components/L2/Window/Window';
20import Window from 'components/L2/Window/Window';
20import HeaderPane from 'components/L2/Window/HeaderPane';
21import HeaderPane from 'components/L2/Window/HeaderPane';
@@ -48,6 +49,8 @@ export default function LoginSelector({
48 // Tab props
49 // Tab props
49 ...rest
50 ...rest
50}: LoginSelectorProps) {
51}: LoginSelectorProps) {
52+ useLoginView(WALLET_TYPES.WALLET_CONNECT);
53+
51 const { push, names }: any = useHistory();
54 const { push, names }: any = useHistory();
52 const [showModal, setShowModal] = useState(false);
55 const [showModal, setShowModal] = useState(false);
53
56
@@ -58,6 +61,8 @@ export default function LoginSelector({
58 setAuthToken,
61 setAuthToken,
59 }: any = useWallet();
62 }: any = useWallet();
60
63
64+ const { connect } = useWalletConnect();
65+
61 const { setPointCursor }: any = usePointCursor();
66 const { setPointCursor }: any = usePointCursor();
62 const { web3 }: any = useNetwork();
67 const { web3 }: any = useNetwork();
63 const _web3 = need.web3(web3);
68 const _web3 = need.web3(web3);
@@ -106,6 +111,9 @@ export default function LoginSelector({
106 if (value === NAMES.METAMASK) {
111 if (value === NAMES.METAMASK) {
107 connectMetamask();
112 connectMetamask();
108 } else {
113 } else {
114+ if (value === NAMES.WALLET_CONNECT) {
115+ connect();
116+ }
109 setCurrentTab(value);
117 setCurrentTab(value);
110 }
118 }
111 };
119 };
src/views/Point/MigrateL2.tsx+1−1
@@ -244,7 +244,7 @@ export default function MigrateL2() {
244 className="bold"
244 className="bold"
245 target="_blank"
245 target="_blank"
246 rel="noreferrer"
246 rel="noreferrer"
247− href="https://discord.com/channels/879614191672115260/879624035028324362">
247+ href="https://urbit-org-9l0a6849p-urbit.vercel.app/docs/azimuth/l2/layer2">
248 Learn More
248 Learn More
249 </a>
249 </a>
250 </Box>
250 </Box>