From 2f1103f92cb121deda2e5a3afa83506c6100574a Mon Sep 17 00:00:00 2001 From: chaojun Date: Wed, 23 Oct 2024 17:50:49 +0800 Subject: [PATCH] Implement reply as proxy, #3909 --- .../next-common/components/comment/editor.js | 36 ++++++++++++++----- .../selectProxyAccountPopup/index.js | 9 +++-- .../components/splitButton/index.js | 9 +++-- .../components/splitCommentButton/index.js | 25 +------------ .../next-common/sima/actions/proxyComment.js | 27 ++++++++++++++ .../post/context/commentActionsProvider.js | 7 +++- 6 files changed, 74 insertions(+), 39 deletions(-) diff --git a/packages/next-common/components/comment/editor.js b/packages/next-common/components/comment/editor.js index e9a8978c42..46c7ec8fd5 100644 --- a/packages/next-common/components/comment/editor.js +++ b/packages/next-common/components/comment/editor.js @@ -66,6 +66,7 @@ function CommentEditor( createCommentReply, updateComment, createPostProxyComment, + createCommentProxyReply, } = useCommentActions(); const createComment = async (realAddress) => { @@ -78,16 +79,33 @@ function CommentEditor( let result; if (comment) { - result = await createCommentReply(post, comment, content, contentType); - } else if (realAddress) { - result = await createPostProxyComment( - realAddress, - post, - content, - contentType, - ); + if (realAddress) { + result = await createCommentProxyReply( + realAddress, + post, + comment, + content, + contentType, + ); + } else { + result = await createCommentReply( + post, + comment, + content, + contentType, + ); + } } else { - result = await createPostComment(post, content, contentType); + if (realAddress) { + result = await createPostProxyComment( + realAddress, + post, + content, + contentType, + ); + } else { + result = await createPostComment(post, content, contentType); + } } if (!isMounted()) { diff --git a/packages/next-common/components/selectProxyAccountPopup/index.js b/packages/next-common/components/selectProxyAccountPopup/index.js index fcb47b9e22..e8f51047a7 100644 --- a/packages/next-common/components/selectProxyAccountPopup/index.js +++ b/packages/next-common/components/selectProxyAccountPopup/index.js @@ -2,14 +2,17 @@ import Popup from "../popup/wrapper/Popup"; import { ProxiedAccounts } from "../switchSignerPopup"; import { noop } from "lodash-es"; import SignerPopupWrapper from "../popupWithSigner/signerPopupWrapper"; +import { GeneralProxiesProvider } from "next-common/context/proxy"; export default function SelectProxyAccountPopup({ onClose, onSelect = noop }) { return ( -
- -
+ +
+ +
+
); diff --git a/packages/next-common/components/splitButton/index.js b/packages/next-common/components/splitButton/index.js index baf6abbf8d..10b6e2d599 100644 --- a/packages/next-common/components/splitButton/index.js +++ b/packages/next-common/components/splitButton/index.js @@ -16,6 +16,7 @@ export default function SplitButton({ loading, disabled, dropdownContent, + children, ...props }) { const [showDropdown, setShowDropdown] = useState(false); @@ -23,7 +24,11 @@ export default function SplitButton({ useClickAway(ref, () => setShowDropdown(false)); if (loading) { - return ; + return ( + + {children} + + ); } return ( @@ -33,7 +38,7 @@ export default function SplitButton({ {...props} className="rounded-tr-none rounded-br-none" > - Comment + {children}
- {action} - - ); - } - return ( <> ); } - -export default function SplitCommentButton(props) { - return ( - - - - ); -} diff --git a/packages/next-common/sima/actions/proxyComment.js b/packages/next-common/sima/actions/proxyComment.js index 76b69939b6..b89ee29691 100644 --- a/packages/next-common/sima/actions/proxyComment.js +++ b/packages/next-common/sima/actions/proxyComment.js @@ -27,3 +27,30 @@ export function useCreateDiscussionProxyComment() { [signSimaMessage], ); } + +export function useCreateDiscussionCommentProxyReply() { + const signSimaMessage = useSignSimaMessage(); + + return useCallback( + async (realAddress, post, comment, content, contentType) => { + checkSimaDataSource(comment); + + const entity = { + action: "comment", + cid: comment.cid, + ...getContentField(content, contentType), + timestamp: Date.now(), + real: { + address: realAddress, + section: "proxy", + }, + }; + const data = await signSimaMessage(entity); + return await nextApi.post( + `sima/discussions/${post.cid}/comments/${comment.cid}/replies`, + data, + ); + }, + [signSimaMessage], + ); +} diff --git a/packages/next-common/sima/components/post/context/commentActionsProvider.js b/packages/next-common/sima/components/post/context/commentActionsProvider.js index 433dc410c9..9919f0b9ff 100644 --- a/packages/next-common/sima/components/post/context/commentActionsProvider.js +++ b/packages/next-common/sima/components/post/context/commentActionsProvider.js @@ -6,13 +6,17 @@ import { import { useDiscussionCommentUpVote } from "next-common/sima/actions/upVote"; import { useDiscussionCommentCancelUpVote } from "next-common/sima/actions/cancelUpVote"; import { useGetComment } from "next-common/noSima/actions/comment"; -import { useCreateDiscussionProxyComment } from "next-common/sima/actions/proxyComment"; +import { + useCreateDiscussionCommentProxyReply, + useCreateDiscussionProxyComment, +} from "next-common/sima/actions/proxyComment"; export function DiscussionCommentActionsProvider({ children }) { const getComment = useGetComment(); const createPostComment = useCreateDiscussionComment(); const createPostProxyComment = useCreateDiscussionProxyComment(); const createCommentReply = useCreateDiscussionCommentReply(); + const createCommentProxyReply = useCreateDiscussionCommentProxyReply(); const upVoteComment = useDiscussionCommentUpVote(); const cancelUpVoteComment = useDiscussionCommentCancelUpVote(); @@ -25,6 +29,7 @@ export function DiscussionCommentActionsProvider({ children }) { upVoteComment, cancelUpVoteComment, createPostProxyComment, + createCommentProxyReply, }} > {children}