@@ -24,7 +24,9 @@ interface ContractRowProps {
24
24
const ContractRow = ( { contract, i } : ContractRowProps ) => {
25
25
//---------------------------------Connect to contract---------------------------------
26
26
const blockHeader = useBlockHeader ( ) ;
27
- const _contract = useContract ( contract . address , metadata , 'rococo-contracts-testnet' ) ;
27
+
28
+ const _contract = useContract ( contract . address , metadata ) ;
29
+
28
30
//---------------------------------UseStates---------------------------------
29
31
const [ loading , setLoading ] = useState < 'loading' | 'done' | 'error' > ( 'loading' ) ;
30
32
const [ amountBeneficiaries , setAmountBeneficiaries ] = useState < null | string [ ] > ( null ) ;
@@ -36,60 +38,35 @@ const ContractRow = ({ contract, i }: ContractRowProps) => {
36
38
37
39
//---------------------------------Api---------------------------------
38
40
const api = useApi ( 'rococo-contracts-testnet' ) ;
39
- const chainInfo = api ?. api . registry . getChainProperties ( ) . toHuman ( ) ;
40
-
41
- //---------------------------------Get from contract---------------------------------
42
- const getAmountBeneficiaries = useCall < any | undefined > ( _contract ?. contract , 'getListBeneficiaries' ) ;
43
-
44
- const getNextBlockPeriod = useCall < any | undefined > ( _contract ?. contract , 'getNextBlockPeriod' ) ;
45
-
46
- const getContractBalance = useCall < any | undefined > ( _contract ?. contract , 'getContractBalance' ) ;
47
-
48
- const getTotalDebts = useCall < any | undefined > ( _contract ?. contract , 'getTotalDebts' ) ;
49
-
50
- const getPeriodicity = useCall < any | undefined > ( _contract ?. contract , 'getPeriodicity' ) ;
51
41
52
- const getState = useCall < boolean | undefined > ( _contract ?. contract , 'isPaused' ) ;
42
+ const chainInfo = api ?. api . registry . getChainProperties ( ) ! . toHuman ( ) ;
53
43
54
- //---------------------------------Set in states---------------------------------
55
- const seeBeneficiaries = async ( ) => {
56
- const b = pickDecoded ( await getAmountBeneficiaries . send ( ) ) ;
57
- setAmountBeneficiaries ( b ) ;
58
- } ;
44
+ //---------------------------------Get from contract---------------------------------
45
+ const getAmountBeneficiaries = useCall < string [ ] > ( _contract , 'getListBeneficiaries' ) ;
59
46
60
- const seeContractBalance = async ( ) => {
61
- const contractBalance = pickDecoded ( await getContractBalance . send ( ) ) ;
62
- contractBalance !== undefined && setContractBalance ( parseInt ( contractBalance . replace ( / , / g, '' ) ) ) ;
63
- } ;
47
+ const getNextBlockPeriod = useCall ( _contract , 'getNextBlockPeriod' ) ;
64
48
65
- const seeNextBlockPeriod = async ( ) => {
66
- const nextPeriodString = pickDecoded ( await getNextBlockPeriod . send ( ) ) ;
67
- nextPeriodString !== undefined && setNextBlockPeriod ( parseInt ( await nextPeriodString . replace ( / , / g, '' ) ) ) ;
68
- } ;
49
+ const getContractBalance = useCall ( _contract , 'getContractBalance' ) ;
69
50
70
- const seeTotalDebts = async ( ) => setFundsNeeded ( pickDecoded ( await getTotalDebts . send ( ) ) ) ;
51
+ const getTotalDebts = useCall ( _contract , ' getTotalDebts' ) ;
71
52
72
- const seePeriodicity = async ( ) => setPeriodicity ( pickDecoded ( await getPeriodicity . send ( ) ) ) ;
53
+ // π€π€π€ Get periodicity from contract
54
+ const getPeriodicity = useCall ( _contract , 'getPeriodicity' ) ;
73
55
74
- const seeState = async ( ) => setState ( pickDecoded ( await getState . send ( ) ) ) ;
75
56
76
57
//---------------------------------Initialize functions---------------------------------
77
58
useEffect ( ( ) => {
78
- if ( blockHeader ?. blockNumber && _contract ?. contract !== undefined ) {
79
- seeBeneficiaries ( ) ;
80
- seeNextBlockPeriod ( ) ;
81
- seeContractBalance ( ) ;
82
- seeTotalDebts ( ) ;
83
- seePeriodicity ( ) ;
84
- seeState ( ) ;
59
+ if ( _contract ) {
60
+ getAmountBeneficiaries . send ( ) ;
61
+ getContractBalance . send ( ) ;
62
+ getNextBlockPeriod . send ( ) ;
63
+ getTotalDebts . send ( ) ;
64
+ getPeriodicity . send ( ) ;
85
65
setLoading ( 'done' ) ;
86
66
}
87
- } , [ blockHeader ?. blockNumber , _contract ] ) ;
67
+ } , [ _contract ] ) ;
88
68
89
- //---------------------------------See in console---------------------------------
90
- useEffect ( ( ) => { } , [ ] ) ;
91
-
92
- //---------------------------------Truncate numbers---------------------------------
69
+ //---------------------------------Truncate numbers-------------------------------------
93
70
function trunc ( x : number , p = 0 ) {
94
71
var s = x . toString ( ) ;
95
72
var l = s . length ;
@@ -99,83 +76,95 @@ const ContractRow = ({ contract, i }: ContractRowProps) => {
99
76
}
100
77
101
78
return loading === 'done' ? (
102
- < Link href = { `/contracts/${ contract . address } ` } >
103
- < tr
104
- className = {
105
- i % 2 === 0
106
- ? `flex gap-[50px] items-center text-[14px] font-normal text-black tracking-[0.25px] ${ archivo . className } hover:bg-opwhite transition duration-150 px-1`
107
- : `flex gap-[50px] items-center text-[14px] bg-[#ECECEC] font-normal text-black tracking-[0.25px] ${ archivo . className } hover:bg-opwhite transition duration-150 px-1`
108
- }
109
- >
110
- < td className = "w-[150px]" >
111
- < p > { contract . name } </ p >
112
- </ td >
113
- < td className = "w-[100px]" >
114
- { amountBeneficiaries ? (
115
- < p > { amountBeneficiaries . length } </ p >
116
- ) : (
117
- < div className = "flex items-center w-full" >
118
- < AiOutlineLoading className = "animate-spin" />
119
- </ div >
120
- ) }
121
- </ td >
122
- < td className = "w-[80px]" >
123
- { periodicity ? (
124
- < p > { periodicity } </ p >
125
- ) : (
126
- < div className = "flex items-center w-full" >
127
- < AiOutlineLoading className = "animate-spin" />
128
- </ div >
129
- ) }
130
- </ td >
131
- < td className = "w-[80px]" >
132
- { contractBalance !== null ? (
133
- < p className = "text-ellipsis" >
134
- { trunc ( Math . pow ( contractBalance * 10 , parseInt ( chainInfo . tokenDecimals [ 0 ] ) ) , 2 ) } { chainInfo ?. tokenSymbol }
135
- </ p >
136
- ) : (
137
- < div className = "flex items-center w-full" >
138
- < AiOutlineLoading className = "animate-spin" />
139
- </ div >
140
- ) }
141
- </ td >
142
- < td className = "w-[80px]" >
143
- { fundsNeeded !== null && chainInfo !== undefined ? (
144
- < p className = "text-ellipsis" >
145
- { trunc ( Math . pow ( parseInt ( fundsNeeded ) * 10 , parseInt ( chainInfo . tokenDecimals [ 0 ] ) ) , 2 ) } { ' ' }
146
- { chainInfo ?. tokenSymbol }
147
- </ p >
148
- ) : (
149
- < div className = "flex items-center w-full h-full" >
150
- < AiOutlineLoading className = "animate-spin" />
151
- </ div >
152
- ) }
153
- </ td >
154
- < td className = "w-[80px]" >
155
- { /* π€π€π€ Calculate real next pay day π€π€π€ */ }
156
- { nextBlockPeriod !== null ? (
157
- < p className = "text-ellipsis" > { trunc ( nextBlockPeriod / periodicity / 7200 ) } </ p >
158
- ) : (
159
- < div className = "flex items-center w-full" >
160
- < AiOutlineLoading className = "animate-spin" />
161
- </ div >
162
- ) }
163
- </ td >
164
- < td className = "w-[80px]" >
165
- { /* π€π€π€ Show network π€π€π€ */ }
166
- < p > network</ p >
167
- </ td >
168
- < td className = "w-[80px]" > { state !== undefined && state ? < p > paused</ p > : < p > running</ p > } </ td >
169
- < td className = "w-[100px]" >
170
- < Link href = { `/contracts/${ contract . address } ` } >
171
- < Button type = "text" text = "view" icon = "" />
172
- </ Link >
173
- </ td >
174
- < td className = "w-[100px]" >
175
- < IoIosAlert className = "w-5 h-5 text-opdanger" />
176
- </ td >
177
- </ tr >
178
- </ Link >
79
+
80
+ < tr
81
+ className = {
82
+ i % 2 === 0
83
+ ? `flex gap-[50px] items-center px-3 text-[14px] font-normal text-black tracking-[0.25px] ${ archivo . className } `
84
+ : `flex gap-[50px] items-center px-3 text-[14px] bg-[#ECECEC] font-normal text-black tracking-[0.25px] ${ archivo . className } `
85
+ }
86
+ >
87
+ < td className = "w-[150px]" >
88
+ < p > { contract . name } </ p >
89
+ </ td >
90
+ < td className = "w-[100px]" >
91
+ { getAmountBeneficiaries ? (
92
+ < p > { pickDecoded ( getAmountBeneficiaries . result ! ) ?. length } </ p >
93
+ ) : (
94
+ < div className = "flex items-center w-full" >
95
+ < AiOutlineLoading className = "animate-spin" />
96
+ </ div >
97
+ ) }
98
+ </ td >
99
+ < td className = "w-[80px]" >
100
+ { periodicity ? (
101
+ < p > { getPeriodicity . result ?. ok } </ p >
102
+ ) : (
103
+ < div className = "flex items-center w-full" >
104
+ < AiOutlineLoading className = "animate-spin" />
105
+ </ div >
106
+ ) }
107
+ </ td >
108
+ < td className = "w-[80px]" >
109
+ { contractBalance !== null ? (
110
+ < p className = "text-ellipsis overflow-hidden" >
111
+ { trunc (
112
+ Math . pow (
113
+ contractBalance * 10 ,
114
+ // parseInt(chainInfo?.tokenDecimals[0])
115
+ 2 , //TODO remove this
116
+ ) ,
117
+ 2 ,
118
+ ) } { ' ' }
119
+ { chainInfo ?. tokenSymbol ?. toString ( ) }
120
+ </ p >
121
+ ) : (
122
+ < div className = "flex items-center w-full" >
123
+ < AiOutlineLoading className = "animate-spin" />
124
+ </ div >
125
+ ) }
126
+ </ td >
127
+ < td className = "w-[80px]" >
128
+ { fundsNeeded !== null && chainInfo !== undefined ? (
129
+ < p className = "text-ellipsis overflow-hidden" >
130
+ { trunc ( Math . pow ( parseInt ( fundsNeeded ) * 10 , parseInt ( chainInfo . tokenDecimals [ 0 ] ) ) , 2 ) } { ' ' }
131
+ { chainInfo ?. tokenSymbol ?. toString ( ) }
132
+ </ p >
133
+ ) : (
134
+ < div className = "flex items-center w-full" >
135
+ < AiOutlineLoading className = "animate-spin" />
136
+ </ div >
137
+ ) }
138
+ </ td >
139
+ < td className = "w-[80px]" >
140
+ { /* π€π€π€ Calculate real next pay day π€π€π€ */ }
141
+ { nextBlockPeriod !== null ? (
142
+ < p className = "text-ellipsis overflow-hidden" > { trunc ( nextBlockPeriod / periodicity / 7200 ) } </ p >
143
+ ) : (
144
+ < div className = "flex items-center w-full" >
145
+ < AiOutlineLoading className = "animate-spin" />
146
+ </ div >
147
+ ) }
148
+ </ td >
149
+ < td className = "w-[80px]" >
150
+ { /* π€π€π€ Show network π€π€π€ */ }
151
+ < p > network</ p >
152
+ </ td >
153
+ < td className = "w-[80px]" >
154
+ { /* π€π€π€ Show state π€π€π€ */ }
155
+
156
+ < p > state</ p >
157
+ </ td >
158
+ < td className = "w-[100px]" >
159
+ < Link href = { `/contracts/${ contract . address } ` } >
160
+ < Button type = "text" text = "view" icon = "" />
161
+ </ Link >
162
+ </ td >
163
+ < td className = "w-[100px]" >
164
+ < IoIosAlert className = "w-5 h-5 text-opdanger" />
165
+ </ td >
166
+ </ tr >
167
+
179
168
) : (
180
169
< div className = "flex items-center w-full" >
181
170
< AiOutlineLoading className = "w-5 h-5 animate-spin mx-auto my-2" />
0 commit comments