@bitsocial/bitsocial-react-hooks 0.1.0

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.
Files changed (269) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +1365 -0
  3. package/dist/hooks/accounts/accounts.d.ts +64 -0
  4. package/dist/hooks/accounts/accounts.d.ts.map +1 -0
  5. package/dist/hooks/accounts/accounts.js +706 -0
  6. package/dist/hooks/accounts/accounts.js.map +1 -0
  7. package/dist/hooks/accounts/index.d.ts +2 -0
  8. package/dist/hooks/accounts/index.d.ts.map +1 -0
  9. package/dist/hooks/accounts/index.js +2 -0
  10. package/dist/hooks/accounts/index.js.map +1 -0
  11. package/dist/hooks/accounts/utils.d.ts +6 -0
  12. package/dist/hooks/accounts/utils.d.ts.map +1 -0
  13. package/dist/hooks/accounts/utils.js +226 -0
  14. package/dist/hooks/accounts/utils.js.map +1 -0
  15. package/dist/hooks/actions/actions.d.ts +19 -0
  16. package/dist/hooks/actions/actions.d.ts.map +1 -0
  17. package/dist/hooks/actions/actions.js +552 -0
  18. package/dist/hooks/actions/actions.js.map +1 -0
  19. package/dist/hooks/actions/index.d.ts +2 -0
  20. package/dist/hooks/actions/index.d.ts.map +1 -0
  21. package/dist/hooks/actions/index.js +2 -0
  22. package/dist/hooks/actions/index.js.map +1 -0
  23. package/dist/hooks/authors/author-avatars.d.ts +28 -0
  24. package/dist/hooks/authors/author-avatars.d.ts.map +1 -0
  25. package/dist/hooks/authors/author-avatars.js +191 -0
  26. package/dist/hooks/authors/author-avatars.js.map +1 -0
  27. package/dist/hooks/authors/authors.d.ts +37 -0
  28. package/dist/hooks/authors/authors.d.ts.map +1 -0
  29. package/dist/hooks/authors/authors.js +509 -0
  30. package/dist/hooks/authors/authors.js.map +1 -0
  31. package/dist/hooks/authors/index.d.ts +2 -0
  32. package/dist/hooks/authors/index.d.ts.map +1 -0
  33. package/dist/hooks/authors/index.js +2 -0
  34. package/dist/hooks/authors/index.js.map +1 -0
  35. package/dist/hooks/authors/utils.d.ts +4 -0
  36. package/dist/hooks/authors/utils.d.ts.map +1 -0
  37. package/dist/hooks/authors/utils.js +21 -0
  38. package/dist/hooks/authors/utils.js.map +1 -0
  39. package/dist/hooks/comments.d.ts +17 -0
  40. package/dist/hooks/comments.d.ts.map +1 -0
  41. package/dist/hooks/comments.js +351 -0
  42. package/dist/hooks/comments.js.map +1 -0
  43. package/dist/hooks/communities.d.ts +31 -0
  44. package/dist/hooks/communities.d.ts.map +1 -0
  45. package/dist/hooks/communities.js +389 -0
  46. package/dist/hooks/communities.js.map +1 -0
  47. package/dist/hooks/feeds/feeds.d.ts +18 -0
  48. package/dist/hooks/feeds/feeds.d.ts.map +1 -0
  49. package/dist/hooks/feeds/feeds.js +315 -0
  50. package/dist/hooks/feeds/feeds.js.map +1 -0
  51. package/dist/hooks/feeds/index.d.ts +2 -0
  52. package/dist/hooks/feeds/index.d.ts.map +1 -0
  53. package/dist/hooks/feeds/index.js +2 -0
  54. package/dist/hooks/feeds/index.js.map +1 -0
  55. package/dist/hooks/pkc-rpc.d.ts +7 -0
  56. package/dist/hooks/pkc-rpc.d.ts.map +1 -0
  57. package/dist/hooks/pkc-rpc.js +88 -0
  58. package/dist/hooks/pkc-rpc.js.map +1 -0
  59. package/dist/hooks/replies.d.ts +5 -0
  60. package/dist/hooks/replies.d.ts.map +1 -0
  61. package/dist/hooks/replies.js +155 -0
  62. package/dist/hooks/replies.js.map +1 -0
  63. package/dist/hooks/states.d.ts +15 -0
  64. package/dist/hooks/states.d.ts.map +1 -0
  65. package/dist/hooks/states.js +213 -0
  66. package/dist/hooks/states.js.map +1 -0
  67. package/dist/hooks/utils/use-interval.d.ts +3 -0
  68. package/dist/hooks/utils/use-interval.d.ts.map +1 -0
  69. package/dist/hooks/utils/use-interval.js +36 -0
  70. package/dist/hooks/utils/use-interval.js.map +1 -0
  71. package/dist/hooks/utils/use-previous.d.ts +1 -0
  72. package/dist/hooks/utils/use-previous.js +10 -0
  73. package/dist/index.d.ts +82 -0
  74. package/dist/index.d.ts.map +1 -0
  75. package/dist/index.js +128 -0
  76. package/dist/index.js.map +1 -0
  77. package/dist/lib/chain/chain.d.ts +36 -0
  78. package/dist/lib/chain/chain.d.ts.map +1 -0
  79. package/dist/lib/chain/chain.js +195 -0
  80. package/dist/lib/chain/chain.js.map +1 -0
  81. package/dist/lib/chain/index.d.ts +4 -0
  82. package/dist/lib/chain/index.d.ts.map +1 -0
  83. package/dist/lib/chain/index.js +4 -0
  84. package/dist/lib/chain/index.js.map +1 -0
  85. package/dist/lib/community-address.d.ts +6 -0
  86. package/dist/lib/community-address.d.ts.map +1 -0
  87. package/dist/lib/community-address.js +26 -0
  88. package/dist/lib/community-address.js.map +1 -0
  89. package/dist/lib/community-ref.d.ts +23 -0
  90. package/dist/lib/community-ref.d.ts.map +1 -0
  91. package/dist/lib/community-ref.js +113 -0
  92. package/dist/lib/community-ref.js.map +1 -0
  93. package/dist/lib/debug-utils.d.ts +9 -0
  94. package/dist/lib/debug-utils.d.ts.map +1 -0
  95. package/dist/lib/debug-utils.js +21 -0
  96. package/dist/lib/debug-utils.js.map +1 -0
  97. package/dist/lib/feed-sort-type.d.ts +2 -0
  98. package/dist/lib/feed-sort-type.d.ts.map +1 -0
  99. package/dist/lib/feed-sort-type.js +22 -0
  100. package/dist/lib/feed-sort-type.js.map +1 -0
  101. package/dist/lib/localforage-lru/index.d.ts +3 -0
  102. package/dist/lib/localforage-lru/index.d.ts.map +1 -0
  103. package/dist/lib/localforage-lru/index.js +46 -0
  104. package/dist/lib/localforage-lru/index.js.map +1 -0
  105. package/dist/lib/localforage-lru/localforage-lru.d.ts +6 -0
  106. package/dist/lib/localforage-lru/localforage-lru.d.ts.map +1 -0
  107. package/dist/lib/localforage-lru/localforage-lru.js +182 -0
  108. package/dist/lib/localforage-lru/localforage-lru.js.map +1 -0
  109. package/dist/lib/pkc-compat.d.ts +25 -0
  110. package/dist/lib/pkc-compat.d.ts.map +1 -0
  111. package/dist/lib/pkc-compat.js +131 -0
  112. package/dist/lib/pkc-compat.js.map +1 -0
  113. package/dist/lib/pkc-js/fixtures/markdown-example.d.ts +3 -0
  114. package/dist/lib/pkc-js/fixtures/markdown-example.d.ts.map +1 -0
  115. package/dist/lib/pkc-js/fixtures/markdown-example.js +280 -0
  116. package/dist/lib/pkc-js/fixtures/markdown-example.js.map +1 -0
  117. package/dist/lib/pkc-js/index.d.ts +11 -0
  118. package/dist/lib/pkc-js/index.d.ts.map +1 -0
  119. package/dist/lib/pkc-js/index.js +85 -0
  120. package/dist/lib/pkc-js/index.js.map +1 -0
  121. package/dist/lib/pkc-js/pkc-js-mock-content.d.ts +3 -0
  122. package/dist/lib/pkc-js/pkc-js-mock-content.d.ts.map +1 -0
  123. package/dist/lib/pkc-js/pkc-js-mock-content.js +1235 -0
  124. package/dist/lib/pkc-js/pkc-js-mock-content.js.map +1 -0
  125. package/dist/lib/pkc-js/pkc-js-mock.d.ts +137 -0
  126. package/dist/lib/pkc-js/pkc-js-mock.d.ts.map +1 -0
  127. package/dist/lib/pkc-js/pkc-js-mock.js +644 -0
  128. package/dist/lib/pkc-js/pkc-js-mock.js.map +1 -0
  129. package/dist/lib/polyfill.d.ts +3 -0
  130. package/dist/lib/polyfill.d.ts.map +1 -0
  131. package/dist/lib/polyfill.js +14 -0
  132. package/dist/lib/polyfill.js.map +1 -0
  133. package/dist/lib/protocol-compat.d.ts +14 -0
  134. package/dist/lib/protocol-compat.d.ts.map +1 -0
  135. package/dist/lib/protocol-compat.js +67 -0
  136. package/dist/lib/protocol-compat.js.map +1 -0
  137. package/dist/lib/test-utils.d.ts +29 -0
  138. package/dist/lib/test-utils.d.ts.map +1 -0
  139. package/dist/lib/test-utils.js +184 -0
  140. package/dist/lib/test-utils.js.map +1 -0
  141. package/dist/lib/utils/comment-moderation.d.ts +4 -0
  142. package/dist/lib/utils/comment-moderation.d.ts.map +1 -0
  143. package/dist/lib/utils/comment-moderation.js +56 -0
  144. package/dist/lib/utils/comment-moderation.js.map +1 -0
  145. package/dist/lib/utils/index.d.ts +4 -0
  146. package/dist/lib/utils/index.d.ts.map +1 -0
  147. package/dist/lib/utils/index.js +4 -0
  148. package/dist/lib/utils/index.js.map +1 -0
  149. package/dist/lib/utils/utils.d.ts +23 -0
  150. package/dist/lib/utils/utils.d.ts.map +1 -0
  151. package/dist/lib/utils/utils.js +375 -0
  152. package/dist/lib/utils/utils.js.map +1 -0
  153. package/dist/lib/validator.d.ts +30 -0
  154. package/dist/lib/validator.d.ts.map +1 -0
  155. package/dist/lib/validator.js +307 -0
  156. package/dist/lib/validator.js.map +1 -0
  157. package/dist/stores/accounts/account-generator.d.ts +51 -0
  158. package/dist/stores/accounts/account-generator.d.ts.map +1 -0
  159. package/dist/stores/accounts/account-generator.js +160 -0
  160. package/dist/stores/accounts/account-generator.js.map +1 -0
  161. package/dist/stores/accounts/accounts-actions-internal.d.ts +8 -0
  162. package/dist/stores/accounts/accounts-actions-internal.d.ts.map +1 -0
  163. package/dist/stores/accounts/accounts-actions-internal.js +403 -0
  164. package/dist/stores/accounts/accounts-actions-internal.js.map +1 -0
  165. package/dist/stores/accounts/accounts-actions.d.ts +46 -0
  166. package/dist/stores/accounts/accounts-actions.d.ts.map +1 -0
  167. package/dist/stores/accounts/accounts-actions.js +1341 -0
  168. package/dist/stores/accounts/accounts-actions.js.map +1 -0
  169. package/dist/stores/accounts/accounts-database.d.ts +34 -0
  170. package/dist/stores/accounts/accounts-database.d.ts.map +1 -0
  171. package/dist/stores/accounts/accounts-database.js +685 -0
  172. package/dist/stores/accounts/accounts-database.js.map +1 -0
  173. package/dist/stores/accounts/accounts-store.d.ts +32 -0
  174. package/dist/stores/accounts/accounts-store.d.ts.map +1 -0
  175. package/dist/stores/accounts/accounts-store.js +169 -0
  176. package/dist/stores/accounts/accounts-store.js.map +1 -0
  177. package/dist/stores/accounts/index.d.ts +4 -0
  178. package/dist/stores/accounts/index.d.ts.map +1 -0
  179. package/dist/stores/accounts/index.js +4 -0
  180. package/dist/stores/accounts/index.js.map +1 -0
  181. package/dist/stores/accounts/utils.d.ts +49 -0
  182. package/dist/stores/accounts/utils.d.ts.map +1 -0
  183. package/dist/stores/accounts/utils.js +419 -0
  184. package/dist/stores/accounts/utils.js.map +1 -0
  185. package/dist/stores/authors-comments/authors-comments-store.d.ts +37 -0
  186. package/dist/stores/authors-comments/authors-comments-store.d.ts.map +1 -0
  187. package/dist/stores/authors-comments/authors-comments-store.js +338 -0
  188. package/dist/stores/authors-comments/authors-comments-store.js.map +1 -0
  189. package/dist/stores/authors-comments/index.d.ts +4 -0
  190. package/dist/stores/authors-comments/index.d.ts.map +1 -0
  191. package/dist/stores/authors-comments/index.js +4 -0
  192. package/dist/stores/authors-comments/index.js.map +1 -0
  193. package/dist/stores/authors-comments/utils.d.ts +14 -0
  194. package/dist/stores/authors-comments/utils.d.ts.map +1 -0
  195. package/dist/stores/authors-comments/utils.js +81 -0
  196. package/dist/stores/authors-comments/utils.js.map +1 -0
  197. package/dist/stores/comments/comments-store.d.ts +19 -0
  198. package/dist/stores/comments/comments-store.d.ts.map +1 -0
  199. package/dist/stores/comments/comments-store.js +385 -0
  200. package/dist/stores/comments/comments-store.js.map +1 -0
  201. package/dist/stores/comments/index.d.ts +4 -0
  202. package/dist/stores/comments/index.d.ts.map +1 -0
  203. package/dist/stores/comments/index.js +4 -0
  204. package/dist/stores/comments/index.js.map +1 -0
  205. package/dist/stores/communities/communities-store.d.ts +17 -0
  206. package/dist/stores/communities/communities-store.d.ts.map +1 -0
  207. package/dist/stores/communities/communities-store.js +304 -0
  208. package/dist/stores/communities/communities-store.js.map +1 -0
  209. package/dist/stores/communities/index.d.ts +4 -0
  210. package/dist/stores/communities/index.d.ts.map +1 -0
  211. package/dist/stores/communities/index.js +4 -0
  212. package/dist/stores/communities/index.js.map +1 -0
  213. package/dist/stores/communities-pages/communities-pages-store.d.ts +23 -0
  214. package/dist/stores/communities-pages/communities-pages-store.d.ts.map +1 -0
  215. package/dist/stores/communities-pages/communities-pages-store.js +316 -0
  216. package/dist/stores/communities-pages/communities-pages-store.js.map +1 -0
  217. package/dist/stores/communities-pages/index.d.ts +4 -0
  218. package/dist/stores/communities-pages/index.d.ts.map +1 -0
  219. package/dist/stores/communities-pages/index.js +4 -0
  220. package/dist/stores/communities-pages/index.js.map +1 -0
  221. package/dist/stores/feeds/feed-sorter.d.ts +5 -0
  222. package/dist/stores/feeds/feed-sorter.d.ts.map +1 -0
  223. package/dist/stores/feeds/feed-sorter.js +135 -0
  224. package/dist/stores/feeds/feed-sorter.js.map +1 -0
  225. package/dist/stores/feeds/feeds-store.d.ts +25 -0
  226. package/dist/stores/feeds/feeds-store.d.ts.map +1 -0
  227. package/dist/stores/feeds/feeds-store.js +459 -0
  228. package/dist/stores/feeds/feeds-store.js.map +1 -0
  229. package/dist/stores/feeds/index.d.ts +4 -0
  230. package/dist/stores/feeds/index.d.ts.map +1 -0
  231. package/dist/stores/feeds/index.js +4 -0
  232. package/dist/stores/feeds/index.js.map +1 -0
  233. package/dist/stores/feeds/utils.d.ts +43 -0
  234. package/dist/stores/feeds/utils.d.ts.map +1 -0
  235. package/dist/stores/feeds/utils.js +736 -0
  236. package/dist/stores/feeds/utils.js.map +1 -0
  237. package/dist/stores/replies/index.d.ts +4 -0
  238. package/dist/stores/replies/index.d.ts.map +1 -0
  239. package/dist/stores/replies/index.js +4 -0
  240. package/dist/stores/replies/index.js.map +1 -0
  241. package/dist/stores/replies/replies-comments-store.d.ts +8 -0
  242. package/dist/stores/replies/replies-comments-store.d.ts.map +1 -0
  243. package/dist/stores/replies/replies-comments-store.js +23 -0
  244. package/dist/stores/replies/replies-comments-store.js.map +1 -0
  245. package/dist/stores/replies/replies-store.d.ts +29 -0
  246. package/dist/stores/replies/replies-store.d.ts.map +1 -0
  247. package/dist/stores/replies/replies-store.js +413 -0
  248. package/dist/stores/replies/replies-store.js.map +1 -0
  249. package/dist/stores/replies/utils.d.ts +25 -0
  250. package/dist/stores/replies/utils.d.ts.map +1 -0
  251. package/dist/stores/replies/utils.js +549 -0
  252. package/dist/stores/replies/utils.js.map +1 -0
  253. package/dist/stores/replies-pages/index.d.ts +4 -0
  254. package/dist/stores/replies-pages/index.d.ts.map +1 -0
  255. package/dist/stores/replies-pages/index.js +4 -0
  256. package/dist/stores/replies-pages/index.js.map +1 -0
  257. package/dist/stores/replies-pages/replies-pages-store.d.ts +20 -0
  258. package/dist/stores/replies-pages/replies-pages-store.d.ts.map +1 -0
  259. package/dist/stores/replies-pages/replies-pages-store.js +270 -0
  260. package/dist/stores/replies-pages/replies-pages-store.js.map +1 -0
  261. package/dist/stores/replies-pages/utils.d.ts +3 -0
  262. package/dist/stores/replies-pages/utils.d.ts.map +1 -0
  263. package/dist/stores/replies-pages/utils.js +43 -0
  264. package/dist/stores/replies-pages/utils.js.map +1 -0
  265. package/dist/types.d.ts +638 -0
  266. package/dist/types.d.ts.map +1 -0
  267. package/dist/types.js +3 -0
  268. package/dist/types.js.map +1 -0
  269. package/package.json +160 -0
