on master help sign in
Fixing roller timer display, csv download, and show invite
commit4f027ea8ba120d70083a9f91bb486bd1fa86d729 authorWill Galebach <willbach@gmail.com> dateWed 3 Nov 2021, 21:47 (5 years ago) parentc17fe59
7 files changed+50−18
src/lib/useRoller.ts+7−3 src/lib/utils/invite.ts+1−1 src/lib/utils/roller.ts+1−1 src/store/storage/roller.ts+1−1 src/views/Invite/Cohort.tsx+31−11 src/views/Login/LoginSelector.tsx+8 src/views/Point/MigrateL2.tsx+1−1
src/lib/useRoller.ts+7−3
@@ -313,7 +313,9 @@ export default function useRoller() {
313313 getDetails
314314 ).filter((p: number) => isPlanet(p) && availablePoints.includes(p));
315315
316− const invitePlanets = spawnedPoints.concat(outgoingPoints);
316+ const invitePlanets = spawnedPoints.concat(
317+ outgoingPoints.filter((p: number) => !spawnedPoints.includes(p))
318+ );
317319
318320 if (isDevelopment) {
319321 console.log('INVITED PLANETS', invitePlanets);
@@ -406,8 +408,10 @@ export default function useRoller() {
406408 setPendingTransactions(newPending);
407409 setInvitePoints(
408410 invitePoints
409− .concat(outgoingPoints)
410− .filter(p => !pendingSpawns.has(p))
411+ .concat(
412+ outgoingPoints.filter((p: number) => !invitePoints.includes(p))
413+ )
414+ .filter((p: number) => !pendingSpawns.has(p))
411415 );
412416 }
413417 } catch (e) {
src/lib/utils/invite.ts+1−1
@@ -31,4 +31,4 @@ export const generateCsvLine = (ind: number, ticket: string, planet: number) =>
3131 )},${planet},${ticket}\n`;
3232
3333export 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) =>
3030 invite.planet === point;
3131
3232export const getTimeToNextBatch = (nextBatch: number, now: number) => {
33− const toNext = nextBatch - now;
33+ const toNext = Math.max(nextBatch - now, 0);
3434 const hours = Math.floor(toNext / HOUR);
3535 const minutes = Math.floor((toNext - hours * HOUR) / MINUTE);
3636 const seconds = Math.floor(
src/store/storage/roller.ts+1−1
@@ -15,7 +15,7 @@ export const getStoredInvites = (ls: SecureLS): Invites => {
1515export const setStoredInvites = (ls: SecureLS, newInvites: Invite[]) => {
1616 let invites: Invites = {};
1717 try {
18− invites = ls.get(INVITES_KEY);
18+ invites = ls.get(INVITES_KEY) || {};
1919 } catch (e) {}
2020
2121 newInvites.forEach(invite => {
src/views/Invite/Cohort.tsx+31−11
@@ -75,7 +75,7 @@ export default function InviteCohort() {
7575 const { contracts }: any = useNetwork();
7676 const { syncControlledPoints }: any = usePointCache();
7777
78− const point = Just(pointCursor)
78+ const point = pointCursor.getOrElse(null);
7979 const _contracts = need.contracts(contracts);
8080
8181 const [numInvites, setNumInvites] = useState(
@@ -83,13 +83,25 @@ export default function InviteCohort() {
8383 );
8484 const [showInviteForm, setShowInviteForm] = useState(false);
8585 const [loading, setLoading] = useState(false);
86− const [error, setError] = useState('');
8786 const [downloadingCsv, setDownloadingCsv] = useState(false);
87+ const [error, setError] = useState('');
8888 const [l1Invite, setL1Invite] = useState<L1Invite | null>(null);
8989 const [page, setPage] = useState(0);
9090
9191 const { construct, unconstruct, completed, bind } = useIssueChild();
9292
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+
93105 useEffect(() => {
94106 if (invitePoints.length > 0) {
95107 getInvites(currentL2);
@@ -101,7 +113,7 @@ export default function InviteCohort() {
101113 const _authToken = authToken.getOrElse(null);
102114
103115 const setUpInvite = async () => {
104− setLoading(true);
116+ setDownloadingCsv(true);
105117 const possiblePoints = await azimuth.azimuth.getUnspawnedChildren(
106118 _contracts,
107119 point
@@ -132,7 +144,7 @@ export default function InviteCohort() {
132144 setError('No available planets');
133145 }
134146
135− setLoading(false);
147+ setDownloadingCsv(false);
136148 };
137149
138150 if (!currentL2 && _contracts && point && _authToken && showInviteForm) {
@@ -154,7 +166,12 @@ export default function InviteCohort() {
154166 useEffect(() => {
155167 const storedInvites = getStoredInvites(ls);
156168
157− if (!completed || !l1Invite || storedInvites[l1Invite.planet]) {
169+ if (
170+ !currentL2 ||
171+ !completed ||
172+ !l1Invite ||
173+ storedInvites[l1Invite.planet]
174+ ) {
158175 return;
159176 }
160177
@@ -164,7 +181,7 @@ export default function InviteCohort() {
164181 setL1Invite(null);
165182 unconstruct();
166183 pop();
167− }, [completed]); // eslint-disable-line react-hooks/exhaustive-deps
184+ }, [completed, currentL2]); // eslint-disable-line react-hooks/exhaustive-deps
168185
169186 const invitesToDisplay = invites.slice(
170187 page * INVITES_PER_PAGE,
@@ -198,7 +215,7 @@ export default function InviteCohort() {
198215
199216 const downloadCsv = useCallback(() => {
200217 const generateAndDownload = async () => {
201− setDownloadingCsv(true);
218+ setLoading(true);
202219 const invites = await getInvites(currentL2, true);
203220 if (invites) {
204221 const csv = invites.reduce(
@@ -218,14 +235,14 @@ export default function InviteCohort() {
218235 } else {
219236 setError('There was an error creating the CSV');
220237 }
221− setDownloadingCsv(false);
238+ setLoading(false);
222239 setInviteGeneratingNum(0);
223240 };
224241 generateAndDownload();
225242 }, [
226243 getInvites,
227244 setError,
228− setDownloadingCsv,
245+ setLoading,
229246 setInviteGeneratingNum,
230247 currentL2,
231248 point,
@@ -261,7 +278,7 @@ export default function InviteCohort() {
261278 ) : (
262279 <Button2
263280 className="secondary"
264− onClick={() => showInvite(invite.planet)}>
281+ onClick={() => onClickShowInvite(invite.planet)}>
265282 Show Invite
266283 </Button2>
267284 )}
@@ -437,7 +454,10 @@ export default function InviteCohort() {
437454 Add More
438455 </Button>
439456 )}
440− <LoadingOverlay loading={downloadingCsv} text={downloadingCsvText} />
457+ <LoadingOverlay
458+ loading={downloadingCsv || loading}
459+ text={downloadingCsv ? downloadingCsvText : undefined}
460+ />
441461 </View>
442462 );
443463}
src/views/Login/LoginSelector.tsx+8
@@ -15,6 +15,7 @@ import { MetamaskWallet } from 'lib/metamask';
1515import { getAuthToken } from 'lib/authToken';
1616import * as need from 'lib/need';
1717import { useWalletConnect } from 'lib/useWalletConnect';
18+import useLoginView from 'lib/useLoginView';
1819
1920import Window from 'components/L2/Window/Window';
2021import HeaderPane from 'components/L2/Window/HeaderPane';
@@ -48,6 +49,8 @@ export default function LoginSelector({
4849 // Tab props
4950 ...rest
5051}: LoginSelectorProps) {
52+ useLoginView(WALLET_TYPES.WALLET_CONNECT);
53+
5154 const { push, names }: any = useHistory();
5255 const [showModal, setShowModal] = useState(false);
5356
@@ -58,6 +61,8 @@ export default function LoginSelector({
5861 setAuthToken,
5962 }: any = useWallet();
6063
64+ const { connect } = useWalletConnect();
65+
6166 const { setPointCursor }: any = usePointCursor();
6267 const { web3 }: any = useNetwork();
6368 const _web3 = need.web3(web3);
@@ -106,6 +111,9 @@ export default function LoginSelector({
106111 if (value === NAMES.METAMASK) {
107112 connectMetamask();
108113 } else {
114+ if (value === NAMES.WALLET_CONNECT) {
115+ connect();
116+ }
109117 setCurrentTab(value);
110118 }
111119 };
src/views/Point/MigrateL2.tsx+1−1
@@ -244,7 +244,7 @@ export default function MigrateL2() {
244244 className="bold"
245245 target="_blank"
246246 rel="noreferrer"
247− href="https://discord.com/channels/879614191672115260/879624035028324362">
247+ href="https://urbit-org-9l0a6849p-urbit.vercel.app/docs/azimuth/l2/layer2">
248248 Learn More
249249 </a>
250250 </Box>