11import React , { PureComponent } from "react" ;
22import { Link } from "react-router-dom" ;
33import { If , Then , Else } from "react-if" ;
4- import { Row , Col , Button , Avatar , Tag , Typography , message , Icon } from "antd" ;
4+ import { Row , Col , Button , Avatar , Tag , Typography , message } from "antd" ;
55import queryString from "query-string" ;
66import { EditOutlined , TeamOutlined } from "@ant-design/icons" ;
77
88import StatisticalData from "@components/StatisticalData/" ;
9- import { getTeamDesc , fetchElectorVoteWithRecords } from "@api/vote" ;
9+ import {
10+ getTeamDesc ,
11+ fetchElectorVoteWithRecords ,
12+ fetchPageableCandidateInformation ,
13+ fetchCount ,
14+ } from "@api/vote" ;
1015import { fetchCurrentMinerPubkeyList } from "@api/consensus" ;
1116import {
1217 FROM_WALLET ,
@@ -28,6 +33,8 @@ const clsPrefix = "team-detail";
2833
2934const ellipsis = { rows : 1 } ;
3035
36+ const TableItemCount = 20 ;
37+
3138class TeamDetail extends PureComponent {
3239 constructor ( props ) {
3340 super ( props ) ;
@@ -106,18 +113,30 @@ class TeamDetail extends PureComponent {
106113 this . fetchTheUsersActiveVoteRecords ( ) ;
107114 }
108115
109- fetchAllCandidateInfo ( ) {
110- const { electionContract } = this . props ;
116+ async fetchTotal ( ) {
117+ const res = await fetchCount ( this . props . electionContract , "" ) ;
118+ const total = res . value ?. length || 0 ;
119+ return total ;
120+ }
111121
112- electionContract . GetPageableCandidateInformation . call ( {
113- start : 0 ,
114- length : A_NUMBER_LARGE_ENOUGH_TO_GET_ALL , // give a number large enough to make sure that we get all the nodes
115- // FIXME: [unstable] sometimes any number large than 5 assign to length will cost error when fetch data
116- } )
117- . then ( ( res ) => this . processAllCandidateInfo ( res . value ) )
118- . catch ( ( err ) => {
119- console . error ( err ) ;
120- } ) ;
122+ async fetchAllCandidateInfo ( ) {
123+ try {
124+ const total = await this . fetchTotal ( ) ;
125+ const { electionContract } = this . props ;
126+ let start = 0 ;
127+ let result = [ ] ;
128+ while ( start <= total ) {
129+ const res = await fetchPageableCandidateInformation ( electionContract , {
130+ start,
131+ length : TableItemCount ,
132+ } ) ;
133+ result = result . concat ( res . value ) ;
134+ start += 20 ;
135+ }
136+ this . processAllCandidateInfo ( result ) ;
137+ } catch ( e ) {
138+ console . error ( e ) ;
139+ }
121140 }
122141
123142 processAllCandidateInfo ( allCandidateInfo ) {
@@ -257,21 +276,21 @@ class TeamDetail extends PureComponent {
257276 return (
258277 < section className = { `${ clsPrefix } -header card-container` } >
259278 < Row >
260- < Col md = { 18 } sm = { 24 } xs = { 24 } className = ' card-container-left' >
279+ < Col md = { 18 } sm = { 24 } xs = { 24 } className = " card-container-left" >
261280 < Row className = { `${ clsPrefix } -team-avatar-info` } >
262- < Col md = { 6 } sm = { 6 } xs = { 6 } className = ' team-avatar-container' >
281+ < Col md = { 6 } sm = { 6 } xs = { 6 } className = " team-avatar-container" >
263282 { data . avatar ? (
264- < Avatar shape = ' square' size = { avatarSize } src = { data . avatar } />
283+ < Avatar shape = " square" size = { avatarSize } src = { data . avatar } />
265284 ) : (
266- < Avatar shape = ' square' size = { avatarSize } >
285+ < Avatar shape = " square" size = { avatarSize } >
267286 U
268287 </ Avatar >
269288 ) }
270289 </ Col >
271290 < Col className = { `${ clsPrefix } -team-info` } md = { 18 } sm = { 18 } xs = { 18 } >
272291 < h5 className = { `${ clsPrefix } -node-name ellipsis` } >
273292 { data . name ? data . name : formattedAddress }
274- < Tag color = ' #f50' >
293+ < Tag color = " #f50" >
275294 { isBP ? "BP" : isCandidate ? "Candidate" : "Quited" }
276295 </ Tag >
277296 </ h5 >
@@ -290,8 +309,8 @@ class TeamDetail extends PureComponent {
290309 Official Website:
291310 < a
292311 href = { data . officialWebsite }
293- target = ' _blank'
294- rel = ' noreferrer noopener'
312+ target = " _blank"
313+ rel = " noreferrer noopener"
295314 >
296315 { data . officialWebsite }
297316 </ a >
@@ -304,16 +323,16 @@ class TeamDetail extends PureComponent {
304323 Email:
305324 < a
306325 href = { `mailto:${ data . mail } ` }
307- target = ' _blank'
308- rel = ' noreferrer noopener'
326+ target = " _blank"
327+ rel = " noreferrer noopener"
309328 >
310329 { data . mail }
311330 </ a >
312331 </ Paragraph >
313332 </ Then >
314333 </ If >
315334 { hasAuth ? (
316- < Button type = ' primary' shape = ' round' className = ' edit-btn' >
335+ < Button type = " primary" shape = " round" className = " edit-btn" >
317336 < Link
318337 to = { {
319338 pathname : "/vote/apply/keyin" ,
@@ -327,13 +346,13 @@ class TeamDetail extends PureComponent {
327346 </ Col >
328347 </ Row >
329348 </ Col >
330- < Col md = { 6 } xs = { 0 } className = ' card-container-right' >
349+ < Col md = { 6 } xs = { 0 } className = " card-container-right" >
331350 < Button
332- className = ' table-btn vote-btn'
333- type = ' primary'
334- shape = ' round'
351+ className = " table-btn vote-btn"
352+ type = " primary"
353+ shape = " round"
335354 disabled = { ! isCandidate }
336- data-role = ' vote'
355+ data-role = " vote"
337356 data-shoulddetectlock
338357 data-votetype = { FROM_WALLET }
339358 data-nodeaddress = { formattedAddress }
@@ -343,10 +362,10 @@ class TeamDetail extends PureComponent {
343362 Vote
344363 </ Button >
345364 < Button
346- className = ' table-btn redeem-btn'
347- type = ' primary'
348- shape = ' round'
349- data-role = ' redeem'
365+ className = " table-btn redeem-btn"
366+ type = " primary"
367+ shape = " round"
368+ data-role = " redeem"
350369 data-shoulddetectlock
351370 data-nodeaddress = { formattedAddress }
352371 data-targetpublickey = { this . teamPubkey }
@@ -372,43 +391,43 @@ class TeamDetail extends PureComponent {
372391 { topTeamInfo }
373392 < StatisticalData data = { staticsData } inline />
374393 < section className = { `${ clsPrefix } -intro card-container` } >
375- < h5 className = ' card-header' >
376- < EditOutlined className = ' card-header-icon' />
394+ < h5 className = " card-header" >
395+ < EditOutlined className = " card-header-icon" />
377396 Introduction
378397 </ h5 >
379- < div className = ' card-content' >
398+ < div className = " card-content" >
380399 < If condition = { ! ! data . intro } >
381400 < Then >
382401 < p > { data . intro } </ p >
383402 </ Then >
384403 < Else >
385- < div className = ' vote-team-detail-empty' >
404+ < div className = " vote-team-detail-empty" >
386405 The team didn't fill the introduction.
387406 </ div >
388407 </ Else >
389408 </ If >
390409 </ div >
391410 </ section >
392411 < section className = { `${ clsPrefix } -social-network card-container` } >
393- < h5 className = ' card-header' >
394- < TeamOutlined className = ' card-header-icon' />
412+ < h5 className = " card-header" >
413+ < TeamOutlined className = " card-header-icon" />
395414 Social Network
396415 </ h5 >
397- < div className = ' card-content' >
416+ < div className = " card-content" >
398417 < If condition = { ! ! ( data . socials && data . socials . length > 0 ) } >
399418 < Then >
400- < div className = ' vote-team-detail-social-network' >
419+ < div className = " vote-team-detail-social-network" >
401420 { ( data . socials || [ ] ) . map ( ( item ) => (
402- < div className = ' vote-team-detail-social-network-item' >
403- < span className = ' vote-team-detail-social-network-item-title' >
421+ < div className = " vote-team-detail-social-network-item" >
422+ < span className = " vote-team-detail-social-network-item-title" >
404423 { item . type }
405424 </ span >
406- < span className = ' vote-team-detail-social-network-item-url' >
425+ < span className = " vote-team-detail-social-network-item-url" >
407426 :
408427 < a
409428 href = { item . url }
410- target = ' _blank'
411- rel = ' noreferrer noopener'
429+ target = " _blank"
430+ rel = " noreferrer noopener"
412431 >
413432 { item . url }
414433 </ a >
@@ -418,7 +437,7 @@ class TeamDetail extends PureComponent {
418437 </ div >
419438 </ Then >
420439 < Else >
421- < span className = ' vote-team-detail-empty' >
440+ < span className = " vote-team-detail-empty" >
422441 The team didn't fill the social contacts.
423442 </ span >
424443 </ Else >
0 commit comments