on master help sign in
Merge pull request #949 from urbit/hm/remove-birthdays

Remove birthday store

commit3628fc518f206a85f5f8da5ea6e61a22e3c7896a authortomholford <16504501+tomholford@users.noreply.github.com> dateWed 9 Feb 2022, 17:57 (5 years ago) parentccc6b6469b7547
3 files changed+2−71
src/lib/usePointBirthday.js−7 src/store/lib/useBirthdaysStore.js−59 src/store/lib/usePointStore.js+2−5
src/lib/usePointBirthday.jsdeleted−7
@@ -1,7 +0,0 @@
1−import { usePointCache } from 'store/pointCache';
2−
3−export default function usePointBirthday(point) {
4− const { getBirthday } = usePointCache();
5−
6− return getBirthday(point);
7−}
src/store/lib/useBirthdaysStore.jsdeleted−59
@@ -1,59 +0,0 @@
1−import { useCallback, useState } from 'react';
2−import { Just, Nothing } from 'folktale/maybe';
3−import * as azimuth from 'azimuth-js';
4−
5−import { useNetwork } from '../network';
6−
7−export default function useBirthdayStore() {
8− const { contracts, web3 } = useNetwork();
9− const [birthdayCache, _setBirthdayCache] = useState({});
10−
11− const addToBirthdayCache = useCallback(
12− entry =>
13− _setBirthdayCache(cache => ({
14− ...cache,
15− ...entry,
16− })),
17− [_setBirthdayCache]
18− );
19−
20− const getBirthday = useCallback(point => birthdayCache[point] || Nothing(), [
21− birthdayCache,
22− ]);
23−
24− const syncBirthday = useCallback(
25− async point => {
26− const _contracts = contracts.getOrElse(null);
27− const _web3 = web3.getOrElse(null);
28− if (!_contracts || !_web3) {
29− return;
30− }
31−
32− // birthday will not change after being set, so bail if we already know
33− if (Just.hasInstance(getBirthday(point))) {
34− return;
35− }
36−
37− const birthBlock = await azimuth.azimuth.getActivationBlock(
38− _contracts,
39− point
40− );
41−
42− if (birthBlock > 0) {
43− const block = await _web3.eth.getBlock(birthBlock);
44− addToBirthdayCache({
45− [point]: Just(new Date(block.timestamp * 1000)),
46− });
47− } else {
48− // TODO: better encoding for "no birthday" state using Result.Ok/Error
49− // if there's no birthday, just use today
50− addToBirthdayCache({
51− [point]: Just(new Date()),
52− });
53− }
54− },
55− [contracts, web3, addToBirthdayCache, getBirthday]
56− );
57−
58− return { getBirthday, syncBirthday };
59−}
src/store/lib/usePointStore.js+2−5
@@ -1,7 +1,6 @@
11import { useCallback } from 'react';
22
33import useDetailsStore from './useDetailsStore';
4−import useBirthdaysStore from './useBirthdaysStore';
54import useRekeyDateStore from './useRekeyDateStore';
65import useInvitesStore from './useInvitesStore';
76import useControlledPointsStore from './useControlledPointsStore';
@@ -10,7 +9,6 @@ import useResidents from './useResidentsStore';
109
1110export default function usePointStore() {
1211 const { syncDetails, ...details } = useDetailsStore();
13− const { syncBirthday, ...birthdays } = useBirthdaysStore();
1412 const { syncRekeyDate, ...rekeyDates } = useRekeyDateStore();
1513 const { syncInvites, ...invites } = useInvitesStore();
1614 const {
@@ -21,8 +19,8 @@ export default function usePointStore() {
2119 const ecliptic = useEclipticOwnerStore();
2220
2321 const syncDates = useCallback(
24− async point => Promise.all([syncBirthday(point), syncRekeyDate(point)]),
25− [syncBirthday, syncRekeyDate]
22+ async point => Promise.all([syncRekeyDate(point)]),
23+ [syncRekeyDate]
2624 );
2725
2826 const syncExtras = useCallback(
@@ -39,7 +37,6 @@ export default function usePointStore() {
3937
4038 return {
4139 ...details,
42− ...birthdays,
4340 ...rekeyDates,
4441 ...invites,
4542 ...controlledPoints,