@bitsocial/bitsocial-react-hooks 0.3.1 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/hooks/communities.d.ts.map +1 -1
- package/dist/hooks/communities.js +74 -23
- package/dist/hooks/communities.js.map +1 -1
- package/dist/lib/pkc-js/pkc-js-mock.d.ts.map +1 -1
- package/dist/lib/pkc-js/pkc-js-mock.js +11 -0
- package/dist/lib/pkc-js/pkc-js-mock.js.map +1 -1
- package/dist/stores/accounts/accounts-actions.js +4 -4
- package/dist/stores/accounts/accounts-actions.js.map +1 -1
- package/dist/types.d.ts +13 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
## [0.3.3](https://github.com/bitsocialnet/bitsocial-react-hooks/compare/v0.3.2...v0.3.3) (2026-11-21)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **deps:** upgrade pkc-js to 0.0.154 and prepare 0.3.3 ([#195](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/195)) ([1071165](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/107116519a9f3bdacc568132651e9a769cb0c42b)), closes [#573](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/573) [#534](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/534) [#564](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/564)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## [0.3.2](https://github.com/bitsocialnet/bitsocial-react-hooks/compare/v0.3.1...v0.3.2) (2026-11-20)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* **communities:** report each community's load status in useCommunities ([#193](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/193)) ([66b3408](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/66b340860ce75aaf929bcd5151d2bb063271c408))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
1
19
|
## [0.3.1](https://github.com/bitsocialnet/bitsocial-react-hooks/compare/v0.3.0...v0.3.1) (2026-11-20)
|
|
2
20
|
|
|
3
21
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"communities.d.ts","sourceRoot":"","sources":["../../src/hooks/communities.ts"],"names":[],"mappings":"AAMA,OAAO,
|
|
1
|
+
{"version":3,"file":"communities.d.ts","sourceRoot":"","sources":["../../src/hooks/communities.ts"],"names":[],"mappings":"AAMA,OAAO,EAIL,cAAc,EAEd,kCAAkC,EAClC,iCAAiC,EACjC,mBAAmB,EACnB,kBAAkB,EAClB,qBAAqB,EACrB,oBAAoB,EACpB,wBAAwB,EACxB,uBAAuB,EACxB,MAAM,UAAU,CAAC;AA+FlB;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,kBAAkB,CAuI9E;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,CAAC,EAAE,wBAAwB,GAAG,uBAAuB,CAyF7F;AAeD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,oBAAoB,CAoJpF;AAGD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,CAAC,EAAE,MAAM,YAqBtD;AAED;;;;GAIG;AAEH,wBAAgB,2BAA2B,CACzC,OAAO,CAAC,EAAE,kCAAkC,GAC3C,iCAAiC,CA6HnC;AAGD,eAAO,MAAM,uBAAuB,GAClC,kBAAkB,MAAM,EACxB,gBAAgB,cAAc,iBAe/B,CAAC"}
|
|
@@ -16,13 +16,49 @@ import assert from "../lib/assert.js";
|
|
|
16
16
|
import useInterval from "./utils/use-interval.js";
|
|
17
17
|
import createStore from "zustand";
|
|
18
18
|
import { resolveEnsTxtRecord } from "../lib/chain/index.js";
|
|
19
|
-
import useCommunitiesStore, { getCommunityFirstLoadFailure } from "../stores/communities/index.js";
|
|
19
|
+
import useCommunitiesStore, { getCommunityFirstLoadFailure, } from "../stores/communities/index.js";
|
|
20
20
|
import useAccountsStore from "../stores/accounts/index.js";
|
|
21
|
-
|
|
21
|
+
// the deprecated default export warns on every call outside production
|
|
22
|
+
import { shallow } from "zustand/shallow";
|
|
22
23
|
import { getChainProviders, getPkcCommunityAddresses } from "../lib/pkc-compat.js";
|
|
23
24
|
import { getCommunityRefKey, getUniqueSortedCommunityRefs } from "../lib/community-ref.js";
|
|
24
25
|
let communityAutoUpdateSubscriptionCount = 0;
|
|
25
26
|
const emptyErrors = [];
|
|
27
|
+
const emptyCommunityLoadStatuses = [];
|
|
28
|
+
// The load status of a community, shared by useCommunity and useCommunities so they can't disagree
|
|
29
|
+
// about the same community. `restartsStoppedCommunity`: the hook keeps the community updating, so it
|
|
30
|
+
// restarts one the store stopped because nothing used it.
|
|
31
|
+
const getCommunityLoadStatus = (community, syncStatus, errors, onlyIfCached, restartsStoppedCommunity) => {
|
|
32
|
+
const firstLoadFailure = getCommunityFirstLoadFailure(syncStatus, community);
|
|
33
|
+
let state = (community === null || community === void 0 ? void 0 : community.updatingState) || "initializing";
|
|
34
|
+
// the first load failed non-retriably: it threw before the community reached the store,
|
|
35
|
+
// update() rejected, which ends in "stopped", or pkc-js reported failed. Kept through the next
|
|
36
|
+
// attempts, instead of going back to loading on each one, until a record loads.
|
|
37
|
+
if (firstLoadFailure === "non-retriable") {
|
|
38
|
+
state = "failed";
|
|
39
|
+
}
|
|
40
|
+
// force succeeded even if the community is fetching a new update
|
|
41
|
+
if (community === null || community === void 0 ? void 0 : community.updatedAt) {
|
|
42
|
+
state = "succeeded";
|
|
43
|
+
}
|
|
44
|
+
let syncState = (syncStatus === null || syncStatus === void 0 ? void 0 : syncStatus.syncState) || (onlyIfCached ? "stopped" : "initializing");
|
|
45
|
+
// the store stops a community once nothing uses it and the hook's effect restarts it, so the
|
|
46
|
+
// render before the effect does not report a terminal state for a community about to load
|
|
47
|
+
if ((syncStatus === null || syncStatus === void 0 ? void 0 : syncStatus.stoppedUntilUsed) && restartsStoppedCommunity) {
|
|
48
|
+
syncState = "loading";
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
state,
|
|
52
|
+
syncState,
|
|
53
|
+
hasCachedData: typeof (community === null || community === void 0 ? void 0 : community.updatedAt) === "number",
|
|
54
|
+
firstLoadFailed: firstLoadFailure !== undefined,
|
|
55
|
+
lastFetchAttemptAt: syncStatus === null || syncStatus === void 0 ? void 0 : syncStatus.lastFetchAttemptAt,
|
|
56
|
+
lastSuccessfulFetchAt: syncStatus === null || syncStatus === void 0 ? void 0 : syncStatus.lastSuccessfulFetchAt,
|
|
57
|
+
lastRetriableError: syncStatus === null || syncStatus === void 0 ? void 0 : syncStatus.lastRetriableError,
|
|
58
|
+
error: errors === null || errors === void 0 ? void 0 : errors[errors.length - 1],
|
|
59
|
+
errors: errors || emptyErrors,
|
|
60
|
+
};
|
|
61
|
+
};
|
|
26
62
|
const parseMaybeJson = (value) => (typeof value === "string" ? JSON.parse(value) : value);
|
|
27
63
|
const tryParseMaybeJson = (value) => {
|
|
28
64
|
try {
|
|
@@ -140,26 +176,8 @@ export function useCommunity(options) {
|
|
|
140
176
|
]));
|
|
141
177
|
return Object.assign(Object.assign({}, (storedCommunity || { address: (communityInput === null || communityInput === void 0 ? void 0 : communityInput.name) || (communityInput === null || communityInput === void 0 ? void 0 : communityInput.publicKey) })), summaryValues);
|
|
142
178
|
}, [account === null || account === void 0 ? void 0 : account.pkc, storedCommunity, communityInput, communityEditSummary]);
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
// the first load failed non-retriably: it threw before the community reached the store,
|
|
146
|
-
// update() rejected, which ends in "stopped", or pkc-js reported failed. Kept through the next
|
|
147
|
-
// attempts, instead of going back to loading on each one, until a record loads.
|
|
148
|
-
if (firstLoadFailure === "non-retriable") {
|
|
149
|
-
state = "failed";
|
|
150
|
-
}
|
|
151
|
-
// force succeeded even if the community is fecthing a new update
|
|
152
|
-
if (mergedCommunity === null || mergedCommunity === void 0 ? void 0 : mergedCommunity.updatedAt) {
|
|
153
|
-
state = "succeeded";
|
|
154
|
-
}
|
|
155
|
-
let syncState = (syncStatus === null || syncStatus === void 0 ? void 0 : syncStatus.syncState) || (onlyIfCached ? "stopped" : "initializing");
|
|
156
|
-
// the store stops a community once nothing uses it and this hook's effect restarts it, so the
|
|
157
|
-
// render before the effect does not report a terminal state for a community about to load
|
|
158
|
-
if ((syncStatus === null || syncStatus === void 0 ? void 0 : syncStatus.stoppedUntilUsed) && !onlyIfCached && autoUpdate && communityInput && account) {
|
|
159
|
-
syncState = "loading";
|
|
160
|
-
}
|
|
161
|
-
return useMemo(() => (Object.assign(Object.assign({}, mergedCommunity), { state,
|
|
162
|
-
syncState, hasCachedData: typeof (mergedCommunity === null || mergedCommunity === void 0 ? void 0 : mergedCommunity.updatedAt) === "number", firstLoadFailed: firstLoadFailure !== undefined, lastFetchAttemptAt: syncStatus === null || syncStatus === void 0 ? void 0 : syncStatus.lastFetchAttemptAt, lastSuccessfulFetchAt: syncStatus === null || syncStatus === void 0 ? void 0 : syncStatus.lastSuccessfulFetchAt, lastRetriableError: syncStatus === null || syncStatus === void 0 ? void 0 : syncStatus.lastRetriableError, error: errors === null || errors === void 0 ? void 0 : errors[errors.length - 1], errors: errors || [] })), [mergedCommunity, communityKey, errors, syncState, syncStatus]);
|
|
179
|
+
const restartsStoppedCommunity = Boolean(!onlyIfCached && autoUpdate && communityInput && account);
|
|
180
|
+
return useMemo(() => (Object.assign(Object.assign({}, mergedCommunity), getCommunityLoadStatus(mergedCommunity, syncStatus, errors, onlyIfCached, restartsStoppedCommunity))), [mergedCommunity, communityKey, errors, syncStatus, onlyIfCached, restartsStoppedCommunity]);
|
|
163
181
|
}
|
|
164
182
|
/**
|
|
165
183
|
* @param community - The community identifier, e.g. {name: 'memes.eth'} or {publicKey: '12D3KooW...'}
|
|
@@ -262,6 +280,7 @@ export function useCommunities(options) {
|
|
|
262
280
|
const communityKeys = useMemo(() => normalizedCommunityRefs.map(getCommunityRefKey), [normalizedCommunityRefs]);
|
|
263
281
|
const communities = useCommunitiesStore((state) => communityKeys.map((communityKey) => state.communities[communityKey || ""]), shallow);
|
|
264
282
|
const communitiesErrors = useCommunitiesStore((state) => communityKeys.map((communityKey) => state.errors[communityKey || ""]), shallow);
|
|
283
|
+
const communitiesSyncStatuses = useCommunitiesStore((state) => communityKeys.map((communityKey) => state.syncStatuses[communityKey || ""]), shallow);
|
|
265
284
|
const addCommunityToStore = useCommunitiesStore((state) => state.addCommunityToStore);
|
|
266
285
|
const startCommunityAutoUpdate = useCommunitiesStore((state) => state.startCommunityAutoUpdate);
|
|
267
286
|
const stopCommunityAutoUpdate = useCommunitiesStore((state) => state.stopCommunityAutoUpdate);
|
|
@@ -307,12 +326,44 @@ export function useCommunities(options) {
|
|
|
307
326
|
: communities.indexOf(undefined) === -1
|
|
308
327
|
? "succeeded"
|
|
309
328
|
: "fetching-ipns";
|
|
329
|
+
// derived like useCommunity, which also restarts a community the store stopped
|
|
330
|
+
const restartsStoppedCommunities = Boolean(!onlyIfCached && autoUpdate && account);
|
|
331
|
+
// a store change to one of the communities that leaves the statuses as they were, e.g. its
|
|
332
|
+
// clients, a change to one status, or reordered communities keep the previous objects of the
|
|
333
|
+
// unchanged statuses, found by community key. The previous statuses are the last committed ones,
|
|
334
|
+
// a render React discards doesn't replace them.
|
|
335
|
+
const previousCommunityLoadStatuses = useRef({
|
|
336
|
+
communityKeys: [],
|
|
337
|
+
statuses: emptyCommunityLoadStatuses,
|
|
338
|
+
});
|
|
339
|
+
const communityLoadStatuses = useMemo(() => {
|
|
340
|
+
const previous = previousCommunityLoadStatuses.current;
|
|
341
|
+
const previousStatusesByKey = new Map();
|
|
342
|
+
previous.communityKeys.forEach((communityKey, index) => previousStatusesByKey.set(communityKey, previous.statuses[index]));
|
|
343
|
+
const statuses = communities.map((community, index) => {
|
|
344
|
+
const status = getCommunityLoadStatus(community, communitiesSyncStatuses[index], communitiesErrors[index], onlyIfCached, restartsStoppedCommunities);
|
|
345
|
+
const previousStatus = previousStatusesByKey.get(communityKeys[index]);
|
|
346
|
+
return previousStatus && shallow(previousStatus, status) ? previousStatus : status;
|
|
347
|
+
});
|
|
348
|
+
return shallow(previous.statuses, statuses) ? previous.statuses : statuses;
|
|
349
|
+
}, [
|
|
350
|
+
communityKeys,
|
|
351
|
+
communities,
|
|
352
|
+
communitiesSyncStatuses,
|
|
353
|
+
communitiesErrors,
|
|
354
|
+
onlyIfCached,
|
|
355
|
+
restartsStoppedCommunities,
|
|
356
|
+
]);
|
|
357
|
+
useEffect(() => {
|
|
358
|
+
previousCommunityLoadStatuses.current = { communityKeys, statuses: communityLoadStatuses };
|
|
359
|
+
}, [communityKeys, communityLoadStatuses]);
|
|
310
360
|
return useMemo(() => ({
|
|
311
361
|
communities,
|
|
362
|
+
communityLoadStatuses,
|
|
312
363
|
state,
|
|
313
364
|
error: errors[errors.length - 1],
|
|
314
365
|
errors,
|
|
315
|
-
}), [communities, state, errors, communityKeys.toString()]);
|
|
366
|
+
}), [communities, communityLoadStatuses, state, errors, communityKeys.toString()]);
|
|
316
367
|
}
|
|
317
368
|
// TODO: pkc.listCommunities() has been removed, rename this and use event communitieschanged instead of polling
|
|
318
369
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"communities.js","sourceRoot":"","sources":["../../src/hooks/communities.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,SAAS,MAAM,kBAAkB,CAAC;AACzC,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM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\nimport { useAccount } from \"./accounts\";\nimport validator from \"../lib/validator\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:communities:hooks\");\nimport assert from \"../lib/assert\";\nimport {\n Community,\n CommunityStats,\n ChainProviders,\n CommunitySyncState,\n UseResolvedCommunityAddressOptions,\n UseResolvedCommunityAddressResult,\n UseCommunityOptions,\n UseCommunityResult,\n UseCommunitiesOptions,\n UseCommunitiesResult,\n UseCommunityStatsOptions,\n UseCommunityStatsResult,\n} from \"../types\";\nimport useInterval from \"./utils/use-interval\";\nimport createStore from \"zustand\";\nimport { resolveEnsTxtRecord } from \"../lib/chain\";\nimport useCommunitiesStore, { getCommunityFirstLoadFailure } from \"../stores/communities\";\nimport useAccountsStore from \"../stores/accounts\";\nimport shallow from \"zustand/shallow\";\nimport { getChainProviders, getPkcCommunityAddresses } from \"../lib/pkc-compat\";\nimport { getCommunityRefKey, getUniqueSortedCommunityRefs } from \"../lib/community-ref\";\n\nlet communityAutoUpdateSubscriptionCount = 0;\nconst emptyErrors: Error[] = [];\n\nconst parseMaybeJson = (value: unknown) => (typeof value === \"string\" ? JSON.parse(value) : value);\n\nconst tryParseMaybeJson = (value: unknown) => {\n try {\n return parseMaybeJson(value);\n } catch {\n return value;\n }\n};\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n !!value && typeof value === \"object\";\n\nconst isCommunityStatsPayload = (value: unknown): value is CommunityStats =>\n isRecord(value) &&\n (\"hourActiveUserCount\" in value || \"weekActiveUserCount\" in value || \"allPostCount\" in value);\n\nconst parseFetchedCommunityStats = (fetchedCid: unknown): CommunityStats => {\n const parsedCid = parseMaybeJson(fetchedCid);\n if (isCommunityStatsPayload(parsedCid)) {\n return parsedCid;\n }\n if (isRecord(parsedCid) && \"content\" in parsedCid) {\n const parsedContent = tryParseMaybeJson(parsedCid.content);\n if (isCommunityStatsPayload(parsedContent)) {\n return parsedContent;\n }\n }\n return parsedCid as CommunityStats;\n};\n\n/**\n * @param community - The community identifier, e.g. {name: 'memes.eth'} or {publicKey: '12D3KooW...'}\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\nexport function useCommunity(options?: UseCommunityOptions): UseCommunityResult {\n assert(\n !options || typeof options === \"object\",\n `useCommunity options argument '${options}' not an object`,\n );\n const opts = options ?? {};\n const { community: communityInput, accountName, onlyIfCached, autoUpdate = true } = opts;\n const account = useAccount({ accountName });\n const accountId = account?.id || \"\";\n validator.validateUseCommunityArguments({\n community: communityInput,\n communityAddress: (opts as any).communityAddress,\n account,\n });\n const communityKey = communityInput ? getCommunityRefKey(communityInput) : \"\";\n const storedCommunity = useCommunitiesStore((state: any) => state.communities[communityKey]);\n const addCommunityToStore = useCommunitiesStore((state: any) => state.addCommunityToStore);\n const startCommunityAutoUpdate = useCommunitiesStore(\n (state: any) => state.startCommunityAutoUpdate,\n );\n const stopCommunityAutoUpdate = useCommunitiesStore(\n (state: any) => state.stopCommunityAutoUpdate,\n );\n const autoUpdateSubscriptionId = useRef(`useCommunity-${++communityAutoUpdateSubscriptionCount}`);\n const errors = useCommunitiesStore((state: any) => state.errors[communityKey]);\n const syncStatus = useCommunitiesStore((state: any) => state.syncStatuses[communityKey]);\n const communityEditSummary = useAccountsStore((state: any) => {\n const accountEditsSummaries = state.accountsEditsSummaries[accountId] || {};\n const candidateCommunityKeys = [\n storedCommunity?.address,\n storedCommunity?.name,\n storedCommunity?.publicKey,\n communityInput?.name,\n communityInput?.publicKey,\n ];\n for (const candidateCommunityKey of candidateCommunityKeys) {\n if (\n typeof candidateCommunityKey === \"string\" &&\n accountEditsSummaries[candidateCommunityKey]\n ) {\n return accountEditsSummaries[candidateCommunityKey];\n }\n }\n });\n\n useEffect(() => {\n if (!communityInput || !account || onlyIfCached) {\n return;\n }\n if (!autoUpdate) {\n // load the community once if it isn't already in store, without keeping it updating\n if (!storedCommunity) {\n addCommunityToStore(communityInput, account).catch((error: unknown) =>\n log.error(\"useCommunity addCommunityToStore error\", { communityInput, error }),\n );\n }\n return;\n }\n // keep the community updating while mounted, it stops a grace period after the last\n // subscriber unmounts\n const subscriberId = autoUpdateSubscriptionId.current;\n startCommunityAutoUpdate(communityInput, subscriberId, account).catch((error: unknown) =>\n log.error(\"useCommunity startCommunityAutoUpdate error\", { communityInput, error }),\n );\n return () => {\n stopCommunityAutoUpdate(communityInput, subscriberId).catch((error: unknown) =>\n log.error(\"useCommunity stopCommunityAutoUpdate error\", { communityInput, error }),\n );\n };\n }, [communityKey, account?.id, onlyIfCached, autoUpdate]);\n\n if (account && communityInput) {\n log(\"useCommunity\", {\n community: communityInput,\n communityKey,\n storedCommunity,\n account,\n });\n }\n\n const mergedCommunity = useMemo(() => {\n if (!communityEditSummary) {\n return storedCommunity;\n }\n const localCommunityAddresses = getPkcCommunityAddresses(account?.pkc);\n const editedCommunityAddress = communityEditSummary.address?.value;\n const inputCommunityIdentifiers = [communityInput?.name, communityInput?.publicKey].filter(\n (communityIdentifier): communityIdentifier is string =>\n typeof communityIdentifier === \"string\",\n );\n if (\n !storedCommunity &&\n editedCommunityAddress &&\n !inputCommunityIdentifiers.some((communityIdentifier) =>\n localCommunityAddresses.includes(communityIdentifier),\n ) &&\n !localCommunityAddresses.includes(editedCommunityAddress)\n ) {\n return storedCommunity;\n }\n if (\n storedCommunity?.address &&\n editedCommunityAddress &&\n storedCommunity.address !== editedCommunityAddress\n ) {\n return storedCommunity;\n }\n const summaryValues = Object.fromEntries(\n Object.entries(communityEditSummary).map(([propertyName, propertySummary]: [string, any]) => [\n propertyName,\n propertySummary?.value,\n ]),\n );\n return {\n ...(storedCommunity || { address: communityInput?.name || communityInput?.publicKey }),\n ...summaryValues,\n };\n }, [account?.pkc, storedCommunity, communityInput, communityEditSummary]);\n\n const firstLoadFailure = getCommunityFirstLoadFailure(syncStatus, mergedCommunity);\n let state = mergedCommunity?.updatingState || \"initializing\";\n // the first load failed non-retriably: it threw before the community reached the store,\n // update() rejected, which ends in \"stopped\", or pkc-js reported failed. Kept through the next\n // attempts, instead of going back to loading on each one, until a record loads.\n if (firstLoadFailure === \"non-retriable\") {\n state = \"failed\";\n }\n // force succeeded even if the community is fecthing a new update\n if (mergedCommunity?.updatedAt) {\n state = \"succeeded\";\n }\n\n let syncState: CommunitySyncState =\n syncStatus?.syncState || (onlyIfCached ? \"stopped\" : \"initializing\");\n // the store stops a community once nothing uses it and this hook's effect restarts it, so the\n // render before the effect does not report a terminal state for a community about to load\n if (syncStatus?.stoppedUntilUsed && !onlyIfCached && autoUpdate && communityInput && account) {\n syncState = \"loading\";\n }\n\n return useMemo(\n () => ({\n ...mergedCommunity,\n state,\n syncState,\n hasCachedData: typeof mergedCommunity?.updatedAt === \"number\",\n firstLoadFailed: firstLoadFailure !== undefined,\n lastFetchAttemptAt: syncStatus?.lastFetchAttemptAt,\n lastSuccessfulFetchAt: syncStatus?.lastSuccessfulFetchAt,\n lastRetriableError: syncStatus?.lastRetriableError,\n error: errors?.[errors.length - 1],\n errors: errors || [],\n }),\n [mergedCommunity, communityKey, errors, syncState, syncStatus],\n );\n}\n\n/**\n * @param community - The community identifier, e.g. {name: 'memes.eth'} or {publicKey: '12D3KooW...'}\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\nexport function useCommunityStats(options?: UseCommunityStatsOptions): UseCommunityStatsResult {\n assert(\n !options || typeof options === \"object\",\n `useCommunityStats options argument '${options}' not an object`,\n );\n const opts = options ?? {};\n const { community, accountName, onlyIfCached } = opts;\n validator.validateUseCommunityStatsArguments({\n community,\n communityAddress: (opts as any).communityAddress,\n });\n const account = useAccount({ accountName });\n const communityKey = community ? getCommunityRefKey(community) : \"\";\n const fetchedCommunity = useCommunity({ community, onlyIfCached });\n const communityStatsCid = fetchedCommunity?.statsCid;\n const communityStats = useCommunitiesStatsStore(\n (state: CommunitiesStatsState) => state.communitiesStats[communityKey],\n );\n const setCommunityStats = useCommunitiesStatsStore(\n (state: CommunitiesStatsState) => state.setCommunityStats,\n );\n const [fetchError, setFetchError] = useState<Error | undefined>();\n\n useEffect(() => {\n setFetchError(undefined);\n if (!communityKey || !communityStatsCid || !account) {\n return;\n }\n let cancelled = false;\n (async () => {\n let fetchedCid;\n try {\n fetchedCid = await account.pkc.fetchCid({ cid: communityStatsCid });\n fetchedCid = parseFetchedCommunityStats(fetchedCid);\n if (cancelled) {\n return;\n }\n setCommunityStats(communityKey, fetchedCid);\n } catch (error) {\n const normalizedError =\n error instanceof Error ? error : new Error(typeof error === \"string\" ? error : \"error\");\n if (cancelled) {\n return;\n }\n setFetchError(normalizedError);\n log.error(\"useCommunityStats pkc.fetchCid error\", {\n community,\n communityKey,\n communityStatsCid,\n fetchedCommunity,\n fetchedCid,\n error: normalizedError,\n });\n }\n })();\n return () => {\n cancelled = true;\n };\n }, [communityStatsCid, account?.id, communityKey, setCommunityStats]);\n\n if (account && communityStatsCid) {\n log(\"useCommunityStats\", {\n community,\n communityKey,\n communityStatsCid,\n communityStats,\n fetchedCommunity,\n account,\n });\n }\n\n const state =\n !communityKey || !account || !communityStatsCid\n ? \"uninitialized\"\n : fetchError\n ? \"failed\"\n : communityStats\n ? \"succeeded\"\n : \"fetching-ipfs\";\n\n return useMemo(\n () => ({\n ...communityStats,\n state,\n error: fetchError,\n errors: fetchError ? [fetchError] : [],\n }),\n [communityStats, state, fetchError],\n );\n}\n\ntype CommunitiesStatsState = {\n communitiesStats: { [communityAddress: string]: CommunityStats };\n setCommunityStats: Function;\n};\n\nconst useCommunitiesStatsStore = createStore<CommunitiesStatsState>((setState: Function) => ({\n communitiesStats: {},\n setCommunityStats: (communityAddress: string, communityStats: CommunityStats) =>\n setState((state: CommunitiesStatsState) => ({\n communitiesStats: { ...state.communitiesStats, [communityAddress]: communityStats },\n })),\n}));\n\n/**\n * @param communities - The communities to fetch, e.g. [{name: 'memes.eth'}, {publicKey: '12D3KooW...'}]\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\nexport function useCommunities(options?: UseCommunitiesOptions): UseCommunitiesResult {\n assert(\n !options || typeof options === \"object\",\n `useCommunities options argument '${options}' not an object`,\n );\n const opts = options ?? {};\n const { communities: communitiesInput, accountName, onlyIfCached, autoUpdate = true } = opts;\n const account = useAccount({ accountName });\n validator.validateUseCommunitiesArguments({\n communities: communitiesInput,\n communityRefs: (opts as any).communityRefs,\n communityAddresses: (opts as any).communityAddresses,\n account,\n });\n const normalizedCommunityRefs = useMemo(() => communitiesInput || [], [communitiesInput]);\n const communityKeys = useMemo(\n () => normalizedCommunityRefs.map(getCommunityRefKey),\n [normalizedCommunityRefs],\n );\n const communities: (Community | undefined)[] = useCommunitiesStore(\n (state: any) => communityKeys.map((communityKey) => state.communities[communityKey || \"\"]),\n shallow,\n );\n const communitiesErrors: (Error[] | undefined)[] = useCommunitiesStore(\n (state: any) => communityKeys.map((communityKey) => state.errors[communityKey || \"\"]),\n shallow,\n );\n const addCommunityToStore = useCommunitiesStore((state: any) => state.addCommunityToStore);\n const startCommunityAutoUpdate = useCommunitiesStore(\n (state: any) => state.startCommunityAutoUpdate,\n );\n const stopCommunityAutoUpdate = useCommunitiesStore(\n (state: any) => state.stopCommunityAutoUpdate,\n );\n const autoUpdateSubscriptionId = useRef(\n `useCommunities-${++communityAutoUpdateSubscriptionCount}`,\n );\n\n // keyed by the community keys, so a new array of the same communities does not resubscribe\n useEffect(() => {\n if (!normalizedCommunityRefs.length || !account) {\n return;\n }\n if (onlyIfCached) {\n return;\n }\n const uniqueCommunityRefs = getUniqueSortedCommunityRefs(normalizedCommunityRefs);\n if (!autoUpdate) {\n // load the communities once, without keeping them updating\n for (const communityRef of uniqueCommunityRefs) {\n addCommunityToStore(communityRef, account).catch((error: unknown) =>\n log.error(\"useCommunities addCommunityToStore error\", { communityRef, error }),\n );\n }\n return;\n }\n const subscriberId = autoUpdateSubscriptionId.current;\n for (const communityRef of uniqueCommunityRefs) {\n startCommunityAutoUpdate(communityRef, subscriberId, account).catch((error: unknown) =>\n log.error(\"useCommunities startCommunityAutoUpdate error\", { communityRef, error }),\n );\n }\n return () => {\n for (const communityRef of uniqueCommunityRefs) {\n stopCommunityAutoUpdate(communityRef, subscriberId).catch((error: unknown) =>\n log.error(\"useCommunities stopCommunityAutoUpdate error\", { communityRef, error }),\n );\n }\n };\n }, [account?.id, communityKeys.toString(), onlyIfCached, autoUpdate]);\n\n if (account && normalizedCommunityRefs.length) {\n log(\"useCommunities\", {\n requestedCommunities: normalizedCommunityRefs,\n communityKeys,\n communities,\n account,\n });\n }\n\n const errors = useMemo(\n () => communitiesErrors.flatMap((communityErrors) => communityErrors || []),\n [communitiesErrors],\n );\n const hasFailedCommunity = communities.some(\n (community, index) => !community && Boolean(communitiesErrors[index]?.length),\n );\n const state = hasFailedCommunity\n ? \"failed\"\n : communities.indexOf(undefined) === -1\n ? \"succeeded\"\n : \"fetching-ipns\";\n\n return useMemo(\n () => ({\n communities,\n state,\n error: errors[errors.length - 1],\n errors,\n }),\n [communities, state, errors, communityKeys.toString()],\n );\n}\n\n// TODO: pkc.listCommunities() has been removed, rename this and use event communitieschanged instead of polling\n/**\n * Returns all the owner communities created by pkc-js by calling pkc.listCommunities()\n */\nexport function useListCommunities(accountName?: string) {\n const account = useAccount({ accountName });\n const [communityAddresses, setCommunityAddresses] = useState<string[]>([]);\n\n const delay = 1000;\n const immediate = true;\n useInterval(\n () => {\n const pkc = account?.pkc;\n if (!pkc) return;\n const newAddrs = getPkcCommunityAddresses(pkc);\n if (newAddrs.toString() !== communityAddresses.toString()) {\n log(\"useListCommunities\", { communityAddresses });\n setCommunityAddresses(newAddrs);\n }\n },\n delay,\n immediate,\n );\n\n return communityAddresses;\n}\n\n/**\n * @param communityAddress - The community address to resolve to a public key, e.g. 'news.eth' resolves to '12D3KooW...'.\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\n// NOTE: useResolvedCommunityAddress tests are skipped, if changes are made they must be tested manually\nexport function useResolvedCommunityAddress(\n options?: UseResolvedCommunityAddressOptions,\n): UseResolvedCommunityAddressResult {\n assert(\n !options || typeof options === \"object\",\n `useResolvedCommunityAddress options argument '${options}' not an object`,\n );\n let { communityAddress, accountName, cache } = options ?? {};\n\n // cache by default\n if (typeof cache !== \"boolean\") {\n cache = true;\n }\n\n // poll every 15 seconds, about the duration of an eth block\n let interval = 15000;\n // no point in polling often if caching is on\n if (cache) {\n interval = 1000 * 60 * 60 * 25;\n }\n\n const account = useAccount({ accountName });\n const chainProviders = getChainProviders(account);\n const [resolvedAddress, setResolvedAddress] = useState<string>();\n const [errors, setErrors] = useState<Error[]>([]);\n const [state, setState] = useState<string>();\n // the address that resolvedAddress, state and errors belong to: the ref for completions that land\n // later, the state for rendering because it updates in the same render as the result\n const resultAddress = useRef<string | undefined>(undefined);\n const [renderedResultAddress, setRenderedResultAddress] = useState<string>();\n\n let initialState = \"initializing\";\n // before those defined, nothing can happen\n if (options && account && communityAddress) {\n initialState = \"ready\";\n }\n\n useInterval(\n () => {\n if (!account || !communityAddress) {\n resultAddress.current = undefined;\n setRenderedResultAddress(undefined);\n setResolvedAddress(undefined);\n setState(undefined);\n setErrors((prevErrors) => (prevErrors.length ? [] : prevErrors));\n return;\n }\n\n // a new address starts without the result of the previous address\n const address = communityAddress;\n let currentState = state;\n if (resultAddress.current !== address) {\n resultAddress.current = address;\n setRenderedResultAddress(address);\n currentState = undefined;\n setResolvedAddress(undefined);\n setErrors((prevErrors) => (prevErrors.length ? [] : prevErrors));\n setState(undefined);\n }\n\n // address isn't a crypto domain, can't be resolved\n if (!communityAddress?.includes(\".\")) {\n if (currentState !== \"failed\") {\n setErrors([Error(\"not a crypto domain\")]);\n setState(\"failed\");\n setResolvedAddress(undefined);\n }\n return;\n }\n\n // only support resolving '.eth' for now\n if (!communityAddress?.endsWith(\".eth\")) {\n if (currentState !== \"failed\") {\n setErrors([Error(\"crypto domain type unsupported\")]);\n setState(\"failed\");\n setResolvedAddress(undefined);\n }\n return;\n }\n\n (async () => {\n try {\n // later polls keep reporting the current result instead of going back to resolving\n if (!currentState) {\n setState(\"resolving\");\n }\n const res = await resolveCommunityAddress(address, chainProviders);\n // the address changed while resolving\n if (resultAddress.current !== address) {\n return;\n }\n setState(\"succeeded\");\n setErrors((prevErrors) => (prevErrors.length ? [] : prevErrors));\n setResolvedAddress(res);\n } catch (error: any) {\n if (resultAddress.current !== address) {\n return;\n }\n setErrors((prevErrors) => [...prevErrors, error]);\n setState(\"failed\");\n setResolvedAddress(undefined);\n log.error(\"useResolvedCommunityAddress resolveCommunityAddress error\", {\n communityAddress,\n chainProviders,\n error,\n });\n }\n })();\n },\n interval,\n true,\n [communityAddress, chainProviders],\n );\n\n // only support ENS at the moment\n const chainProvider = chainProviders?.[\"eth\"];\n\n // log('useResolvedCommunityAddress', {communityAddress, state, errors, resolvedAddress, chainProviders})\n // until the interval has run for a new address, the stored result is the previous address's\n const isCurrentResult = renderedResultAddress === communityAddress;\n return {\n resolvedAddress: isCurrentResult ? resolvedAddress : undefined,\n chainProvider,\n state: (isCurrentResult && state) || initialState,\n error: isCurrentResult ? errors[errors.length - 1] : undefined,\n errors: isCurrentResult ? errors : emptyErrors,\n };\n}\n\n// NOTE: resolveCommunityAddress tests are skipped, if changes are made they must be tested manually\nexport const resolveCommunityAddress = async (\n communityAddress: string,\n chainProviders: ChainProviders,\n) => {\n let resolvedCommunityAddress;\n if (communityAddress.endsWith(\".eth\")) {\n resolvedCommunityAddress = await resolveEnsTxtRecord(\n communityAddress,\n \"community-address\",\n \"eth\",\n chainProviders?.[\"eth\"]?.urls?.[0],\n chainProviders?.[\"eth\"]?.chainId,\n );\n } else {\n throw Error(`resolveCommunityAddress invalid communityAddress '${communityAddress}'`);\n }\n return resolvedCommunityAddress;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"communities.js","sourceRoot":"","sources":["../../src/hooks/communities.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,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cAAc,aAAd,cAAc,uBAAd,cAAc,CAAG,KAAK,CAAC,CAAC;IAE9C,yGAAyG;IACzG,4FAA4F;IAC5F,MAAM,eAAe,GAAG,qBAAqB,KAAK,gBAAgB,CAAC;IACnE,OAAO;QACL,eAAe,EAAE,eAAe,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,SAAS;QAC9D,aAAa;QACb,KAAK,EAAE,CAAC,eAAe,IAAI,KAAK,CAAC,IAAI,YAAY;QACjD,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS;QAC9D,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW;KAC/C,CAAC;AACJ,CAAC;AAED,oGAAoG;AACpG,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,gBAAwB,EACxB,cAA8B,EAC9B,EAAE;;IACF,IAAI,wBAAwB,CAAC;IAC7B,IAAI,gBAAgB,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACtC,wBAAwB,GAAG,MAAM,mBAAmB,CAClD,gBAAgB,EAChB,mBAAmB,EACnB,KAAK,EACL,MAAA,MAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAG,KAAK,CAAC,0CAAE,IAAI,0CAAG,CAAC,CAAC,EAClC,MAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAG,KAAK,CAAC,0CAAE,OAAO,CACjC,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,MAAM,KAAK,CAAC,qDAAqD,gBAAgB,GAAG,CAAC,CAAC;IACxF,CAAC;IACD,OAAO,wBAAwB,CAAC;AAClC,CAAC,CAAA,CAAC","sourcesContent":["import { useEffect, useState, useMemo, useRef } from \"react\";\nimport { useAccount } from \"./accounts\";\nimport validator from \"../lib/validator\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:communities:hooks\");\nimport assert from \"../lib/assert\";\nimport {\n Community,\n CommunityLoadStatus,\n CommunityStats,\n ChainProviders,\n CommunitySyncState,\n UseResolvedCommunityAddressOptions,\n UseResolvedCommunityAddressResult,\n UseCommunityOptions,\n UseCommunityResult,\n UseCommunitiesOptions,\n UseCommunitiesResult,\n UseCommunityStatsOptions,\n UseCommunityStatsResult,\n} from \"../types\";\nimport useInterval from \"./utils/use-interval\";\nimport createStore from \"zustand\";\nimport { resolveEnsTxtRecord } from \"../lib/chain\";\nimport useCommunitiesStore, {\n CommunitiesState,\n getCommunityFirstLoadFailure,\n} from \"../stores/communities\";\nimport useAccountsStore from \"../stores/accounts\";\n// the deprecated default export warns on every call outside production\nimport { shallow } from \"zustand/shallow\";\nimport { getChainProviders, getPkcCommunityAddresses } from \"../lib/pkc-compat\";\nimport { getCommunityRefKey, getUniqueSortedCommunityRefs } from \"../lib/community-ref\";\n\nlet communityAutoUpdateSubscriptionCount = 0;\nconst emptyErrors: Error[] = [];\nconst emptyCommunityLoadStatuses: CommunityLoadStatus[] = [];\n\ntype CommunitySyncStatus = CommunitiesState[\"syncStatuses\"][string];\n\n// The load status of a community, shared by useCommunity and useCommunities so they can't disagree\n// about the same community. `restartsStoppedCommunity`: the hook keeps the community updating, so it\n// restarts one the store stopped because nothing used it.\nconst getCommunityLoadStatus = (\n community: Community | undefined,\n syncStatus: CommunitySyncStatus | undefined,\n errors: Error[] | undefined,\n onlyIfCached: boolean | undefined,\n restartsStoppedCommunity: boolean,\n): CommunityLoadStatus => {\n const firstLoadFailure = getCommunityFirstLoadFailure(syncStatus, community);\n let state = community?.updatingState || \"initializing\";\n // the first load failed non-retriably: it threw before the community reached the store,\n // update() rejected, which ends in \"stopped\", or pkc-js reported failed. Kept through the next\n // attempts, instead of going back to loading on each one, until a record loads.\n if (firstLoadFailure === \"non-retriable\") {\n state = \"failed\";\n }\n // force succeeded even if the community is fetching a new update\n if (community?.updatedAt) {\n state = \"succeeded\";\n }\n\n let syncState: CommunitySyncState =\n syncStatus?.syncState || (onlyIfCached ? \"stopped\" : \"initializing\");\n // the store stops a community once nothing uses it and the hook's effect restarts it, so the\n // render before the effect does not report a terminal state for a community about to load\n if (syncStatus?.stoppedUntilUsed && restartsStoppedCommunity) {\n syncState = \"loading\";\n }\n\n return {\n state,\n syncState,\n hasCachedData: typeof community?.updatedAt === \"number\",\n firstLoadFailed: firstLoadFailure !== undefined,\n lastFetchAttemptAt: syncStatus?.lastFetchAttemptAt,\n lastSuccessfulFetchAt: syncStatus?.lastSuccessfulFetchAt,\n lastRetriableError: syncStatus?.lastRetriableError,\n error: errors?.[errors.length - 1],\n errors: errors || emptyErrors,\n };\n};\n\nconst parseMaybeJson = (value: unknown) => (typeof value === \"string\" ? JSON.parse(value) : value);\n\nconst tryParseMaybeJson = (value: unknown) => {\n try {\n return parseMaybeJson(value);\n } catch {\n return value;\n }\n};\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n !!value && typeof value === \"object\";\n\nconst isCommunityStatsPayload = (value: unknown): value is CommunityStats =>\n isRecord(value) &&\n (\"hourActiveUserCount\" in value || \"weekActiveUserCount\" in value || \"allPostCount\" in value);\n\nconst parseFetchedCommunityStats = (fetchedCid: unknown): CommunityStats => {\n const parsedCid = parseMaybeJson(fetchedCid);\n if (isCommunityStatsPayload(parsedCid)) {\n return parsedCid;\n }\n if (isRecord(parsedCid) && \"content\" in parsedCid) {\n const parsedContent = tryParseMaybeJson(parsedCid.content);\n if (isCommunityStatsPayload(parsedContent)) {\n return parsedContent;\n }\n }\n return parsedCid as CommunityStats;\n};\n\n/**\n * @param community - The community identifier, e.g. {name: 'memes.eth'} or {publicKey: '12D3KooW...'}\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\nexport function useCommunity(options?: UseCommunityOptions): UseCommunityResult {\n assert(\n !options || typeof options === \"object\",\n `useCommunity options argument '${options}' not an object`,\n );\n const opts = options ?? {};\n const { community: communityInput, accountName, onlyIfCached, autoUpdate = true } = opts;\n const account = useAccount({ accountName });\n const accountId = account?.id || \"\";\n validator.validateUseCommunityArguments({\n community: communityInput,\n communityAddress: (opts as any).communityAddress,\n account,\n });\n const communityKey = communityInput ? getCommunityRefKey(communityInput) : \"\";\n const storedCommunity = useCommunitiesStore((state: any) => state.communities[communityKey]);\n const addCommunityToStore = useCommunitiesStore((state: any) => state.addCommunityToStore);\n const startCommunityAutoUpdate = useCommunitiesStore(\n (state: any) => state.startCommunityAutoUpdate,\n );\n const stopCommunityAutoUpdate = useCommunitiesStore(\n (state: any) => state.stopCommunityAutoUpdate,\n );\n const autoUpdateSubscriptionId = useRef(`useCommunity-${++communityAutoUpdateSubscriptionCount}`);\n const errors = useCommunitiesStore((state: any) => state.errors[communityKey]);\n const syncStatus = useCommunitiesStore((state: any) => state.syncStatuses[communityKey]);\n const communityEditSummary = useAccountsStore((state: any) => {\n const accountEditsSummaries = state.accountsEditsSummaries[accountId] || {};\n const candidateCommunityKeys = [\n storedCommunity?.address,\n storedCommunity?.name,\n storedCommunity?.publicKey,\n communityInput?.name,\n communityInput?.publicKey,\n ];\n for (const candidateCommunityKey of candidateCommunityKeys) {\n if (\n typeof candidateCommunityKey === \"string\" &&\n accountEditsSummaries[candidateCommunityKey]\n ) {\n return accountEditsSummaries[candidateCommunityKey];\n }\n }\n });\n\n useEffect(() => {\n if (!communityInput || !account || onlyIfCached) {\n return;\n }\n if (!autoUpdate) {\n // load the community once if it isn't already in store, without keeping it updating\n if (!storedCommunity) {\n addCommunityToStore(communityInput, account).catch((error: unknown) =>\n log.error(\"useCommunity addCommunityToStore error\", { communityInput, error }),\n );\n }\n return;\n }\n // keep the community updating while mounted, it stops a grace period after the last\n // subscriber unmounts\n const subscriberId = autoUpdateSubscriptionId.current;\n startCommunityAutoUpdate(communityInput, subscriberId, account).catch((error: unknown) =>\n log.error(\"useCommunity startCommunityAutoUpdate error\", { communityInput, error }),\n );\n return () => {\n stopCommunityAutoUpdate(communityInput, subscriberId).catch((error: unknown) =>\n log.error(\"useCommunity stopCommunityAutoUpdate error\", { communityInput, error }),\n );\n };\n }, [communityKey, account?.id, onlyIfCached, autoUpdate]);\n\n if (account && communityInput) {\n log(\"useCommunity\", {\n community: communityInput,\n communityKey,\n storedCommunity,\n account,\n });\n }\n\n const mergedCommunity = useMemo(() => {\n if (!communityEditSummary) {\n return storedCommunity;\n }\n const localCommunityAddresses = getPkcCommunityAddresses(account?.pkc);\n const editedCommunityAddress = communityEditSummary.address?.value;\n const inputCommunityIdentifiers = [communityInput?.name, communityInput?.publicKey].filter(\n (communityIdentifier): communityIdentifier is string =>\n typeof communityIdentifier === \"string\",\n );\n if (\n !storedCommunity &&\n editedCommunityAddress &&\n !inputCommunityIdentifiers.some((communityIdentifier) =>\n localCommunityAddresses.includes(communityIdentifier),\n ) &&\n !localCommunityAddresses.includes(editedCommunityAddress)\n ) {\n return storedCommunity;\n }\n if (\n storedCommunity?.address &&\n editedCommunityAddress &&\n storedCommunity.address !== editedCommunityAddress\n ) {\n return storedCommunity;\n }\n const summaryValues = Object.fromEntries(\n Object.entries(communityEditSummary).map(([propertyName, propertySummary]: [string, any]) => [\n propertyName,\n propertySummary?.value,\n ]),\n );\n return {\n ...(storedCommunity || { address: communityInput?.name || communityInput?.publicKey }),\n ...summaryValues,\n };\n }, [account?.pkc, storedCommunity, communityInput, communityEditSummary]);\n\n const restartsStoppedCommunity = Boolean(\n !onlyIfCached && autoUpdate && communityInput && account,\n );\n return useMemo(\n () => ({\n ...mergedCommunity,\n ...getCommunityLoadStatus(\n mergedCommunity,\n syncStatus,\n errors,\n onlyIfCached,\n restartsStoppedCommunity,\n ),\n }),\n [mergedCommunity, communityKey, errors, syncStatus, onlyIfCached, restartsStoppedCommunity],\n );\n}\n\n/**\n * @param community - The community identifier, e.g. {name: 'memes.eth'} or {publicKey: '12D3KooW...'}\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\nexport function useCommunityStats(options?: UseCommunityStatsOptions): UseCommunityStatsResult {\n assert(\n !options || typeof options === \"object\",\n `useCommunityStats options argument '${options}' not an object`,\n );\n const opts = options ?? {};\n const { community, accountName, onlyIfCached } = opts;\n validator.validateUseCommunityStatsArguments({\n community,\n communityAddress: (opts as any).communityAddress,\n });\n const account = useAccount({ accountName });\n const communityKey = community ? getCommunityRefKey(community) : \"\";\n const fetchedCommunity = useCommunity({ community, onlyIfCached });\n const communityStatsCid = fetchedCommunity?.statsCid;\n const communityStats = useCommunitiesStatsStore(\n (state: CommunitiesStatsState) => state.communitiesStats[communityKey],\n );\n const setCommunityStats = useCommunitiesStatsStore(\n (state: CommunitiesStatsState) => state.setCommunityStats,\n );\n const [fetchError, setFetchError] = useState<Error | undefined>();\n\n useEffect(() => {\n setFetchError(undefined);\n if (!communityKey || !communityStatsCid || !account) {\n return;\n }\n let cancelled = false;\n (async () => {\n let fetchedCid;\n try {\n fetchedCid = await account.pkc.fetchCid({ cid: communityStatsCid });\n fetchedCid = parseFetchedCommunityStats(fetchedCid);\n if (cancelled) {\n return;\n }\n setCommunityStats(communityKey, fetchedCid);\n } catch (error) {\n const normalizedError =\n error instanceof Error ? error : new Error(typeof error === \"string\" ? error : \"error\");\n if (cancelled) {\n return;\n }\n setFetchError(normalizedError);\n log.error(\"useCommunityStats pkc.fetchCid error\", {\n community,\n communityKey,\n communityStatsCid,\n fetchedCommunity,\n fetchedCid,\n error: normalizedError,\n });\n }\n })();\n return () => {\n cancelled = true;\n };\n }, [communityStatsCid, account?.id, communityKey, setCommunityStats]);\n\n if (account && communityStatsCid) {\n log(\"useCommunityStats\", {\n community,\n communityKey,\n communityStatsCid,\n communityStats,\n fetchedCommunity,\n account,\n });\n }\n\n const state =\n !communityKey || !account || !communityStatsCid\n ? \"uninitialized\"\n : fetchError\n ? \"failed\"\n : communityStats\n ? \"succeeded\"\n : \"fetching-ipfs\";\n\n return useMemo(\n () => ({\n ...communityStats,\n state,\n error: fetchError,\n errors: fetchError ? [fetchError] : [],\n }),\n [communityStats, state, fetchError],\n );\n}\n\ntype CommunitiesStatsState = {\n communitiesStats: { [communityAddress: string]: CommunityStats };\n setCommunityStats: Function;\n};\n\nconst useCommunitiesStatsStore = createStore<CommunitiesStatsState>((setState: Function) => ({\n communitiesStats: {},\n setCommunityStats: (communityAddress: string, communityStats: CommunityStats) =>\n setState((state: CommunitiesStatsState) => ({\n communitiesStats: { ...state.communitiesStats, [communityAddress]: communityStats },\n })),\n}));\n\n/**\n * @param communities - The communities to fetch, e.g. [{name: 'memes.eth'}, {publicKey: '12D3KooW...'}]\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\nexport function useCommunities(options?: UseCommunitiesOptions): UseCommunitiesResult {\n assert(\n !options || typeof options === \"object\",\n `useCommunities options argument '${options}' not an object`,\n );\n const opts = options ?? {};\n const { communities: communitiesInput, accountName, onlyIfCached, autoUpdate = true } = opts;\n const account = useAccount({ accountName });\n validator.validateUseCommunitiesArguments({\n communities: communitiesInput,\n communityRefs: (opts as any).communityRefs,\n communityAddresses: (opts as any).communityAddresses,\n account,\n });\n const normalizedCommunityRefs = useMemo(() => communitiesInput || [], [communitiesInput]);\n const communityKeys = useMemo(\n () => normalizedCommunityRefs.map(getCommunityRefKey),\n [normalizedCommunityRefs],\n );\n const communities: (Community | undefined)[] = useCommunitiesStore(\n (state: any) => communityKeys.map((communityKey) => state.communities[communityKey || \"\"]),\n shallow,\n );\n const communitiesErrors: (Error[] | undefined)[] = useCommunitiesStore(\n (state: any) => communityKeys.map((communityKey) => state.errors[communityKey || \"\"]),\n shallow,\n );\n const communitiesSyncStatuses: (CommunitySyncStatus | undefined)[] = useCommunitiesStore(\n (state: CommunitiesState) =>\n communityKeys.map((communityKey) => state.syncStatuses[communityKey || \"\"]),\n shallow,\n );\n const addCommunityToStore = useCommunitiesStore((state: any) => state.addCommunityToStore);\n const startCommunityAutoUpdate = useCommunitiesStore(\n (state: any) => state.startCommunityAutoUpdate,\n );\n const stopCommunityAutoUpdate = useCommunitiesStore(\n (state: any) => state.stopCommunityAutoUpdate,\n );\n const autoUpdateSubscriptionId = useRef(\n `useCommunities-${++communityAutoUpdateSubscriptionCount}`,\n );\n\n // keyed by the community keys, so a new array of the same communities does not resubscribe\n useEffect(() => {\n if (!normalizedCommunityRefs.length || !account) {\n return;\n }\n if (onlyIfCached) {\n return;\n }\n const uniqueCommunityRefs = getUniqueSortedCommunityRefs(normalizedCommunityRefs);\n if (!autoUpdate) {\n // load the communities once, without keeping them updating\n for (const communityRef of uniqueCommunityRefs) {\n addCommunityToStore(communityRef, account).catch((error: unknown) =>\n log.error(\"useCommunities addCommunityToStore error\", { communityRef, error }),\n );\n }\n return;\n }\n const subscriberId = autoUpdateSubscriptionId.current;\n for (const communityRef of uniqueCommunityRefs) {\n startCommunityAutoUpdate(communityRef, subscriberId, account).catch((error: unknown) =>\n log.error(\"useCommunities startCommunityAutoUpdate error\", { communityRef, error }),\n );\n }\n return () => {\n for (const communityRef of uniqueCommunityRefs) {\n stopCommunityAutoUpdate(communityRef, subscriberId).catch((error: unknown) =>\n log.error(\"useCommunities stopCommunityAutoUpdate error\", { communityRef, error }),\n );\n }\n };\n }, [account?.id, communityKeys.toString(), onlyIfCached, autoUpdate]);\n\n if (account && normalizedCommunityRefs.length) {\n log(\"useCommunities\", {\n requestedCommunities: normalizedCommunityRefs,\n communityKeys,\n communities,\n account,\n });\n }\n\n const errors = useMemo(\n () => communitiesErrors.flatMap((communityErrors) => communityErrors || []),\n [communitiesErrors],\n );\n const hasFailedCommunity = communities.some(\n (community, index) => !community && Boolean(communitiesErrors[index]?.length),\n );\n const state = hasFailedCommunity\n ? \"failed\"\n : communities.indexOf(undefined) === -1\n ? \"succeeded\"\n : \"fetching-ipns\";\n\n // derived like useCommunity, which also restarts a community the store stopped\n const restartsStoppedCommunities = Boolean(!onlyIfCached && autoUpdate && account);\n // a store change to one of the communities that leaves the statuses as they were, e.g. its\n // clients, a change to one status, or reordered communities keep the previous objects of the\n // unchanged statuses, found by community key. The previous statuses are the last committed ones,\n // a render React discards doesn't replace them.\n const previousCommunityLoadStatuses = useRef({\n communityKeys: [] as string[],\n statuses: emptyCommunityLoadStatuses,\n });\n const communityLoadStatuses = useMemo(() => {\n const previous = previousCommunityLoadStatuses.current;\n const previousStatusesByKey = new Map<string, CommunityLoadStatus>();\n previous.communityKeys.forEach((communityKey, index) =>\n previousStatusesByKey.set(communityKey, previous.statuses[index]),\n );\n const statuses = communities.map((community, index) => {\n const status = getCommunityLoadStatus(\n community,\n communitiesSyncStatuses[index],\n communitiesErrors[index],\n onlyIfCached,\n restartsStoppedCommunities,\n );\n const previousStatus = previousStatusesByKey.get(communityKeys[index]);\n return previousStatus && shallow(previousStatus, status) ? previousStatus : status;\n });\n return shallow(previous.statuses, statuses) ? previous.statuses : statuses;\n }, [\n communityKeys,\n communities,\n communitiesSyncStatuses,\n communitiesErrors,\n onlyIfCached,\n restartsStoppedCommunities,\n ]);\n useEffect(() => {\n previousCommunityLoadStatuses.current = { communityKeys, statuses: communityLoadStatuses };\n }, [communityKeys, communityLoadStatuses]);\n\n return useMemo(\n () => ({\n communities,\n communityLoadStatuses,\n state,\n error: errors[errors.length - 1],\n errors,\n }),\n [communities, communityLoadStatuses, state, errors, communityKeys.toString()],\n );\n}\n\n// TODO: pkc.listCommunities() has been removed, rename this and use event communitieschanged instead of polling\n/**\n * Returns all the owner communities created by pkc-js by calling pkc.listCommunities()\n */\nexport function useListCommunities(accountName?: string) {\n const account = useAccount({ accountName });\n const [communityAddresses, setCommunityAddresses] = useState<string[]>([]);\n\n const delay = 1000;\n const immediate = true;\n useInterval(\n () => {\n const pkc = account?.pkc;\n if (!pkc) return;\n const newAddrs = getPkcCommunityAddresses(pkc);\n if (newAddrs.toString() !== communityAddresses.toString()) {\n log(\"useListCommunities\", { communityAddresses });\n setCommunityAddresses(newAddrs);\n }\n },\n delay,\n immediate,\n );\n\n return communityAddresses;\n}\n\n/**\n * @param communityAddress - The community address to resolve to a public key, e.g. 'news.eth' resolves to '12D3KooW...'.\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\n// NOTE: useResolvedCommunityAddress tests are skipped, if changes are made they must be tested manually\nexport function useResolvedCommunityAddress(\n options?: UseResolvedCommunityAddressOptions,\n): UseResolvedCommunityAddressResult {\n assert(\n !options || typeof options === \"object\",\n `useResolvedCommunityAddress options argument '${options}' not an object`,\n );\n let { communityAddress, accountName, cache } = options ?? {};\n\n // cache by default\n if (typeof cache !== \"boolean\") {\n cache = true;\n }\n\n // poll every 15 seconds, about the duration of an eth block\n let interval = 15000;\n // no point in polling often if caching is on\n if (cache) {\n interval = 1000 * 60 * 60 * 25;\n }\n\n const account = useAccount({ accountName });\n const chainProviders = getChainProviders(account);\n const [resolvedAddress, setResolvedAddress] = useState<string>();\n const [errors, setErrors] = useState<Error[]>([]);\n const [state, setState] = useState<string>();\n // the address that resolvedAddress, state and errors belong to: the ref for completions that land\n // later, the state for rendering because it updates in the same render as the result\n const resultAddress = useRef<string | undefined>(undefined);\n const [renderedResultAddress, setRenderedResultAddress] = useState<string>();\n\n let initialState = \"initializing\";\n // before those defined, nothing can happen\n if (options && account && communityAddress) {\n initialState = \"ready\";\n }\n\n useInterval(\n () => {\n if (!account || !communityAddress) {\n resultAddress.current = undefined;\n setRenderedResultAddress(undefined);\n setResolvedAddress(undefined);\n setState(undefined);\n setErrors((prevErrors) => (prevErrors.length ? [] : prevErrors));\n return;\n }\n\n // a new address starts without the result of the previous address\n const address = communityAddress;\n let currentState = state;\n if (resultAddress.current !== address) {\n resultAddress.current = address;\n setRenderedResultAddress(address);\n currentState = undefined;\n setResolvedAddress(undefined);\n setErrors((prevErrors) => (prevErrors.length ? [] : prevErrors));\n setState(undefined);\n }\n\n // address isn't a crypto domain, can't be resolved\n if (!communityAddress?.includes(\".\")) {\n if (currentState !== \"failed\") {\n setErrors([Error(\"not a crypto domain\")]);\n setState(\"failed\");\n setResolvedAddress(undefined);\n }\n return;\n }\n\n // only support resolving '.eth' for now\n if (!communityAddress?.endsWith(\".eth\")) {\n if (currentState !== \"failed\") {\n setErrors([Error(\"crypto domain type unsupported\")]);\n setState(\"failed\");\n setResolvedAddress(undefined);\n }\n return;\n }\n\n (async () => {\n try {\n // later polls keep reporting the current result instead of going back to resolving\n if (!currentState) {\n setState(\"resolving\");\n }\n const res = await resolveCommunityAddress(address, chainProviders);\n // the address changed while resolving\n if (resultAddress.current !== address) {\n return;\n }\n setState(\"succeeded\");\n setErrors((prevErrors) => (prevErrors.length ? [] : prevErrors));\n setResolvedAddress(res);\n } catch (error: any) {\n if (resultAddress.current !== address) {\n return;\n }\n setErrors((prevErrors) => [...prevErrors, error]);\n setState(\"failed\");\n setResolvedAddress(undefined);\n log.error(\"useResolvedCommunityAddress resolveCommunityAddress error\", {\n communityAddress,\n chainProviders,\n error,\n });\n }\n })();\n },\n interval,\n true,\n [communityAddress, chainProviders],\n );\n\n // only support ENS at the moment\n const chainProvider = chainProviders?.[\"eth\"];\n\n // log('useResolvedCommunityAddress', {communityAddress, state, errors, resolvedAddress, chainProviders})\n // until the interval has run for a new address, the stored result is the previous address's\n const isCurrentResult = renderedResultAddress === communityAddress;\n return {\n resolvedAddress: isCurrentResult ? resolvedAddress : undefined,\n chainProvider,\n state: (isCurrentResult && state) || initialState,\n error: isCurrentResult ? errors[errors.length - 1] : undefined,\n errors: isCurrentResult ? errors : emptyErrors,\n };\n}\n\n// NOTE: resolveCommunityAddress tests are skipped, if changes are made they must be tested manually\nexport const resolveCommunityAddress = async (\n communityAddress: string,\n chainProviders: ChainProviders,\n) => {\n let resolvedCommunityAddress;\n if (communityAddress.endsWith(\".eth\")) {\n resolvedCommunityAddress = await resolveEnsTxtRecord(\n communityAddress,\n \"community-address\",\n \"eth\",\n chainProviders?.[\"eth\"]?.urls?.[0],\n chainProviders?.[\"eth\"]?.chainId,\n );\n } else {\n throw Error(`resolveCommunityAddress invalid communityAddress '${communityAddress}'`);\n }\n return resolvedCommunityAddress;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pkc-js-mock.d.ts","sourceRoot":"","sources":["../../../src/lib/pkc-js/pkc-js-mock.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAClC,OAAO,KAAK,EAAE,2BAA2B,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAC5F,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAG3D,eAAO,MAAM,mBAAmB,wBAAuD,CAAC;AAQxF,eAAO,MAAM,cAAc,YAG1B,CAAC;AACF,eAAO,MAAM,cAAc,YAE1B,CAAC;AAEF,cAAM,kBAAmB,SAAQ,YAAY;IAC3C,KAAK,SAAa;CACnB;AAED,qBAAa,GAAI,SAAQ,YAAY;IACnC,aAAa,EAAE,GAAG,EAAE,CAAC;IACrB,eAAe,EAAE;QACf,OAAO,EAAE;YACP,aAAa,EAAE;gBAAE,CAAC,WAAW,EAAE,MAAM,GAAG,kBAAkB,CAAA;aAAE,CAAC;SAC9D,CAAC;KACH,CAAC;gBAEU,OAAO,GAAE,GAAQ;IAgBvB,oBAAoB,CAAC,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE;IAiBjD,iBAAiB,CACrB,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,0BAA0B,CAAC;IAKhC,YAAY;;;;IAOZ,eAAe,CAAC,sBAAsB,EAAE,GAAG;IA+C3C,YAAY,CAAC,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE;IAqB/C,IAAI,WAAW;;;;QAQd;IAEK,aAAa,CAAC,oBAAoB,EAAE,GAAG;IAIvC,UAAU,CAAC,OAAO,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE;IAazC,YAAY,CAAC,UAAU,CAAC,EAAE,MAAM;IAQ1B,UAA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,GAAG,SAAS,CAAC;IAClC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,OAAO,EAAE,GAAG,CAAC;IACb,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;gBAEZ,oBAAoB,CAAC,EAAE,GAAG;IAqChC,MAAM;IAuBZ,mBAAmB;IAoBb,mCAAmC;CAuB1C;AAED,qBAAa,IAAK,SAAQ,WAAW;CAAG;AAExC,qBAAa,WAAY,SAAQ,WAAW;CAAG;AAE/C,qBAAa,iBAAkB,SAAQ,WAAW;CAAG;AAErD,qBAAa,aAAc,SAAQ,WAAW;CAAG;AAEjD,QAAA,MAAM,SAAS,EAAE,GAEhB,CAAC;AAeF,eAAe,SAAS,CAAC"}
|
|
@@ -499,6 +499,8 @@ export class Community extends EventEmitter {
|
|
|
499
499
|
Object.defineProperty(Community.prototype, "roles", { enumerable: true });
|
|
500
500
|
let challengeRequestCount = 0;
|
|
501
501
|
let challengeAnswerCount = 0;
|
|
502
|
+
// kept outside the instances so the hooks never copy it into stored or cloned publications
|
|
503
|
+
const publishCalledPublications = new WeakSet();
|
|
502
504
|
class Publication extends EventEmitter {
|
|
503
505
|
constructor() {
|
|
504
506
|
super(...arguments);
|
|
@@ -507,6 +509,15 @@ class Publication extends EventEmitter {
|
|
|
507
509
|
}
|
|
508
510
|
publish() {
|
|
509
511
|
return __awaiter(this, void 0, void 0, function* () {
|
|
512
|
+
// like pkc-js 0.0.154, an instance runs one challenge exchange: publishing again needs a new
|
|
513
|
+
// instance (the mock has no pre-flight that could reject before anything is sent)
|
|
514
|
+
if (publishCalledPublications.has(this)) {
|
|
515
|
+
throw Object.assign(Error("pkc-js-mock publish() was already called on this publication instance, create a new instance to publish again"), {
|
|
516
|
+
code: "ERR_PUBLICATION_PUBLISH_ALREADY_CALLED",
|
|
517
|
+
details: { state: this.state, publishingState: this.publishingState },
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
publishCalledPublications.add(this);
|
|
510
521
|
this.state = "publishing";
|
|
511
522
|
this.publishingState = "publishing-challenge-request";
|
|
512
523
|
this.emit("statechange", "publishing");
|