Skip to content

Commit 4eb6e97

Browse files
committed
fix: comment data not reload, #5008
1 parent 9d65dc8 commit 4eb6e97

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

packages/next-common/components/actions/commentActions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { useUser } from "next-common/context/user";
1010
import useMentionList from "next-common/utils/hooks/useMentionList";
1111
import { getFocusEditor, getOnReply } from "next-common/utils/post";
1212
import { useChain } from "next-common/context/chain";
13-
import { usePageProps } from "next-common/context/page";
13+
import { useComments } from "next-common/context/post/comments";
1414
import { noop } from "lodash-es";
1515
import { useDispatch } from "react-redux";
1616
import { newErrorToast } from "next-common/store/reducers/toastSlice";
@@ -48,7 +48,7 @@ export default function CommentActions({
4848
user?.preference?.editor || "markdown",
4949
);
5050
const [isReply, setIsReply] = useState(false);
51-
const { comments } = usePageProps();
51+
const comments = useComments();
5252

5353
const users = useMentionList(post, comments);
5454

packages/next-common/hooks/usePostCommentsFilteredData.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useMemo, useState } from "react";
1+
import { useEffect, useMemo, useState } from "react";
22
import { usePostCommentsData } from "./usePostComments";
33
import { useContextApi } from "next-common/context/api";
44
import { cloneDeep, every, has, map, orderBy, filter } from "lodash-es";
@@ -7,9 +7,9 @@ import { useGetAddressVotesDataFn } from "./useAddressVotesData";
77
import { getAddressVotingBalance } from "next-common/utils/referendumUtil";
88
import { useCommittedCommentFilterParams } from "next-common/components/comment/filter/utils";
99
import { useIsDVAddressFn } from "./useIsDVAddress";
10-
import { useShallowCompareEffect } from "react-use";
1110
import { defaultSortBy } from "next-common/components/comment/filter/sorter";
1211
import { usePostCommentsMerging } from "./usePostCommentsMerging";
12+
import { normalizeAddress } from "next-common/utils/address";
1313

1414
function isDeletedComment(comment) {
1515
return comment?.content?.trim?.() !== "[Deleted]";
@@ -30,13 +30,13 @@ export function usePostCommentsFilteredData() {
3030
const [, setCommentsMerging] = usePostCommentsMerging();
3131
const [mergedComments, setMergedComments] = useState(commentsData);
3232

33-
useShallowCompareEffect(() => {
33+
useEffect(() => {
3434
setCommentsMerging(
3535
!every(mergedComments.items, (item) => has(item, "balance")),
3636
);
37-
}, [mergedComments.items]);
37+
}, [mergedComments.items, setCommentsMerging]);
3838

39-
useShallowCompareEffect(() => {
39+
useEffect(() => {
4040
const data = cloneDeep(commentsData);
4141

4242
merge();
@@ -55,12 +55,20 @@ export function usePostCommentsFilteredData() {
5555
).toNumber();
5656

5757
// merge balance
58-
if (api) {
59-
if (address) {
60-
item.balance = await getAddressVotingBalance(api, address);
61-
} else {
62-
item.balance = 0;
58+
try {
59+
if (api) {
60+
if (address) {
61+
const normalizedAddress = normalizeAddress(address);
62+
item.balance = await getAddressVotingBalance(
63+
api,
64+
normalizedAddress,
65+
);
66+
} else {
67+
item.balance = 0;
68+
}
6369
}
70+
} catch (e) {
71+
console.error(e);
6472
}
6573

6674
return item;

packages/next-common/utils/referendumUtil.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function getThresholdOfSuperMajorityApprove(turnout, totalIssuance) {
4444
}
4545

4646
export async function getAddressVotingBalance(api, address) {
47-
const account = await api.query.system.account(address);
47+
const account = await api?.query.system?.account(address);
4848
const jsonAccount = account?.toJSON();
4949
return jsonAccount?.data?.free;
5050
}

0 commit comments

Comments
 (0)