@bitsocial/bitsocial-react-hooks 0.1.34 → 0.1.36

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 (33) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +19 -14
  3. package/dist/hooks/accounts/accounts.d.ts +4 -4
  4. package/dist/hooks/accounts/accounts.js +4 -4
  5. package/dist/hooks/accounts/accounts.js.map +1 -1
  6. package/dist/hooks/authors/author-avatars.d.ts +2 -2
  7. package/dist/hooks/authors/author-avatars.js +2 -2
  8. package/dist/hooks/authors/author-avatars.js.map +1 -1
  9. package/dist/hooks/authors/authors.d.ts +5 -5
  10. package/dist/hooks/authors/authors.js +5 -5
  11. package/dist/hooks/authors/authors.js.map +1 -1
  12. package/dist/hooks/comments.d.ts +2 -2
  13. package/dist/hooks/comments.js +2 -2
  14. package/dist/hooks/comments.js.map +1 -1
  15. package/dist/hooks/communities.d.ts +4 -4
  16. package/dist/hooks/communities.js +4 -4
  17. package/dist/hooks/communities.js.map +1 -1
  18. package/dist/hooks/feeds/feeds.d.ts +2 -2
  19. package/dist/hooks/feeds/feeds.js +2 -2
  20. package/dist/hooks/feeds/feeds.js.map +1 -1
  21. package/dist/hooks/pkc-rpc.d.ts +1 -1
  22. package/dist/hooks/pkc-rpc.js +1 -1
  23. package/dist/hooks/pkc-rpc.js.map +1 -1
  24. package/dist/hooks/states.d.ts +2 -2
  25. package/dist/hooks/states.js +2 -2
  26. package/dist/hooks/states.js.map +1 -1
  27. package/dist/stores/accounts/account-generator.d.ts.map +1 -1
  28. package/dist/stores/accounts/account-generator.js +12 -14
  29. package/dist/stores/accounts/account-generator.js.map +1 -1
  30. package/dist/stores/accounts/accounts-actions.d.ts.map +1 -1
  31. package/dist/stores/accounts/accounts-actions.js +6 -3
  32. package/dist/stores/accounts/accounts-actions.js.map +1 -1
  33. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"author-avatars.js","sourceRoot":"","sources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AAG,CAAE,WAAW,EAChB,MAAA,MAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAG,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,WAAW,CAAC,0CAAE,IAAI,0CAAG,CAAC,CAAC,EAC7C,MAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAG,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,WAAW,CAAC,0CAAE,OAAO,CAC5C,CAAC;IAEF,MAAM,yBAAyB,GAAG,mBAAmB,CACnD,aAAa,EACb,GAAG,CAAC,SAAS,EACb,GAAG,CAAC,OAAO,EACX,GAAG,CAAC,EAAE,CACP,CAAC;IACF,MAAM,gBAAgB,GAAG,MAAM,CAAC,KAAK,CAAC,aAAa,CACjD,yBAAyB,EACzB,GAAG,CAAC,SAAS,CAAC,SAAS,CACxB,CAAC;IAEF,IAAI,QAAQ,GAAG,IAAI,CAAC;IACpB,IAAI,sBAAsB,KAAK,gBAAgB,EAAE,CAAC;QAChD,QAAQ,GAAG,KAAK,CAAC;IACnB,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAA,CAAC","sourcesContent":["import { useEffect, useState, useMemo } from \"react\";\nimport { useAccount } from \"../accounts\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:authors:hooks\");\nimport assert from \"assert\";\nimport { Nft, ChainProviders, Author } from \"../../types\";\nimport { ethers } from \"ethers\";\nimport { getNftMetadataUrl, getNftImageUrl, getNftOwner } from \"../../lib/chain\";\nimport { getChainProviders } from \"../../lib/pkc-compat\";\nimport createStore from \"zustand\";\n\nconst noMediaIpfsGatewayUrl = \"http://no-media-ipfs-gateway-url\";\n\n/**\n * @param nft - The NFT object to resolve the 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: useNftMetadataUrl tests are skipped, if changes are made they must be tested manually\nexport function useNftMetadataUrl(nft?: Nft, accountName?: string) {\n const account = useAccount({ accountName });\n const ipfsGatewayUrl = account?.mediaIpfsGatewayUrl || noMediaIpfsGatewayUrl;\n const chainProviders = getChainProviders(account);\n const [nftMetadataUrl, setNftMetadataUrl] = useState();\n const [error, setError] = useState<Error | undefined>();\n\n const getNftMetadataUrlArgs = [\n nft?.address,\n nft?.id,\n nft?.chainTicker,\n chainProviders?.[nft?.chainTicker]?.urls?.[0],\n chainProviders?.[nft?.chainTicker]?.chainId,\n ipfsGatewayUrl,\n ];\n\n useEffect(() => {\n // reset\n setError(undefined);\n setNftMetadataUrl(undefined);\n\n if (!account || !nft) {\n return;\n }\n\n (async () => {\n try {\n const url = await getNftMetadataUrl(...getNftMetadataUrlArgs);\n setNftMetadataUrl(url);\n } catch (error: any) {\n setError(error);\n log.error(\"useNftMetadataUrl getNftMetadataUrl error\", {\n nft,\n ipfsGatewayUrl,\n chainProviders,\n error,\n });\n }\n })();\n }, getNftMetadataUrlArgs);\n\n // log('useNftMetadataUrl', {nft, ipfsGatewayUrl, nftMetadataUrl, chainProviders})\n return { metadataUrl: nftMetadataUrl, error };\n}\n\n/**\n * @param nftMetadataUrl - The NFT URL to resolve the 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: useNftImageUrl tests are skipped, if changes are made they must be tested manually\nexport function useNftImageUrl(nftMetadataUrl?: string, accountName?: string) {\n assert(\n !nftMetadataUrl || typeof nftMetadataUrl === \"string\",\n `useNftImageUrl invalid argument nftMetadataUrl '${nftMetadataUrl}' not a string`,\n );\n const account = useAccount({ accountName });\n const ipfsGatewayUrl = account?.mediaIpfsGatewayUrl || noMediaIpfsGatewayUrl;\n const [imageUrl, setImageUrl] = useState();\n const [error, setError] = useState<Error | undefined>();\n\n useEffect(() => {\n // reset\n setError(undefined);\n setImageUrl(undefined);\n\n if (!account || !nftMetadataUrl) {\n return;\n }\n\n (async () => {\n try {\n const url = await getNftImageUrl(nftMetadataUrl, ipfsGatewayUrl);\n setImageUrl(url);\n } catch (error: any) {\n setError(error);\n log.error(\"useNftImageUrl getNftImageUrl error\", { nftMetadataUrl, ipfsGatewayUrl, error });\n }\n })();\n }, [nftMetadataUrl, ipfsGatewayUrl]);\n\n // log('useNftImageUrl', {nftMetadataUrl, ipfsGatewayUrl, imageUrl})\n return { imageUrl, error };\n}\n\n// NOTE: useVerifiedAuthorAvatarSignature tests are skipped, if changes are made they must be tested manually\nexport function useVerifiedAuthorAvatarSignature(author?: Author, accountName?: string) {\n const account = useAccount({ accountName });\n const chainProviders = getChainProviders(account);\n const [verified, setVerified] = useState<boolean>();\n const [error, setError] = useState<Error | undefined>();\n\n useEffect(() => {\n // reset\n setError(undefined);\n setVerified(undefined);\n\n if (!account || !author?.avatar) {\n return;\n }\n\n (async () => {\n try {\n const res = await verifyAuthorAvatarSignature(\n author.avatar,\n author.address,\n chainProviders,\n );\n setVerified(res);\n } catch (error: any) {\n setError(error);\n log.error(\"useVerifiedAuthorAvatarSignature verifyAuthorAvatarSignature error\", {\n author,\n chainProviders,\n error,\n });\n }\n })();\n }, [author?.avatar, author?.address, chainProviders]);\n\n // don't verify nft signature when using mock content during development\n if (process.env.REACT_APP_BITSOCIAL_REACT_HOOKS_MOCK_CONTENT) {\n return { verified: true, error: undefined };\n }\n\n // log('useVerifiedAuthorAvatarSignature', {author, verified, chainProviders})\n return { verified, error };\n}\n\nconst defaultWhitelistedTokenAddresses = [\n // xpleb nfts\n \"0x890a2e81836e0e76e0f49995e6b51ca6ce6f39ed\",\n // plebsquat\n \"0x52e6cd20f5fca56da5a0e489574c92af118b8188\",\n];\n\ntype AuthorAvatarsWhitelistedTokenAddressesState = {\n authorAvatarsWhitelistedTokenAddresses: { [tokenAddress: string]: boolean };\n setAuthorAvatarsWhitelistedTokenAddresses: (tokenAddresses: string[]) => void;\n};\n\nconst useAuthorAvatarsWhitelistedTokenAddressesStore =\n createStore<AuthorAvatarsWhitelistedTokenAddressesState>(\n (setState: Function, getState: Function) => ({\n authorAvatarsWhitelistedTokenAddresses: {},\n setAuthorAvatarsWhitelistedTokenAddresses: (tokenAddresses: string[]) => {\n const authorAvatarsWhitelistedTokenAddresses: { [tokenAddress: string]: boolean } = {};\n for (const tokenAddress of tokenAddresses) {\n authorAvatarsWhitelistedTokenAddresses[tokenAddress] = true;\n // make sure lower case version exists\n authorAvatarsWhitelistedTokenAddresses[tokenAddress.toLowerCase()] = true;\n }\n setState({ authorAvatarsWhitelistedTokenAddresses });\n },\n }),\n );\nexport const setAuthorAvatarsWhitelistedTokenAddresses =\n useAuthorAvatarsWhitelistedTokenAddressesStore.getState()\n .setAuthorAvatarsWhitelistedTokenAddresses;\nsetAuthorAvatarsWhitelistedTokenAddresses(defaultWhitelistedTokenAddresses); // init default\n\nexport function useAuthorAvatarIsWhitelisted(nft?: Nft) {\n // TODO: make a list that a dao can vote it, get the list from pkc.getDefaults()\n // TODO: make community owners able to whitelist their own nfts in their communities\n // TODO: make each user able to whitelist/blacklist any nft they want for their own client\n // TODO: make hook to list which default nfts are whitelisted to display to the user\n\n const authorAvatarsWhitelistedTokenAddresses = useAuthorAvatarsWhitelistedTokenAddressesStore(\n (state: AuthorAvatarsWhitelistedTokenAddressesState) =>\n state.authorAvatarsWhitelistedTokenAddresses,\n );\n\n const isWhitelisted =\n nft?.address && Boolean(authorAvatarsWhitelistedTokenAddresses[nft?.address?.toLowerCase()]);\n return isWhitelisted;\n}\n\nexport const getNftMessageToSign = (\n authorAddress: string,\n timestamp: number,\n tokenAddress: string,\n tokenId: string,\n) => {\n // use plain JSON so the user can read what he's signing\n // property names must always be in this order for signature to match so don't use JSON.stringify\n return `{\"domainSeparator\":\"pkc-author-avatar\",\"authorAddress\":\"${authorAddress}\",\"timestamp\":${timestamp},\"tokenAddress\":\"${tokenAddress}\",\"tokenId\":\"${tokenId}\"}`;\n};\n\n// NOTE: verifyAuthorAvatarSignature tests are skipped, if changes are made they must be tested manually\nexport const verifyAuthorAvatarSignature = async (\n nft: Nft,\n authorAddress: string,\n chainProviders: ChainProviders,\n) => {\n assert(\n nft && typeof nft === \"object\",\n `verifyAuthorAvatarSignature invalid nft argument '${nft}'`,\n );\n assert(nft?.address, `verifyAuthorAvatarSignature invalid nft.address '${nft?.address}'`);\n assert(\n nft?.id && typeof nft?.id === \"string\",\n `verifyAuthorAvatarSignature invalid nft.tokenAddress '${nft?.id}' not a string`,\n );\n assert(\n typeof nft?.timestamp === \"number\",\n `verifyAuthorAvatarSignature invalid nft.timestamp '${nft?.timestamp}' not a number`,\n );\n assert(nft?.signature, `verifyAuthorAvatarSignature invalid nft.signature '${nft?.signature}'`);\n assert(\n nft?.signature?.signature,\n `verifyAuthorAvatarSignature invalid nft.signature.signature '${nft?.signature?.signature}'`,\n );\n assert(authorAddress, `verifyAuthorAvatarSignature invalid authorAddress '${authorAddress}'`);\n\n // get the owner of the nft at nft.id\n const currentNftOwnerAddress = await getNftOwner(\n nft?.address,\n nft?.id,\n nft?.chainTicker,\n chainProviders?.[nft?.chainTicker]?.urls?.[0],\n chainProviders?.[nft?.chainTicker]?.chainId,\n );\n\n const messageThatShouldBeSigned = getNftMessageToSign(\n authorAddress,\n nft.timestamp,\n nft.address,\n nft.id,\n );\n const signatureAddress = ethers.utils.verifyMessage(\n messageThatShouldBeSigned,\n nft.signature.signature,\n );\n\n let verified = true;\n if (currentNftOwnerAddress !== signatureAddress) {\n verified = false;\n }\n return verified;\n};\n"]}
