on master help sign in
invites: removing unused code and converting files to TS
commit89063619f9a20f0ff74023fd94c464d6058b3e6c authorHunter Miller <hunter@hmiller.dev> dateThu 17 Feb 2022, 16:28 (5 years ago) parentc635e69
6 files changed+36−103
src/Bridge.js → src/Bridge.tsx+24−14 src/components/GlobalErrorBoundary.js → src/components/GlobalErrorBoundary.tsx+11−4 src/index.js → src/index.tsx src/lib/useInvites.js−7 src/store/lib/useInvitesStore.js−71 src/store/lib/usePointStore.js+1−7
src/Bridge.js → src/Bridge.tsxrenamed+24−14
@@ -1,4 +1,3 @@
1−import React from 'react';
21import { useEffect } from 'react';
32import { Just, Nothing } from 'folktale/maybe';
43import { IndigoApp } from 'indigo-react';
@@ -26,6 +25,8 @@ import { useRollerStore } from 'store/rollerStore';
2625import { Box } from '@tlon/indigo-react';
2726import LoadingOverlay from 'components/L2/LoadingOverlay';
2827import { useRollerPoller } from 'lib/useRollerPoller';
28+import { BrowserRouter, Route, Routes } from 'react-router-dom';
29+import InviteCohort from 'views/Invite/Cohort';
2930
3031const INITIAL_NETWORK_TYPE = isRopsten
3132 ? NETWORK_TYPES.ROPSTEN
@@ -39,8 +40,8 @@ const IS_STUBBED = isDevelopment && SHOULD_STUB_LOCAL;
3940
4041const INITIAL_WALLET = IS_STUBBED
4142 ? walletFromMnemonic(
42− process.env.REACT_APP_DEV_MNEMONIC,
43− process.env.REACT_APP_HD_PATH
43+ process.env.REACT_APP_DEV_MNEMONIC as string,
44+ process.env.REACT_APP_HD_PATH as string
4445 )
4546 : undefined;
4647const INITIAL_MNEMONIC = IS_STUBBED
@@ -94,7 +95,8 @@ function Bridge() {
9495 }, []);
9596
9697 return (
97− <WithErrorBoundary render={error => <GlobalErrorBoundary error={error} />}>
98+ <WithErrorBoundary
99+ render={(error: Error) => <GlobalErrorBoundary error={error} />}>
98100 <Provider
99101 views={ROUTES}
100102 names={ROUTE_NAMES}
@@ -103,16 +105,24 @@ function Bridge() {
103105 initialWallet={INITIAL_WALLET}
104106 initialMnemonic={INITIAL_MNEMONIC}
105107 initialPointCursor={INITIAL_POINT_CURSOR}>
106− <IndigoApp>
107− <ThemeProvider theme={light}>
108− <Router />
109− </ThemeProvider>
110− </IndigoApp>
111− <Modal show={modalText !== undefined} hide={() => setModalText()}>
112− <Box width="280px">{modalText}</Box>
113− </Modal>
114− <LoadingOverlay loading={loading} />
115− <Poller />
108+ <BrowserRouter>
109+ <IndigoApp>
110+ <ThemeProvider theme={light}>
111+ <Router />
112+ <Routes>
113+ <Route path="/" element={null} />
114+ <Route path="/point/:point">
115+ <Route path="invites" element={<InviteCohort />} />
116+ </Route>
117+ </Routes>
118+ </ThemeProvider>
119+ </IndigoApp>
120+ <Modal show={modalText !== undefined} hide={() => setModalText('')}>
121+ <Box width="280px">{modalText}</Box>
122+ </Modal>
123+ <LoadingOverlay loading={loading} />
124+ <Poller />
125+ </BrowserRouter>
116126 </Provider>
117127 </WithErrorBoundary>
118128 );
src/components/GlobalErrorBoundary.js → src/components/GlobalErrorBoundary.tsxrenamed+11−4
@@ -1,11 +1,11 @@
1−import React, { useMemo } from 'react';
1+import { useMemo } from 'react';
22import newGithubIssueUrl from 'new-github-issue-url';
33import { OutButton, RestartButton } from './Buttons';
44import { versionLabel } from 'lib/flags';
55
6−const buildTitle = error => `Error Report: ${error.message}`;
6+const buildTitle = (error: Error) => `Error Report: ${error.message}`;
77
8−const buildBody = error => `\n
8+const buildBody = (error: Error) => `\n
99<!-- Thanks for submitting this error! Can you help us identify the issue by providing additional context? -->
1010\n
1111## Context
@@ -27,7 +27,14 @@ In Bridge version ${versionLabel}.\n
2727 * error might have originated from within those components, making this
2828 * whole error boundary useless.
2929 */
30−export default function GlobalErrorBoundary({ error }) {
30+
31+interface GlobalErrorBoundaryProps {
32+ error: Error;
33+}
34+
35+export default function GlobalErrorBoundary({
36+ error,
37+}: GlobalErrorBoundaryProps) {
3138 const url = useMemo(
3239 () =>
3340 newGithubIssueUrl({
src/index.js → src/index.tsxrenamed

The content is the same.

src/lib/useInvites.jsdeleted−7
@@ -1,7 +0,0 @@
1−import { usePointCache } from 'store/pointCache';
2−
3−export default function useInvites(point) {
4− const { getInvites } = usePointCache();
5−
6− return getInvites(point);
7−}
src/store/lib/useInvitesStore.jsdeleted−71
@@ -1,71 +0,0 @@
1−import { useCallback } from 'react';
2−import { Just, Nothing } from 'folktale/maybe';
3−import * as azimuth from 'azimuth-js';
4−import { chain } from 'lodash';
5−
6−import { useNetwork } from '../network';
7−import useSetState from 'lib/useSetState';
8−
9−// the default value of a point's invites
10−const EMPTY_INVITES = {
11− availableInvites: Nothing(),
12− sentInvites: Nothing(),
13− acceptedInvites: Nothing(),
14− acceptedPoints: Nothing(),
15− pendingPoints: Nothing(),
16−};
17−
18−export default function useInvitesStore() {
19− const { contracts } = useNetwork();
20− const [invitesCache, addToInvitesCache] = useSetState({});
21−
22− const getInvites = useCallback(
23− point => invitesCache[point] || EMPTY_INVITES,
24− [invitesCache]
25− );
26−
27− const syncInvites = useCallback(
28− async point => {
29− const _contracts = contracts.getOrElse(null);
30− if (!_contracts) {
31− return;
32− }
33−
34− const [availableInvites, invitedPoints] = await Promise.all([
35− azimuth.delegatedSending.getTotalUsableInvites(_contracts, point),
36− azimuth.delegatedSending.getInvited(_contracts, point),
37− ]);
38−
39− const activity = await Promise.all(
40− invitedPoints.map(invitedPoint =>
41− azimuth.azimuth.isActive(_contracts, invitedPoint)
42− )
43− );
44−
45− const sentInvites = invitedPoints.length;
46− const acceptedInvites = activity.filter(i => !!i).length;
47−
48− const [acceptedPoints, pendingPoints] = chain(invitedPoints)
49− .zipWith(activity, (point, active) => ({
50− point,
51− active: !!active,
52− }))
53− .partition('active')
54− .map(arr => arr.map(x => x.point))
55− .value();
56−
57− addToInvitesCache({
58− [point]: {
59− availableInvites: Just(availableInvites),
60− sentInvites: Just(sentInvites),
61− acceptedInvites: Just(acceptedInvites),
62− pendingPoints: Just(pendingPoints),
63− acceptedPoints: Just(acceptedPoints),
64− },
65− });
66− },
67− [contracts, addToInvitesCache]
68− );
69−
70− return { getInvites, syncInvites };
71−}
src/store/lib/usePointStore.js+1−7
@@ -2,7 +2,6 @@ import { useCallback } from 'react';
22
33import useDetailsStore from './useDetailsStore';
44import useRekeyDateStore from './useRekeyDateStore';
5−import useInvitesStore from './useInvitesStore';
65import useControlledPointsStore from './useControlledPointsStore';
76import useEclipticOwnerStore from './useEclipticOwnerStore';
87import useResidents from './useResidentsStore';
@@ -10,7 +9,6 @@ import useResidents from './useResidentsStore';
109export default function usePointStore() {
1110 const { syncDetails, ...details } = useDetailsStore();
1211 const { syncRekeyDate, ...rekeyDates } = useRekeyDateStore();
13− const { syncInvites, ...invites } = useInvitesStore();
1412 const {
1513 syncControlledPoints,
1614 ...controlledPoints
@@ -27,24 +25,20 @@ export default function usePointStore() {
2725 async point =>
2826 Promise.all([
2927 syncDetails(point),
30− //
3128 syncDates(point),
3229 syncResidentCount(point),
33− syncInvites(point),
3430 ]),
35− [syncDates, syncDetails, syncInvites, syncResidentCount]
31+ [syncDates, syncDetails, syncResidentCount]
3632 );
3733
3834 return {
3935 ...details,
4036 ...rekeyDates,
41− ...invites,
4237 ...controlledPoints,
4338 ...ecliptic,
4439 ...residents,
4540 syncDetails,
4641 syncRekeyDate,
47− syncInvites,
4842 syncControlledPoints,
4943 syncDates,
5044 syncResidents,