@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.
- package/LICENSE +674 -0
- package/README.md +1365 -0
- package/dist/hooks/accounts/accounts.d.ts +64 -0
- package/dist/hooks/accounts/accounts.d.ts.map +1 -0
- package/dist/hooks/accounts/accounts.js +706 -0
- package/dist/hooks/accounts/accounts.js.map +1 -0
- package/dist/hooks/accounts/index.d.ts +2 -0
- package/dist/hooks/accounts/index.d.ts.map +1 -0
- package/dist/hooks/accounts/index.js +2 -0
- package/dist/hooks/accounts/index.js.map +1 -0
- package/dist/hooks/accounts/utils.d.ts +6 -0
- package/dist/hooks/accounts/utils.d.ts.map +1 -0
- package/dist/hooks/accounts/utils.js +226 -0
- package/dist/hooks/accounts/utils.js.map +1 -0
- package/dist/hooks/actions/actions.d.ts +19 -0
- package/dist/hooks/actions/actions.d.ts.map +1 -0
- package/dist/hooks/actions/actions.js +552 -0
- package/dist/hooks/actions/actions.js.map +1 -0
- package/dist/hooks/actions/index.d.ts +2 -0
- package/dist/hooks/actions/index.d.ts.map +1 -0
- package/dist/hooks/actions/index.js +2 -0
- package/dist/hooks/actions/index.js.map +1 -0
- package/dist/hooks/authors/author-avatars.d.ts +28 -0
- package/dist/hooks/authors/author-avatars.d.ts.map +1 -0
- package/dist/hooks/authors/author-avatars.js +191 -0
- package/dist/hooks/authors/author-avatars.js.map +1 -0
- package/dist/hooks/authors/authors.d.ts +37 -0
- package/dist/hooks/authors/authors.d.ts.map +1 -0
- package/dist/hooks/authors/authors.js +509 -0
- package/dist/hooks/authors/authors.js.map +1 -0
- package/dist/hooks/authors/index.d.ts +2 -0
- package/dist/hooks/authors/index.d.ts.map +1 -0
- package/dist/hooks/authors/index.js +2 -0
- package/dist/hooks/authors/index.js.map +1 -0
- package/dist/hooks/authors/utils.d.ts +4 -0
- package/dist/hooks/authors/utils.d.ts.map +1 -0
- package/dist/hooks/authors/utils.js +21 -0
- package/dist/hooks/authors/utils.js.map +1 -0
- package/dist/hooks/comments.d.ts +17 -0
- package/dist/hooks/comments.d.ts.map +1 -0
- package/dist/hooks/comments.js +351 -0
- package/dist/hooks/comments.js.map +1 -0
- package/dist/hooks/communities.d.ts +31 -0
- package/dist/hooks/communities.d.ts.map +1 -0
- package/dist/hooks/communities.js +389 -0
- package/dist/hooks/communities.js.map +1 -0
- package/dist/hooks/feeds/feeds.d.ts +18 -0
- package/dist/hooks/feeds/feeds.d.ts.map +1 -0
- package/dist/hooks/feeds/feeds.js +315 -0
- package/dist/hooks/feeds/feeds.js.map +1 -0
- package/dist/hooks/feeds/index.d.ts +2 -0
- package/dist/hooks/feeds/index.d.ts.map +1 -0
- package/dist/hooks/feeds/index.js +2 -0
- package/dist/hooks/feeds/index.js.map +1 -0
- package/dist/hooks/pkc-rpc.d.ts +7 -0
- package/dist/hooks/pkc-rpc.d.ts.map +1 -0
- package/dist/hooks/pkc-rpc.js +88 -0
- package/dist/hooks/pkc-rpc.js.map +1 -0
- package/dist/hooks/replies.d.ts +5 -0
- package/dist/hooks/replies.d.ts.map +1 -0
- package/dist/hooks/replies.js +155 -0
- package/dist/hooks/replies.js.map +1 -0
- package/dist/hooks/states.d.ts +15 -0
- package/dist/hooks/states.d.ts.map +1 -0
- package/dist/hooks/states.js +213 -0
- package/dist/hooks/states.js.map +1 -0
- package/dist/hooks/utils/use-interval.d.ts +3 -0
- package/dist/hooks/utils/use-interval.d.ts.map +1 -0
- package/dist/hooks/utils/use-interval.js +36 -0
- package/dist/hooks/utils/use-interval.js.map +1 -0
- package/dist/hooks/utils/use-previous.d.ts +1 -0
- package/dist/hooks/utils/use-previous.js +10 -0
- package/dist/index.d.ts +82 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +128 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/chain/chain.d.ts +36 -0
- package/dist/lib/chain/chain.d.ts.map +1 -0
- package/dist/lib/chain/chain.js +195 -0
- package/dist/lib/chain/chain.js.map +1 -0
- package/dist/lib/chain/index.d.ts +4 -0
- package/dist/lib/chain/index.d.ts.map +1 -0
- package/dist/lib/chain/index.js +4 -0
- package/dist/lib/chain/index.js.map +1 -0
- package/dist/lib/community-address.d.ts +6 -0
- package/dist/lib/community-address.d.ts.map +1 -0
- package/dist/lib/community-address.js +26 -0
- package/dist/lib/community-address.js.map +1 -0
- package/dist/lib/community-ref.d.ts +23 -0
- package/dist/lib/community-ref.d.ts.map +1 -0
- package/dist/lib/community-ref.js +113 -0
- package/dist/lib/community-ref.js.map +1 -0
- package/dist/lib/debug-utils.d.ts +9 -0
- package/dist/lib/debug-utils.d.ts.map +1 -0
- package/dist/lib/debug-utils.js +21 -0
- package/dist/lib/debug-utils.js.map +1 -0
- package/dist/lib/feed-sort-type.d.ts +2 -0
- package/dist/lib/feed-sort-type.d.ts.map +1 -0
- package/dist/lib/feed-sort-type.js +22 -0
- package/dist/lib/feed-sort-type.js.map +1 -0
- package/dist/lib/localforage-lru/index.d.ts +3 -0
- package/dist/lib/localforage-lru/index.d.ts.map +1 -0
- package/dist/lib/localforage-lru/index.js +46 -0
- package/dist/lib/localforage-lru/index.js.map +1 -0
- package/dist/lib/localforage-lru/localforage-lru.d.ts +6 -0
- package/dist/lib/localforage-lru/localforage-lru.d.ts.map +1 -0
- package/dist/lib/localforage-lru/localforage-lru.js +182 -0
- package/dist/lib/localforage-lru/localforage-lru.js.map +1 -0
- package/dist/lib/pkc-compat.d.ts +25 -0
- package/dist/lib/pkc-compat.d.ts.map +1 -0
- package/dist/lib/pkc-compat.js +131 -0
- package/dist/lib/pkc-compat.js.map +1 -0
- package/dist/lib/pkc-js/fixtures/markdown-example.d.ts +3 -0
- package/dist/lib/pkc-js/fixtures/markdown-example.d.ts.map +1 -0
- package/dist/lib/pkc-js/fixtures/markdown-example.js +280 -0
- package/dist/lib/pkc-js/fixtures/markdown-example.js.map +1 -0
- package/dist/lib/pkc-js/index.d.ts +11 -0
- package/dist/lib/pkc-js/index.d.ts.map +1 -0
- package/dist/lib/pkc-js/index.js +85 -0
- package/dist/lib/pkc-js/index.js.map +1 -0
- package/dist/lib/pkc-js/pkc-js-mock-content.d.ts +3 -0
- package/dist/lib/pkc-js/pkc-js-mock-content.d.ts.map +1 -0
- package/dist/lib/pkc-js/pkc-js-mock-content.js +1235 -0
- package/dist/lib/pkc-js/pkc-js-mock-content.js.map +1 -0
- package/dist/lib/pkc-js/pkc-js-mock.d.ts +137 -0
- package/dist/lib/pkc-js/pkc-js-mock.d.ts.map +1 -0
- package/dist/lib/pkc-js/pkc-js-mock.js +644 -0
- package/dist/lib/pkc-js/pkc-js-mock.js.map +1 -0
- package/dist/lib/polyfill.d.ts +3 -0
- package/dist/lib/polyfill.d.ts.map +1 -0
- package/dist/lib/polyfill.js +14 -0
- package/dist/lib/polyfill.js.map +1 -0
- package/dist/lib/protocol-compat.d.ts +14 -0
- package/dist/lib/protocol-compat.d.ts.map +1 -0
- package/dist/lib/protocol-compat.js +67 -0
- package/dist/lib/protocol-compat.js.map +1 -0
- package/dist/lib/test-utils.d.ts +29 -0
- package/dist/lib/test-utils.d.ts.map +1 -0
- package/dist/lib/test-utils.js +184 -0
- package/dist/lib/test-utils.js.map +1 -0
- package/dist/lib/utils/comment-moderation.d.ts +4 -0
- package/dist/lib/utils/comment-moderation.d.ts.map +1 -0
- package/dist/lib/utils/comment-moderation.js +56 -0
- package/dist/lib/utils/comment-moderation.js.map +1 -0
- package/dist/lib/utils/index.d.ts +4 -0
- package/dist/lib/utils/index.d.ts.map +1 -0
- package/dist/lib/utils/index.js +4 -0
- package/dist/lib/utils/index.js.map +1 -0
- package/dist/lib/utils/utils.d.ts +23 -0
- package/dist/lib/utils/utils.d.ts.map +1 -0
- package/dist/lib/utils/utils.js +375 -0
- package/dist/lib/utils/utils.js.map +1 -0
- package/dist/lib/validator.d.ts +30 -0
- package/dist/lib/validator.d.ts.map +1 -0
- package/dist/lib/validator.js +307 -0
- package/dist/lib/validator.js.map +1 -0
- package/dist/stores/accounts/account-generator.d.ts +51 -0
- package/dist/stores/accounts/account-generator.d.ts.map +1 -0
- package/dist/stores/accounts/account-generator.js +160 -0
- package/dist/stores/accounts/account-generator.js.map +1 -0
- package/dist/stores/accounts/accounts-actions-internal.d.ts +8 -0
- package/dist/stores/accounts/accounts-actions-internal.d.ts.map +1 -0
- package/dist/stores/accounts/accounts-actions-internal.js +403 -0
- package/dist/stores/accounts/accounts-actions-internal.js.map +1 -0
- package/dist/stores/accounts/accounts-actions.d.ts +46 -0
- package/dist/stores/accounts/accounts-actions.d.ts.map +1 -0
- package/dist/stores/accounts/accounts-actions.js +1341 -0
- package/dist/stores/accounts/accounts-actions.js.map +1 -0
- package/dist/stores/accounts/accounts-database.d.ts +34 -0
- package/dist/stores/accounts/accounts-database.d.ts.map +1 -0
- package/dist/stores/accounts/accounts-database.js +685 -0
- package/dist/stores/accounts/accounts-database.js.map +1 -0
- package/dist/stores/accounts/accounts-store.d.ts +32 -0
- package/dist/stores/accounts/accounts-store.d.ts.map +1 -0
- package/dist/stores/accounts/accounts-store.js +169 -0
- package/dist/stores/accounts/accounts-store.js.map +1 -0
- package/dist/stores/accounts/index.d.ts +4 -0
- package/dist/stores/accounts/index.d.ts.map +1 -0
- package/dist/stores/accounts/index.js +4 -0
- package/dist/stores/accounts/index.js.map +1 -0
- package/dist/stores/accounts/utils.d.ts +49 -0
- package/dist/stores/accounts/utils.d.ts.map +1 -0
- package/dist/stores/accounts/utils.js +419 -0
- package/dist/stores/accounts/utils.js.map +1 -0
- package/dist/stores/authors-comments/authors-comments-store.d.ts +37 -0
- package/dist/stores/authors-comments/authors-comments-store.d.ts.map +1 -0
- package/dist/stores/authors-comments/authors-comments-store.js +338 -0
- package/dist/stores/authors-comments/authors-comments-store.js.map +1 -0
- package/dist/stores/authors-comments/index.d.ts +4 -0
- package/dist/stores/authors-comments/index.d.ts.map +1 -0
- package/dist/stores/authors-comments/index.js +4 -0
- package/dist/stores/authors-comments/index.js.map +1 -0
- package/dist/stores/authors-comments/utils.d.ts +14 -0
- package/dist/stores/authors-comments/utils.d.ts.map +1 -0
- package/dist/stores/authors-comments/utils.js +81 -0
- package/dist/stores/authors-comments/utils.js.map +1 -0
- package/dist/stores/comments/comments-store.d.ts +19 -0
- package/dist/stores/comments/comments-store.d.ts.map +1 -0
- package/dist/stores/comments/comments-store.js +385 -0
- package/dist/stores/comments/comments-store.js.map +1 -0
- package/dist/stores/comments/index.d.ts +4 -0
- package/dist/stores/comments/index.d.ts.map +1 -0
- package/dist/stores/comments/index.js +4 -0
- package/dist/stores/comments/index.js.map +1 -0
- package/dist/stores/communities/communities-store.d.ts +17 -0
- package/dist/stores/communities/communities-store.d.ts.map +1 -0
- package/dist/stores/communities/communities-store.js +304 -0
- package/dist/stores/communities/communities-store.js.map +1 -0
- package/dist/stores/communities/index.d.ts +4 -0
- package/dist/stores/communities/index.d.ts.map +1 -0
- package/dist/stores/communities/index.js +4 -0
- package/dist/stores/communities/index.js.map +1 -0
- package/dist/stores/communities-pages/communities-pages-store.d.ts +23 -0
- package/dist/stores/communities-pages/communities-pages-store.d.ts.map +1 -0
- package/dist/stores/communities-pages/communities-pages-store.js +316 -0
- package/dist/stores/communities-pages/communities-pages-store.js.map +1 -0
- package/dist/stores/communities-pages/index.d.ts +4 -0
- package/dist/stores/communities-pages/index.d.ts.map +1 -0
- package/dist/stores/communities-pages/index.js +4 -0
- package/dist/stores/communities-pages/index.js.map +1 -0
- package/dist/stores/feeds/feed-sorter.d.ts +5 -0
- package/dist/stores/feeds/feed-sorter.d.ts.map +1 -0
- package/dist/stores/feeds/feed-sorter.js +135 -0
- package/dist/stores/feeds/feed-sorter.js.map +1 -0
- package/dist/stores/feeds/feeds-store.d.ts +25 -0
- package/dist/stores/feeds/feeds-store.d.ts.map +1 -0
- package/dist/stores/feeds/feeds-store.js +459 -0
- package/dist/stores/feeds/feeds-store.js.map +1 -0
- package/dist/stores/feeds/index.d.ts +4 -0
- package/dist/stores/feeds/index.d.ts.map +1 -0
- package/dist/stores/feeds/index.js +4 -0
- package/dist/stores/feeds/index.js.map +1 -0
- package/dist/stores/feeds/utils.d.ts +43 -0
- package/dist/stores/feeds/utils.d.ts.map +1 -0
- package/dist/stores/feeds/utils.js +736 -0
- package/dist/stores/feeds/utils.js.map +1 -0
- package/dist/stores/replies/index.d.ts +4 -0
- package/dist/stores/replies/index.d.ts.map +1 -0
- package/dist/stores/replies/index.js +4 -0
- package/dist/stores/replies/index.js.map +1 -0
- package/dist/stores/replies/replies-comments-store.d.ts +8 -0
- package/dist/stores/replies/replies-comments-store.d.ts.map +1 -0
- package/dist/stores/replies/replies-comments-store.js +23 -0
- package/dist/stores/replies/replies-comments-store.js.map +1 -0
- package/dist/stores/replies/replies-store.d.ts +29 -0
- package/dist/stores/replies/replies-store.d.ts.map +1 -0
- package/dist/stores/replies/replies-store.js +413 -0
- package/dist/stores/replies/replies-store.js.map +1 -0
- package/dist/stores/replies/utils.d.ts +25 -0
- package/dist/stores/replies/utils.d.ts.map +1 -0
- package/dist/stores/replies/utils.js +549 -0
- package/dist/stores/replies/utils.js.map +1 -0
- package/dist/stores/replies-pages/index.d.ts +4 -0
- package/dist/stores/replies-pages/index.d.ts.map +1 -0
- package/dist/stores/replies-pages/index.js +4 -0
- package/dist/stores/replies-pages/index.js.map +1 -0
- package/dist/stores/replies-pages/replies-pages-store.d.ts +20 -0
- package/dist/stores/replies-pages/replies-pages-store.d.ts.map +1 -0
- package/dist/stores/replies-pages/replies-pages-store.js +270 -0
- package/dist/stores/replies-pages/replies-pages-store.js.map +1 -0
- package/dist/stores/replies-pages/utils.d.ts +3 -0
- package/dist/stores/replies-pages/utils.d.ts.map +1 -0
- package/dist/stores/replies-pages/utils.js +43 -0
- package/dist/stores/replies-pages/utils.js.map +1 -0
- package/dist/types.d.ts +638 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +160 -0
|
@@ -0,0 +1,509 @@
|
|
|
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 useInterval from "../utils/use-interval.js";
|
|
12
|
+
import { useAccount } from "../accounts/index.js";
|
|
13
|
+
import Logger from "@pkcprotocol/pkc-logger";
|
|
14
|
+
const log = Logger("bitsocial-react-hooks:authors:hooks");
|
|
15
|
+
import assert from "assert";
|
|
16
|
+
import { useNftMetadataUrl, useNftImageUrl, useVerifiedAuthorAvatarSignature, useAuthorAvatarIsWhitelisted, } from "./author-avatars.js";
|
|
17
|
+
import { useComment } from "../comments.js";
|
|
18
|
+
import { useAuthorCommentsName, usePkcAddress } from "./utils.js";
|
|
19
|
+
import useAuthorsCommentsStore from "../../stores/authors-comments/index.js";
|
|
20
|
+
import PkcJs from "../../lib/pkc-js/index.js";
|
|
21
|
+
import { getConfiguredNameResolverInfoByKey, getChainProviders, getMatchingNameResolvers, getProtocolClient, getProtocolNameResolverClients, resolveAuthorNameWithProtocol, } from "../../lib/pkc-compat.js";
|
|
22
|
+
import QuickLRU from "quick-lru";
|
|
23
|
+
export { setAuthorAvatarsWhitelistedTokenAddresses } from "./author-avatars.js";
|
|
24
|
+
const cacheResolveAuthorAddressPromise = (address, promise) => {
|
|
25
|
+
resolveAuthorAddressPromises[address] = promise;
|
|
26
|
+
const clearCachedPromise = () => {
|
|
27
|
+
if (resolveAuthorAddressPromises[address] === promise) {
|
|
28
|
+
delete resolveAuthorAddressPromises[address];
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
void promise.then(clearCachedPromise, clearCachedPromise);
|
|
32
|
+
return promise;
|
|
33
|
+
};
|
|
34
|
+
const removeStateChangeListener = (client, listener) => {
|
|
35
|
+
var _a;
|
|
36
|
+
if (typeof (client === null || client === void 0 ? void 0 : client.off) === "function") {
|
|
37
|
+
client.off("statechange", listener);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
(_a = client === null || client === void 0 ? void 0 : client.removeListener) === null || _a === void 0 ? void 0 : _a.call(client, "statechange", listener);
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* @param authorAddress - The address of the author
|
|
44
|
+
* @param commentCid - The last known comment cid of the author (not possible to get an author without providing at least 1 comment cid)
|
|
45
|
+
* @param acountName - The nickname of the account, e.g. 'Account 1'. If no accountName is provided, use
|
|
46
|
+
* the active account.
|
|
47
|
+
*/
|
|
48
|
+
export function useAuthorComments(options) {
|
|
49
|
+
assert(!options || typeof options === "object", `useAuthorComments options argument '${options}' not an object`);
|
|
50
|
+
const { authorAddress, commentCid, accountName, filter } = options || {};
|
|
51
|
+
const account = useAccount({ accountName });
|
|
52
|
+
const authorCommentsName = useAuthorCommentsName(account === null || account === void 0 ? void 0 : account.id, authorAddress, filter);
|
|
53
|
+
const incrementPageNumber = useAuthorsCommentsStore((state) => state.incrementPageNumber);
|
|
54
|
+
const addAuthorCommentsToStore = useAuthorsCommentsStore((state) => state.addAuthorCommentsToStore);
|
|
55
|
+
const hasMoreBufferedComments = useAuthorsCommentsStore((state) => state.hasMoreBufferedComments[authorCommentsName || ""]);
|
|
56
|
+
const hasNextCommentCidToFetch = useAuthorsCommentsStore((state) => Boolean(state.nextCommentCidsToFetch[authorAddress || ""]));
|
|
57
|
+
const authorComments = useAuthorsCommentsStore((state) => state.loadedComments[authorCommentsName || ""]);
|
|
58
|
+
const lastCommentCid = useAuthorsCommentsStore((state) => state.lastCommentCids[authorAddress || ""]);
|
|
59
|
+
// add authors comments to store
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (!authorAddress || !commentCid || !account) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
addAuthorCommentsToStore(authorCommentsName, authorAddress, commentCid, filter, account);
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
log.error("useAuthorComments addAuthorCommentsToStore error", { authorCommentsName, error });
|
|
69
|
+
}
|
|
70
|
+
}, [authorCommentsName, commentCid]);
|
|
71
|
+
const loadMore = () => __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
try {
|
|
73
|
+
if (!authorAddress || !account) {
|
|
74
|
+
throw Error("useAuthorComments cannot load more authorComments not initalized yet");
|
|
75
|
+
}
|
|
76
|
+
incrementPageNumber(authorCommentsName);
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
// wait 100 ms so infinite scroll doesn't spam this function
|
|
80
|
+
yield new Promise((r) => setTimeout(r, 50));
|
|
81
|
+
// TODO: maybe add these errors to errors array
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
const hasMore = hasMoreBufferedComments || hasNextCommentCidToFetch;
|
|
85
|
+
const authorResult = useAuthor({ commentCid, authorAddress, accountName });
|
|
86
|
+
const state = authorResult.state;
|
|
87
|
+
const errors = authorResult.errors;
|
|
88
|
+
if (authorResult.author) {
|
|
89
|
+
log("useAuthorComments", {
|
|
90
|
+
authorAddress,
|
|
91
|
+
commentCid,
|
|
92
|
+
// authorComments,
|
|
93
|
+
authorCommentsSize: (authorComments === null || authorComments === void 0 ? void 0 : authorComments.length) || 0,
|
|
94
|
+
lastCommentCid,
|
|
95
|
+
hasMoreBufferedComments,
|
|
96
|
+
hasNextCommentCidToFetch,
|
|
97
|
+
hasMore,
|
|
98
|
+
state,
|
|
99
|
+
errors,
|
|
100
|
+
authorResult,
|
|
101
|
+
accountName,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return useMemo(() => ({
|
|
105
|
+
authorComments: authorComments || [],
|
|
106
|
+
lastCommentCid,
|
|
107
|
+
hasMore,
|
|
108
|
+
loadMore,
|
|
109
|
+
state,
|
|
110
|
+
error: errors[errors.length - 1],
|
|
111
|
+
errors,
|
|
112
|
+
}), [authorComments, lastCommentCid, hasMore, errors, state]);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* @param authorAddress - The address of the author
|
|
116
|
+
* @param commentCid - The last known comment cid of the author (not possible to get an author without providing at least 1 comment cid)
|
|
117
|
+
* @param acountName - The nickname of the account, e.g. 'Account 1'. If no accountName is provided, use
|
|
118
|
+
* the active account.
|
|
119
|
+
*/
|
|
120
|
+
export function useAuthor(options) {
|
|
121
|
+
var _a;
|
|
122
|
+
assert(!options || typeof options === "object", `useAuthor options argument '${options}' not an object`);
|
|
123
|
+
const { authorAddress, commentCid, accountName } = options || {};
|
|
124
|
+
const comment = useComment({ commentCid, accountName });
|
|
125
|
+
// the commentCid doesnt have the same author address as authorAddress
|
|
126
|
+
const useAuthorError = useMemo(() => {
|
|
127
|
+
var _a;
|
|
128
|
+
// if comment is loaded and author address is different from authorAddress
|
|
129
|
+
if ((comment === null || comment === void 0 ? void 0 : comment.timestamp) && authorAddress && ((_a = comment === null || comment === void 0 ? void 0 : comment.author) === null || _a === void 0 ? void 0 : _a.address) !== authorAddress) {
|
|
130
|
+
return Error("commentCid author.address is different from authorAddress");
|
|
131
|
+
}
|
|
132
|
+
if (commentCid && !authorAddress) {
|
|
133
|
+
return Error("missing UseAuthorOptions.authorAddress");
|
|
134
|
+
}
|
|
135
|
+
if (!commentCid && authorAddress) {
|
|
136
|
+
return Error("missing UseAuthorOptions.commentCid");
|
|
137
|
+
}
|
|
138
|
+
}, [commentCid, comment === null || comment === void 0 ? void 0 : comment.timestamp, (_a = comment === null || comment === void 0 ? void 0 : comment.author) === null || _a === void 0 ? void 0 : _a.address, authorAddress]);
|
|
139
|
+
// if has author error, don't return the autor
|
|
140
|
+
let author;
|
|
141
|
+
if (!useAuthorError) {
|
|
142
|
+
author = comment === null || comment === void 0 ? void 0 : comment.author;
|
|
143
|
+
}
|
|
144
|
+
// merge comment.errors with useAuthorError
|
|
145
|
+
const errors = useMemo(() => {
|
|
146
|
+
if (useAuthorError) {
|
|
147
|
+
return [...comment.errors, useAuthorError];
|
|
148
|
+
}
|
|
149
|
+
return comment.errors;
|
|
150
|
+
}, [comment.errors, useAuthorError]);
|
|
151
|
+
// if has author error, state failed
|
|
152
|
+
let state = author ? "succeeded" : (comment === null || comment === void 0 ? void 0 : comment.state) || "initializing";
|
|
153
|
+
if (useAuthorError) {
|
|
154
|
+
state = "failed";
|
|
155
|
+
}
|
|
156
|
+
if (comment === null || comment === void 0 ? void 0 : comment.timestamp) {
|
|
157
|
+
log("useAuthor", {
|
|
158
|
+
authorAddress,
|
|
159
|
+
commentCid,
|
|
160
|
+
author,
|
|
161
|
+
comment,
|
|
162
|
+
useAuthorError,
|
|
163
|
+
state,
|
|
164
|
+
accountName,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
return useMemo(() => ({
|
|
168
|
+
author,
|
|
169
|
+
state,
|
|
170
|
+
error: errors[errors.length - 1],
|
|
171
|
+
errors,
|
|
172
|
+
}), [author, errors, state]);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* @param author - The Author object to resolve the avatar image URL of.
|
|
176
|
+
* @param acountName - The nickname of the account, e.g. 'Account 1'. If no accountName is provided, use
|
|
177
|
+
* the active account.
|
|
178
|
+
*/
|
|
179
|
+
// NOTE: useAuthorAvatar tests are skipped, if changes are made they must be tested manually
|
|
180
|
+
export function useAuthorAvatar(options) {
|
|
181
|
+
var _a, _b;
|
|
182
|
+
assert(!options || typeof options === "object", `useAuthorAvatar options argument '${options}' not an object`);
|
|
183
|
+
const { author, accountName } = options || {};
|
|
184
|
+
const account = useAccount({ accountName });
|
|
185
|
+
// TODO: resolve crypto domain and check if one of the record is a profile pic
|
|
186
|
+
const { verified, error: signatureError } = useVerifiedAuthorAvatarSignature(author, accountName);
|
|
187
|
+
const verifiedError = verified === false && Error(`nft ownership signature proof invalid`);
|
|
188
|
+
const isWhitelisted = useAuthorAvatarIsWhitelisted(author === null || author === void 0 ? void 0 : author.avatar);
|
|
189
|
+
const whitelistedError = isWhitelisted === false && Error(`nft collection '${(_a = author === null || author === void 0 ? void 0 : author.avatar) === null || _a === void 0 ? void 0 : _a.address}' not whitelisted`);
|
|
190
|
+
// don't try to get avatar image url at all if signature isn't verified and whitelisted
|
|
191
|
+
const avatar = verified && isWhitelisted ? author === null || author === void 0 ? void 0 : author.avatar : undefined;
|
|
192
|
+
const { metadataUrl, error: nftMetadataError } = useNftMetadataUrl(avatar, accountName);
|
|
193
|
+
const { imageUrl, error: nftImageUrlError } = useNftImageUrl(metadataUrl, accountName);
|
|
194
|
+
const chainProvider = (_b = getChainProviders(account)) === null || _b === void 0 ? void 0 : _b[avatar === null || avatar === void 0 ? void 0 : avatar.chainTicker];
|
|
195
|
+
const error = whitelistedError ||
|
|
196
|
+
verifiedError ||
|
|
197
|
+
signatureError ||
|
|
198
|
+
nftMetadataError ||
|
|
199
|
+
nftImageUrlError ||
|
|
200
|
+
undefined;
|
|
201
|
+
const errors = useMemo(() => (error ? [error] : []), [error]);
|
|
202
|
+
let state = "initializing";
|
|
203
|
+
if (!(author === null || author === void 0 ? void 0 : author.avatar)) {
|
|
204
|
+
// do nothing, is initializing
|
|
205
|
+
}
|
|
206
|
+
else if (error) {
|
|
207
|
+
state = "failed";
|
|
208
|
+
}
|
|
209
|
+
else if (imageUrl !== undefined) {
|
|
210
|
+
state = "succeeded";
|
|
211
|
+
}
|
|
212
|
+
else if (metadataUrl !== undefined) {
|
|
213
|
+
state = "fetching-metadata";
|
|
214
|
+
}
|
|
215
|
+
else if (verified !== undefined) {
|
|
216
|
+
state = "fetching-uri";
|
|
217
|
+
}
|
|
218
|
+
else if (author === null || author === void 0 ? void 0 : author.avatar) {
|
|
219
|
+
state = "fetching-owner";
|
|
220
|
+
}
|
|
221
|
+
if (author === null || author === void 0 ? void 0 : author.avatar) {
|
|
222
|
+
log("useAuthorAvatar", { author, state, verified, isWhitelisted, metadataUrl, imageUrl });
|
|
223
|
+
}
|
|
224
|
+
return useMemo(() => ({
|
|
225
|
+
imageUrl,
|
|
226
|
+
metadataUrl,
|
|
227
|
+
chainProvider,
|
|
228
|
+
state,
|
|
229
|
+
error,
|
|
230
|
+
errors,
|
|
231
|
+
}), [imageUrl, metadataUrl, chainProvider, state, error]);
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* @param author - The Author object to resolve the address of.
|
|
235
|
+
* @param acountName - The nickname of the account, e.g. 'Account 1'. If no accountName is provided, use
|
|
236
|
+
* the active account.
|
|
237
|
+
*/
|
|
238
|
+
export function useAuthorAddress(options) {
|
|
239
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
240
|
+
assert(!options || typeof options === "object", `useAuthorAddress options argument '${options}' not an object`);
|
|
241
|
+
const { comment, accountName } = options || {};
|
|
242
|
+
const account = useAccount({ accountName });
|
|
243
|
+
const protocolClient = getProtocolClient(account);
|
|
244
|
+
const isCryptoName = !!((_c = (_b = (_a = comment === null || comment === void 0 ? void 0 : comment.author) === null || _a === void 0 ? void 0 : _a.address) === null || _b === void 0 ? void 0 : _b.includes) === null || _c === void 0 ? void 0 : _c.call(_b, "."));
|
|
245
|
+
const [resolvedAddress, setResolvedAddress] = useState(isCryptoName ? resolvedAuthorAddressCache.get((_d = comment === null || comment === void 0 ? void 0 : comment.author) === null || _d === void 0 ? void 0 : _d.address) : undefined);
|
|
246
|
+
const signerAddress = usePkcAddress(isCryptoName ? (_e = comment === null || comment === void 0 ? void 0 : comment.signature) === null || _e === void 0 ? void 0 : _e.publicKey : undefined);
|
|
247
|
+
// useful for triggering css animation when the address changes from unverified to verified
|
|
248
|
+
const [authorAddressChanged, setAuthorAddressChanged] = useState(false);
|
|
249
|
+
useEffect(() => {
|
|
250
|
+
var _a, _b;
|
|
251
|
+
if (!protocolClient || !((_a = comment === null || comment === void 0 ? void 0 : comment.author) === null || _a === void 0 ? void 0 : _a.address) || !isCryptoName) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const addr = (_b = comment === null || comment === void 0 ? void 0 : comment.author) === null || _b === void 0 ? void 0 : _b.address;
|
|
255
|
+
const resolveAuthorAddressNoCache = () => {
|
|
256
|
+
const existing = resolveAuthorAddressPromises[addr];
|
|
257
|
+
if (existing)
|
|
258
|
+
return existing;
|
|
259
|
+
log("useAuthorAddress protocol.resolveAuthorName", { address: addr });
|
|
260
|
+
return cacheResolveAuthorAddressPromise(addr, resolveAuthorNameWithProtocol(protocolClient, { address: addr }));
|
|
261
|
+
};
|
|
262
|
+
const resolveAuthorAddress = () => __awaiter(this, void 0, void 0, function* () {
|
|
263
|
+
const cached = resolvedAuthorAddressCache.get(addr);
|
|
264
|
+
if (cached)
|
|
265
|
+
return cached;
|
|
266
|
+
const res = yield resolveAuthorAddressNoCache();
|
|
267
|
+
resolvedAuthorAddressCache.set(addr, res);
|
|
268
|
+
return res;
|
|
269
|
+
});
|
|
270
|
+
resolveAuthorAddress()
|
|
271
|
+
.then((_resolvedAddress) => {
|
|
272
|
+
if (_resolvedAddress !== resolvedAddress) {
|
|
273
|
+
setResolvedAddress(_resolvedAddress);
|
|
274
|
+
setAuthorAddressChanged(true);
|
|
275
|
+
}
|
|
276
|
+
})
|
|
277
|
+
.catch((error) => log.error("useAuthorAddress error", { error, comment }));
|
|
278
|
+
}, [protocolClient, (_f = comment === null || comment === void 0 ? void 0 : comment.author) === null || _f === void 0 ? void 0 : _f.address, isCryptoName]);
|
|
279
|
+
// use signer address by default
|
|
280
|
+
let authorAddress = signerAddress;
|
|
281
|
+
// if author address was resolved successfully, use author address
|
|
282
|
+
if (resolvedAddress && signerAddress === resolvedAddress) {
|
|
283
|
+
authorAddress = (_g = comment === null || comment === void 0 ? void 0 : comment.author) === null || _g === void 0 ? void 0 : _g.address;
|
|
284
|
+
}
|
|
285
|
+
// if isn't crypto name, always use author address
|
|
286
|
+
if (!isCryptoName) {
|
|
287
|
+
authorAddress = (_h = comment === null || comment === void 0 ? void 0 : comment.author) === null || _h === void 0 ? void 0 : _h.address;
|
|
288
|
+
}
|
|
289
|
+
// if comment has no signature, it's a pending account comment, no need to verify it
|
|
290
|
+
// TODO: eventually account comments will have a signature immediately
|
|
291
|
+
if (comment && !(comment === null || comment === void 0 ? void 0 : comment.signature)) {
|
|
292
|
+
authorAddress = (_j = comment === null || comment === void 0 ? void 0 : comment.author) === null || _j === void 0 ? void 0 : _j.address;
|
|
293
|
+
}
|
|
294
|
+
let shortAuthorAddress = authorAddress && PkcJs.PKC.getShortAddress({ address: authorAddress });
|
|
295
|
+
// if shortAddress is smaller than crypto name, give a longer
|
|
296
|
+
// shortAddress to cause the least UI displacement as possible
|
|
297
|
+
// -4 chars because most fonts will make the address larger
|
|
298
|
+
if (isCryptoName &&
|
|
299
|
+
authorAddress &&
|
|
300
|
+
shortAuthorAddress.length < ((_l = (_k = comment === null || comment === void 0 ? void 0 : comment.author) === null || _k === void 0 ? void 0 : _k.address) === null || _l === void 0 ? void 0 : _l.length) - 4) {
|
|
301
|
+
const restOfAuthorAddress = authorAddress.split(shortAuthorAddress).pop();
|
|
302
|
+
shortAuthorAddress = (shortAuthorAddress + restOfAuthorAddress).substring(0, ((_o = (_m = comment === null || comment === void 0 ? void 0 : comment.author) === null || _m === void 0 ? void 0 : _m.address) === null || _o === void 0 ? void 0 : _o.length) - 4);
|
|
303
|
+
}
|
|
304
|
+
return useMemo(() => ({
|
|
305
|
+
authorAddress,
|
|
306
|
+
shortAuthorAddress,
|
|
307
|
+
authorAddressChanged,
|
|
308
|
+
state: "initializing",
|
|
309
|
+
error: undefined,
|
|
310
|
+
errors: [],
|
|
311
|
+
}), [authorAddress, shortAuthorAddress]);
|
|
312
|
+
}
|
|
313
|
+
// TODO: figure out how to upgrade to quick-lru 6+ to use maxAge
|
|
314
|
+
const resolvedAuthorAddressCache = new QuickLRU({ maxSize: 1000 });
|
|
315
|
+
const resolveAuthorAddressPromises = {};
|
|
316
|
+
/** For tests: reset caches to make resolution paths deterministic. */
|
|
317
|
+
export function resetAuthorAddressCacheForTesting() {
|
|
318
|
+
resolvedAuthorAddressCache.clear();
|
|
319
|
+
for (const k of Object.keys(resolveAuthorAddressPromises)) {
|
|
320
|
+
delete resolveAuthorAddressPromises[k];
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* @param author - The author with author.address to resolve to a public key, e.g. 'john.eth' resolves to '12D3KooW...'.
|
|
325
|
+
* @param acountName - The nickname of the account, e.g. 'Account 1'. If no accountName is provided, use
|
|
326
|
+
* the active account.
|
|
327
|
+
*/
|
|
328
|
+
// NOTE: useResolvedAuthorAddress tests are skipped, if changes are made they must be tested manually
|
|
329
|
+
export function useResolvedAuthorAddress(options) {
|
|
330
|
+
var _a, _b;
|
|
331
|
+
assert(!options || typeof options === "object", `useResolvedAuthorAddress options argument '${options}' not an object`);
|
|
332
|
+
let { author, accountName, cache } = options || {};
|
|
333
|
+
// cache by default
|
|
334
|
+
if (typeof cache !== "boolean") {
|
|
335
|
+
cache = true;
|
|
336
|
+
}
|
|
337
|
+
// poll every 15 seconds, about the duration of an eth block
|
|
338
|
+
let interval = 15000;
|
|
339
|
+
// no point in polling often if caching is on
|
|
340
|
+
if (cache) {
|
|
341
|
+
interval = 1000 * 60 * 60 * 25;
|
|
342
|
+
}
|
|
343
|
+
const account = useAccount({ accountName });
|
|
344
|
+
const protocolClient = getProtocolClient(account);
|
|
345
|
+
const chainProviders = getChainProviders(account);
|
|
346
|
+
const configuredNameResolvers = useMemo(() => getMatchingNameResolvers(account, author === null || author === void 0 ? void 0 : author.address), [account, author === null || author === void 0 ? void 0 : author.address]);
|
|
347
|
+
const configuredNameResolversByKey = useMemo(() => getConfiguredNameResolverInfoByKey(account), [account]);
|
|
348
|
+
const [resolvedAddress, setResolvedAddress] = useState();
|
|
349
|
+
const [errors, setErrors] = useState([]);
|
|
350
|
+
const [state, setState] = useState();
|
|
351
|
+
const [activeNameResolverKey, setActiveNameResolverKey] = useState();
|
|
352
|
+
let initialState = "initializing";
|
|
353
|
+
// before those defined, nothing can happen
|
|
354
|
+
if (options && account && (author === null || author === void 0 ? void 0 : author.address)) {
|
|
355
|
+
initialState = "ready";
|
|
356
|
+
}
|
|
357
|
+
const isCryptoName = (_b = (_a = author === null || author === void 0 ? void 0 : author.address) === null || _a === void 0 ? void 0 : _a.includes) === null || _b === void 0 ? void 0 : _b.call(_a, ".");
|
|
358
|
+
const resolveAuthorAddressNoCache = () => {
|
|
359
|
+
if (Boolean(resolveAuthorAddressPromises[author === null || author === void 0 ? void 0 : author.address])) {
|
|
360
|
+
return resolveAuthorAddressPromises[author === null || author === void 0 ? void 0 : author.address];
|
|
361
|
+
}
|
|
362
|
+
log("useResolvedAuthorAddress protocol.resolveAuthorName", { address: author === null || author === void 0 ? void 0 : author.address });
|
|
363
|
+
return cacheResolveAuthorAddressPromise(author === null || author === void 0 ? void 0 : author.address, resolveAuthorNameWithProtocol(protocolClient, {
|
|
364
|
+
address: author === null || author === void 0 ? void 0 : author.address,
|
|
365
|
+
}));
|
|
366
|
+
};
|
|
367
|
+
const resolveAuthorAddress = () => __awaiter(this, void 0, void 0, function* () {
|
|
368
|
+
const cached = resolvedAuthorAddressCache.get(author === null || author === void 0 ? void 0 : author.address);
|
|
369
|
+
if (cached) {
|
|
370
|
+
return cached;
|
|
371
|
+
}
|
|
372
|
+
const res = yield resolveAuthorAddressNoCache();
|
|
373
|
+
resolvedAuthorAddressCache.set(author === null || author === void 0 ? void 0 : author.address, res);
|
|
374
|
+
return res;
|
|
375
|
+
});
|
|
376
|
+
useEffect(() => {
|
|
377
|
+
if (!protocolClient || !(author === null || author === void 0 ? void 0 : author.address)) {
|
|
378
|
+
setActiveNameResolverKey(undefined);
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
const nameResolverClients = getProtocolNameResolverClients(protocolClient);
|
|
382
|
+
const entries = Object.entries(nameResolverClients);
|
|
383
|
+
if (!entries.length) {
|
|
384
|
+
setActiveNameResolverKey(undefined);
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
const syncFromCurrentClients = () => {
|
|
388
|
+
var _a;
|
|
389
|
+
const nextActiveKey = (_a = entries.find(([, client]) => (client === null || client === void 0 ? void 0 : client.state) && client.state !== "stopped")) === null || _a === void 0 ? void 0 : _a[0];
|
|
390
|
+
if (nextActiveKey) {
|
|
391
|
+
setActiveNameResolverKey(nextActiveKey);
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
syncFromCurrentClients();
|
|
395
|
+
const disposers = entries.map(([resolverKey, client]) => {
|
|
396
|
+
if (typeof (client === null || client === void 0 ? void 0 : client.on) !== "function") {
|
|
397
|
+
return undefined;
|
|
398
|
+
}
|
|
399
|
+
const onStateChange = (resolverState) => {
|
|
400
|
+
setActiveNameResolverKey((previousResolverKey) => {
|
|
401
|
+
var _a;
|
|
402
|
+
if (resolverState !== "stopped") {
|
|
403
|
+
return resolverKey;
|
|
404
|
+
}
|
|
405
|
+
if (previousResolverKey !== resolverKey) {
|
|
406
|
+
return previousResolverKey;
|
|
407
|
+
}
|
|
408
|
+
return (((_a = entries.find(([candidateResolverKey, candidateClient]) => candidateResolverKey !== resolverKey &&
|
|
409
|
+
(candidateClient === null || candidateClient === void 0 ? void 0 : candidateClient.state) &&
|
|
410
|
+
candidateClient.state !== "stopped")) === null || _a === void 0 ? void 0 : _a[0]) || previousResolverKey);
|
|
411
|
+
});
|
|
412
|
+
};
|
|
413
|
+
client.on("statechange", onStateChange);
|
|
414
|
+
return () => removeStateChangeListener(client, onStateChange);
|
|
415
|
+
});
|
|
416
|
+
return () => {
|
|
417
|
+
for (const dispose of disposers) {
|
|
418
|
+
dispose === null || dispose === void 0 ? void 0 : dispose();
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
}, [author === null || author === void 0 ? void 0 : author.address, protocolClient]);
|
|
422
|
+
useInterval(() => {
|
|
423
|
+
// no options, do nothing or reset
|
|
424
|
+
if (!account || !(author === null || author === void 0 ? void 0 : author.address)) {
|
|
425
|
+
if (resolvedAddress !== undefined) {
|
|
426
|
+
setResolvedAddress(undefined);
|
|
427
|
+
}
|
|
428
|
+
if (state !== undefined) {
|
|
429
|
+
setState(undefined);
|
|
430
|
+
}
|
|
431
|
+
if (errors.length) {
|
|
432
|
+
setErrors([]);
|
|
433
|
+
}
|
|
434
|
+
if (activeNameResolverKey !== undefined) {
|
|
435
|
+
setActiveNameResolverKey(undefined);
|
|
436
|
+
}
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
// address isn't a crypto domain, can't be resolved
|
|
440
|
+
if (!isCryptoName) {
|
|
441
|
+
if (state !== "failed") {
|
|
442
|
+
setErrors([Error("not a crypto domain")]);
|
|
443
|
+
setState("failed");
|
|
444
|
+
setResolvedAddress(undefined);
|
|
445
|
+
setActiveNameResolverKey(undefined);
|
|
446
|
+
}
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
if (!configuredNameResolvers.length) {
|
|
450
|
+
if (state !== "failed") {
|
|
451
|
+
setErrors([Error("crypto domain type unsupported")]);
|
|
452
|
+
setState("failed");
|
|
453
|
+
setResolvedAddress(undefined);
|
|
454
|
+
setActiveNameResolverKey(undefined);
|
|
455
|
+
}
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
(() => __awaiter(this, void 0, void 0, function* () {
|
|
459
|
+
try {
|
|
460
|
+
setActiveNameResolverKey((previousResolverKey) => { var _a; return previousResolverKey || ((_a = configuredNameResolvers[0]) === null || _a === void 0 ? void 0 : _a.key); });
|
|
461
|
+
setState("resolving");
|
|
462
|
+
let res;
|
|
463
|
+
if (cache) {
|
|
464
|
+
res = yield resolveAuthorAddress();
|
|
465
|
+
}
|
|
466
|
+
else {
|
|
467
|
+
res = yield resolveAuthorAddressNoCache();
|
|
468
|
+
}
|
|
469
|
+
setState("succeeded");
|
|
470
|
+
// TODO: check if resolved address is the same as author.signer.publicKey
|
|
471
|
+
if (res !== resolvedAddress) {
|
|
472
|
+
setResolvedAddress(res);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
catch (error) {
|
|
476
|
+
setErrors((previousErrors) => [...previousErrors, error]);
|
|
477
|
+
setState("failed");
|
|
478
|
+
setResolvedAddress(undefined);
|
|
479
|
+
log.error("useResolvedAuthorAddress resolveAuthorAddress error", {
|
|
480
|
+
author,
|
|
481
|
+
chainProviders,
|
|
482
|
+
error,
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
}))();
|
|
486
|
+
}, interval, true, [author === null || author === void 0 ? void 0 : author.address, configuredNameResolvers, protocolClient]);
|
|
487
|
+
const nameResolver = (activeNameResolverKey && configuredNameResolversByKey[activeNameResolverKey]) ||
|
|
488
|
+
configuredNameResolvers[0];
|
|
489
|
+
const chainProvider = (nameResolver === null || nameResolver === void 0 ? void 0 : nameResolver.chainTicker)
|
|
490
|
+
? chainProviders === null || chainProviders === void 0 ? void 0 : chainProviders[nameResolver.chainTicker]
|
|
491
|
+
: undefined;
|
|
492
|
+
log("useResolvedAuthorAddress", {
|
|
493
|
+
author,
|
|
494
|
+
state,
|
|
495
|
+
errors,
|
|
496
|
+
resolvedAddress,
|
|
497
|
+
chainProviders,
|
|
498
|
+
nameResolver,
|
|
499
|
+
});
|
|
500
|
+
return useMemo(() => ({
|
|
501
|
+
resolvedAddress,
|
|
502
|
+
chainProvider,
|
|
503
|
+
nameResolver,
|
|
504
|
+
state: state || initialState,
|
|
505
|
+
error: errors[errors.length - 1],
|
|
506
|
+
errors,
|
|
507
|
+
}), [resolvedAddress, chainProvider, nameResolver, state, errors]);
|
|
508
|
+
}
|
|
509
|
+
//# sourceMappingURL=authors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authors.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MAAM,GAAG,CAAC,CAAC;QAChC,MAAM;KACP,CAAC,EACF,CAAC,eAAe,EAAE,aAAa,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,CAAC,CAC9D,CAAC;AACJ,CAAC","sourcesContent":["import { useEffect, useState, useMemo } from \"react\";\nimport useInterval from \"../utils/use-interval\";\nimport { useAccount } from \"../accounts\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:authors:hooks\");\nimport assert from \"assert\";\nimport {\n ChainProviders,\n Author,\n UseAuthorOptions,\n UseAuthorResult,\n UseAuthorCommentsOptions,\n UseAuthorCommentsResult,\n UseAuthorAvatarOptions,\n UseAuthorAvatarResult,\n UseResolvedAuthorAddressOptions,\n UseResolvedAuthorAddressResult,\n UseAuthorAddressOptions,\n UseAuthorAddressResult,\n} from \"../../types\";\nimport {\n useNftMetadataUrl,\n useNftImageUrl,\n useVerifiedAuthorAvatarSignature,\n useAuthorAvatarIsWhitelisted,\n} from \"./author-avatars\";\nimport { useComment, useComments } from \"../comments\";\nimport { useAuthorCommentsName, usePkcAddress } from \"./utils\";\nimport useAuthorsCommentsStore from \"../../stores/authors-comments\";\nimport PkcJs from \"../../lib/pkc-js\";\nimport {\n getConfiguredNameResolverInfoByKey,\n getChainProviders,\n getMatchingNameResolvers,\n getProtocolClient,\n getProtocolNameResolverClients,\n resolveAuthorNameWithProtocol,\n} from \"../../lib/pkc-compat\";\nimport QuickLRU from \"quick-lru\";\nexport { setAuthorAvatarsWhitelistedTokenAddresses } from \"./author-avatars\";\n\nconst cacheResolveAuthorAddressPromise = (\n address: string,\n promise: Promise<string>,\n): Promise<string> => {\n resolveAuthorAddressPromises[address] = promise;\n const clearCachedPromise = () => {\n if (resolveAuthorAddressPromises[address] === promise) {\n delete resolveAuthorAddressPromises[address];\n }\n };\n void promise.then(clearCachedPromise, clearCachedPromise);\n return promise;\n};\n\nconst removeStateChangeListener = (client: any, listener: (state: string) => void) => {\n if (typeof client?.off === \"function\") {\n client.off(\"statechange\", listener);\n return;\n }\n client?.removeListener?.(\"statechange\", listener);\n};\n\n/**\n * @param authorAddress - The address of the author\n * @param commentCid - The last known comment cid of the author (not possible to get an author without providing at least 1 comment cid)\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 useAuthorComments(options?: UseAuthorCommentsOptions): UseAuthorCommentsResult {\n assert(\n !options || typeof options === \"object\",\n `useAuthorComments options argument '${options}' not an object`,\n );\n const { authorAddress, commentCid, accountName, filter } = options || {};\n const account = useAccount({ accountName });\n const authorCommentsName = useAuthorCommentsName(account?.id, authorAddress, filter);\n const incrementPageNumber = useAuthorsCommentsStore((state) => state.incrementPageNumber);\n const addAuthorCommentsToStore = useAuthorsCommentsStore(\n (state) => state.addAuthorCommentsToStore,\n );\n const hasMoreBufferedComments = useAuthorsCommentsStore(\n (state) => state.hasMoreBufferedComments[authorCommentsName || \"\"],\n );\n const hasNextCommentCidToFetch = useAuthorsCommentsStore((state) =>\n Boolean(state.nextCommentCidsToFetch[authorAddress || \"\"]),\n );\n const authorComments = useAuthorsCommentsStore(\n (state) => state.loadedComments[authorCommentsName || \"\"],\n );\n const lastCommentCid = useAuthorsCommentsStore(\n (state) => state.lastCommentCids[authorAddress || \"\"],\n );\n\n // add authors comments to store\n useEffect(() => {\n if (!authorAddress || !commentCid || !account) {\n return;\n }\n try {\n addAuthorCommentsToStore(authorCommentsName, authorAddress, commentCid, filter, account);\n } catch (error: any) {\n log.error(\"useAuthorComments addAuthorCommentsToStore error\", { authorCommentsName, error });\n }\n }, [authorCommentsName, commentCid]);\n\n const loadMore = async () => {\n try {\n if (!authorAddress || !account) {\n throw Error(\"useAuthorComments cannot load more authorComments not initalized yet\");\n }\n incrementPageNumber(authorCommentsName);\n } catch (e: any) {\n // wait 100 ms so infinite scroll doesn't spam this function\n await new Promise((r) => setTimeout(r, 50));\n // TODO: maybe add these errors to errors array\n }\n };\n\n const hasMore = hasMoreBufferedComments || hasNextCommentCidToFetch;\n\n const authorResult = useAuthor({ commentCid, authorAddress, accountName });\n const state = authorResult.state;\n const errors = authorResult.errors;\n\n if (authorResult.author) {\n log(\"useAuthorComments\", {\n authorAddress,\n commentCid,\n // authorComments,\n authorCommentsSize: authorComments?.length || 0,\n lastCommentCid,\n hasMoreBufferedComments,\n hasNextCommentCidToFetch,\n hasMore,\n state,\n errors,\n authorResult,\n accountName,\n });\n }\n\n return useMemo(\n () => ({\n authorComments: authorComments || [],\n lastCommentCid,\n hasMore,\n loadMore,\n state,\n error: errors[errors.length - 1],\n errors,\n }),\n [authorComments, lastCommentCid, hasMore, errors, state],\n );\n}\n\n/**\n * @param authorAddress - The address of the author\n * @param commentCid - The last known comment cid of the author (not possible to get an author without providing at least 1 comment cid)\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 useAuthor(options?: UseAuthorOptions): UseAuthorResult {\n assert(\n !options || typeof options === \"object\",\n `useAuthor options argument '${options}' not an object`,\n );\n const { authorAddress, commentCid, accountName } = options || {};\n const comment = useComment({ commentCid, accountName });\n\n // the commentCid doesnt have the same author address as authorAddress\n const useAuthorError = useMemo(() => {\n // if comment is loaded and author address is different from authorAddress\n if (comment?.timestamp && authorAddress && comment?.author?.address !== authorAddress) {\n return Error(\"commentCid author.address is different from authorAddress\");\n }\n if (commentCid && !authorAddress) {\n return Error(\"missing UseAuthorOptions.authorAddress\");\n }\n if (!commentCid && authorAddress) {\n return Error(\"missing UseAuthorOptions.commentCid\");\n }\n }, [commentCid, comment?.timestamp, comment?.author?.address, authorAddress]);\n\n // if has author error, don't return the autor\n let author: Author | undefined;\n if (!useAuthorError) {\n author = comment?.author;\n }\n\n // merge comment.errors with useAuthorError\n const errors = useMemo(() => {\n if (useAuthorError) {\n return [...comment.errors, useAuthorError];\n }\n return comment.errors;\n }, [comment.errors, useAuthorError]);\n\n // if has author error, state failed\n let state = author ? \"succeeded\" : comment?.state || \"initializing\";\n if (useAuthorError) {\n state = \"failed\";\n }\n\n if (comment?.timestamp) {\n log(\"useAuthor\", {\n authorAddress,\n commentCid,\n author,\n comment,\n useAuthorError,\n state,\n accountName,\n });\n }\n\n return useMemo(\n () => ({\n author,\n state,\n error: errors[errors.length - 1],\n errors,\n }),\n [author, errors, state],\n );\n}\n\n/**\n * @param author - The Author object to resolve the avatar image URL of.\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: useAuthorAvatar tests are skipped, if changes are made they must be tested manually\nexport function useAuthorAvatar(options?: UseAuthorAvatarOptions): UseAuthorAvatarResult {\n assert(\n !options || typeof options === \"object\",\n `useAuthorAvatar options argument '${options}' not an object`,\n );\n const { author, accountName } = options || {};\n const account = useAccount({ accountName });\n\n // TODO: resolve crypto domain and check if one of the record is a profile pic\n\n const { verified, error: signatureError } = useVerifiedAuthorAvatarSignature(author, accountName);\n const verifiedError = verified === false && Error(`nft ownership signature proof invalid`);\n const isWhitelisted = useAuthorAvatarIsWhitelisted(author?.avatar);\n const whitelistedError =\n isWhitelisted === false && Error(`nft collection '${author?.avatar?.address}' not whitelisted`);\n // don't try to get avatar image url at all if signature isn't verified and whitelisted\n const avatar = verified && isWhitelisted ? author?.avatar : undefined;\n const { metadataUrl, error: nftMetadataError } = useNftMetadataUrl(avatar, accountName);\n const { imageUrl, error: nftImageUrlError } = useNftImageUrl(metadataUrl, accountName);\n const chainProvider = getChainProviders(account)?.[avatar?.chainTicker];\n\n const error =\n whitelistedError ||\n verifiedError ||\n signatureError ||\n nftMetadataError ||\n nftImageUrlError ||\n undefined;\n const errors = useMemo(() => (error ? [error] : []), [error]);\n\n let state = \"initializing\";\n if (!author?.avatar) {\n // do nothing, is initializing\n } else if (error) {\n state = \"failed\";\n } else if (imageUrl !== undefined) {\n state = \"succeeded\";\n } else if (metadataUrl !== undefined) {\n state = \"fetching-metadata\";\n } else if (verified !== undefined) {\n state = \"fetching-uri\";\n } else if (author?.avatar) {\n state = \"fetching-owner\";\n }\n\n if (author?.avatar) {\n log(\"useAuthorAvatar\", { author, state, verified, isWhitelisted, metadataUrl, imageUrl });\n }\n\n return useMemo(\n () => ({\n imageUrl,\n metadataUrl,\n chainProvider,\n state,\n error,\n errors,\n }),\n [imageUrl, metadataUrl, chainProvider, state, error],\n );\n}\n\n/**\n * @param author - The Author object to resolve the address of.\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 useAuthorAddress(options?: UseAuthorAddressOptions): UseAuthorAddressResult {\n assert(\n !options || typeof options === \"object\",\n `useAuthorAddress options argument '${options}' not an object`,\n );\n const { comment, accountName } = options || {};\n const account = useAccount({ accountName });\n const protocolClient = getProtocolClient(account);\n const isCryptoName = !!comment?.author?.address?.includes?.(\".\");\n const [resolvedAddress, setResolvedAddress] = useState<string | undefined>(\n isCryptoName ? resolvedAuthorAddressCache.get(comment?.author?.address) : undefined,\n );\n const signerAddress = usePkcAddress(isCryptoName ? comment?.signature?.publicKey : undefined);\n\n // useful for triggering css animation when the address changes from unverified to verified\n const [authorAddressChanged, setAuthorAddressChanged] = useState(false);\n\n useEffect(() => {\n if (!protocolClient || !comment?.author?.address || !isCryptoName) {\n return;\n }\n const addr = comment?.author?.address;\n const resolveAuthorAddressNoCache = () => {\n const existing = resolveAuthorAddressPromises[addr];\n if (existing) return existing;\n log(\"useAuthorAddress protocol.resolveAuthorName\", { address: addr });\n return cacheResolveAuthorAddressPromise(\n addr,\n resolveAuthorNameWithProtocol(protocolClient, { address: addr }),\n );\n };\n const resolveAuthorAddress = async () => {\n const cached = resolvedAuthorAddressCache.get(addr);\n if (cached) return cached;\n const res = await resolveAuthorAddressNoCache();\n resolvedAuthorAddressCache.set(addr, res);\n return res;\n };\n resolveAuthorAddress()\n .then((_resolvedAddress: string) => {\n if (_resolvedAddress !== resolvedAddress) {\n setResolvedAddress(_resolvedAddress);\n setAuthorAddressChanged(true);\n }\n })\n .catch((error: any) => log.error(\"useAuthorAddress error\", { error, comment }));\n }, [protocolClient, comment?.author?.address, isCryptoName]);\n\n // use signer address by default\n let authorAddress = signerAddress;\n // if author address was resolved successfully, use author address\n if (resolvedAddress && signerAddress === resolvedAddress) {\n authorAddress = comment?.author?.address;\n }\n // if isn't crypto name, always use author address\n if (!isCryptoName) {\n authorAddress = comment?.author?.address;\n }\n // if comment has no signature, it's a pending account comment, no need to verify it\n // TODO: eventually account comments will have a signature immediately\n if (comment && !comment?.signature) {\n authorAddress = comment?.author?.address;\n }\n\n let shortAuthorAddress = authorAddress && PkcJs.PKC.getShortAddress({ address: authorAddress });\n\n // if shortAddress is smaller than crypto name, give a longer\n // shortAddress to cause the least UI displacement as possible\n // -4 chars because most fonts will make the address larger\n if (\n isCryptoName &&\n authorAddress &&\n shortAuthorAddress.length < comment?.author?.address?.length - 4\n ) {\n const restOfAuthorAddress = authorAddress.split(shortAuthorAddress).pop();\n shortAuthorAddress = (shortAuthorAddress + restOfAuthorAddress).substring(\n 0,\n comment?.author?.address?.length - 4,\n );\n }\n\n return useMemo(\n () => ({\n authorAddress,\n shortAuthorAddress,\n authorAddressChanged,\n state: \"initializing\",\n error: undefined,\n errors: [],\n }),\n [authorAddress, shortAuthorAddress],\n );\n}\n// TODO: figure out how to upgrade to quick-lru 6+ to use maxAge\nconst resolvedAuthorAddressCache = new QuickLRU<string, string>({ maxSize: 1000 });\nconst resolveAuthorAddressPromises: { [address: string]: Promise<string> } = {};\n\n/** For tests: reset caches to make resolution paths deterministic. */\nexport function resetAuthorAddressCacheForTesting() {\n resolvedAuthorAddressCache.clear();\n for (const k of Object.keys(resolveAuthorAddressPromises)) {\n delete resolveAuthorAddressPromises[k];\n }\n}\n\n/**\n * @param author - The author with author.address to resolve to a public key, e.g. 'john.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: useResolvedAuthorAddress tests are skipped, if changes are made they must be tested manually\nexport function useResolvedAuthorAddress(\n options?: UseResolvedAuthorAddressOptions,\n): UseResolvedAuthorAddressResult {\n assert(\n !options || typeof options === \"object\",\n `useResolvedAuthorAddress options argument '${options}' not an object`,\n );\n let { author, 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 protocolClient = getProtocolClient(account);\n const chainProviders = getChainProviders(account);\n const configuredNameResolvers = useMemo(\n () => getMatchingNameResolvers(account, author?.address),\n [account, author?.address],\n );\n const configuredNameResolversByKey = useMemo(\n () => getConfiguredNameResolverInfoByKey(account),\n [account],\n );\n const [resolvedAddress, setResolvedAddress] = useState<string>();\n const [errors, setErrors] = useState<Error[]>([]);\n const [state, setState] = useState<string>();\n const [activeNameResolverKey, setActiveNameResolverKey] = useState<string>();\n\n let initialState = \"initializing\";\n // before those defined, nothing can happen\n if (options && account && author?.address) {\n initialState = \"ready\";\n }\n\n const isCryptoName = author?.address?.includes?.(\".\");\n\n const resolveAuthorAddressNoCache = () => {\n if (Boolean(resolveAuthorAddressPromises[author?.address])) {\n return resolveAuthorAddressPromises[author?.address];\n }\n log(\"useResolvedAuthorAddress protocol.resolveAuthorName\", { address: author?.address });\n return cacheResolveAuthorAddressPromise(\n author?.address,\n resolveAuthorNameWithProtocol(protocolClient, {\n address: author?.address,\n }),\n );\n };\n const resolveAuthorAddress = async () => {\n const cached = resolvedAuthorAddressCache.get(author?.address);\n if (cached) {\n return cached;\n }\n const res = await resolveAuthorAddressNoCache();\n resolvedAuthorAddressCache.set(author?.address, res);\n return res;\n };\n\n useEffect(() => {\n if (!protocolClient || !author?.address) {\n setActiveNameResolverKey(undefined);\n return;\n }\n\n const nameResolverClients = getProtocolNameResolverClients(protocolClient);\n const entries = Object.entries(nameResolverClients);\n if (!entries.length) {\n setActiveNameResolverKey(undefined);\n return;\n }\n\n const syncFromCurrentClients = () => {\n const nextActiveKey = entries.find(\n ([, client]: [string, any]) => client?.state && client.state !== \"stopped\",\n )?.[0];\n if (nextActiveKey) {\n setActiveNameResolverKey(nextActiveKey);\n }\n };\n\n syncFromCurrentClients();\n\n const disposers = entries.map(([resolverKey, client]: [string, any]) => {\n if (typeof client?.on !== \"function\") {\n return undefined;\n }\n\n const onStateChange = (resolverState: string) => {\n setActiveNameResolverKey((previousResolverKey) => {\n if (resolverState !== \"stopped\") {\n return resolverKey;\n }\n if (previousResolverKey !== resolverKey) {\n return previousResolverKey;\n }\n return (\n entries.find(\n ([candidateResolverKey, candidateClient]: [string, any]) =>\n candidateResolverKey !== resolverKey &&\n candidateClient?.state &&\n candidateClient.state !== \"stopped\",\n )?.[0] || previousResolverKey\n );\n });\n };\n\n client.on(\"statechange\", onStateChange);\n return () => removeStateChangeListener(client, onStateChange);\n });\n\n return () => {\n for (const dispose of disposers) {\n dispose?.();\n }\n };\n }, [author?.address, protocolClient]);\n\n useInterval(\n () => {\n // no options, do nothing or reset\n if (!account || !author?.address) {\n if (resolvedAddress !== undefined) {\n setResolvedAddress(undefined);\n }\n if (state !== undefined) {\n setState(undefined);\n }\n if (errors.length) {\n setErrors([]);\n }\n if (activeNameResolverKey !== undefined) {\n setActiveNameResolverKey(undefined);\n }\n return;\n }\n\n // address isn't a crypto domain, can't be resolved\n if (!isCryptoName) {\n if (state !== \"failed\") {\n setErrors([Error(\"not a crypto domain\")]);\n setState(\"failed\");\n setResolvedAddress(undefined);\n setActiveNameResolverKey(undefined);\n }\n return;\n }\n\n if (!configuredNameResolvers.length) {\n if (state !== \"failed\") {\n setErrors([Error(\"crypto domain type unsupported\")]);\n setState(\"failed\");\n setResolvedAddress(undefined);\n setActiveNameResolverKey(undefined);\n }\n return;\n }\n\n (async () => {\n try {\n setActiveNameResolverKey(\n (previousResolverKey) => previousResolverKey || configuredNameResolvers[0]?.key,\n );\n setState(\"resolving\");\n let res;\n if (cache) {\n res = await resolveAuthorAddress();\n } else {\n res = await resolveAuthorAddressNoCache();\n }\n setState(\"succeeded\");\n\n // TODO: check if resolved address is the same as author.signer.publicKey\n\n if (res !== resolvedAddress) {\n setResolvedAddress(res);\n }\n } catch (error: any) {\n setErrors((previousErrors) => [...previousErrors, error]);\n setState(\"failed\");\n setResolvedAddress(undefined);\n log.error(\"useResolvedAuthorAddress resolveAuthorAddress error\", {\n author,\n chainProviders,\n error,\n });\n }\n })();\n },\n interval,\n true,\n [author?.address, configuredNameResolvers, protocolClient],\n );\n\n const nameResolver =\n (activeNameResolverKey && configuredNameResolversByKey[activeNameResolverKey]) ||\n configuredNameResolvers[0];\n const chainProvider = nameResolver?.chainTicker\n ? chainProviders?.[nameResolver.chainTicker]\n : undefined;\n\n log(\"useResolvedAuthorAddress\", {\n author,\n state,\n errors,\n resolvedAddress,\n chainProviders,\n nameResolver,\n });\n\n return useMemo(\n () => ({\n resolvedAddress,\n chainProvider,\n nameResolver,\n state: state || initialState,\n error: errors[errors.length - 1],\n errors,\n }),\n [resolvedAddress, chainProvider, nameResolver, state, errors],\n );\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/authors/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/authors/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC","sourcesContent":["export * from \"./authors\";\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CommentsFilter } from "../../types.js";
|
|
2
|
+
export declare const useAuthorCommentsName: (accountId?: string, authorAddress?: string, filter?: CommentsFilter | undefined) => string;
|
|
3
|
+
export declare const usePkcAddress: (publicKeyBase64?: string) => string | undefined;
|
|
4
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/hooks/authors/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAW,cAAc,EAAE,MAAM,aAAa,CAAC;AAStD,eAAO,MAAM,qBAAqB,GAChC,YAAY,MAAM,EAClB,gBAAgB,MAAM,EACtB,SAAS,cAAc,GAAG,SAAS,WAMpC,CAAC;AAeF,eAAO,MAAM,aAAa,GAAI,kBAAkB,MAAM,uBAKrD,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { fromString as uint8ArrayFromString } from "uint8arrays/from-string";
|
|
3
|
+
import { toString as uint8ArrayToString } from "uint8arrays/to-string";
|
|
4
|
+
import { create as createMultihash } from "multiformats/hashes/digest";
|
|
5
|
+
export const useAuthorCommentsName = (accountId, authorAddress, filter) => {
|
|
6
|
+
return useMemo(() => accountId + "-" + authorAddress + "-" + (filter === null || filter === void 0 ? void 0 : filter.key), [accountId, authorAddress, filter === null || filter === void 0 ? void 0 : filter.key]);
|
|
7
|
+
};
|
|
8
|
+
const protobufPublicKeyPrefix = new Uint8Array([8, 1, 18, 32]);
|
|
9
|
+
const multihashIdentityCode = 0;
|
|
10
|
+
const getPkcAddressFromPublicKey = (publicKeyBase64) => {
|
|
11
|
+
const publicKeyBuffer = uint8ArrayFromString(publicKeyBase64, "base64");
|
|
12
|
+
const publicKeyBufferWithPrefix = new Uint8Array(protobufPublicKeyPrefix.length + publicKeyBuffer.length);
|
|
13
|
+
publicKeyBufferWithPrefix.set(protobufPublicKeyPrefix, 0);
|
|
14
|
+
publicKeyBufferWithPrefix.set(publicKeyBuffer, protobufPublicKeyPrefix.length);
|
|
15
|
+
const multihash = createMultihash(multihashIdentityCode, publicKeyBufferWithPrefix).bytes;
|
|
16
|
+
return uint8ArrayToString(multihash, "base58btc");
|
|
17
|
+
};
|
|
18
|
+
export const usePkcAddress = (publicKeyBase64) => {
|
|
19
|
+
return useMemo(() => (publicKeyBase64 ? getPkcAddressFromPublicKey(publicKeyBase64) : undefined), [publicKeyBase64]);
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=utils.js.map
|