Skip to content

Commit

Permalink
Merge branch 'main' into add-jail-badges
Browse files Browse the repository at this point in the history
  • Loading branch information
robcxyz authored Jan 23, 2024
2 parents e11e0bc + 91ca4a6 commit 47236b7
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 15 deletions.
14 changes: 4 additions & 10 deletions src/components/AddressesPage/AddressDetailPage/AddressInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ const { nid } = config;
const { requestUnjail } = chainMethods;
const _isNotificationAvailable = NotificationManager.available()

const TEST_VARIABLE = true;

function AddressInfo(props) {
const [icxMore, setIcxMore] = useState(false)
const [tokenMore, setTokenMore] = useState(false)
Expand Down Expand Up @@ -251,13 +249,9 @@ function AddressInfo(props) {

async function getRev() {
const rev = await getRevision();
// if chain revision is higher than rev 25 then
// if chain revision is higher than rev 25 then
// unjail functionality is available
if(TEST_VARIABLE === true) {
setChainCanJail(true);
} else {
setChainCanJail(parseInt(rev, 16) >= 25);
}
setChainCanJail(parseInt(rev, 16) >= 25);
}

async function executeUnjail() {
Expand Down Expand Up @@ -456,7 +450,7 @@ function AddressInfo(props) {
{(chainCanJail && is_prep && isConnected) || TEST_VARIABLE ? (
<span>
<button
disabled={TEST_VARIABLE === true ? false : !is_prep || !isConnected}
disabled={!is_prep || !isConnected}
onClick={executeUnjail}
className={compStyles.button}
>
Expand All @@ -472,7 +466,7 @@ function AddressInfo(props) {
<td>Total Votes</td>
<td colSpan="3">
<span>
{convertNumberToText(delegated)}
{convertNumberToText(Math.round(delegated))}

<em>
( {(totalVotes * 100).toPrecision(3)}% )
Expand Down
32 changes: 27 additions & 5 deletions src/components/GovernancePage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ class TableRow extends Component {
loadImage = () => {
this.setState({loaded: true})
}
getBadge = (grade, node_state ) => {
getMainBadge = (grade, node_state ) => {
const className = node_state === 'Synced' ? 'prep-tag' : node_state === 'Inactive'? 'prep-tag off' : 'prep-tag block-synced'
switch(grade) {
case 0:
Expand All @@ -377,6 +377,22 @@ class TableRow extends Component {
return null
}
}
// We only care on the table view if a prep is un-jailing or jailed.
getJailBadge = (jail_flag) => {
let badgeText = '';
let badgeClass = '';
if (jail_flag === 0) {
return false;
}
if ([2, 3, 6, 10].includes(jail_flag)) {
badgeText = 'Unjailing';
badgeClass = 'unjailing';
} else {
badgeText = 'Jail';
badgeClass = 'jail';
}
return <div><span className={`jail-badge ${badgeClass}`}>{badgeText}</span></div>;
}
goAddress = address => {
this.props.history.push('/address/' + address)
}
Expand Down Expand Up @@ -415,6 +431,7 @@ class TableRow extends Component {
irep,
irepUpdatedBlockHeight,
node_state,
jail_flags,
logo,
status,
reward_monthly, reward_monthly_usd,
Expand All @@ -430,15 +447,20 @@ class TableRow extends Component {
const productivity = !total_blocks || Number(total_blocks) === 0 ? 'None' : (Number(validated_blocks) === 0 ? '0.00%' : `${(Number(validated_blocks) / Number(total_blocks) * 100).toFixed(2)}%`)
const prepVoted = IconConverter.toNumber(delegated || 0)
const votedRate = !totalVoted ? 0 : prepVoted / totalVoted
const badge = this.getBadge(grade, prep.node_state)
const mainBadge = this.getMainBadge(grade, prep.node_state)

const jailBadge = this.getJailBadge(parseInt(prep.jail_flags, 16))
const rank = index + 1
return(
<tr>
<td className="rank"><span>{rank || '-'}</span></td>
<td className={(Number(grade) > 2 || grade === '0x3') ? 'black' : 'on'}>
<ul>
<li>{badge}</li>
<li>{logo_256 ? <img src={logo_256 ? logo_256 : logo_svg} onError={this.onError} onLoad={this.loadImage} style={this.state.loaded ? {} : {display: "none"}} alt='logo'/>:""}</li>
<ul className="prep-info-list">
<li>
{mainBadge}
{jailBadge}
</li>
<li>{logo_256 && <img src={logo_256} onError={this.onError} onLoad={this.loadImage} style={this.state.loaded ? {} : {display: "none"}} alt='logo'/>}</li>
<li>
<span className="ellipsis pointer" onClick={()=>{this.goAddress(address)}}>{name}</span>
<em className="ellipsis pointer" onClick={()=>{this.goAddress(address)}}>{address}</em>
Expand Down
33 changes: 33 additions & 0 deletions src/style/css/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -3391,6 +3391,39 @@ table.table-typeP th .itag i{width:14px; height: 14px; background-position: -150
background: #fff;
border: 1px solid #ececec;
}

.jail-badge {
display: inline-block;
color: #1aaaba;
padding: 4px 10px 4px 6px;
border-radius: 4px;
font-size: 9px;
border: 1px solid #d8edf0;
vertical-align: middle;
margin-top: 10px;
height: 18px;
}

.jail-badge:before {
content: '';
width: 6px;
height: 6px;
background: #1aaaba;
border-radius: 50%;
display: inline-block;
margin-right: 6px;
}

.jail-badge.jail {
background: #ececec;
color: #1aaaba;
}
.jail-badge.unjailing {
background-color: white;
color: #1aaaba;
padding: 2px;
border-radius: 4px;
}
.table-typeP .ellipsis {
width: 380px;
}
Expand Down

0 comments on commit 47236b7

Please sign in to comment.