Skip to content

Commit

Permalink
Apr functionality (#88)
Browse files Browse the repository at this point in the history
* in active validator list ui.

* powered by text update.

* validators count

* validators count update

* home page validator tabs.

* text update

* Add lint workflow

* Update lint.yaml

* Update lint.yaml

* Update lint.yaml

* Add deploy workflow

* update deploy.yaml

* Delete deploy.yaml

* new workflow added

* new workflow modified

* envs -> env

* env list to map

* env list to map

* env list to map

* bug fixes

* bug fixes

* bug fixes #2

* bug fixes #3

* bug fixes #4

* Publish via SSH workflow added and in README.md git repo link fixed

* some modifications

* Update deploy.yaml

* update yarn.lock

* omniflix default gas fee updates. (#85)

* Update defaultGasValues.js

* apr integration.

* deployment script fixes.

* ui fixes.

* Unbonding Period, voting period parameters added.

---------

Co-authored-by: Srikanth Reddy <srikanthreddy@Srikanths-MacBook-Pro.local>
Co-authored-by: srikanth.soparla <srikanth.soparla@cosmiclabs.co>
Co-authored-by: poojachigitey <chigiteypooja12@gmail.com>
Co-authored-by: Marri Harish <harishmarri551@gmail.com>
Co-authored-by: 5iddy <siddhuyeturi@gmail.com>
Co-authored-by: noodles <64490027+5iddy@users.noreply.github.com>
  • Loading branch information
7 people committed Apr 24, 2023
1 parent a723ae3 commit 1ab96ff
Show file tree
Hide file tree
Showing 21 changed files with 2,762 additions and 2,487 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ yarn
1. clone repository and install packages

```sh
git clone https://github.dev/OmniFlix/insync.git
git clone https://github.com/OmniFlix/insync.git
cd insync
yarn
```
Expand Down
114 changes: 113 additions & 1 deletion src/actions/stake.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import {
APR_FETCH_ERROR,
APR_FETCH_IN_PROGRESS,
APR_FETCH_SUCCESS,
CLAIM_REWARDS_DIALOG_HIDE,
CLAIM_REWARDS_DIALOG_SHOW,
CLAIM_REWARDS_VALIDATOR_SET,
Expand All @@ -13,6 +16,9 @@ import {
DELEGATED_VALIDATORS_FETCH_ERROR,
DELEGATED_VALIDATORS_FETCH_IN_PROGRESS,
DELEGATED_VALIDATORS_FETCH_SUCCESS,
INACTIVE_VALIDATORS_FETCH_ERROR,
INACTIVE_VALIDATORS_FETCH_IN_PROGRESS,
INACTIVE_VALIDATORS_FETCH_SUCCESS,
SEARCH_LIST_SET,
TO_VALIDATOR_SET,
TOKENS_SET,
Expand All @@ -28,8 +34,17 @@ import {
VALIDATORS_FETCH_SUCCESS,
} from '../constants/stake';
import Axios from 'axios';
import { getDelegatedValidatorsURL, getValidatorURL, validatorImageURL, VALIDATORS_LIST_URL } from '../constants/url';
import {
getDelegatedValidatorsURL,
getValidatorURL,
INACTIVE_VALIDATORS_URL,
validatorImageURL,
VALIDATORS_LIST_URL,
} from '../constants/url';
import { config } from '../config';
import { calculateNominalAPR, calculateRealAPR, getBlocksPerYearReal, getParams } from '../utils/aprCalculation';

const axios = require('axios').default;

const fetchValidatorsInProgress = () => {
return {
Expand Down Expand Up @@ -307,3 +322,100 @@ export const fetchValidatorImage = (id) => (dispatch) => {
));
});
};

const fetchInActiveValidatorsInProgress = () => {
return {
type: INACTIVE_VALIDATORS_FETCH_IN_PROGRESS,
};
};

const fetchInActiveValidatorsSuccess = (list) => {
return {
type: INACTIVE_VALIDATORS_FETCH_SUCCESS,
list,
};
};

const fetchInActiveValidatorsError = (message) => {
return {
type: INACTIVE_VALIDATORS_FETCH_ERROR,
};
};

export const getInActiveValidators = (cb) => (dispatch) => {
dispatch(fetchInActiveValidatorsInProgress());
Axios.get(INACTIVE_VALIDATORS_URL, {
headers: {
Accept: 'application/json, text/plain, */*',
Connection: 'keep-alive',
},
})
.then((res) => {
dispatch(fetchInActiveValidatorsSuccess(res.data && res.data.result));
cb(res.data && res.data.result);
})
.catch((error) => {
dispatch(fetchInActiveValidatorsError(
error.response &&
error.response.data &&
error.response.data.message
? error.response.data.message
: 'Failed!',
));
cb(null);
});
};

const fetchAPRInProgress = () => {
return {
type: APR_FETCH_IN_PROGRESS,
};
};

export const fetchAPRSuccess = (nominalAPR, actualAPR) => {
return {
type: APR_FETCH_SUCCESS,
nominalAPR,
actualAPR,
};
};

const fetchAPRError = (message) => {
return {
type: APR_FETCH_ERROR,
message,
};
};

export const fetchAPR = () => (dispatch) => {
dispatch(fetchAPRInProgress());
(async () => {
try {
const apiUrl = config.REST_URL;
const lcdApi = axios.create({
baseURL: apiUrl,
headers: {
'Content-Type': 'application/json; charset=utf-8',
Accept: 'application/json',
},
timeout: 10000,
});

const params = await getParams(lcdApi);
const blocksYearReal = await getBlocksPerYearReal(lcdApi);
const nominalAPR = calculateNominalAPR(params);
const actualAPR = calculateRealAPR(params, nominalAPR, blocksYearReal);

dispatch(fetchAPRSuccess((nominalAPR * 100), (actualAPR * 100)));
} catch (error) {
dispatch(fetchAPRError(
error.response &&
error.response.data &&
error.response.data.message
? error.response.data.message
: error,
));
return process.exit(-1);
}
})();
};
8 changes: 8 additions & 0 deletions src/constants/stake.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,11 @@ export const CLAIM_REWARDS_VALIDATOR_SET = 'CLAIM_REWARDS_VALIDATOR_SET';
export const VALIDATOR_IMAGE_FETCH_IN_PROGRESS = 'VALIDATOR_IMAGE_FETCH_IN_PROGRESS';
export const VALIDATOR_IMAGE_FETCH_SUCCESS = 'VALIDATOR_IMAGE_FETCH_SUCCESS';
export const VALIDATOR_IMAGE_FETCH_ERROR = 'VALIDATOR_IMAGE_FETCH_ERROR';

export const INACTIVE_VALIDATORS_FETCH_IN_PROGRESS = 'INACTIVE_VALIDATORS_FETCH_IN_PROGRESS';
export const INACTIVE_VALIDATORS_FETCH_SUCCESS = 'INACTIVE_VALIDATORS_FETCH_SUCCESS';
export const INACTIVE_VALIDATORS_FETCH_ERROR = 'INACTIVE_VALIDATORS_FETCH_ERROR';

export const APR_FETCH_IN_PROGRESS = 'APR_FETCH_IN_PROGRESS';
export const APR_FETCH_SUCCESS = 'APR_FETCH_SUCCESS';
export const APR_FETCH_ERROR = 'APR_FETCH_ERROR';
1 change: 1 addition & 0 deletions src/constants/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const urlFetchRewards = (address) => `${REST_URL}/distribution/delegators
export const urlFetchVoteDetails = (proposalId, address) => `${REST_URL}/gov/proposals/${proposalId}/votes/${address}`;

export const VALIDATORS_LIST_URL = `${REST_URL}/staking/validators`;
export const INACTIVE_VALIDATORS_URL = `${REST_URL}/staking/validators?status=BOND_STATUS_UNBONDED`;
export const getValidatorURL = (address) => `${REST_URL}/staking/validators/${address}`;
export const PROPOSALS_LIST_URL = `${REST_URL}/cosmos/gov/v1beta1/proposals?pagination.limit=1000`;
export const getDelegatedValidatorsURL = (address) => `${REST_URL}/staking/delegators/${address}/validators`;
Expand Down
2 changes: 1 addition & 1 deletion src/containers/Home/TokenDetails/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
margin: 0 10px;
}

@media (max-width: 1441px) {
@media (max-width: 2000px) {
.token_details {
margin: 40px 0 0;
width: 100%;
Expand Down
9 changes: 9 additions & 0 deletions src/containers/Home/TokenDetails/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ const TokenDetails = (props) => {
<p>{unStaked / (10 ** config.COIN_DECIMALS)}</p>
</div>
</div>
{props.actualAPR
? <div className="chip_info">
<p>{variables[props.lang]['staking_apr']}</p>
<div className="chip">
<p>{props.actualAPR.toFixed(2) + ' %'}</p>
</div>
</div> : null}
</div>
);
};
Expand All @@ -88,6 +95,7 @@ TokenDetails.propTypes = {
}).isRequired,
rewardsInProgress: PropTypes.bool.isRequired,
unBondingDelegationsInProgress: PropTypes.bool.isRequired,
actualAPR: PropTypes.number,
balance: PropTypes.arrayOf(
PropTypes.shape({
amount: PropTypes.any,
Expand Down Expand Up @@ -116,6 +124,7 @@ TokenDetails.propTypes = {

const stateToProps = (state) => {
return {
actualAPR: state.stake.apr.actualAPR,
delegations: state.accounts.delegations.result,
delegationsInProgress: state.accounts.delegations.inProgress,
balance: state.accounts.balance.result,
Expand Down
2 changes: 1 addition & 1 deletion src/containers/Home/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
background: #FFFFFF;
}

@media (max-width: 1441px) {
@media (max-width: 2000px) {
.home .card {
flex-direction: column;
text-align: center;
Expand Down
26 changes: 24 additions & 2 deletions src/containers/Home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Home extends Component {
render () {
const { active } = this.state;
const filteredProposals = this.props.proposals && this.props.proposals.filter((item) => item.status === 2 ||
item.status === 'PROPOSAL_STATUS_VOTING_PERIOD');
item.status === 'PROPOSAL_STATUS_VOTING_PERIOD');

return (
<>
Expand All @@ -88,10 +88,26 @@ class Home extends Component {
<div className="tabs">
<p className={active === 2 ? 'active' : ''} onClick={() => this.handleChange(2)}>
{variables[this.props.lang]['staked_validators']}
{this.props.delegatedValidatorList &&
this.props.delegatedValidatorList.length
? ' (' + this.props.delegatedValidatorList.length + ')'
: null}
</p>
<span/>
<p className={active === 1 ? 'active' : ''} onClick={() => this.handleChange(1)}>
{variables[this.props.lang]['all_validators']}
{variables[this.props.lang]['active_validators']}
{this.props.validatorList &&
this.props.validatorList.length
? ' (' + this.props.validatorList.length + ')'
: null}
</p>
<span/>
<p className={active === 3 ? 'active' : ''} onClick={() => this.handleChange(3)}>
{variables[this.props.lang]['inactive_validators']}
{this.props.inActiveValidators &&
this.props.inActiveValidators.length
? ' (' + this.props.inActiveValidators.length + ')'
: null}
</p>
</div>
<Button className="view_all" onClick={() => this.handleRedirect('/stake')}>
Expand Down Expand Up @@ -133,12 +149,15 @@ class Home extends Component {
}

Home.propTypes = {
delegatedValidatorList: PropTypes.array.isRequired,
history: PropTypes.shape({
push: PropTypes.func.isRequired,
}).isRequired,
inActiveValidators: PropTypes.array.isRequired,
lang: PropTypes.string.isRequired,
open: PropTypes.bool.isRequired,
proposals: PropTypes.array.isRequired,
validatorList: PropTypes.array.isRequired,
voteDetailsInProgress: PropTypes.bool.isRequired,
address: PropTypes.string,
proposalsInProgress: PropTypes.bool,
Expand All @@ -152,6 +171,9 @@ const stateToProps = (state) => {
proposals: state.proposals._.list,
proposalsInProgress: state.proposals._.inProgress,
voteDetailsInProgress: state.proposals.voteDetails.inProgress,
delegatedValidatorList: state.stake.delegatedValidators.list,
inActiveValidators: state.stake.inActiveValidators.list,
validatorList: state.stake.validators.list,
};
};

Expand Down
5 changes: 3 additions & 2 deletions src/containers/NavBar/ConnectDialog/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import CosmostationConnectButton from './CosmostationConnectButton';
import GetAppRoundedIcon from '@material-ui/icons/GetAppRounded';
import insync from '../../../assets/insync.png';
import './index.css';
import { config } from '../../../config';

const LightTooltip = withStyles((theme) => ({
tooltip: {
Expand Down Expand Up @@ -44,7 +45,7 @@ const ConnectDialog = (props) => {
</IconButton>
</LightTooltip>
</div>
<div className="button_div">
{config.COSMOSTAION && <div className="button_div">
<CosmostationConnectButton proposalTab={props.proposalTab} stake={props.stake}/>
<LightTooltip title="Download the Cosmostation Extension">
<IconButton
Expand All @@ -53,7 +54,7 @@ const ConnectDialog = (props) => {
<GetAppRoundedIcon/>
</IconButton>
</LightTooltip>
</div>
</div>}
</div>
</DialogContent>
</Dialog>
Expand Down
Loading

0 comments on commit 1ab96ff

Please sign in to comment.