Skip to content

Commit

Permalink
staked tokens fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
SrikanthSoparla committed Dec 3, 2024
1 parent b23a9ed commit 549db02
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 35 deletions.
14 changes: 11 additions & 3 deletions src/containers/Home/TokenDetails/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@ import { config } from '../../../config';
// import { gas } from '../../../defaultGasValues';

const TokenDetails = (props) => {
const staked = props.delegations && props.delegations.reduce((accumulator, currentValue) => {
if (currentValue && currentValue.length && currentValue[2]) {
return accumulator + Number(currentValue[2]);
let staked = props.delegatedValidatorList && props.delegatedValidatorList.reduce((accumulator, currentValue) => {
if (currentValue && currentValue.minDenomAmount) {
return accumulator + Number(currentValue.minDenomAmount);
}
}, 0);
staked = staked && staked / 10 ** config.COIN_DECIMALS;
// const staked = props.delegations && props.delegations.reduce((accumulator, currentValue) => {
// if (currentValue && currentValue.length && currentValue[2]) {
// return accumulator + Number(currentValue[2]);
// }
// }, 0);
let balance = null;
props.balance && props.balance.length && props.balance.map((val) => {
if (val && val.length) {
Expand Down Expand Up @@ -104,6 +110,7 @@ TokenDetails.propTypes = {
balance: PropTypes.array.isRequired,
balanceInProgress: PropTypes.bool.isRequired,
delegations: PropTypes.array.isRequired,
delegatedValidatorList: PropTypes.array.isRequired,
delegationsInProgress: PropTypes.bool.isRequired,
lang: PropTypes.string.isRequired,
rewards: PropTypes.shape({
Expand All @@ -126,6 +133,7 @@ TokenDetails.propTypes = {
const stateToProps = (state) => {
return {
delegations: state.accounts.delegations.result,
delegatedValidatorList: state.stake.delegatedValidators.list,
delegationsInProgress: state.accounts.delegations.inProgress,
balance: state.accounts.balance.result,
balanceInProgress: state.accounts.balance.inProgress,
Expand Down
29 changes: 21 additions & 8 deletions src/containers/Stake/DelegateDialog/TokensTextField.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,29 @@ const TokensTextField = (props) => {
// const available = (balance && balance.amount && Number(balance.amount));
// const availableTokens = available / (10 ** config.COIN_DECIMALS);
const availableTokens = balance;
let stakedTokens = props.delegations && props.delegations.reduce((accumulator, currentValue) => {
if (currentValue && currentValue.length && currentValue[2]) {
return accumulator + Number(currentValue[2]);
// let stakedTokens = props.delegations && props.delegations.reduce((accumulator, currentValue) => {
// if (currentValue && currentValue.length && currentValue[2]) {
// return accumulator + Number(currentValue[2]);
// }
// }, 0);

let stakedTokens = props.delegatedValidatorList && props.delegatedValidatorList.reduce((accumulator, currentValue) => {
if (currentValue && currentValue.minDenomAmount) {
return accumulator + Number(currentValue.minDenomAmount);
}
}, 0);

stakedTokens = stakedTokens && stakedTokens / 10 ** config.COIN_DECIMALS;
if (props.selectedValidator && (props.name === 'Undelegate' || props.name === 'Redelegate')) {
const filterList = props.delegations.find((value) => value && value.length && value[1] &&
(props.selectedValidator === value[1]));
// const filterList = props.delegations.find((value) => value && value.length && value[1] &&
// (props.selectedValidator === value[1]));

if (filterList && filterList.length && filterList[2]) {
stakedTokens = Number(filterList[2]);
// if (filterList && filterList.length && filterList[2]) {
// stakedTokens = Number(filterList[2]);
// }
const filterList = props.delegatedValidatorList.find((value) => value && value.validator && value.validator.address &&
(props.selectedValidator === value.validator.address));
if (filterList && filterList.minDenomAmount && filterList.minDenomAmount) {
stakedTokens = filterList.minDenomAmount && Number(filterList.minDenomAmount) / 10 ** config.COIN_DECIMALS;
}
}

Expand Down Expand Up @@ -99,6 +110,7 @@ const TokensTextField = (props) => {
};

TokensTextField.propTypes = {
delegatedValidatorList: PropTypes.array.isRequired,
genesisValidatorList: PropTypes.object.isRequired,
lang: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
Expand All @@ -115,6 +127,7 @@ const stateToProps = (state) => {
balance: state.accounts.balance.result,
vestingBalance: state.accounts.vestingBalance.result,
delegations: state.accounts.delegations.result,
delegatedValidatorList: state.stake.delegatedValidators.list,
lang: state.language,
value: state.stake.tokens,
name: state.stake.delegateDialog.name,
Expand Down
23 changes: 12 additions & 11 deletions src/containers/Stake/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Table extends Component {
customBodyRender: (value, index) => (
<ValidatorName
index={index && index.rowIndex} name={value}
value={index.rowData && index.rowData.length && index.rowData[1]}/>
value={index.rowData && index.rowData.length && index.rowData[2]}/>
),
},
},
Expand Down Expand Up @@ -121,24 +121,25 @@ class Table extends Component {
sort: false,
customBodyRender: (item) => {
let address = null;
let newValue = null;
this.props.delegatedValidatorList && this.props.delegatedValidatorList.length &&
this.props.delegatedValidatorList.map((value) => {
if (value && value.validator && value.validator.address && item &&
(item.address === value.validator.address)) {
address = value.validator.address;
newValue = value.minDenomAmount && value.minDenomAmount / 10 ** config.COIN_DECIMALS;;
}
});
let value = null;
address && this.props.delegations && this.props.delegations.length &&
this.props.delegations.map((val) => {
if (val && val.length && val[1] && (address === val[1])) {
value = val[2];
}
});
// address && this.props.delegations && this.props.delegations.length &&
// this.props.delegations.map((val) => {
// if (val && val.length && val[1] && (address === val[1])) {
// value = val[2];
// }
// });

return (
<div className={value ? 'tokens' : 'no_tokens'}>
{Number(value) || 'no tokens'}
<div className={newValue ? 'tokens' : 'no_tokens'}>
{Number(newValue) || 'no tokens'}
</div>
);
},
Expand Down Expand Up @@ -197,7 +198,7 @@ class Table extends Component {
? dataToMap.map((item) =>
[
// item.description && item.description.moniker,
item.name || item.address,
item.name,
// item,
// parseFloat((Number(item.tokens) / (10 ** config.COIN_DECIMALS)).toFixed(1)),
parseFloat((Number(item.votingPower)).toFixed(1)),
Expand Down
20 changes: 8 additions & 12 deletions src/containers/Stake/ValidatorName.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,14 @@ const ValidatorName = (props) => {
<div className="name_section">
{value && value.alias
? <p className="heading_text1">{value.alias}</p>
: null}
<div className="hash_text" title={props.name}>
<p className="name">{props.name}</p>
{props.name &&
props.name.slice(props.name.length - 6, props.name.length)}
</div>
{value && value.address
? <div className="hash_text" title={value.address}>
<p className="name">{value.address}</p>
{value.address &&
value.address.slice(value.address.length - 6, value.address.length)}
</div> : null}
: props.name
? <p className="heading_text1">{props.name}</p>
: props.value && props.value.address
? <div className="hash_text" title={props.value.address}>
<p className="name">{props.value.address}</p>
{props.value.address &&
props.value.address.slice(props.value.address.length - 6, props.value.address.length)}
</div> : null}
</div>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion src/containers/Stake/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
color: unset;
max-width: 140px;

color: #FFF;
/* color: #FFF; */
font-family: 'Blinker', sans-serif;
font-size: 18px;
font-style: normal;
Expand Down

0 comments on commit 549db02

Please sign in to comment.