1
+ {"version":3,"file":"author-avatars.js","sourceRoot":"","sources":["../../../src/hooks/authors/author-avatars.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAW,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,qCAAqC,CAAC,CAAC;AAC1D,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,MAAM,EAAE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,EACb,GAAG,CAAC,SAAS,EACb,GAAG,CAAC,OAAO,EACX,GAAG,CAAC,EAAE,CACP,CAAC;IACF,MAAM,gBAAgB,GAAG,MAAM,CAAC,KAAK,CAAC,aAAa,CACjD,yBAAyB,EACzB,GAAG,CAAC,SAAS,CAAC,SAAS,CACxB,CAAC;IAEF,IAAI,QAAQ,GAAG,IAAI,CAAC;IACpB,IAAI,sBAAsB,KAAK,gBAAgB,EAAE,CAAC;QAChD,QAAQ,GAAG,KAAK,CAAC;IACnB,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAA,CAAC","sourcesContent":["import { useEffect, useState, useMemo } from \"react\";\nimport { useAccount } from \"../accounts\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:authors:hooks\");\nimport assert from \"assert\";\nimport { Nft, ChainProviders, Author } from \"../../types\";\nimport { ethers } from \"ethers\";\nimport { getNftMetadataUrl, getNftImageUrl, getNftOwner } from \"../../lib/chain\";\nimport { getChainProviders } from \"../../lib/pkc-compat\";\nimport createStore from \"zustand\";\n\nconst noMediaIpfsGatewayUrl = \"http://no-media-ipfs-gateway-url\";\n\n/**\n * @param nft - The NFT object to resolve the URL of.\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\n// NOTE: useNftMetadataUrl tests are skipped, if changes are made they must be tested manually\nexport function useNftMetadataUrl(nft?: Nft, accountName?: string) {\n const account = useAccount({ accountName });\n const ipfsGatewayUrl = account?.mediaIpfsGatewayUrl || noMediaIpfsGatewayUrl;\n const chainProviders = getChainProviders(account);\n const [nftMetadataUrl, setNftMetadataUrl] = useState();\n const [error, setError] = useState<Error | undefined>();\n\n const getNftMetadataUrlArgs = [\n nft?.address,\n nft?.id,\n nft?.chainTicker,\n chainProviders?.[nft?.chainTicker]?.urls?.[0],\n chainProviders?.[nft?.chainTicker]?.chainId,\n ipfsGatewayUrl,\n ];\n\n useEffect(() => {\n // reset\n setError(undefined);\n setNftMetadataUrl(undefined);\n\n if (!account || !nft) {\n return;\n }\n\n (async () => {\n try {\n const url = await getNftMetadataUrl(...getNftMetadataUrlArgs);\n setNftMetadataUrl(url);\n } catch (error: any) {\n setError(error);\n log.error(\"useNftMetadataUrl getNftMetadataUrl error\", {\n nft,\n ipfsGatewayUrl,\n chainProviders,\n error,\n });\n }\n })();\n }, getNftMetadataUrlArgs);\n\n // log('useNftMetadataUrl', {nft, ipfsGatewayUrl, nftMetadataUrl, chainProviders})\n return { metadataUrl: nftMetadataUrl, error };\n}\n\n/**\n * @param nftMetadataUrl - The NFT URL to resolve the image URL of.\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\n// NOTE: useNftImageUrl tests are skipped, if changes are made they must be tested manually\nexport function useNftImageUrl(nftMetadataUrl?: string, accountName?: string) {\n assert(\n !nftMetadataUrl || typeof nftMetadataUrl === \"string\",\n `useNftImageUrl invalid argument nftMetadataUrl '${nftMetadataUrl}' not a string`,\n );\n const account = useAccount({ accountName });\n const ipfsGatewayUrl = account?.mediaIpfsGatewayUrl || noMediaIpfsGatewayUrl;\n const [imageUrl, setImageUrl] = useState();\n const [error, setError] = useState<Error | undefined>();\n\n useEffect(() => {\n // reset\n setError(undefined);\n setImageUrl(undefined);\n\n if (!account || !nftMetadataUrl) {\n return;\n }\n\n (async () => {\n try {\n const url = await getNftImageUrl(nftMetadataUrl, ipfsGatewayUrl);\n setImageUrl(url);\n } catch (error: any) {\n setError(error);\n log.error(\"useNftImageUrl getNftImageUrl error\", { nftMetadataUrl, ipfsGatewayUrl, error });\n }\n })();\n }, [nftMetadataUrl, ipfsGatewayUrl]);\n\n // log('useNftImageUrl', {nftMetadataUrl, ipfsGatewayUrl, imageUrl})\n return { imageUrl, error };\n}\n\n// NOTE: useVerifiedAuthorAvatarSignature tests are skipped, if changes are made they must be tested manually\nexport function useVerifiedAuthorAvatarSignature(author?: Author, accountName?: string) {\n const account = useAccount({ accountName });\n const chainProviders = getChainProviders(account);\n const [verified, setVerified] = useState<boolean>();\n const [error, setError] = useState<Error | undefined>();\n\n useEffect(() => {\n // reset\n setError(undefined);\n setVerified(undefined);\n\n if (!account || !author?.avatar) {\n return;\n }\n\n (async () => {\n try {\n const res = await verifyAuthorAvatarSignature(\n author.avatar,\n author.address,\n chainProviders,\n );\n setVerified(res);\n } catch (error: any) {\n setError(error);\n log.error(\"useVerifiedAuthorAvatarSignature verifyAuthorAvatarSignature error\", {\n author,\n chainProviders,\n error,\n });\n }\n })();\n }, [author?.avatar, author?.address, chainProviders]);\n\n // don't verify nft signature when using mock content during development\n if (process.env.REACT_APP_BITSOCIAL_REACT_HOOKS_MOCK_CONTENT) {\n return { verified: true, error: undefined };\n }\n\n // log('useVerifiedAuthorAvatarSignature', {author, verified, chainProviders})\n return { verified, error };\n}\n\nconst defaultWhitelistedTokenAddresses = [\n // xpleb nfts\n \"0x890a2e81836e0e76e0f49995e6b51ca6ce6f39ed\",\n // plebsquat\n \"0x52e6cd20f5fca56da5a0e489574c92af118b8188\",\n];\n\ntype AuthorAvatarsWhitelistedTokenAddressesState = {\n authorAvatarsWhitelistedTokenAddresses: { [tokenAddress: string]: boolean };\n setAuthorAvatarsWhitelistedTokenAddresses: (tokenAddresses: string[]) => void;\n};\n\nconst useAuthorAvatarsWhitelistedTokenAddressesStore =\n createStore<AuthorAvatarsWhitelistedTokenAddressesState>(\n (setState: Function, getState: Function) => ({\n authorAvatarsWhitelistedTokenAddresses: {},\n setAuthorAvatarsWhitelistedTokenAddresses: (tokenAddresses: string[]) => {\n const authorAvatarsWhitelistedTokenAddresses: { [tokenAddress: string]: boolean } = {};\n for (const tokenAddress of tokenAddresses) {\n authorAvatarsWhitelistedTokenAddresses[tokenAddress] = true;\n // make sure lower case version exists\n authorAvatarsWhitelistedTokenAddresses[tokenAddress.toLowerCase()] = true;\n }\n setState({ authorAvatarsWhitelistedTokenAddresses });\n },\n }),\n );\nexport const setAuthorAvatarsWhitelistedTokenAddresses =\n useAuthorAvatarsWhitelistedTokenAddressesStore.getState()\n .setAuthorAvatarsWhitelistedTokenAddresses;\nsetAuthorAvatarsWhitelistedTokenAddresses(defaultWhitelistedTokenAddresses); // init default\n\nexport function useAuthorAvatarIsWhitelisted(nft?: Nft) {\n // TODO: make a list that a dao can vote it, get the list from pkc.getDefaults()\n // TODO: make community owners able to whitelist their own nfts in their communities\n // TODO: make each user able to whitelist/blacklist any nft they want for their own client\n // TODO: make hook to list which default nfts are whitelisted to display to the user\n\n const authorAvatarsWhitelistedTokenAddresses = useAuthorAvatarsWhitelistedTokenAddressesStore(\n (state: AuthorAvatarsWhitelistedTokenAddressesState) =>\n state.authorAvatarsWhitelistedTokenAddresses,\n );\n\n const isWhitelisted =\n nft?.address && Boolean(authorAvatarsWhitelistedTokenAddresses[nft?.address?.toLowerCase()]);\n return isWhitelisted;\n}\n\nexport const getNftMessageToSign = (\n authorAddress: string,\n timestamp: number,\n tokenAddress: string,\n tokenId: string,\n) => {\n // use plain JSON so the user can read what he's signing\n // property names must always be in this order for signature to match so don't use JSON.stringify\n return `{\"domainSeparator\":\"pkc-author-avatar\",\"authorAddress\":\"${authorAddress}\",\"timestamp\":${timestamp},\"tokenAddress\":\"${tokenAddress}\",\"tokenId\":\"${tokenId}\"}`;\n};\n\n// NOTE: verifyAuthorAvatarSignature tests are skipped, if changes are made they must be tested manually\nexport const verifyAuthorAvatarSignature = async (\n nft: Nft,\n authorAddress: string,\n chainProviders: ChainProviders,\n) => {\n assert(\n nft && typeof nft === \"object\",\n `verifyAuthorAvatarSignature invalid nft argument '${nft}'`,\n );\n assert(nft?.address, `verifyAuthorAvatarSignature invalid nft.address '${nft?.address}'`);\n assert(\n nft?.id && typeof nft?.id === \"string\",\n `verifyAuthorAvatarSignature invalid nft.tokenAddress '${nft?.id}' not a string`,\n );\n assert(\n typeof nft?.timestamp === \"number\",\n `verifyAuthorAvatarSignature invalid nft.timestamp '${nft?.timestamp}' not a number`,\n );\n assert(nft?.signature, `verifyAuthorAvatarSignature invalid nft.signature '${nft?.signature}'`);\n assert(\n nft?.signature?.signature,\n `verifyAuthorAvatarSignature invalid nft.signature.signature '${nft?.signature?.signature}'`,\n );\n assert(authorAddress, `verifyAuthorAvatarSignature invalid authorAddress '${authorAddress}'`);\n\n // get the owner of the nft at nft.id\n const currentNftOwnerAddress = await getNftOwner(\n nft?.address,\n nft?.id,\n nft?.chainTicker,\n chainProviders?.[nft?.chainTicker]?.urls?.[0],\n chainProviders?.[nft?.chainTicker]?.chainId,\n );\n\n const messageThatShouldBeSigned = getNftMessageToSign(\n authorAddress,\n nft.timestamp,\n nft.address,\n nft.id,\n );\n const signatureAddress = ethers.utils.verifyMessage(\n messageThatShouldBeSigned,\n nft.signature.signature,\n );\n\n let verified = true;\n if (currentNftOwnerAddress !== signatureAddress) {\n verified = false;\n }\n return verified;\n};\n"]}
@@ -3,26 +3,26 @@ export { setAuthorAvatarsWhitelistedTokenAddresses } from "./author-avatars.js";
3
3
  /**
4
4
  * @param authorAddress - The address of the author
5
5
  * @param commentCid - The last known comment cid of the author (not possible to get an author without providing at least 1 comment cid)
6
- * @param acountName - The nickname of the account, e.g. 'Account 1'. If no accountName is provided, use
6
+ * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use
7
7
  * the active account.
8
8
  */
9
9
  export declare function useAuthorComments(options?: UseAuthorCommentsOptions): UseAuthorCommentsResult;
10
10
  /**
11
11
  * @param authorAddress - The address of the author
12
12
  * @param commentCid - The last known comment cid of the author (not possible to get an author without providing at least 1 comment cid)
13
- * @param acountName - The nickname of the account, e.g. 'Account 1'. If no accountName is provided, use
13
+ * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use
14
14
  * the active account.
15
15
  */
16
16
  export declare function useAuthor(options?: UseAuthorOptions): UseAuthorResult;
17
17
  /**
18
18
  * @param author - The Author object to resolve the avatar image URL of.
19
- * @param acountName - The nickname of the account, e.g. 'Account 1'. If no accountName is provided, use
19
+ * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use
20
20
  * the active account.
21
21
  */
22
22
  export declare function useAuthorAvatar(options?: UseAuthorAvatarOptions): UseAuthorAvatarResult;
23
23
  /**
24
24
  * @param author - The Author object to resolve the address of.
25
- * @param acountName - The nickname of the account, e.g. 'Account 1'. If no accountName is provided, use
25
+ * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use
26
26
  * the active account.
27
27
  */
28
28
  export declare function useAuthorAddress(options?: UseAuthorAddressOptions): UseAuthorAddressResult;
@@ -30,7 +30,7 @@ export declare function useAuthorAddress(options?: UseAuthorAddressOptions): Use
30
30
  export declare function resetAuthorAddressCacheForTesting(): void;
31
31
  /**
32
32
  * @param author - The author with author.address to resolve to a public key, e.g. 'john.eth' resolves to '12D3KooW...'.
33
- * @param acountName - The nickname of the account, e.g. 'Account 1'. If no accountName is provided, use
33
+ * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use
34
34
  * the active account.
35
35
  */
36
36
  export declare function useResolvedAuthorAddress(options?: UseResolvedAuthorAddressOptions): UseResolvedAuthorAddressResult;
@@ -42,7 +42,7 @@ const removeStateChangeListener = (client, listener) => {
42
42
  /**
43
43
  * @param authorAddress - The address of the author
44
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
45
+ * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use
46
46
  * the active account.
47
47
  */
48
48
  export function useAuthorComments(options) {
@@ -114,7 +114,7 @@ export function useAuthorComments(options) {
114
114
  /**
115
115
  * @param authorAddress - The address of the author
116
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
117
+ * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use
118
118
  * the active account.
119
119
  */
120
120
  export function useAuthor(options) {
@@ -173,7 +173,7 @@ export function useAuthor(options) {
173
173
  }
174
174
  /**
175
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
176
+ * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use
177
177
  * the active account.
178
178
  */
179
179
  // NOTE: useAuthorAvatar tests are skipped, if changes are made they must be tested manually
@@ -232,7 +232,7 @@ export function useAuthorAvatar(options) {
232
232
  }
233
233
  /**
234
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
235
+ * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use
236
236
  * the active account.
237
237
  */
238
238
  export function useAuthorAddress(options) {
@@ -322,7 +322,7 @@ export function resetAuthorAddressCacheForTesting() {
322
322
  }
323
323
  /**
324
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
325
+ * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use
326
326
  * the active account.
327
327
  */
328
328
  // NOTE: useResolvedAuthorAddress tests are skipped, if changes are made they must be tested manually
@@ -1 +1 @@
1
- {"version":3,"file":"authors.js","sourceRoot":"","sources":["../../../src/hooks/authors/authors.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,WAAW,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,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C,CAAC,CAAC;gBAC1D,QAAQ,CAAC,QAAQ,CAAC,CAAC;gBACnB,kBAAkB,CAAC,SAAS,CAAC,CAAC;gBAC9B,GAAG,CAAC,KAAK,CAAC,qDAAqD,EAAE;oBAC/D,MAAM;oBACN,cAAc;oBACd,KAAK;iBACN,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CAAA,CAAC,EAAE,CAAC;IACP,CAAC,EACD,QAAQ,EACR,IAAI,EACJ,CAAC,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,EAAE,uBAAuB,EAAE,cAAc,CAAC,CAC3D,CAAC;IAEF,MAAM,YAAY,GAChB,CAAC,qBAAqB,IAAI,4BAA4B,CAAC,qBAAqB,CAAC,CAAC;QAC9E,uBAAuB,CAAC,CAAC,CAAC,CAAC;IAC7B,MAAM,aAAa,GAAG,CAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,WAAW;QAC7C,CAAC,CAAC,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAG,YAAY,CAAC,WAAW,CAAC;QAC5C,CAAC,CAAC,SAAS,CAAC;IAEd,GAAG,CAAC,0BAA0B,EAAE;QAC9B,MAAM;QACN,KAAK;QACL,MAAM;QACN,eAAe;QACf,cAAc;QACd,YAAY;KACb,CAAC,CAAC;IAEH,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC;QACL,eAAe;QACf,aAAa;QACb,YAAY;QACZ,KAAK,EAAE,KAAK,IAAI,YAAY;QAC5B,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,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\", { name: addr });\n return cacheResolveAuthorAddressPromise(\n addr,\n resolveAuthorNameWithProtocol(protocolClient, { name: 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\", { name: author?.address });\n return cacheResolveAuthorAddressPromise(\n author?.address,\n resolveAuthorNameWithProtocol(protocolClient, {\n name: 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"]}
1
+ {"version":3,"file":"authors.js","sourceRoot":"","sources":["../../../src/hooks/authors/authors.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,WAAW,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,qCAAqC,CAAC,CAAC;AAC1D,OAAO,MAAM,MAAM,QAAQ,CAAC;AAe5B,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,gCAAgC,EAChC,4BAA4B,GAC7B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAe,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,uBAAuB,MAAM,+BAA+B,CAAC;AACpE,OAAO,KAAK,MAAM,kBAAkB,CAAC;AACrC,OAAO,EACL,kCAAkC,EAClC,iBAAiB,EACjB,wBAAwB,EACxB,iBAAiB,EACjB,8BAA8B,EAC9B,6BAA6B,GAC9B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,QAAQ,MAAM,WAA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AY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,WAAW;QAC7C,CAAC,CAAC,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAG,YAAY,CAAC,WAAW,CAAC;QAC5C,CAAC,CAAC,SAAS,CAAC;IAEd,GAAG,CAAC,0BAA0B,EAAE;QAC9B,MAAM;QACN,KAAK;QACL,MAAM;QACN,eAAe;QACf,cAAc;QACd,YAAY;KACb,CAAC,CAAC;IAEH,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC;QACL,eAAe;QACf,aAAa;QACb,YAAY;QACZ,KAAK,EAAE,KAAK,IAAI,YAAY;QAC5B,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,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 KoXpxTwfnjA5'. 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 KoXpxTwfnjA5'. 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 KoXpxTwfnjA5'. 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 KoXpxTwfnjA5'. 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\", { name: addr });\n return cacheResolveAuthorAddressPromise(\n addr,\n resolveAuthorNameWithProtocol(protocolClient, { name: 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 KoXpxTwfnjA5'. 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\", { name: author?.address });\n return cacheResolveAuthorAddressPromise(\n author?.address,\n resolveAuthorNameWithProtocol(protocolClient, {\n name: 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"]}
@@ -4,13 +4,13 @@ export declare function preferFresher(current: Comment | undefined, candidate: C
4
4
  /**
5
5
  * @param commentCid - The IPFS CID of the comment to get
6
6
  * @param community - The community identifier, e.g. {name: 'memes.eth', publicKey: '12D3KooW...'}.
7
- * @param acountName - The nickname of the account, e.g. 'Account 1'. If no accountName is provided, use
7
+ * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use
8
8
  * the active account.
9
9
  */
10
10
  export declare function useComment(options?: UseCommentOptions): UseCommentResult;
11
11
  /**
12
12
  * @param commentCids - The IPFS CIDs of the comments to get
13
- * @param acountName - The nickname of the account, e.g. 'Account 1'. If no accountName is provided, use
13
+ * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use
14
14
  * the active account.
15
15
  */
16
16
  export declare function useComments(options?: UseCommentsOptions): UseCommentsResult;
@@ -94,7 +94,7 @@ const getCommentCreateCommentData = (commentCid, community, ...comments) => {
94
94
  /**
95
95
  * @param commentCid - The IPFS CID of the comment to get
96
96
  * @param community - The community identifier, e.g. {name: 'memes.eth', publicKey: '12D3KooW...'}.
97
- * @param acountName - The nickname of the account, e.g. 'Account 1'. If no accountName is provided, use
97
+ * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use
98
98
  * the active account.
99
99
  */
100
100
  export function useComment(options) {
@@ -243,7 +243,7 @@ export function useComment(options) {
243
243
  }
244
244
  /**
245
245
  * @param commentCids - The IPFS CIDs of the comments to get
246
- * @param acountName - The nickname of the account, e.g. 'Account 1'. If no accountName is provided, use
246
+ * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use
247
247
  * the active account.
248
248
  */
249
249
  export function useComments(options) {
@@ -1 +1 @@
1
- {"version":3,"file":"comments.js","sourceRoot":"","sources":["../../src/hooks/comments.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC1E,OAAO,EA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AAK,CAAC;IAChB,CAAC;IACD,uEAAuE;IACvE,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,KAAK,GAAG,KAAK,CAAC;IAChB,CAAC;IAED,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC;QACL,KAAK;QACL,KAAK;QACL,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;QAChC,MAAM;KACP,CAAC,EACF,CAAC,KAAK,EAAE,KAAK,CAAC,CACf,CAAC;AACJ,CAAC","sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { useAccount } from \"./accounts\";\nimport validator from \"../lib/validator\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:comments:hooks\");\nimport assert from \"assert\";\nimport {\n Comment,\n UseCommentsOptions,\n UseCommentsResult,\n UseCommentOptions,\n UseCommentResult,\n UseValidateCommentOptions,\n UseValidateCommentResult,\n} from \"../types\";\nimport useCommentsStore from \"../stores/comments\";\nimport useAccountsStore from \"../stores/accounts\";\nimport { commentIsValid } from \"../lib/utils\";\nimport {\n addCommentModeration,\n addCommentModerationToComments,\n} from \"../lib/utils/comment-moderation\";\nimport useCommunitiesPagesStore from \"../stores/communities-pages\";\nimport useRepliesPagesStore from \"../stores/replies-pages\";\nimport shallow from \"zustand/shallow\";\nimport { assertCommunityRef } from \"../lib/community-ref\";\nimport {\n addOptimisticVoteCounts,\n addOptimisticVoteCountsToComments,\n} from \"../lib/utils/optimistic-vote-counts\";\n\nexport function getCommentFreshness(comment: Comment | undefined): number {\n if (!comment) return 0;\n return Math.max(comment.updatedAt ?? 0, comment.timestamp ?? 0, 0);\n}\n\nexport function preferFresher(\n current: Comment | undefined,\n candidate: Comment | undefined,\n): Comment | undefined {\n if (!candidate) return current;\n if (!current) return candidate;\n return getCommentFreshness(candidate) > getCommentFreshness(current) ? candidate : current;\n}\n\nconst getCommentStateAndReplyCount = (comment: Comment | undefined) => {\n let state = comment?.updatingState || \"initializing\";\n // force 'fetching-ipns' even if could be something else, so the frontend can use\n // the correct loading skeleton\n if (comment?.timestamp) {\n state = \"fetching-update-ipns\";\n }\n // force succeeded even if the comment is fecthing a new update\n if (comment?.updatedAt) {\n state = \"succeeded\";\n }\n\n // force succeeded if the comment is newer than 5 minutes, no need to display loading skeleton if comment was just created\n let replyCount = comment?.replyCount;\n if (\n comment?.replyCount === undefined &&\n comment?.timestamp &&\n comment?.timestamp > Date.now() / 1000 - 5 * 60\n ) {\n state = \"succeeded\";\n // set replyCount because some frontend are likely to check if replyCount === undefined to show a loading skeleton\n replyCount = 0;\n }\n\n return { state, replyCount };\n};\n\nconst getCommentsState = (comments: (Comment | undefined)[]) =>\n comments.every((comment) => getCommentStateAndReplyCount(comment).state === \"succeeded\")\n ? \"succeeded\"\n : \"fetching-ipfs\";\n\nlet commentAutoUpdateSubscriptionCount = 0;\nlet commentsAutoUpdateSubscriptionCount = 0;\n\nconst getCommentCreateCommentData = (\n commentCid: string | undefined,\n community: UseCommentOptions[\"community\"] | undefined,\n ...comments: (Comment | undefined)[]\n) => {\n if (!commentCid) {\n return undefined;\n }\n\n const createCommentData: Comment = { cid: commentCid };\n let hasCommunityData = false;\n for (const comment of comments) {\n if (!comment) {\n continue;\n }\n if (!createCommentData.communityPublicKey && comment.communityPublicKey) {\n createCommentData.communityPublicKey = comment.communityPublicKey;\n hasCommunityData = true;\n }\n if (!createCommentData.communityName && comment.communityName) {\n createCommentData.communityName = comment.communityName;\n hasCommunityData = true;\n }\n }\n\n if (community?.publicKey) {\n createCommentData.communityPublicKey = community.publicKey;\n hasCommunityData = true;\n }\n if (community?.name) {\n createCommentData.communityName = community.name;\n hasCommunityData = true;\n }\n\n return hasCommunityData ? createCommentData : undefined;\n};\n\n/**\n * @param commentCid - The IPFS CID of the comment to get\n * @param community - The community identifier, 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 useComment(options?: UseCommentOptions): UseCommentResult {\n assert(\n !options || typeof options === \"object\",\n `useComment options argument '${options}' not an object`,\n );\n const { commentCid, community, accountName, onlyIfCached, autoUpdate = true } = options ?? {};\n if (community !== undefined) {\n assertCommunityRef(community, \"useComment community\");\n }\n const account = useAccount({ accountName });\n const commentFromStore = useCommentsStore((state: any) => state.comments[commentCid || \"\"]);\n const addCommentToStore = useCommentsStore((state: any) => state.addCommentToStore);\n const startCommentAutoUpdate = useCommentsStore((state: any) => state.startCommentAutoUpdate);\n const stopCommentAutoUpdate = useCommentsStore((state: any) => state.stopCommentAutoUpdate);\n const refreshCommentInStore = useCommentsStore((state: any) => state.refreshComment);\n const communitiesPagesComment = useCommunitiesPagesStore(\n (state: any) => state.comments[commentCid || \"\"],\n );\n const repliesPagesComment = useRepliesPagesStore(\n (state: any) => state.comments[commentCid || \"\"],\n );\n const errors = useCommentsStore((state: any) => state.errors[commentCid || \"\"]);\n\n // get account comment of the cid if any\n const accountCommentInfo = useAccountsStore(\n (state: any) => state.commentCidsToAccountsComments[commentCid || \"\"],\n );\n const accountComment = useAccountsStore(\n (state: any) =>\n state.accountsComments[accountCommentInfo?.accountId || \"\"]?.[\n Number(accountCommentInfo?.accountCommentIndex)\n ],\n );\n const accountVote = useAccountsStore((state: any) =>\n account?.id && commentCid ? state.accountsVotes[account.id]?.[commentCid] : undefined,\n );\n const createCommentData = useMemo(\n () =>\n getCommentCreateCommentData(\n commentCid,\n community,\n communitiesPagesComment,\n repliesPagesComment,\n ),\n [\n commentCid,\n community?.name,\n community?.publicKey,\n communitiesPagesComment?.communityName,\n communitiesPagesComment?.communityPublicKey,\n repliesPagesComment?.communityName,\n repliesPagesComment?.communityPublicKey,\n ],\n );\n const autoUpdateSubscriptionId = useRef(`useComment-${++commentAutoUpdateSubscriptionCount}`);\n const currentCommentCidRef = useRef<string | undefined>(commentCid);\n currentCommentCidRef.current = commentCid;\n const [frozenComment, setFrozenComment] = useState<Comment | undefined>();\n const [freezeSettledCid, setFreezeSettledCid] = useState<string>();\n\n useEffect(() => {\n if (!commentCid || !account) {\n return;\n }\n validator.validateUseCommentArguments(commentCid, account);\n if (!commentFromStore && !onlyIfCached) {\n // if comment isn't already in store, add it\n const addCommentPromise = createCommentData\n ? addCommentToStore(commentCid, account, createCommentData)\n : addCommentToStore(commentCid, account);\n addCommentPromise.catch((error: unknown) =>\n log.error(\"useComment addCommentToStore error\", { commentCid, error }),\n );\n }\n }, [commentCid, account?.id, onlyIfCached, createCommentData]);\n\n useEffect(() => {\n if (!commentCid || !account || onlyIfCached || !autoUpdate) {\n return;\n }\n\n const startAutoUpdatePromise = createCommentData\n ? startCommentAutoUpdate(\n commentCid,\n autoUpdateSubscriptionId.current,\n account,\n createCommentData,\n )\n : startCommentAutoUpdate(commentCid, autoUpdateSubscriptionId.current, account);\n startAutoUpdatePromise.catch((error: unknown) =>\n log.error(\"useComment startCommentAutoUpdate error\", { commentCid, error }),\n );\n\n return () => {\n stopCommentAutoUpdate(commentCid, autoUpdateSubscriptionId.current).catch((error: unknown) =>\n log.error(\"useComment stopCommentAutoUpdate error\", { commentCid, error }),\n );\n };\n }, [commentCid, account?.id, onlyIfCached, autoUpdate, createCommentData]);\n\n let selectedComment = commentFromStore;\n\n if (commentCid && communitiesPagesComment) {\n selectedComment = preferFresher(selectedComment, communitiesPagesComment);\n }\n if (commentCid && repliesPagesComment) {\n selectedComment = preferFresher(selectedComment, repliesPagesComment);\n }\n\n // if comment is still not defined, but account comment is, use account comment\n // check `comment.timestamp` instead of `comment` in case comment exists but in a loading state\n const commentFromStoreNotLoaded = !selectedComment?.timestamp;\n if (commentCid && commentFromStoreNotLoaded && accountComment) {\n selectedComment = accountComment;\n }\n\n const selectedCommentState = getCommentStateAndReplyCount(selectedComment).state;\n const freezeSettledForCurrentCid = freezeSettledCid === commentCid;\n\n useEffect(() => {\n if (autoUpdate) {\n setFrozenComment(undefined);\n setFreezeSettledCid(undefined);\n return;\n }\n\n setFrozenComment(undefined);\n setFreezeSettledCid(undefined);\n }, [commentCid, autoUpdate]);\n\n useEffect(() => {\n if (autoUpdate) {\n return;\n }\n if (!commentCid) {\n setFrozenComment(undefined);\n setFreezeSettledCid(undefined);\n return;\n }\n if (freezeSettledForCurrentCid || !selectedComment) {\n return;\n }\n\n setFrozenComment(selectedComment);\n if (selectedCommentState === \"succeeded\") {\n setFreezeSettledCid(commentCid);\n }\n }, [autoUpdate, commentCid, selectedComment, selectedCommentState, freezeSettledForCurrentCid]);\n\n const frozenCommentForCurrentCid = frozenComment?.cid === commentCid ? frozenComment : undefined;\n let comment = autoUpdate\n ? selectedComment\n : freezeSettledForCurrentCid\n ? frozenCommentForCurrentCid\n : frozenCommentForCurrentCid || selectedComment;\n comment = addCommentModeration(comment);\n comment = addOptimisticVoteCounts(comment, accountVote);\n\n const { state, replyCount } = getCommentStateAndReplyCount(comment);\n\n if (account && commentCid) {\n log(\"useComment\", {\n commentCid,\n comment,\n replyCount,\n state,\n commentFromStore,\n communitiesPagesComment,\n repliesPagesComment,\n accountComment,\n commentsStore: useCommentsStore.getState().comments,\n account,\n onlyIfCached,\n autoUpdate,\n });\n }\n\n const refresh = useCallback(async () => {\n if (!commentCid || !account) {\n throw Error(\"useComment cannot refresh comment not initialized yet\");\n }\n\n const refreshCommentCid = commentCid;\n const refreshedComment = createCommentData\n ? await refreshCommentInStore(refreshCommentCid, account, createCommentData)\n : await refreshCommentInStore(refreshCommentCid, account);\n if (!autoUpdate && refreshedComment && currentCommentCidRef.current === refreshCommentCid) {\n setFrozenComment(refreshedComment);\n setFreezeSettledCid(refreshCommentCid);\n }\n }, [account, autoUpdate, commentCid, createCommentData, refreshCommentInStore]);\n\n return useMemo(\n () => ({\n ...comment,\n replyCount,\n state,\n refresh,\n error: errors?.[errors.length - 1],\n errors: errors || [],\n }),\n [comment, commentCid, errors, refresh, state, replyCount],\n );\n}\n\n/**\n * @param commentCids - The IPFS CIDs of the comments to get\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 useComments(options?: UseCommentsOptions): UseCommentsResult {\n assert(\n !options || typeof options === \"object\",\n `useComments options argument '${options}' not an object`,\n );\n const { commentCids = [], accountName, onlyIfCached, autoUpdate = true } = options ?? {};\n const account = useAccount({ accountName });\n const accountVotes = useAccountsStore((state: any) =>\n account?.id ? state.accountsVotes[account.id] : undefined,\n );\n const commentsStoreComments: (Comment | undefined)[] = useCommentsStore(\n (state: any) => commentCids.map((commentCid) => state.comments[commentCid || \"\"]),\n shallow,\n );\n const communitiesPagesComments: (Comment | undefined)[] = useCommunitiesPagesStore(\n (state: any) => commentCids.map((commentCid) => state.comments[commentCid || \"\"]),\n shallow,\n );\n\n const addCommentToStore = useCommentsStore((state: any) => state.addCommentToStore);\n const startCommentAutoUpdate = useCommentsStore((state: any) => state.startCommentAutoUpdate);\n const stopCommentAutoUpdate = useCommentsStore((state: any) => state.stopCommentAutoUpdate);\n const refreshCommentInStore = useCommentsStore((state: any) => state.refreshComment);\n const autoUpdateSubscriptionId = useRef(`useComments-${++commentsAutoUpdateSubscriptionCount}`);\n const commentCidsKey = JSON.stringify(commentCids);\n const commentsKey = `${account?.id || \"\"}:${commentCidsKey}`;\n const currentCommentsKeyRef = useRef(commentsKey);\n currentCommentsKeyRef.current = commentsKey;\n const [frozenComments, setFrozenComments] = useState<(Comment | undefined)[]>([]);\n const [frozenCommentsKey, setFrozenCommentsKey] = useState<string>();\n const [freezeSettledKey, setFreezeSettledKey] = useState<string>();\n\n useEffect(() => {\n if (!commentCids || !account) {\n return;\n }\n validator.validateUseCommentsArguments(commentCids, account);\n if (onlyIfCached) {\n return;\n }\n const uniqueCommentCids = new Set(commentCids);\n for (const commentCid of uniqueCommentCids) {\n addCommentToStore(commentCid, account).catch((error: unknown) =>\n log.error(\"useComments addCommentToStore error\", { commentCid, error }),\n );\n }\n }, [commentCidsKey, account?.id, onlyIfCached]);\n\n useEffect(() => {\n if (!commentCids || !account || onlyIfCached || !autoUpdate) {\n return;\n }\n\n const uniqueCommentCids = [...new Set(commentCids)];\n for (const commentCid of uniqueCommentCids) {\n startCommentAutoUpdate(commentCid, autoUpdateSubscriptionId.current, account).catch(\n (error: unknown) =>\n log.error(\"useComments startCommentAutoUpdate error\", { commentCid, error }),\n );\n }\n\n return () => {\n for (const commentCid of uniqueCommentCids) {\n stopCommentAutoUpdate(commentCid, autoUpdateSubscriptionId.current).catch(\n (error: unknown) =>\n log.error(\"useComments stopCommentAutoUpdate error\", { commentCid, error }),\n );\n }\n };\n }, [commentCidsKey, account?.id, onlyIfCached, autoUpdate]);\n\n if (account && commentCids?.length) {\n log(\"useComments\", {\n commentCids,\n commentsStoreComments,\n commentsStore: useCommentsStore.getState().comments,\n account,\n });\n }\n\n // if comment from community pages exists and is fresher (or current missing), use it instead\n const liveComments = useMemo(() => {\n const result = [...commentsStoreComments];\n for (const i in result) {\n const candidate = communitiesPagesComments[i];\n if (candidate) result[i] = preferFresher(result[i], candidate);\n }\n return result;\n }, [commentsStoreComments, communitiesPagesComments]);\n\n const liveCommentsSettled = liveComments.every(\n (comment) => getCommentStateAndReplyCount(comment).state === \"succeeded\",\n );\n const freezeSettledForCurrentKey = freezeSettledKey === commentsKey;\n\n useEffect(() => {\n if (autoUpdate) {\n setFrozenComments([]);\n setFrozenCommentsKey(undefined);\n setFreezeSettledKey(undefined);\n return;\n }\n\n setFrozenComments([]);\n setFrozenCommentsKey(undefined);\n setFreezeSettledKey(undefined);\n }, [commentsKey, autoUpdate]);\n\n useEffect(() => {\n if (autoUpdate || freezeSettledForCurrentKey) {\n return;\n }\n\n setFrozenComments(liveComments);\n setFrozenCommentsKey(commentsKey);\n if (liveCommentsSettled) {\n setFreezeSettledKey(commentsKey);\n }\n }, [autoUpdate, commentsKey, freezeSettledForCurrentKey, liveComments, liveCommentsSettled]);\n\n const frozenCommentsForCurrentSelection =\n frozenCommentsKey === commentsKey ? frozenComments : undefined;\n const comments = autoUpdate ? liveComments : frozenCommentsForCurrentSelection || liveComments;\n const normalizedComments = useMemo(\n () => addOptimisticVoteCountsToComments(addCommentModerationToComments(comments), accountVotes),\n [comments, accountVotes],\n );\n\n // succeed if no comments are undefined\n const state = getCommentsState(normalizedComments);\n\n const refresh = useCallback(async () => {\n if (!account) {\n throw Error(\"useComments cannot refresh comments not initialized yet\");\n }\n const uniqueCommentCids = [...new Set(commentCids)];\n const refreshedComments = await Promise.all(\n uniqueCommentCids.map((commentCid) => refreshCommentInStore(commentCid, account)),\n );\n\n if (!autoUpdate && currentCommentsKeyRef.current === commentsKey) {\n const latestCommunitiesPagesComments = useCommunitiesPagesStore.getState().comments;\n const refreshedCommentsByCid = uniqueCommentCids.reduce(\n (\n refreshedCommentsMap: { [commentCid: string]: Comment | undefined },\n commentCid,\n index,\n ) => {\n refreshedCommentsMap[commentCid] = refreshedComments[index];\n return refreshedCommentsMap;\n },\n {},\n );\n setFrozenComments(\n commentCids.map((commentCid) =>\n preferFresher(\n refreshedCommentsByCid[commentCid || \"\"],\n latestCommunitiesPagesComments[commentCid || \"\"],\n ),\n ),\n );\n setFrozenCommentsKey(commentsKey);\n setFreezeSettledKey(commentsKey);\n }\n }, [account, autoUpdate, commentCids, commentsKey, refreshCommentInStore]);\n\n return useMemo(\n () => ({\n comments: normalizedComments,\n state,\n refresh,\n error: undefined,\n errors: [],\n }),\n [normalizedComments, commentsKey, refresh, state],\n );\n}\n\nexport function useValidateComment(options?: UseValidateCommentOptions): UseValidateCommentResult {\n assert(\n !options || typeof options === \"object\",\n `useValidateComment options argument '${options}' not an object`,\n );\n let { comment, validateReplies, accountName } = options ?? {};\n validateReplies = validateReplies ?? true;\n const [validated, setValidated] = useState<boolean | undefined>();\n const [errors] = useState([]);\n const account = useAccount({ accountName });\n\n useEffect(() => {\n if (!comment || !account?.pkc) {\n setValidated(undefined);\n return;\n }\n // don't automatically block community because what community it comes from\n // a malicious community could try to block other communities, etc\n const blockCommunity = false;\n commentIsValid(comment, { validateReplies, blockCommunity }, account.pkc).then((validated) =>\n setValidated(validated),\n );\n }, [comment, validateReplies, account?.pkc]);\n\n let state = \"initializing\";\n if (validated === true) {\n state = \"succeeded\";\n }\n if (validated === false) {\n state = \"failed\";\n }\n\n // start valid at true always because most of the time the value will be true and we dont want to cause a rerender\n let valid = true;\n if (validated == false) {\n valid = false;\n }\n // if comment isn't defined, it would be confusing for valid to be true\n if (!comment) {\n valid = false;\n }\n\n return useMemo(\n () => ({\n valid,\n state,\n error: errors[errors.length - 1],\n errors,\n }),\n [valid, state],\n );\n}\n"]}
1
+ {"version":3,"file":"comments.js","sourceRoot":"","sources":["../../src/hooks/comments.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,SAAS,MAAM,kBAAkB,CAAC;AACzC,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,sCAAsC,CAAC,CAAC;AAC3D,OAAO,MAAM,MAAM,QAAQ,CAAC;AAU5B,OAAO,gBAAgB,MAAM,oBAAoB,CAAC;AAClD,OAAO,gBAAgB,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EACL,oBAAoB,EACpB,8BAA8B,GAC/B,MAAM,iCAAiC,CAAC;AACzC,OAAO,wBAAwB,MAAM,6BAA6B,CAAC;AACnE,OAAO,oBAAoB,MAAM,yBAAyB,CAAC;AAC3D,OAAO,OAAO,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EACL,uBAAuB,EACvB,iCAAiC,GAClC,MAAM,qCAAqC,CAAC;AAE7C,MAAM,UAAU,mBAAmB,CAAC,OAA4B;;IAC9D,IAAI,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AC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAC3F,YAAY,CAAC,SAAS,CAAC,CACxB,CAAC;IACJ,CAAC,EAAE,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,CAAC,CAAC,CAAC;IAE7C,IAAI,KAAK,GAAG,cAAc,CAAC;IAC3B,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;QACvB,KAAK,GAAG,WAAW,CAAC;IACtB,CAAC;IACD,IAAI,SAAS,KAAK,KAAK,EAAE,CAAC;QACxB,KAAK,GAAG,QAAQ,CAAC;IACnB,CAAC;IAED,kHAAkH;IAClH,IAAI,KAAK,GAAG,IAAI,CAAC;IACjB,IAAI,SAAS,IAAI,KAAK,EAAE,CAAC;QACvB,KAAK,GAAG,KAAK,CAAC;IAChB,CAAC;IACD,uEAAuE;IACvE,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,KAAK,GAAG,KAAK,CAAC;IAChB,CAAC;IAED,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC;QACL,KAAK;QACL,KAAK;QACL,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;QAChC,MAAM;KACP,CAAC,EACF,CAAC,KAAK,EAAE,KAAK,CAAC,CACf,CAAC;AACJ,CAAC","sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { useAccount } from \"./accounts\";\nimport validator from \"../lib/validator\";\nimport Logger from \"@pkcprotocol/pkc-logger\";\nconst log = Logger(\"bitsocial-react-hooks:comments:hooks\");\nimport assert from \"assert\";\nimport {\n Comment,\n UseCommentsOptions,\n UseCommentsResult,\n UseCommentOptions,\n UseCommentResult,\n UseValidateCommentOptions,\n UseValidateCommentResult,\n} from \"../types\";\nimport useCommentsStore from \"../stores/comments\";\nimport useAccountsStore from \"../stores/accounts\";\nimport { commentIsValid } from \"../lib/utils\";\nimport {\n addCommentModeration,\n addCommentModerationToComments,\n} from \"../lib/utils/comment-moderation\";\nimport useCommunitiesPagesStore from \"../stores/communities-pages\";\nimport useRepliesPagesStore from \"../stores/replies-pages\";\nimport shallow from \"zustand/shallow\";\nimport { assertCommunityRef } from \"../lib/community-ref\";\nimport {\n addOptimisticVoteCounts,\n addOptimisticVoteCountsToComments,\n} from \"../lib/utils/optimistic-vote-counts\";\n\nexport function getCommentFreshness(comment: Comment | undefined): number {\n if (!comment) return 0;\n return Math.max(comment.updatedAt ?? 0, comment.timestamp ?? 0, 0);\n}\n\nexport function preferFresher(\n current: Comment | undefined,\n candidate: Comment | undefined,\n): Comment | undefined {\n if (!candidate) return current;\n if (!current) return candidate;\n return getCommentFreshness(candidate) > getCommentFreshness(current) ? candidate : current;\n}\n\nconst getCommentStateAndReplyCount = (comment: Comment | undefined) => {\n let state = comment?.updatingState || \"initializing\";\n // force 'fetching-ipns' even if could be something else, so the frontend can use\n // the correct loading skeleton\n if (comment?.timestamp) {\n state = \"fetching-update-ipns\";\n }\n // force succeeded even if the comment is fecthing a new update\n if (comment?.updatedAt) {\n state = \"succeeded\";\n }\n\n // force succeeded if the comment is newer than 5 minutes, no need to display loading skeleton if comment was just created\n let replyCount = comment?.replyCount;\n if (\n comment?.replyCount === undefined &&\n comment?.timestamp &&\n comment?.timestamp > Date.now() / 1000 - 5 * 60\n ) {\n state = \"succeeded\";\n // set replyCount because some frontend are likely to check if replyCount === undefined to show a loading skeleton\n replyCount = 0;\n }\n\n return { state, replyCount };\n};\n\nconst getCommentsState = (comments: (Comment | undefined)[]) =>\n comments.every((comment) => getCommentStateAndReplyCount(comment).state === \"succeeded\")\n ? \"succeeded\"\n : \"fetching-ipfs\";\n\nlet commentAutoUpdateSubscriptionCount = 0;\nlet commentsAutoUpdateSubscriptionCount = 0;\n\nconst getCommentCreateCommentData = (\n commentCid: string | undefined,\n community: UseCommentOptions[\"community\"] | undefined,\n ...comments: (Comment | undefined)[]\n) => {\n if (!commentCid) {\n return undefined;\n }\n\n const createCommentData: Comment = { cid: commentCid };\n let hasCommunityData = false;\n for (const comment of comments) {\n if (!comment) {\n continue;\n }\n if (!createCommentData.communityPublicKey && comment.communityPublicKey) {\n createCommentData.communityPublicKey = comment.communityPublicKey;\n hasCommunityData = true;\n }\n if (!createCommentData.communityName && comment.communityName) {\n createCommentData.communityName = comment.communityName;\n hasCommunityData = true;\n }\n }\n\n if (community?.publicKey) {\n createCommentData.communityPublicKey = community.publicKey;\n hasCommunityData = true;\n }\n if (community?.name) {\n createCommentData.communityName = community.name;\n hasCommunityData = true;\n }\n\n return hasCommunityData ? createCommentData : undefined;\n};\n\n/**\n * @param commentCid - The IPFS CID of the comment to get\n * @param community - The community identifier, e.g. {name: 'memes.eth', publicKey: '12D3KooW...'}.\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\nexport function useComment(options?: UseCommentOptions): UseCommentResult {\n assert(\n !options || typeof options === \"object\",\n `useComment options argument '${options}' not an object`,\n );\n const { commentCid, community, accountName, onlyIfCached, autoUpdate = true } = options ?? {};\n if (community !== undefined) {\n assertCommunityRef(community, \"useComment community\");\n }\n const account = useAccount({ accountName });\n const commentFromStore = useCommentsStore((state: any) => state.comments[commentCid || \"\"]);\n const addCommentToStore = useCommentsStore((state: any) => state.addCommentToStore);\n const startCommentAutoUpdate = useCommentsStore((state: any) => state.startCommentAutoUpdate);\n const stopCommentAutoUpdate = useCommentsStore((state: any) => state.stopCommentAutoUpdate);\n const refreshCommentInStore = useCommentsStore((state: any) => state.refreshComment);\n const communitiesPagesComment = useCommunitiesPagesStore(\n (state: any) => state.comments[commentCid || \"\"],\n );\n const repliesPagesComment = useRepliesPagesStore(\n (state: any) => state.comments[commentCid || \"\"],\n );\n const errors = useCommentsStore((state: any) => state.errors[commentCid || \"\"]);\n\n // get account comment of the cid if any\n const accountCommentInfo = useAccountsStore(\n (state: any) => state.commentCidsToAccountsComments[commentCid || \"\"],\n );\n const accountComment = useAccountsStore(\n (state: any) =>\n state.accountsComments[accountCommentInfo?.accountId || \"\"]?.[\n Number(accountCommentInfo?.accountCommentIndex)\n ],\n );\n const accountVote = useAccountsStore((state: any) =>\n account?.id && commentCid ? state.accountsVotes[account.id]?.[commentCid] : undefined,\n );\n const createCommentData = useMemo(\n () =>\n getCommentCreateCommentData(\n commentCid,\n community,\n communitiesPagesComment,\n repliesPagesComment,\n ),\n [\n commentCid,\n community?.name,\n community?.publicKey,\n communitiesPagesComment?.communityName,\n communitiesPagesComment?.communityPublicKey,\n repliesPagesComment?.communityName,\n repliesPagesComment?.communityPublicKey,\n ],\n );\n const autoUpdateSubscriptionId = useRef(`useComment-${++commentAutoUpdateSubscriptionCount}`);\n const currentCommentCidRef = useRef<string | undefined>(commentCid);\n currentCommentCidRef.current = commentCid;\n const [frozenComment, setFrozenComment] = useState<Comment | undefined>();\n const [freezeSettledCid, setFreezeSettledCid] = useState<string>();\n\n useEffect(() => {\n if (!commentCid || !account) {\n return;\n }\n validator.validateUseCommentArguments(commentCid, account);\n if (!commentFromStore && !onlyIfCached) {\n // if comment isn't already in store, add it\n const addCommentPromise = createCommentData\n ? addCommentToStore(commentCid, account, createCommentData)\n : addCommentToStore(commentCid, account);\n addCommentPromise.catch((error: unknown) =>\n log.error(\"useComment addCommentToStore error\", { commentCid, error }),\n );\n }\n }, [commentCid, account?.id, onlyIfCached, createCommentData]);\n\n useEffect(() => {\n if (!commentCid || !account || onlyIfCached || !autoUpdate) {\n return;\n }\n\n const startAutoUpdatePromise = createCommentData\n ? startCommentAutoUpdate(\n commentCid,\n autoUpdateSubscriptionId.current,\n account,\n createCommentData,\n )\n : startCommentAutoUpdate(commentCid, autoUpdateSubscriptionId.current, account);\n startAutoUpdatePromise.catch((error: unknown) =>\n log.error(\"useComment startCommentAutoUpdate error\", { commentCid, error }),\n );\n\n return () => {\n stopCommentAutoUpdate(commentCid, autoUpdateSubscriptionId.current).catch((error: unknown) =>\n log.error(\"useComment stopCommentAutoUpdate error\", { commentCid, error }),\n );\n };\n }, [commentCid, account?.id, onlyIfCached, autoUpdate, createCommentData]);\n\n let selectedComment = commentFromStore;\n\n if (commentCid && communitiesPagesComment) {\n selectedComment = preferFresher(selectedComment, communitiesPagesComment);\n }\n if (commentCid && repliesPagesComment) {\n selectedComment = preferFresher(selectedComment, repliesPagesComment);\n }\n\n // if comment is still not defined, but account comment is, use account comment\n // check `comment.timestamp` instead of `comment` in case comment exists but in a loading state\n const commentFromStoreNotLoaded = !selectedComment?.timestamp;\n if (commentCid && commentFromStoreNotLoaded && accountComment) {\n selectedComment = accountComment;\n }\n\n const selectedCommentState = getCommentStateAndReplyCount(selectedComment).state;\n const freezeSettledForCurrentCid = freezeSettledCid === commentCid;\n\n useEffect(() => {\n if (autoUpdate) {\n setFrozenComment(undefined);\n setFreezeSettledCid(undefined);\n return;\n }\n\n setFrozenComment(undefined);\n setFreezeSettledCid(undefined);\n }, [commentCid, autoUpdate]);\n\n useEffect(() => {\n if (autoUpdate) {\n return;\n }\n if (!commentCid) {\n setFrozenComment(undefined);\n setFreezeSettledCid(undefined);\n return;\n }\n if (freezeSettledForCurrentCid || !selectedComment) {\n return;\n }\n\n setFrozenComment(selectedComment);\n if (selectedCommentState === \"succeeded\") {\n setFreezeSettledCid(commentCid);\n }\n }, [autoUpdate, commentCid, selectedComment, selectedCommentState, freezeSettledForCurrentCid]);\n\n const frozenCommentForCurrentCid = frozenComment?.cid === commentCid ? frozenComment : undefined;\n let comment = autoUpdate\n ? selectedComment\n : freezeSettledForCurrentCid\n ? frozenCommentForCurrentCid\n : frozenCommentForCurrentCid || selectedComment;\n comment = addCommentModeration(comment);\n comment = addOptimisticVoteCounts(comment, accountVote);\n\n const { state, replyCount } = getCommentStateAndReplyCount(comment);\n\n if (account && commentCid) {\n log(\"useComment\", {\n commentCid,\n comment,\n replyCount,\n state,\n commentFromStore,\n communitiesPagesComment,\n repliesPagesComment,\n accountComment,\n commentsStore: useCommentsStore.getState().comments,\n account,\n onlyIfCached,\n autoUpdate,\n });\n }\n\n const refresh = useCallback(async () => {\n if (!commentCid || !account) {\n throw Error(\"useComment cannot refresh comment not initialized yet\");\n }\n\n const refreshCommentCid = commentCid;\n const refreshedComment = createCommentData\n ? await refreshCommentInStore(refreshCommentCid, account, createCommentData)\n : await refreshCommentInStore(refreshCommentCid, account);\n if (!autoUpdate && refreshedComment && currentCommentCidRef.current === refreshCommentCid) {\n setFrozenComment(refreshedComment);\n setFreezeSettledCid(refreshCommentCid);\n }\n }, [account, autoUpdate, commentCid, createCommentData, refreshCommentInStore]);\n\n return useMemo(\n () => ({\n ...comment,\n replyCount,\n state,\n refresh,\n error: errors?.[errors.length - 1],\n errors: errors || [],\n }),\n [comment, commentCid, errors, refresh, state, replyCount],\n );\n}\n\n/**\n * @param commentCids - The IPFS CIDs of the comments to get\n * @param acountName - The nickname of the account, e.g. 'Account KoXpxTwfnjA5'. If no accountName is provided, use\n * the active account.\n */\nexport function useComments(options?: UseCommentsOptions): UseCommentsResult {\n assert(\n !options || typeof options === \"object\",\n `useComments options argument '${options}' not an object`,\n );\n const { commentCids = [], accountName, onlyIfCached, autoUpdate = true } = options ?? {};\n const account = useAccount({ accountName });\n const accountVotes = useAccountsStore((state: any) =>\n account?.id ? state.accountsVotes[account.id] : undefined,\n );\n const commentsStoreComments: (Comment | undefined)[] = useCommentsStore(\n (state: any) => commentCids.map((commentCid) => state.comments[commentCid || \"\"]),\n shallow,\n );\n const communitiesPagesComments: (Comment | undefined)[] = useCommunitiesPagesStore(\n (state: any) => commentCids.map((commentCid) => state.comments[commentCid || \"\"]),\n shallow,\n );\n\n const addCommentToStore = useCommentsStore((state: any) => state.addCommentToStore);\n const startCommentAutoUpdate = useCommentsStore((state: any) => state.startCommentAutoUpdate);\n const stopCommentAutoUpdate = useCommentsStore((state: any) => state.stopCommentAutoUpdate);\n const refreshCommentInStore = useCommentsStore((state: any) => state.refreshComment);\n const autoUpdateSubscriptionId = useRef(`useComments-${++commentsAutoUpdateSubscriptionCount}`);\n const commentCidsKey = JSON.stringify(commentCids);\n const commentsKey = `${account?.id || \"\"}:${commentCidsKey}`;\n const currentCommentsKeyRef = useRef(commentsKey);\n currentCommentsKeyRef.current = commentsKey;\n const [frozenComments, setFrozenComments] = useState<(Comment | undefined)[]>([]);\n const [frozenCommentsKey, setFrozenCommentsKey] = useState<string>();\n const [freezeSettledKey, setFreezeSettledKey] = useState<string>();\n\n useEffect(() => {\n if (!commentCids || !account) {\n return;\n }\n validator.validateUseCommentsArguments(commentCids, account);\n if (onlyIfCached) {\n return;\n }\n const uniqueCommentCids = new Set(commentCids);\n for (const commentCid of uniqueCommentCids) {\n addCommentToStore(commentCid, account).catch((error: unknown) =>\n log.error(\"useComments addCommentToStore error\", { commentCid, error }),\n );\n }\n }, [commentCidsKey, account?.id, onlyIfCached]);\n\n useEffect(() => {\n if (!commentCids || !account || onlyIfCached || !autoUpdate) {\n return;\n }\n\n const uniqueCommentCids = [...new Set(commentCids)];\n for (const commentCid of uniqueCommentCids) {\n startCommentAutoUpdate(commentCid, autoUpdateSubscriptionId.current, account).catch(\n (error: unknown) =>\n log.error(\"useComments startCommentAutoUpdate error\", { commentCid, error }),\n );\n }\n\n return () => {\n for (const commentCid of uniqueCommentCids) {\n stopCommentAutoUpdate(commentCid, autoUpdateSubscriptionId.current).catch(\n (error: unknown) =>\n log.error(\"useComments stopCommentAutoUpdate error\", { commentCid, error }),\n );\n }\n };\n }, [commentCidsKey, account?.id, onlyIfCached, autoUpdate]);\n\n if (account && commentCids?.length) {\n log(\"useComments\", {\n commentCids,\n commentsStoreComments,\n commentsStore: useCommentsStore.getState().comments,\n account,\n });\n }\n\n // if comment from community pages exists and is fresher (or current missing), use it instead\n const liveComments = useMemo(() => {\n const result = [...commentsStoreComments];\n for (const i in result) {\n const candidate = communitiesPagesComments[i];\n if (candidate) result[i] = preferFresher(result[i], candidate);\n }\n return result;\n }, [commentsStoreComments, communitiesPagesComments]);\n\n const liveCommentsSettled = liveComments.every(\n (comment) => getCommentStateAndReplyCount(comment).state === \"succeeded\",\n );\n const freezeSettledForCurrentKey = freezeSettledKey === commentsKey;\n\n useEffect(() => {\n if (autoUpdate) {\n setFrozenComments([]);\n setFrozenCommentsKey(undefined);\n setFreezeSettledKey(undefined);\n return;\n }\n\n setFrozenComments([]);\n setFrozenCommentsKey(undefined);\n setFreezeSettledKey(undefined);\n }, [commentsKey, autoUpdate]);\n\n useEffect(() => {\n if (autoUpdate || freezeSettledForCurrentKey) {\n return;\n }\n\n setFrozenComments(liveComments);\n setFrozenCommentsKey(commentsKey);\n if (liveCommentsSettled) {\n setFreezeSettledKey(commentsKey);\n }\n }, [autoUpdate, commentsKey, freezeSettledForCurrentKey, liveComments, liveCommentsSettled]);\n\n const frozenCommentsForCurrentSelection =\n frozenCommentsKey === commentsKey ? frozenComments : undefined;\n const comments = autoUpdate ? liveComments : frozenCommentsForCurrentSelection || liveComments;\n const normalizedComments = useMemo(\n () => addOptimisticVoteCountsToComments(addCommentModerationToComments(comments), accountVotes),\n [comments, accountVotes],\n );\n\n // succeed if no comments are undefined\n const state = getCommentsState(normalizedComments);\n\n const refresh = useCallback(async () => {\n if (!account) {\n throw Error(\"useComments cannot refresh comments not initialized yet\");\n }\n const uniqueCommentCids = [...new Set(commentCids)];\n const refreshedComments = await Promise.all(\n uniqueCommentCids.map((commentCid) => refreshCommentInStore(commentCid, account)),\n );\n\n if (!autoUpdate && currentCommentsKeyRef.current === commentsKey) {\n const latestCommunitiesPagesComments = useCommunitiesPagesStore.getState().comments;\n const refreshedCommentsByCid = uniqueCommentCids.reduce(\n (\n refreshedCommentsMap: { [commentCid: string]: Comment | undefined },\n commentCid,\n index,\n ) => {\n refreshedCommentsMap[commentCid] = refreshedComments[index];\n return refreshedCommentsMap;\n },\n {},\n );\n setFrozenComments(\n commentCids.map((commentCid) =>\n preferFresher(\n refreshedCommentsByCid[commentCid || \"\"],\n latestCommunitiesPagesComments[commentCid || \"\"],\n ),\n ),\n );\n setFrozenCommentsKey(commentsKey);\n setFreezeSettledKey(commentsKey);\n }\n }, [account, autoUpdate, commentCids, commentsKey, refreshCommentInStore]);\n\n return useMemo(\n () => ({\n comments: normalizedComments,\n state,\n refresh,\n error: undefined,\n errors: [],\n }),\n [normalizedComments, commentsKey, refresh, state],\n );\n}\n\nexport function useValidateComment(options?: UseValidateCommentOptions): UseValidateCommentResult {\n assert(\n !options || typeof options === \"object\",\n `useValidateComment options argument '${options}' not an object`,\n );\n let { comment, validateReplies, accountName } = options ?? {};\n validateReplies = validateReplies ?? true;\n const [validated, setValidated] = useState<boolean | undefined>();\n const [errors] = useState([]);\n const account = useAccount({ accountName });\n\n useEffect(() => {\n if (!comment || !account?.pkc) {\n setValidated(undefined);\n return;\n }\n // don't automatically block community because what community it comes from\n // a malicious community could try to block other communities, etc\n const blockCommunity = false;\n commentIsValid(comment, { validateReplies, blockCommunity }, account.pkc).then((validated) =>\n setValidated(validated),\n );\n }, [comment, validateReplies, account?.pkc]);\n\n let state = \"initializing\";\n if (validated === true) {\n state = \"succeeded\";\n }\n if (validated === false) {\n state = \"failed\";\n }\n\n // start valid at true always because most of the time the value will be true and we dont want to cause a rerender\n let valid = true;\n if (validated == false) {\n valid = false;\n }\n // if comment isn't defined, it would be confusing for valid to be true\n if (!comment) {\n valid = false;\n }\n\n return useMemo(\n () => ({\n valid,\n state,\n error: errors[errors.length - 1],\n errors,\n }),\n [valid, state],\n );\n}\n"]}