1
- import { useMemo , useState } from "react" ;
1
+ import { useEffect , useMemo , useState } from "react" ;
2
2
import { usePostCommentsData } from "./usePostComments" ;
3
3
import { useContextApi } from "next-common/context/api" ;
4
4
import { cloneDeep , every , has , map , orderBy , filter } from "lodash-es" ;
@@ -7,9 +7,9 @@ import { useGetAddressVotesDataFn } from "./useAddressVotesData";
7
7
import { getAddressVotingBalance } from "next-common/utils/referendumUtil" ;
8
8
import { useCommittedCommentFilterParams } from "next-common/components/comment/filter/utils" ;
9
9
import { useIsDVAddressFn } from "./useIsDVAddress" ;
10
- import { useShallowCompareEffect } from "react-use" ;
11
10
import { defaultSortBy } from "next-common/components/comment/filter/sorter" ;
12
11
import { usePostCommentsMerging } from "./usePostCommentsMerging" ;
12
+ import { normalizeAddress } from "next-common/utils/address" ;
13
13
14
14
function isDeletedComment ( comment ) {
15
15
return comment ?. content ?. trim ?. ( ) !== "[Deleted]" ;
@@ -30,13 +30,13 @@ export function usePostCommentsFilteredData() {
30
30
const [ , setCommentsMerging ] = usePostCommentsMerging ( ) ;
31
31
const [ mergedComments , setMergedComments ] = useState ( commentsData ) ;
32
32
33
- useShallowCompareEffect ( ( ) => {
33
+ useEffect ( ( ) => {
34
34
setCommentsMerging (
35
35
! every ( mergedComments . items , ( item ) => has ( item , "balance" ) ) ,
36
36
) ;
37
- } , [ mergedComments . items ] ) ;
37
+ } , [ mergedComments . items , setCommentsMerging ] ) ;
38
38
39
- useShallowCompareEffect ( ( ) => {
39
+ useEffect ( ( ) => {
40
40
const data = cloneDeep ( commentsData ) ;
41
41
42
42
merge ( ) ;
@@ -55,12 +55,20 @@ export function usePostCommentsFilteredData() {
55
55
) . toNumber ( ) ;
56
56
57
57
// 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
+ }
63
69
}
70
+ } catch ( e ) {
71
+ console . error ( e ) ;
64
72
}
65
73
66
74
return item ;
0 commit comments