@@ -0,0 +1,389 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { useEffect, useState, useMemo } from "react";
11
+ import { useAccount } from "./accounts/index.js";
12
+ import validator from "../lib/validator.js";
13
+ import Logger from "@pkcprotocol/pkc-logger";
14
+ const log = Logger("bitsocial-react-hooks:communities:hooks");
15
+ import assert from "assert";
16
+ import useInterval from "./utils/use-interval.js";
17
+ import createStore from "zustand";
18
+ import { resolveEnsTxtRecord } from "../lib/chain/index.js";
19
+ import useCommunitiesStore from "../stores/communities/index.js";
20
+ import useAccountsStore from "../stores/accounts/index.js";
21
+ import shallow from "zustand/shallow";
22
+ import { getChainProviders, getPkcCommunityAddresses } from "../lib/pkc-compat.js";
23
+ import { getCommunityRefKey, getUniqueSortedCommunityRefs } from "../lib/community-ref.js";
24
+ const parseMaybeJson = (value) => (typeof value === "string" ? JSON.parse(value) : value);
25
+ const tryParseMaybeJson = (value) => {
26
+ try {
27
+ return parseMaybeJson(value);
28
+ }
29
+ catch (_a) {
30
+ return value;
31
+ }
32
+ };
33
+ const isRecord = (value) => !!value && typeof value === "object";
34
+ const isCommunityStatsPayload = (value) => isRecord(value) &&
35
+ ("hourActiveUserCount" in value || "weekActiveUserCount" in value || "allPostCount" in value);
36
+ const parseFetchedCommunityStats = (fetchedCid) => {
37
+ const parsedCid = parseMaybeJson(fetchedCid);
38
+ if (isCommunityStatsPayload(parsedCid)) {
39
+ return parsedCid;
40
+ }
41
+ if (isRecord(parsedCid) && "content" in parsedCid) {
42
+ const parsedContent = tryParseMaybeJson(parsedCid.content);
43
+ if (isCommunityStatsPayload(parsedContent)) {
44
+ return parsedContent;
45
+ }
46
+ }
47
+ return parsedCid;
48
+ };
49
+ /**
50
+ * @param community - The community identifier, e.g. {name: 'memes.eth'} or {publicKey: '12D3KooW...'}
51
+ * @param acountName - The nickname of the account, e.g. 'Account 1'. If no accountName is provided, use
52
+ * the active account.
53
+ */
54
+ export function useCommunity(options) {
55
+ assert(!options || typeof options === "object", `useCommunity options argument '${options}' not an object`);
56
+ const opts = options !== null && options !== void 0 ? options : {};
57
+ const { community: communityInput, accountName, onlyIfCached } = opts;
58
+ const account = useAccount({ accountName });
59
+ const accountId = (account === null || account === void 0 ? void 0 : account.id) || "";
60
+ validator.validateUseCommunityArguments({
61
+ community: communityInput,
62
+ communityAddress: opts.communityAddress,
63
+ account,
64
+ });
65
+ const communityKey = communityInput ? getCommunityRefKey(communityInput) : "";
66
+ const storedCommunity = useCommunitiesStore((state) => state.communities[communityKey]);
67
+ const addCommunityToStore = useCommunitiesStore((state) => state.addCommunityToStore);
68
+ const errors = useCommunitiesStore((state) => state.errors[communityKey]);
69
+ const communityEditSummary = useAccountsStore((state) => {
70
+ const accountEditsSummaries = state.accountsEditsSummaries[accountId] || {};
71
+ const candidateCommunityKeys = [
72
+ storedCommunity === null || storedCommunity === void 0 ? void 0 : storedCommunity.address,
73
+ storedCommunity === null || storedCommunity === void 0 ? void 0 : storedCommunity.name,
74
+ storedCommunity === null || storedCommunity === void 0 ? void 0 : storedCommunity.publicKey,
75
+ communityInput === null || communityInput === void 0 ? void 0 : communityInput.name,
76
+ communityInput === null || communityInput === void 0 ? void 0 : communityInput.publicKey,
77
+ ];
78
+ for (const candidateCommunityKey of candidateCommunityKeys) {
79
+ if (typeof candidateCommunityKey === "string" &&
80
+ accountEditsSummaries[candidateCommunityKey]) {
81
+ return accountEditsSummaries[candidateCommunityKey];
82
+ }
83
+ }
84
+ });
85
+ useEffect(() => {
86
+ if (!communityInput || !account) {
87
+ return;
88
+ }
89
+ if (!storedCommunity && !onlyIfCached) {
90
+ // if community isn't already in store, add it
91
+ addCommunityToStore(communityInput, account).catch((error) => log.error("useCommunity addCommunityToStore error", { communityInput, error }));
92
+ }
93
+ }, [communityKey, account === null || account === void 0 ? void 0 : account.id]);
94
+ if (account && communityInput) {
95
+ log("useCommunity", {
96
+ community: communityInput,
97
+ communityKey,
98
+ storedCommunity,
99
+ account,
100
+ });
101
+ }
102
+ const mergedCommunity = useMemo(() => {
103
+ var _a;
104
+ if (!communityEditSummary) {
105
+ return storedCommunity;
106
+ }
107
+ const localCommunityAddresses = getPkcCommunityAddresses(account === null || account === void 0 ? void 0 : account.pkc);
108
+ const editedCommunityAddress = (_a = communityEditSummary.address) === null || _a === void 0 ? void 0 : _a.value;
109
+ const inputCommunityIdentifiers = [communityInput === null || communityInput === void 0 ? void 0 : communityInput.name, communityInput === null || communityInput === void 0 ? void 0 : communityInput.publicKey].filter((communityIdentifier) => typeof communityIdentifier === "string");
110
+ if (!storedCommunity &&
111
+ editedCommunityAddress &&
112
+ !inputCommunityIdentifiers.some((communityIdentifier) => localCommunityAddresses.includes(communityIdentifier)) &&
113
+ !localCommunityAddresses.includes(editedCommunityAddress)) {
114
+ return storedCommunity;
115
+ }
116
+ if ((storedCommunity === null || storedCommunity === void 0 ? void 0 : storedCommunity.address) &&
117
+ editedCommunityAddress &&
118
+ storedCommunity.address !== editedCommunityAddress) {
119
+ return storedCommunity;
120
+ }
121
+ const summaryValues = Object.fromEntries(Object.entries(communityEditSummary).map(([propertyName, propertySummary]) => [
122
+ propertyName,
123
+ propertySummary === null || propertySummary === void 0 ? void 0 : propertySummary.value,
124
+ ]));
125
+ 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);
126
+ }, [account === null || account === void 0 ? void 0 : account.pkc, storedCommunity, communityInput, communityEditSummary]);
127
+ let state = (mergedCommunity === null || mergedCommunity === void 0 ? void 0 : mergedCommunity.updatingState) || "initializing";
128
+ // force succeeded even if the community is fecthing a new update
129
+ if (mergedCommunity === null || mergedCommunity === void 0 ? void 0 : mergedCommunity.updatedAt) {
130
+ state = "succeeded";
131
+ }
132
+ return useMemo(() => (Object.assign(Object.assign({}, mergedCommunity), { state, error: errors === null || errors === void 0 ? void 0 : errors[errors.length - 1], errors: errors || [] })), [mergedCommunity, communityKey, errors]);
133
+ }
134
+ /**
135
+ * @param community - The community identifier, e.g. {name: 'memes.eth'} or {publicKey: '12D3KooW...'}
136
+ * @param acountName - The nickname of the account, e.g. 'Account 1'. If no accountName is provided, use
137
+ * the active account.
138
+ */
139
+ export function useCommunityStats(options) {
140
+ assert(!options || typeof options === "object", `useCommunityStats options argument '${options}' not an object`);
141
+ const opts = options !== null && options !== void 0 ? options : {};
142
+ const { community, accountName, onlyIfCached } = opts;
143
+ validator.validateUseCommunityStatsArguments({
144
+ community,
145
+ communityAddress: opts.communityAddress,
146
+ });
147
+ const account = useAccount({ accountName });
148
+ const communityKey = community ? getCommunityRefKey(community) : "";
149
+ const fetchedCommunity = useCommunity({ community, onlyIfCached });
150
+ const communityStatsCid = fetchedCommunity === null || fetchedCommunity === void 0 ? void 0 : fetchedCommunity.statsCid;
151
+ const communityStats = useCommunitiesStatsStore((state) => state.communitiesStats[communityKey]);
152
+ const setCommunityStats = useCommunitiesStatsStore((state) => state.setCommunityStats);
153
+ const [fetchError, setFetchError] = useState();
154
+ useEffect(() => {
155
+ setFetchError(undefined);
156
+ if (!communityKey || !communityStatsCid || !account) {
157
+ return;
158
+ }
159
+ let cancelled = false;
160
+ (() => __awaiter(this, void 0, void 0, function* () {
161
+ let fetchedCid;
162
+ try {
163
+ fetchedCid = yield account.pkc.fetchCid({ cid: communityStatsCid });
164
+ fetchedCid = parseFetchedCommunityStats(fetchedCid);
165
+ if (cancelled) {
166
+ return;
167
+ }
168
+ setCommunityStats(communityKey, fetchedCid);
169
+ }
170
+ catch (error) {
171
+ const normalizedError = error instanceof Error ? error : new Error(typeof error === "string" ? error : "error");
172
+ if (cancelled) {
173
+ return;
174
+ }
175
+ setFetchError(normalizedError);
176
+ log.error("useCommunityStats pkc.fetchCid error", {
177
+ community,
178
+ communityKey,
179
+ communityStatsCid,
180
+ fetchedCommunity,
181
+ fetchedCid,
182
+ error: normalizedError,
183
+ });
184
+ }
185
+ }))();
186
+ return () => {
187
+ cancelled = true;
188
+ };
189
+ }, [communityStatsCid, account === null || account === void 0 ? void 0 : account.id, communityKey, setCommunityStats]);
190
+ if (account && communityStatsCid) {
191
+ log("useCommunityStats", {
192
+ community,
193
+ communityKey,
194
+ communityStatsCid,
195
+ communityStats,
196
+ fetchedCommunity,
197
+ account,
198
+ });
199
+ }
200
+ const state = !communityKey || !account || !communityStatsCid
201
+ ? "uninitialized"
202
+ : fetchError
203
+ ? "failed"
204
+ : communityStats
205
+ ? "succeeded"
206
+ : "fetching-ipfs";
207
+ return useMemo(() => (Object.assign(Object.assign({}, communityStats), { state, error: fetchError, errors: fetchError ? [fetchError] : [] })), [communityStats, state, fetchError]);
208
+ }
209
+ const useCommunitiesStatsStore = createStore((setState) => ({
210
+ communitiesStats: {},
211
+ setCommunityStats: (communityAddress, communityStats) => setState((state) => ({
212
+ communitiesStats: Object.assign(Object.assign({}, state.communitiesStats), { [communityAddress]: communityStats }),
213
+ })),
214
+ }));
215
+ /**
216
+ * @param communities - The communities to fetch, e.g. [{name: 'memes.eth'}, {publicKey: '12D3KooW...'}]
217
+ * @param acountName - The nickname of the account, e.g. 'Account 1'. If no accountName is provided, use
218
+ * the active account.
219
+ */
220
+ export function useCommunities(options) {
221
+ assert(!options || typeof options === "object", `useCommunities options argument '${options}' not an object`);
222
+ const opts = options !== null && options !== void 0 ? options : {};
223
+ const { communities: communitiesInput, accountName, onlyIfCached } = opts;
224
+ const account = useAccount({ accountName });
225
+ validator.validateUseCommunitiesArguments({
226
+ communities: communitiesInput,
227
+ communityRefs: opts.communityRefs,
228
+ communityAddresses: opts.communityAddresses,
229
+ account,
230
+ });
231
+ const normalizedCommunityRefs = useMemo(() => communitiesInput || [], [communitiesInput]);
232
+ const communityKeys = useMemo(() => normalizedCommunityRefs.map(getCommunityRefKey), [normalizedCommunityRefs]);
233
+ const communities = useCommunitiesStore((state) => communityKeys.map((communityKey) => state.communities[communityKey || ""]), shallow);
234
+ const communitiesErrors = useCommunitiesStore((state) => communityKeys.map((communityKey) => state.errors[communityKey || ""]), shallow);
235
+ const addCommunityToStore = useCommunitiesStore((state) => state.addCommunityToStore);
236
+ useEffect(() => {
237
+ if (!normalizedCommunityRefs.length || !account) {
238
+ return;
239
+ }
240
+ if (onlyIfCached) {
241
+ return;
242
+ }
243
+ const uniqueCommunityRefs = getUniqueSortedCommunityRefs(normalizedCommunityRefs);
244
+ for (const communityRef of uniqueCommunityRefs) {
245
+ addCommunityToStore(communityRef, account).catch((error) => log.error("useCommunities addCommunityToStore error", { communityRef, error }));
246
+ }
247
+ }, [account === null || account === void 0 ? void 0 : account.id, communityKeys.toString(), onlyIfCached, normalizedCommunityRefs]);
248
+ if (account && normalizedCommunityRefs.length) {
249
+ log("useCommunities", {
250
+ requestedCommunities: normalizedCommunityRefs,
251
+ communityKeys,
252
+ communities,
253
+ account,
254
+ });
255
+ }
256
+ const errors = useMemo(() => communitiesErrors.flatMap((communityErrors) => communityErrors || []), [communitiesErrors]);
257
+ const hasFailedCommunity = communities.some((community, index) => { var _a; return !community && Boolean((_a = communitiesErrors[index]) === null || _a === void 0 ? void 0 : _a.length); });
258
+ const state = hasFailedCommunity
259
+ ? "failed"
260
+ : communities.indexOf(undefined) === -1
261
+ ? "succeeded"
262
+ : "fetching-ipns";
263
+ return useMemo(() => ({
264
+ communities,
265
+ state,
266
+ error: errors[errors.length - 1],
267
+ errors,
268
+ }), [communities, state, errors, communityKeys.toString()]);
269
+ }
270
+ // TODO: pkc.listCommunities() has been removed, rename this and use event communitieschanged instead of polling
271
+ /**
272
+ * Returns all the owner communities created by pkc-js by calling pkc.listCommunities()
273
+ */
274
+ export function useListCommunities(accountName) {
275
+ const account = useAccount({ accountName });
276
+ const [communityAddresses, setCommunityAddresses] = useState([]);
277
+ const delay = 1000;
278
+ const immediate = true;
279
+ useInterval(() => {
280
+ const pkc = account === null || account === void 0 ? void 0 : account.pkc;
281
+ if (!pkc)
282
+ return;
283
+ const newAddrs = getPkcCommunityAddresses(pkc);
284
+ if (newAddrs.toString() !== communityAddresses.toString()) {
285
+ log("useListCommunities", { communityAddresses });
286
+ setCommunityAddresses(newAddrs);
287
+ }
288
+ }, delay, immediate);
289
+ return communityAddresses;
290
+ }
291
+ /**
292
+ * @param communityAddress - The community address to resolve to a public key, e.g. 'news.eth' resolves to '12D3KooW...'.
293
+ * @param acountName - The nickname of the account, e.g. 'Account 1'. If no accountName is provided, use
294
+ * the active account.
295
+ */
296
+ // NOTE: useResolvedCommunityAddress tests are skipped, if changes are made they must be tested manually
297
+ export function useResolvedCommunityAddress(options) {
298
+ assert(!options || typeof options === "object", `useResolvedCommunityAddress options argument '${options}' not an object`);
299
+ let { communityAddress, accountName, cache } = options !== null && options !== void 0 ? options : {};
300
+ // cache by default
301
+ if (typeof cache !== "boolean") {
302
+ cache = true;
303
+ }
304
+ // poll every 15 seconds, about the duration of an eth block
305
+ let interval = 15000;
306
+ // no point in polling often if caching is on
307
+ if (cache) {
308
+ interval = 1000 * 60 * 60 * 25;
309
+ }
310
+ const account = useAccount({ accountName });
311
+ const chainProviders = getChainProviders(account);
312
+ const [resolvedAddress, setResolvedAddress] = useState();
313
+ const [errors, setErrors] = useState([]);
314
+ const [state, setState] = useState();
315
+ let initialState = "initializing";
316
+ // before those defined, nothing can happen
317
+ if (options && account && communityAddress) {
318
+ initialState = "ready";
319
+ }
320
+ useInterval(() => {
321
+ if (!account || !communityAddress) {
322
+ setResolvedAddress(undefined);
323
+ setState(undefined);
324
+ setErrors((prevErrors) => (prevErrors.length ? [] : prevErrors));
325
+ return;
326
+ }
327
+ // address isn't a crypto domain, can't be resolved
328
+ if (!(communityAddress === null || communityAddress === void 0 ? void 0 : communityAddress.includes("."))) {
329
+ if (state !== "failed") {
330
+ setErrors([Error("not a crypto domain")]);
331
+ setState("failed");
332
+ setResolvedAddress(undefined);
333
+ }
334
+ return;
335
+ }
336
+ // only support resolving '.eth' for now
337
+ if (!(communityAddress === null || communityAddress === void 0 ? void 0 : communityAddress.endsWith(".eth"))) {
338
+ if (state !== "failed") {
339
+ setErrors([Error("crypto domain type unsupported")]);
340
+ setState("failed");
341
+ setResolvedAddress(undefined);
342
+ }
343
+ return;
344
+ }
345
+ (() => __awaiter(this, void 0, void 0, function* () {
346
+ try {
347
+ setState("resolving");
348
+ const res = yield resolveCommunityAddress(communityAddress, chainProviders);
349
+ setState("succeeded");
350
+ if (res !== resolvedAddress) {
351
+ setResolvedAddress(res);
352
+ }
353
+ }
354
+ catch (error) {
355
+ setErrors([...errors, error]);
356
+ setState("failed");
357
+ setResolvedAddress(undefined);
358
+ log.error("useResolvedCommunityAddress resolveCommunityAddress error", {
359
+ communityAddress,
360
+ chainProviders,
361
+ error,
362
+ });
363
+ }
364
+ }))();
365
+ }, interval, true, [communityAddress, chainProviders]);
366
+ // only support ENS at the moment
367
+ const chainProvider = chainProviders === null || chainProviders === void 0 ? void 0 : chainProviders["eth"];
368
+ // log('useResolvedCommunityAddress', {communityAddress, state, errors, resolvedAddress, chainProviders})
369
+ return {
370
+ resolvedAddress,
371
+ chainProvider,
372
+ state: state || initialState,
373
+ error: errors[errors.length - 1],
374
+ errors,
375
+ };
376
+ }
377
+ // NOTE: resolveCommunityAddress tests are skipped, if changes are made they must be tested manually
378
+ export const resolveCommunityAddress = (communityAddress, chainProviders) => __awaiter(void 0, void 0, void 0, function* () {
379
+ var _a, _b, _c;
380
+ let resolvedCommunityAddress;
381
+ if (communityAddress.endsWith(".eth")) {
382
+ resolvedCommunityAddress = yield resolveEnsTxtRecord(communityAddress, "community-address", "eth", (_b = (_a = chainProviders === null || chainProviders === void 0 ? void 0 : chainProviders["eth"]) === null || _a === void 0 ? void 0 : _a.urls) === null || _b === void 0 ? void 0 : _b[0], (_c = chainProviders === null || chainProviders === void 0 ? void 0 : chainProviders["eth"]) === null || _c === void 0 ? void 0 : _c.chainId);
383
+ }
384
+ else {
385
+ throw Error(`resolveCommunityAddress invalid communityAddress '${communityAddress}'`);
386
+ }
387
+ return resolvedCommunityAddress;
388
+ });
389
+ //# sourceMappingURL=communities.js.map
@@ -0,0 +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,OAAO,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,SAAS,MAAM,kBAAkB,CAAC;AACzC,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7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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 } 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 \"assert\";\nimport {\n Community,\n CommunityStats,\n ChainProviders,\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 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\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 1'. 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 } = 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 errors = useCommunitiesStore((state: any) => state.errors[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) {\n return;\n }\n if (!storedCommunity && !onlyIfCached) {\n // if community isn't already in store, add it\n addCommunityToStore(communityInput, account).catch((error: unknown) =>\n log.error(\"useCommunity addCommunityToStore error\", { communityInput, error }),\n );\n }\n }, [communityKey, account?.id]);\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 let state = mergedCommunity?.updatingState || \"initializing\";\n // force succeeded even if the community is fecthing a new update\n if (mergedCommunity?.updatedAt) {\n state = \"succeeded\";\n }\n\n return useMemo(\n () => ({\n ...mergedCommunity,\n state,\n error: errors?.[errors.length - 1],\n errors: errors || [],\n }),\n [mergedCommunity, communityKey, errors],\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 1'. 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 1'. 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 } = 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\n useEffect(() => {\n if (!normalizedCommunityRefs.length || !account) {\n return;\n }\n if (onlyIfCached) {\n return;\n }\n const uniqueCommunityRefs = getUniqueSortedCommunityRefs(normalizedCommunityRefs);\n for (const communityRef of uniqueCommunityRefs) {\n addCommunityToStore(communityRef, account).catch((error: unknown) =>\n log.error(\"useCommunities addCommunityToStore error\", { communityRef, error }),\n );\n }\n }, [account?.id, communityKeys.toString(), onlyIfCached, normalizedCommunityRefs]);\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 1'. 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\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 setResolvedAddress(undefined);\n setState(undefined);\n setErrors((prevErrors) => (prevErrors.length ? [] : prevErrors));\n return;\n }\n\n // address isn't a crypto domain, can't be resolved\n if (!communityAddress?.includes(\".\")) {\n if (state !== \"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 (state !== \"failed\") {\n setErrors([Error(\"crypto domain type unsupported\")]);\n setState(\"failed\");\n setResolvedAddress(undefined);\n }\n return;\n }\n\n (async () => {\n try {\n setState(\"resolving\");\n const res = await resolveCommunityAddress(communityAddress, chainProviders);\n setState(\"succeeded\");\n if (res !== resolvedAddress) {\n setResolvedAddress(res);\n }\n } catch (error: any) {\n setErrors([...errors, 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 return {\n resolvedAddress,\n chainProvider,\n state: state || initialState,\n error: errors[errors.length - 1],\n errors,\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"]}
@@ -0,0 +1,18 @@
1
+ import { UseBufferedFeedsOptions, UseBufferedFeedsResult, UseFeedOptions, UseFeedResult } from "../../types.js";
2
+ /**
3
+ * @param communities - The communities to fetch, e.g. [{name: 'memes.eth'}, {publicKey: '12D3KooW...'}]
4
+ * @param sortType - The sorting algo for the feed: 'hot' | 'new' | 'active' | 'topHour' | 'topDay' | 'topWeek' | 'topMonth' | 'topYear' | 'topAll' | 'controversialHour' | 'controversialDay' | 'controversialWeek' | 'controversialMonth' | 'controversialYear' | 'controversialAll'
5
+ * @param acountName - The nickname of the account, e.g. 'Account 1'. If no accountName is provided, use
6
+ * the active account.
7
+ */
8
+ export declare function useFeed(options?: UseFeedOptions): UseFeedResult;
9
+ /**
10
+ * Use useBufferedFeeds to buffer multiple feeds in the background so what when
11
+ * they are called by useFeed later, they are already preloaded.
12
+ *
13
+ * @param feedOptions - The options of the feed
14
+ * @param acountName - The nickname of the account, e.g. 'Account 1'. If no accountName is provided, use
15
+ * the active account.
16
+ */
17
+ export declare function useBufferedFeeds(options?: UseBufferedFeedsOptions): UseBufferedFeedsResult;
18
+ //# sourceMappingURL=feeds.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feeds.d.ts","sourceRoot":"","sources":["../../../src/hooks/feeds/feeds.ts"],"names":[],"mappings":"AAOA,OAAO,EAGL,uBAAuB,EACvB,sBAAsB,EACtB,cAAc,EACd,aAAa,EAEd,MAAM,aAAa,CAAC;AAUrB;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,aAAa,CAgL/D;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE,uBAAuB,GAAG,sBAAsB,CA0I1F"}