Skip to content
Snippets Groups Projects
Commit 9d3ebe72 authored by Quoc Huy Nguyen Dinh's avatar Quoc Huy Nguyen Dinh
Browse files

Fix witness rank display & simplify witness owner display logic

parent bc5478f4
No related branches found
No related tags found
2 merge requests!142merge develop to master for new release,!140Fix witness rank display & simplify witness owner display logic
...@@ -246,13 +246,12 @@ class Witnesses extends React.Component { ...@@ -246,13 +246,12 @@ class Witnesses extends React.Component {
); );
}); });
let witness_vote_count = 30; let witness_vote_count = 30;
let rank = 0;
let foundWitnessToHighlight = false; let foundWitnessToHighlight = false;
let previousTotalVoteHpf = 0; let previousTotalVoteHpf = 0;
const now = Moment(); const now = Moment();
const processedWitnesses = sortedWitnesses.map((item) => { const processedWitnesses = sortedWitnesses.map((witnessEntry, witnessIndex) => {
const witnessName = item.get('owner'); const witnessName = witnessEntry.get('owner');
if (witnessName === witnessToHighlight) { if (witnessName === witnessToHighlight) {
foundWitnessToHighlight = true; foundWitnessToHighlight = true;
} }
...@@ -275,11 +274,11 @@ class Witnesses extends React.Component { ...@@ -275,11 +274,11 @@ class Witnesses extends React.Component {
.split(','); .split(',');
} }
witnessOwnerNames = witnessOwnerNames.filter((ownerName) => { witnessOwnerNames = witnessOwnerNames.filter((ownerName) => {
return ownerName !== item.get('owner'); return ownerName !== witnessEntry.get('owner');
}); });
} }
const totalVotesVests = item.get('votes'); const totalVotesVests = witnessEntry.get('votes');
const totalVotesHpf = vestsToHpf( const totalVotesHpf = vestsToHpf(
state, state,
`${totalVotesVests / 1000000} VESTS` `${totalVotesVests / 1000000} VESTS`
...@@ -300,12 +299,12 @@ class Witnesses extends React.Component { ...@@ -300,12 +299,12 @@ class Witnesses extends React.Component {
previousTotalVoteHpf = totalVotesHpf; previousTotalVoteHpf = totalVotesHpf;
const thread = item.get('url').replace('steemit.com', 'hive.blog'); const thread = witnessEntry.get('url').replace('steemit.com', 'hive.blog');
const myVote = witness_votes const myVote = witness_votes
? witness_votes.has(witnessName) ? witness_votes.has(witnessName)
: null; : null;
const signingKey = item.get('signing_key'); const signingKey = witnessEntry.get('signing_key');
let witnessCreated = item.get('created'); let witnessCreated = witnessEntry.get('created');
if (witnessCreated === '1970-01-01T00:00:00') { if (witnessCreated === '1970-01-01T00:00:00') {
witnessCreated = '2016-06-01T00:00:00'; witnessCreated = '2016-06-01T00:00:00';
} }
...@@ -327,10 +326,10 @@ class Witnesses extends React.Component { ...@@ -327,10 +326,10 @@ class Witnesses extends React.Component {
witnessAge = `${witnessAgeWeeks} ${tt('g.weeks')}`; witnessAge = `${witnessAgeWeeks} ${tt('g.weeks')}`;
} }
const lastBlock = item.get('last_confirmed_block_num'); const lastBlock = witnessEntry.get('last_confirmed_block_num');
const runningVersion = item.get('running_version'); const runningVersion = witnessEntry.get('running_version');
const hbdExchangeRate = item.get('hbd_exchange_rate'); const hbdExchangeRate = witnessEntry.get('hbd_exchange_rate');
const hbdExchangeUpdateDate = item.get('last_hbd_exchange_update'); const hbdExchangeUpdateDate = witnessEntry.get('last_hbd_exchange_update');
const noBlock7days = (head_block - lastBlock) * 3 > 604800; const noBlock7days = (head_block - lastBlock) * 3 > 604800;
const isDisabled = signingKey == DISABLED_SIGNING_KEY; const isDisabled = signingKey == DISABLED_SIGNING_KEY;
const votingActive = witnessVotesInProgress.has(witnessName); const votingActive = witnessVotesInProgress.has(witnessName);
...@@ -395,17 +394,22 @@ class Witnesses extends React.Component { ...@@ -395,17 +394,22 @@ class Witnesses extends React.Component {
// Don't display the witness // Don't display the witness
if ( if (
// If rank over 100 // If index over 100
rank > 100 witnessIndex > 100
// And no blocked produced for over 30 days // And no blocked produced for over 30 days
&& witnessLastBlockAgeInDays > witnessFilterLastBlockAgeThresholdInDays && witnessLastBlockAgeInDays > witnessFilterLastBlockAgeThresholdInDays
// And not voted by current user // And not voted by current user
&& !myVote && !myVote
) { ) {
rank += 1;
return null; return null;
} }
const rank = witnessIndex + 1;
const array2list = (array) => {
const lastElement = array.pop();
return array.length ? `${array.join(', ')} & ${lastElement}` : lastElement;
};
return ( return (
<tr <tr
key={witnessName} key={witnessName}
...@@ -415,13 +419,10 @@ class Witnesses extends React.Component { ...@@ -415,13 +419,10 @@ class Witnesses extends React.Component {
})} })}
> >
<td className="Witnesses__rank"> <td className="Witnesses__rank">
{rank < 10 && '0'} {rank < 10 ? `0${rank}` : rank}
{rank += 1}
&nbsp;&nbsp; &nbsp;&nbsp;
<span className={classUp}> <span className={classUp}>
{votingActive ? ( {votingActive ? up : (
up
) : (
<a <a
href="#" href="#"
onClick={accountWitnessVote.bind( onClick={accountWitnessVote.bind(
...@@ -444,9 +445,7 @@ class Witnesses extends React.Component { ...@@ -444,9 +445,7 @@ class Witnesses extends React.Component {
<Link <Link
to={`${$STM_Config.social_url}/@${witnessName}`} to={`${$STM_Config.social_url}/@${witnessName}`}
style={ownerStyle} style={ownerStyle}
title={tt( title={tt('witnesses_jsx.navigate_to_witness_profile')}
'witnesses_jsx.navigate_to_witness_profile'
)}
> >
<Userpic <Userpic
account={witnessName} account={witnessName}
...@@ -460,38 +459,12 @@ class Witnesses extends React.Component { ...@@ -460,38 +459,12 @@ class Witnesses extends React.Component {
<div> <div>
{witnessSocialLink(witnessName)} {witnessSocialLink(witnessName)}
{witnessOwnerNames && witnessOwnerNames.length > 0 && ( {witnessOwnerNames && witnessOwnerNames.length > 0 && (
<span> <span>
{' '} {' '}
{tt('witnesses_jsx.by')} {tt('witnesses_jsx.by')}
{' '} {' '}
{witnessOwnerNames.map( {array2list(witnessOwnerNames)}
(ownerName, index) => { </span>
if (
witnessOwnerNames.length > 1
&& index === witnessOwnerNames.length - 1
) {
return (
<span key={ownerName}>
{' '}
&
{' '}
{witnessSocialLink(
ownerName
)}
</span>
);
}
return (
<span key={ownerName}>
{index > 0 && ', '}
{witnessSocialLink(
ownerName
)}
</span>
);
}
)}
</span>
)} )}
<Link <Link
to={`/~witnesses?highlight=${witnessName}`} to={`/~witnesses?highlight=${witnessName}`}
...@@ -501,9 +474,7 @@ class Witnesses extends React.Component { ...@@ -501,9 +474,7 @@ class Witnesses extends React.Component {
witnessName, witnessName,
]); ]);
}} }}
title={tt( title={tt('witnesses_jsx.link_to_highlight_witness')}
'witnesses_jsx.link_to_highlight_witness'
)}
> >
<Icon <Icon
name="chain" name="chain"
...@@ -519,15 +490,11 @@ class Witnesses extends React.Component { ...@@ -519,15 +490,11 @@ class Witnesses extends React.Component {
<strong> <strong>
<span <span
role="img" role="img"
aria-label={tt( aria-label={tt('witnesses_jsx.not_produced_over_a_week')}
'witnesses_jsx.not_produced_over_a_week'
)}
> >
⚠️ ⚠️
</span> </span>
{tt( {tt('witnesses_jsx.not_produced_over_a_week')}
'witnesses_jsx.not_produced_over_a_week'
)}
</strong> </strong>
</div> </div>
)} )}
...@@ -543,14 +510,11 @@ class Witnesses extends React.Component { ...@@ -543,14 +510,11 @@ class Witnesses extends React.Component {
to={`https://hiveblocks.com/b/${lastBlock}`} to={`https://hiveblocks.com/b/${lastBlock}`}
target="_blank" target="_blank"
> >
# {`#${lastBlock}`}
{lastBlock}
</Link> </Link>
{' '} {' '}
{blockGap(head_block, lastBlock)} {blockGap(head_block, lastBlock)}
{' '} {` on v${runningVersion}`}
on v
{runningVersion}
</div> </div>
{isDisabled && ( {isDisabled && (
<div> <div>
...@@ -564,9 +528,7 @@ class Witnesses extends React.Component { ...@@ -564,9 +528,7 @@ class Witnesses extends React.Component {
)} )}
{!isDisabled && ( {!isDisabled && (
<div> <div>
{`${tt( {`${tt('witnesses_jsx.witness_age')}: ${witnessAge}`}
'witnesses_jsx.witness_age'
)}: ${witnessAge}`}
</div> </div>
)} )}
</small> </small>
...@@ -627,11 +589,7 @@ class Witnesses extends React.Component { ...@@ -627,11 +589,7 @@ class Witnesses extends React.Component {
) : ( ) : (
<a <a
href="#" href="#"
onClick={accountWitnessVote.bind( onClick={accountWitnessVote.bind(this, item, false)}
this,
item,
false
)}
title={tt('g.remove_vote')} title={tt('g.remove_vote')}
> >
{up} {up}
...@@ -657,16 +615,11 @@ class Witnesses extends React.Component { ...@@ -657,16 +615,11 @@ class Witnesses extends React.Component {
<div> <div>
<p> <p>
<strong> <strong>
{tt( {tt('witnesses_jsx.you_have_votes_remaining', { count: witness_vote_count })}
'witnesses_jsx.you_have_votes_remaining',
{ count: witness_vote_count }
)}
. .
</strong> </strong>
{' '} {' '}
{tt( {tt('witnesses_jsx.you_can_vote_for_maximum_of_witnesses')}
'witnesses_jsx.you_can_vote_for_maximum_of_witnesses'
)}
. .
</p> </p>
<p>{tt('witnesses_jsx.witness_list_notes')}</p> <p>{tt('witnesses_jsx.witness_list_notes')}</p>
...@@ -704,9 +657,7 @@ class Witnesses extends React.Component { ...@@ -704,9 +657,7 @@ class Witnesses extends React.Component {
> >
<div className="column"> <div className="column">
<p> <p>
{tt( {tt('witnesses_jsx.if_you_want_to_vote_outside_of_top_enter_account_name')}
'witnesses_jsx.if_you_want_to_vote_outside_of_top_enter_account_name'
)}
. .
</p> </p>
<form> <form>
...@@ -734,11 +685,7 @@ class Witnesses extends React.Component { ...@@ -734,11 +685,7 @@ class Witnesses extends React.Component {
onClick={accountWitnessVote.bind( onClick={accountWitnessVote.bind(
this, this,
customUsername, customUsername,
!(witness_votes !(witness_votes ? witness_votes.has(customUsername) : null)
? witness_votes.has(
customUsername
)
: null)
)} )}
> >
{tt('g.vote')} {tt('g.vote')}
...@@ -790,9 +737,7 @@ class Witnesses extends React.Component { ...@@ -790,9 +737,7 @@ class Witnesses extends React.Component {
className="button" className="button"
onClick={accountWitnessProxy} onClick={accountWitnessProxy}
> >
{tt( {tt('witnesses_jsx.witness_proxy_clear')}
'witnesses_jsx.witness_proxy_clear'
)}
</button> </button>
</div> </div>
</div> </div>
...@@ -824,9 +769,7 @@ class Witnesses extends React.Component { ...@@ -824,9 +769,7 @@ class Witnesses extends React.Component {
className="button" className="button"
onClick={accountWitnessProxy} onClick={accountWitnessProxy}
> >
{tt( {tt('witnesses_jsx.witness_proxy_set')}
'witnesses_jsx.witness_proxy_set'
)}
</button> </button>
</div> </div>
</div> </div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment