Skip to content

Commit 93024bb

Browse files
apr integration, unbonding tokens info. (#233)
1 parent 867c8ab commit 93024bb

File tree

10 files changed

+70
-85
lines changed

10 files changed

+70
-85
lines changed

src/actions/stake.js

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import {
4545
} from '../constants/stake';
4646
import Axios from 'axios';
4747
import {
48+
APR_PARAMETERS_URL,
4849
GENESIS_VALIDATORS_LIST_URL,
4950
getDelegatedValidatorsURL,
5051
getUnBondingValidatorsURL,
@@ -546,11 +547,11 @@ const fetchAPRInProgress = () => {
546547
};
547548
};
548549

549-
export const fetchAPRSuccess = (nominalAPR, actualAPR) => {
550+
export const fetchAPRSuccess = (apr, result) => {
550551
return {
551552
type: APR_FETCH_SUCCESS,
552-
nominalAPR,
553-
actualAPR,
553+
apr,
554+
result,
554555
};
555556
};
556557

@@ -561,37 +562,33 @@ const fetchAPRError = (message) => {
561562
};
562563
};
563564

564-
export const fetchAPR = () => (dispatch) => {
565+
export const fetchAPR = (cb) => (dispatch) => {
565566
dispatch(fetchAPRInProgress());
566-
(async () => {
567-
try {
568-
const apiUrl = config.REST_URL;
569-
const lcdApi = axios.create({
570-
baseURL: apiUrl,
571-
headers: {
572-
'Content-Type': 'application/json; charset=utf-8',
573-
Accept: 'application/json',
574-
},
575-
timeout: 10000,
576-
});
577-
578-
const params = await getParams(lcdApi);
579-
const blocksYearReal = await getBlocksPerYearReal(lcdApi);
580-
const nominalAPR = calculateNominalAPR(params);
581-
const actualAPR = calculateRealAPR(params, nominalAPR, blocksYearReal);
582567

583-
dispatch(fetchAPRSuccess((nominalAPR * 100), (actualAPR * 100)));
584-
} catch (error) {
568+
Axios.get(APR_PARAMETERS_URL, {
569+
headers: {
570+
Accept: 'application/json, text/plain, */*',
571+
},
572+
})
573+
.then((result) => {
574+
const apr = result?.data?.apr && Number(result.data.apr) * 100 ;
575+
dispatch(fetchAPRSuccess(apr, result));
576+
if (cb) {
577+
cb(apr, result);
578+
}
579+
})
580+
.catch((error) => {
585581
dispatch(fetchAPRError(
586582
error.response &&
587583
error.response.data &&
588584
error.response.data.message
589585
? error.response.data.message
590-
: error,
586+
: 'Failed!',
591587
));
592-
return null;
593-
}
594-
})();
588+
if (cb) {
589+
cb(null);
590+
}
591+
});
595592
};
596593

597594
export const selectMultiValidators = (value) => {

src/assets/userDetails/unstake.png

6 Bytes
Loading

src/constants/url.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const urlFetchRevealedPubkey = (address) => `${REST_URL}/api/v1/revealed-
1818
export const VALIDATORS_LIST_URL = () => `${REST_URL}/api/v1/pos/validator/all?state=consensus`;
1919
export const GENESIS_VALIDATORS_LIST_URL = 'https://namada.info/shielded-expedition.88f17d1d14/output/genesis_tm_address_to_alias.json';
2020
export const INACTIVE_VALIDATORS_URL = `${REST_URL}/api/v1/pos/validator/all?state=belowCapacity&state=belowThreshold&state=inactive&state=jailed&state=unknown`;
21+
export const APR_PARAMETERS_URL = `${REST_URL}/api/v1/chain/parameters`;
2122
export const INACTIVE_VALIDATORS_UNBONDING_URL = `${REST_URL}/cosmos/staking/v1beta1/validators?pagination.limit=1000&status=BOND_STATUS_UNBONDING`;
2223
export const getValidatorURL = (address) => `${REST_URL}/cosmos/staking/v1beta1/validators/${address}`;
2324
export const PROPOSALS_LIST_URL = `${REST_URL}/api/v1/gov/proposal/all`;

src/containers/Home/TokenDetails/index.css

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@
2828
display: flex;
2929
align-items: center;
3030
justify-content: center;
31+
width: 210px;
3132
padding: 10px 20px;
32-
margin: 10px 0;
33-
width: 230px;
34-
padding: 10px 40px;
35-
height: 80px;
33+
height: 60px;
3634
margin: 10px auto;
3735
}
3836

src/containers/Home/TokenDetails/index.js

Lines changed: 25 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import variables from '../../../utils/variables';
55
import totalTokens from '../../../assets/userDetails/totalTokens.png';
66
import stakedTokens from '../../../assets/userDetails/stakedTokens.png';
77
import NamadaLogo from '../../../assets/masp/namada_logo.svg';
8-
// import unStake from '../../../assets/userDetails/unstake.png';
8+
import unStake from '../../../assets/userDetails/unstake.png';
99
import rewardsIcon from '../../../assets/userDetails/rewards.svg';
1010
import { connect } from 'react-redux';
1111
import StakeTokensButton from './StakeTokensButton';
@@ -46,32 +46,13 @@ const TokenDetails = (props) => {
4646
return null;
4747
});
4848

49-
// let shieldedBalance = null;
50-
// props.shieldedBalance && props.shieldedBalance.length && props.shieldedBalance.map((val) => {
51-
// if (val && val.length) {
52-
// val.map((value) => {
53-
// if (value === config.TOKEN_ADDRESS) {
54-
// shieldedBalance = val[1];
55-
// }
56-
// });
57-
// }
58-
59-
// return null;
60-
// });
61-
6249
const available = balance && balance / 10 ** config.COIN_DECIMALS;
63-
// const shieldedAvailable = shieldedBalance && shieldedBalance / 10 ** config.COIN_DECIMALS;
64-
let unStaked = 0;
65-
props.unBondingDelegations && props.unBondingDelegations.length &&
66-
props.unBondingDelegations.map((delegation) => {
67-
delegation.entries && delegation.entries.length &&
68-
delegation.entries.map((entry) => {
69-
unStaked = unStaked + Number(entry.balance);
70-
71-
return null;
72-
});
73-
return null;
74-
});
50+
let unStaked = props.unBondingDelegations && props.unBondingDelegations.reduce((accumulator, currentValue) => {
51+
if (currentValue && currentValue.minDenomAmount) {
52+
return accumulator + Number(currentValue.minDenomAmount);
53+
}
54+
}, 0);
55+
unStaked = unStaked && unStaked / 10 ** config.COIN_DECIMALS;
7556

7657
// const gasValue = (gas.claim_reward + gas.delegate) * config.GAS_PRICE_STEP_AVERAGE;
7758
let rewards = props.rewards && props.rewards.length &&
@@ -82,8 +63,6 @@ const TokenDetails = (props) => {
8263
}, 0);
8364
rewards = rewards ? rewards / 10 ** config.COIN_DECIMALS : 0;
8465

85-
const shieldedRewards = props.shieldedRewards && props.shieldedRewards / 10 ** config.COIN_DECIMALS;
86-
8766
const handleTransfer = () => {
8867
const value = {
8968
name: 'Transparent Namada',
@@ -129,13 +108,6 @@ const TokenDetails = (props) => {
129108
<StakeTokensButton/>
130109
</div>
131110
</div>
132-
{/* <div className="chip_info">
133-
<p>{variables[props.lang]['shielded_available_tokens']}</p>
134-
<div className="chip">
135-
<img alt="available tokens" src={totalTokens}/>
136-
<p>{shieldedAvailable || 0}</p>
137-
</div>
138-
</div> */}
139111
<div className="chip_info">
140112
<p>{variables[props.lang]['staked_tokens']}</p>
141113
{props.delegatedValidatorListInProgress ? (
@@ -184,13 +156,20 @@ const TokenDetails = (props) => {
184156
<ClaimButton disable={rewards <= 0}/>
185157
</div>
186158
</div> */}
187-
{/* <div className="chip_info"> */}
188-
{/* <p>{variables[props.lang]['un_staked_tokens']}</p> */}
189-
{/* <div className="chip"> */}
190-
{/* <img alt="unstaked tokens" src={unStake}/> */}
191-
{/* <p>{unStaked}</p> */}
192-
{/* </div> */}
193-
{/* </div> */}
159+
<div className="chip_info">
160+
<p>{variables[props.lang]['unbounding']}</p>
161+
<div className="chip">
162+
<img alt="unstaked tokens" src={unStake}/>
163+
<p>{unStaked}</p>
164+
</div>
165+
</div>
166+
{props.actualAPR
167+
? <div className="chip_info">
168+
<p>{variables[props.lang]['staking_apr']}</p>
169+
<div className="chip">
170+
<p>{props.actualAPR.toFixed(2) + ' %'}</p>
171+
</div>
172+
</div> : null}
194173
</div>
195174
);
196175
};
@@ -213,6 +192,7 @@ TokenDetails.propTypes = {
213192
showTransparentTokensTransferDialog: PropTypes.func.isRequired,
214193
shieldedRewards: PropTypes.object.isRequired,
215194
shieldedRewardsInProgress: PropTypes.bool.isRequired,
195+
actualAPR: PropTypes.number,
216196
shieldedBalance: PropTypes.array,
217197
shieldedBalanceInProgress: PropTypes.bool,
218198
unBondingDelegations: PropTypes.arrayOf(
@@ -229,6 +209,7 @@ TokenDetails.propTypes = {
229209

230210
const stateToProps = (state) => {
231211
return {
212+
actualAPR: state.stake.apr.apr,
232213
delegations: state.accounts.delegations.result,
233214
delegatedValidatorList: state.stake.delegatedValidators.list,
234215
delegatedValidatorListInProgress: state.stake.delegatedValidators.inProgress,
@@ -237,8 +218,8 @@ const stateToProps = (state) => {
237218
balanceInProgress: state.accounts.balance.inProgress,
238219
shieldedBalance: state.accounts.shieldedBalance.result,
239220
shieldedBalanceInProgress: state.accounts.shieldedBalance.inProgress,
240-
unBondingDelegations: state.accounts.unBondingDelegations.result,
241-
unBondingDelegationsInProgress: state.accounts.unBondingDelegations.inProgress,
221+
unBondingDelegations: state.stake.unBondingValidators.list,
222+
unBondingDelegationsInProgress: state.stake.unBondingValidators.inProgress,
242223
rewards: state.accounts.rewards.result,
243224
rewardsInProgress: state.accounts.rewards.inProgress,
244225
shieldedRewards: state.accounts.shieldedRewards.result,

src/containers/Home/index.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,14 @@ margin-bottom: 0;
216216
}
217217
}
218218

219+
@media (max-width: 1441px) {
220+
.home .card {
221+
flex-direction: column;
222+
padding: 50px;
223+
text-align: center;
224+
}
225+
}
226+
219227
@media (max-width: 1300px) {
220228
.home .card {
221229
flex-direction: column;

src/containers/NavBar/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@ class NavBar extends Component {
187187
this.handleFetchValidators(DEFAULT_PAGE, 0);
188188
}
189189

190-
// if (!this.props.actualAPR && !this.props.aprInProgress) {
191-
// this.props.fetchAPR();
192-
// }
190+
if (!this.props.actualAPR && !this.props.aprInProgress) {
191+
this.props.fetchAPR();
192+
}
193193

194194
// if (this.props.inActiveValidatorsList && !this.props.inActiveValidatorsList.length && !this.props.inActiveValidatorsInProgress && !this.props.proposalTab) {
195195
// this.props.getInActiveValidators((data) => {
@@ -692,7 +692,7 @@ const stateToProps = (state) => {
692692
return {
693693
address: state.accounts.address.value,
694694
aprInProgress: state.stake.apr.inProgress,
695-
actualAPR: state.stake.apr.actualAPR,
695+
actualAPR: state.stake.apr.apr,
696696
balance: state.accounts.balance.result,
697697
balanceInProgress: state.accounts.balance.inProgress,
698698
delegations: state.accounts.delegations.result,

src/containers/Stake/Table.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ Table.propTypes = {
353353

354354
const stateToProps = (state) => {
355355
return {
356-
actualAPR: state.stake.apr.actualAPR,
356+
actualAPR: state.stake.apr.apr,
357357
address: state.accounts.address.value,
358358
lang: state.language,
359359
validatorList: state.stake.validators.list,

src/containers/Stake/UnbondingTable.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ UnbondingTable.propTypes = {
197197

198198
const stateToProps = (state) => {
199199
return {
200-
actualAPR: state.stake.apr.actualAPR,
200+
actualAPR: state.stake.apr.apr,
201201
address: state.accounts.address.value,
202202
lang: state.language,
203203
validatorList: state.stake.validators.list,
@@ -210,7 +210,7 @@ const stateToProps = (state) => {
210210
delegatedValidatorListInProgress: state.stake.delegatedValidators.inProgress,
211211
inActiveValidators: state.stake.inActiveValidators.list,
212212
unBondingValidatorsList: state.stake.unBondingValidators.list,
213-
unBondingValidatorsProgress: state.stake.unBondingValidators.inProgress,
213+
unBondingValidatorsProgress: state.stake.unBondingValidators.inProgress,
214214
};
215215
};
216216

src/reducers/stake.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,8 @@ const inActiveValidators = (state = {
454454

455455
const apr = (state = {
456456
inProgress: false,
457-
nominalAPR: null,
458-
actualAPR: null,
457+
apr: null,
458+
result: null,
459459
}, action) => {
460460
switch (action.type) {
461461
case APR_FETCH_IN_PROGRESS:
@@ -467,8 +467,8 @@ const apr = (state = {
467467
return {
468468
...state,
469469
inProgress: false,
470-
nominalAPR: action.nominalAPR,
471-
actualAPR: action.actualAPR,
470+
apr: action.apr,
471+
result: action.result,
472472
};
473473
case APR_FETCH_ERROR:
474474
return {

0 commit comments

Comments
 (0)