@@ -34,45 +34,8 @@ export const ResourceCreditsInfo = (props: any) => {
34
34
const [ transferAmount , setTransferAmount ] = useState ( 0 ) ;
35
35
const [ customJsonAmount , setCustomJsonAmount ] = useState ( 0 ) ;
36
36
37
- useEffect ( ( ) => {
38
- findRcAccounts ( account . name )
39
- . then ( ( r ) => {
40
- const outGoing = r . map ( ( a : any ) => a . delegated_rc ) ;
41
- const delegated = outGoing [ 0 ] ;
42
- const formatOutGoing : any = rcFormatter ( delegated ) ;
43
- setDelegated ( formatOutGoing ) ;
44
- const availableResourceCredit : any = r . map ( ( a : any ) => Number ( a . rc_manabar . current_mana ) ) ;
45
- const inComing : any = r . map ( ( a : any ) => Number ( a . received_delegated_rc ) ) ;
46
- const formatIncoming = rcFormatter ( inComing ) ;
47
- const totalRc = Number ( availableResourceCredit ) + Number ( inComing ) ;
48
- setReceivedDelegation ( formatIncoming ) ;
49
- setResourceCredit ( totalRc ) ;
50
-
51
- const rcOperationsCost = async ( ) => {
52
- const rcStats : any = await getRcOperationStats ( ) ;
53
- const operationCosts = rcStats . rc_stats . ops ;
54
- const commentCost = operationCosts . comment_operation . avg_cost ;
55
- const transferCost = operationCosts . transfer_operation . avg_cost ;
56
- const voteCost = operationCosts . vote_operation . avg_cost ;
57
- const customJsonOperationsCosts = operationCosts . custom_json_operation . avg_cost ;
58
-
59
- const commentCount : number = Math . ceil ( Number ( availableResourceCredit ) / commentCost ) ;
60
- const votetCount : number = Math . ceil ( Number ( availableResourceCredit ) / voteCost ) ;
61
- const transferCount : number = Math . ceil ( Number ( availableResourceCredit ) / transferCost ) ;
62
- const customJsonCount : number = Math . ceil (
63
- Number ( availableResourceCredit ) / customJsonOperationsCosts
64
- ) ;
65
- setCommentAmount ( commentCount ) ;
66
- setVoteAmount ( votetCount ) ;
67
- setTransferAmount ( transferCount ) ;
68
- setCustomJsonAmount ( customJsonCount ) ;
69
- } ;
70
- rcOperationsCost ( ) ;
71
- } )
72
- . catch ( console . log ) ;
73
- } , [ ] ) ;
74
-
75
37
const showModal = ( ) => {
38
+ fetchRCData ( ) ;
76
39
setShowRcInfo ( true ) ;
77
40
} ;
78
41
@@ -114,6 +77,44 @@ export const ResourceCreditsInfo = (props: any) => {
114
77
setShowConfirmDelete ( false ) ;
115
78
} ;
116
79
80
+ const fetchRCData = ( ) => {
81
+ findRcAccounts ( account . name )
82
+ . then ( ( r ) => {
83
+ const outGoing = r . map ( ( a : any ) => a . delegated_rc ) ;
84
+ const delegated = outGoing [ 0 ] ;
85
+ const formatOutGoing : any = rcFormatter ( delegated ) ;
86
+ setDelegated ( formatOutGoing ) ;
87
+ const availableResourceCredit : any = r . map ( ( a : any ) => Number ( a . rc_manabar . current_mana ) ) ;
88
+ const inComing : any = r . map ( ( a : any ) => Number ( a . received_delegated_rc ) ) ;
89
+ const formatIncoming = rcFormatter ( inComing ) ;
90
+ const totalRc = Number ( availableResourceCredit ) + Number ( inComing ) ;
91
+ setReceivedDelegation ( formatIncoming ) ;
92
+ setResourceCredit ( totalRc ) ;
93
+
94
+ const rcOperationsCost = async ( ) => {
95
+ const rcStats : any = await getRcOperationStats ( ) ;
96
+ const operationCosts = rcStats . rc_stats . ops ;
97
+ const commentCost = operationCosts . comment_operation . avg_cost ;
98
+ const transferCost = operationCosts . transfer_operation . avg_cost ;
99
+ const voteCost = operationCosts . vote_operation . avg_cost ;
100
+ const customJsonOperationsCosts = operationCosts . custom_json_operation . avg_cost ;
101
+
102
+ const commentCount : number = Math . ceil ( Number ( availableResourceCredit ) / commentCost ) ;
103
+ const votetCount : number = Math . ceil ( Number ( availableResourceCredit ) / voteCost ) ;
104
+ const transferCount : number = Math . ceil ( Number ( availableResourceCredit ) / transferCost ) ;
105
+ const customJsonCount : number = Math . ceil (
106
+ Number ( availableResourceCredit ) / customJsonOperationsCosts
107
+ ) ;
108
+ setCommentAmount ( commentCount ) ;
109
+ setVoteAmount ( votetCount ) ;
110
+ setTransferAmount ( transferCount ) ;
111
+ setCustomJsonAmount ( customJsonCount ) ;
112
+ } ;
113
+ rcOperationsCost ( ) ;
114
+ } )
115
+ . catch ( console . log ) ;
116
+ } ;
117
+
117
118
return (
118
119
< div >
119
120
< div className = "cursor-pointer d-flex flex-column mb-1" onClick = { showModal } >
0 commit comments