on master help sign in
Merge pull request #582 from urbit/m/whale-greasing

store: more nuanced syncing

commitfbc8b0c2d7e37fa74382f89aa99452c6b4a9fccb authorfang <github@fang.io> dateMon 28 Jun 2021, 20:05 (5 years ago) parent8eec223d55748d
10 files changed+30−64
src/components/Passport.js+2−2 src/lib/useSyncPoints.js+9−9 src/store/lib/usePointStore.js+7−25 src/views/Activate.js+2−4 src/views/CreateGalaxy.js+2−2 src/views/Invite/Cohort.js+2−2 src/views/IssueChild.js+2−5 src/views/Point.js+2−2 src/views/Points.js−11 src/views/Release/Active.js+2−2
src/components/Passport.js+2−2
@@ -7,7 +7,7 @@ import 'style/anim.css';
77import * as need from 'lib/need';
88import { chunkStr, Matrix, walk, rand } from 'lib/card';
99import usePermissionsForPoint from 'lib/usePermissionsForPoint';
10−import { useSyncOwnedPoints } from 'lib/useSyncPoints';
10+import { useSyncDetails } from 'lib/useSyncPoints';
1111import { buildKeyType } from 'lib/point';
1212
1313import { useWallet } from 'store/wallet';
@@ -212,7 +212,7 @@ const Cell = props => {
212212 *
213213 */
214214function MiniPassport({ point, inverted, ...rest }) {
215− useSyncOwnedPoints([point]);
215+ useSyncDetails([point]);
216216 const { wallet } = useWallet();
217217 const address = need.addressFromWallet(wallet);
218218
src/lib/useSyncPoints.js+9−9
@@ -16,17 +16,17 @@ const buildSyncHook = getFn =>
1616 }, [fn, prevPoints, points]);
1717 };
1818
19−export const useSyncKnownPoints = buildSyncHook(function() {
20− const { syncKnownPoint } = usePointCache();
21− return syncKnownPoint;
19+export const useSyncDates = buildSyncHook(function() {
20+ const { syncDates } = usePointCache();
21+ return syncDates;
2222});
2323
24−export const useSyncForeignPoints = buildSyncHook(function() {
25− const { syncForeignPoint } = usePointCache();
26− return syncForeignPoint;
24+export const useSyncDetails = buildSyncHook(function() {
25+ const { syncDetails } = usePointCache();
26+ return syncDetails;
2727});
2828
29−export const useSyncOwnedPoints = buildSyncHook(function() {
30− const { syncOwnedPoint } = usePointCache();
31− return syncOwnedPoint;
29+export const useSyncExtras = buildSyncHook(function() {
30+ const { syncExtras } = usePointCache();
31+ return syncExtras;
3232});
src/store/lib/usePointStore.js+7−25
@@ -20,38 +20,21 @@ export default function usePointStore() {
2020 const { syncResidents, syncResidentCount, ...residents } = useResidents();
2121 const ecliptic = useEclipticOwnerStore();
2222
23− // sync all of the on-chain info required to display a known point
24− const syncKnownPoint = useCallback(
23+ const syncDates = useCallback(
2524 async point => Promise.all([syncBirthday(point), syncRekeyDate(point)]),
2625 [syncBirthday, syncRekeyDate]
2726 );
2827
29− // sync all of the on-chain info required to display a foreign point
30− const syncForeignPoint = useCallback(
31− async point => {
32− syncDetails(point);
33− },
34− [syncDetails]
35− );
36−
37− // sync all of the on-chain info required for a point that the user owns
38− const syncOwnedPoint = useCallback(
28+ const syncExtras = useCallback(
3929 async point =>
4030 Promise.all([
41− syncForeignPoint(point),
42− syncKnownPoint(point),
31+ syncDetails(point),
4332 //
33+ syncDates(point),
4434 syncResidentCount(point),
45− syncDetails(point),
4635 syncInvites(point),
4736 ]),
48− [
49− syncForeignPoint,
50− syncKnownPoint,
51− syncDetails,
52− syncInvites,
53− syncResidentCount,
54− ]
37+ [syncDates, syncDetails, syncInvites, syncResidentCount]
5538 );
5639
5740 return {
@@ -66,9 +49,8 @@ export default function usePointStore() {
6649 syncRekeyDate,
6750 syncInvites,
6851 syncControlledPoints,
69− syncKnownPoint,
70− syncOwnedPoint,
71− syncForeignPoint,
52+ syncDates,
7253 syncResidents,
54+ syncExtras,
7355 };
7456}
src/views/Activate.js+2−4
@@ -2,7 +2,7 @@ import React, { useEffect } from 'react';
22
33import useRouter from 'lib/useRouter';
44import { LocalRouterProvider } from 'lib/LocalRouter';
5−import { useSyncKnownPoints } from 'lib/useSyncPoints';
5+import { useSyncDates } from 'lib/useSyncPoints';
66
77import { ActivateFlowProvider } from './Activate/ActivateFlow';
88import useActivateFlowState from './Activate/useActivateFlowState';
@@ -38,9 +38,7 @@ export default function Activate() {
3838 }, []);
3939
4040 // when we know the derived point, ensure we have the data to display it
41− useSyncKnownPoints(
42− [state.derivedPoint.getOrElse(null)].filter(p => p !== null)
43− );
41+ useSyncDates([state.derivedPoint.getOrElse(null)].filter(p => p !== null));
4442
4543 return (
4644 <LocalRouterProvider value={router}>
src/views/CreateGalaxy.js+2−2
@@ -29,7 +29,7 @@ import CopiableAddress from 'components/CopiableAddress';
2929
3030function useCreateGalaxy() {
3131 const { contracts } = useNetwork();
32− const { syncKnownPoint } = usePointCache();
32+ const { syncDates } = usePointCache();
3333
3434 const _contracts = need.contracts(contracts);
3535
@@ -43,7 +43,7 @@ function useCreateGalaxy() {
4343 },
4444 [_contracts]
4545 ),
46− useCallback(() => syncKnownPoint(galaxy), [galaxy, syncKnownPoint]),
46+ useCallback(() => syncDates(galaxy), [galaxy, syncDates]),
4747 GAS_LIMITS.DEFAULT
4848 );
4949}
src/views/Invite/Cohort.js+2−2
@@ -26,7 +26,7 @@ import Inviter from 'views/Invite/Inviter';
2626
2727import { ReactComponent as SearchIcon } from 'assets/search.svg';
2828import CopyButton from 'components/CopyButton';
29−import { useSyncForeignPoints } from 'lib/useSyncPoints';
29+import { useSyncDetails } from 'lib/useSyncPoints';
3030import { useNetwork } from 'store/network';
3131import NavHeader from 'components/NavHeader';
3232
@@ -305,7 +305,7 @@ export default function InviteCohort() {
305305
306306 const [selectedInvite, _setSelectedInvite] = useState();
307307
308− useSyncForeignPoints([..._acceptedPoints, ..._pendingPoints]);
308+ useSyncDetails([..._acceptedPoints, ..._pendingPoints]);
309309
310310 const setSelectedInvite = useCallback(
311311 p => _setSelectedInvite(old => (old === p ? null : p)),
src/views/IssueChild.js+2−5
@@ -34,7 +34,7 @@ import convertToInt from 'lib/convertToInt';
3434
3535function useIssueChild() {
3636 const { contracts } = useNetwork();
37− const { syncKnownPoint } = usePointCache();
37+ const { syncDates } = usePointCache();
3838
3939 const _contracts = need.contracts(contracts);
4040
@@ -48,10 +48,7 @@ function useIssueChild() {
4848 },
4949 [_contracts]
5050 ),
51− useCallback(() => syncKnownPoint(spawnedPoint), [
52− spawnedPoint,
53− syncKnownPoint,
54− ]),
51+ useCallback(() => syncDates(spawnedPoint), [spawnedPoint, syncDates]),
5552 GAS_LIMITS.DEFAULT
5653 );
5754}
src/views/Point.js+2−2
@@ -18,7 +18,7 @@ import { ForwardButton } from 'components/Buttons';
1818
1919import * as need from 'lib/need';
2020import useInvites from 'lib/useInvites';
21−import { useSyncOwnedPoints } from 'lib/useSyncPoints';
21+import { useSyncExtras } from 'lib/useSyncPoints';
2222import useCurrentPermissions from 'lib/useCurrentPermissions';
2323import { useLocalRouter } from 'lib/LocalRouter';
2424
@@ -216,7 +216,7 @@ export default function Point() {
216216 })();
217217
218218 // sync the current cursor
219− useSyncOwnedPoints([point]);
219+ useSyncExtras([point]);
220220
221221 const address = need.addressFromWallet(wallet);
222222
src/views/Points.js−11
@@ -12,7 +12,6 @@ import { useStarReleaseCache } from 'store/starRelease';
1212import * as need from 'lib/need';
1313import { isZeroAddress, abbreviateAddress } from 'lib/wallet';
1414import useIsEclipticOwner from 'lib/useIsEclipticOwner';
15−import { useSyncKnownPoints, useSyncOwnedPoints } from 'lib/useSyncPoints';
1615import useRejectedIncomingPointTransfers from 'lib/useRejectedIncomingPointTransfers';
1716import pluralize from 'lib/pluralize';
1817import newGithubIssueUrl from 'new-github-issue-url';
@@ -203,16 +202,6 @@ export default function Points() {
203202 useEffect(() => {
204203 syncStarReleaseDetails();
205204 }, [syncStarReleaseDetails]);
206− // sync display details for known points
207− useSyncKnownPoints([
208− ...ownedPoints,
209− ...incomingPoints,
210− ...managingPoints,
211− ...votingPoints,
212− ...spawningPoints,
213− ]);
214−
215− useSyncOwnedPoints(ownedPoints);
216205
217206 const goCreateGalaxy = useCallback(() => push(names.CREATE_GALAXY), [
218207 names.CREATE_GALAXY,
src/views/Release/Active.js+2−2
@@ -10,13 +10,13 @@ import { useWallet } from 'store/wallet';
1010
1111import * as need from 'lib/need';
1212import usePermissionsForPoint from 'lib/usePermissionsForPoint';
13−import { useSyncOwnedPoints } from 'lib/useSyncPoints';
13+import { useSyncDetails } from 'lib/useSyncPoints';
1414import { buildKeyType } from 'lib/point';
1515
1616function ActiveViewRow({ point, goPoint }) {
1717 const { wallet } = useWallet();
1818 const address = need.addressFromWallet(wallet);
19− useSyncOwnedPoints([point]);
19+ useSyncDetails([point]);
2020 const permissions = usePermissionsForPoint(address, point);
2121
2222 const keyType = buildKeyType(permissions);