Skip to content

Commit

Permalink
account switch, validators images, rewards display.
Browse files Browse the repository at this point in the history
  • Loading branch information
SrikanthSoparla committed Dec 4, 2024
1 parent 549db02 commit 237062a
Show file tree
Hide file tree
Showing 19 changed files with 395 additions and 196 deletions.
38 changes: 19 additions & 19 deletions config-overrides.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require("html-webpack-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
webpack: function override (config, env) {
Expand All @@ -13,16 +13,16 @@ module.exports = {
};
config.resolve.alias = {
...config.resolve.alias,
"../package.json": path.resolve(
'../package.json': path.resolve(
__dirname,
"node_modules/@heliaxdev/namada-sdk/package.json",
'node_modules/@heliaxdev/namada-sdk/package.json',
),
};
config.resolve.extensions = [...config.resolve.extensions, '.ts', '.js', '.wasm'];
config.plugins = [
...config.plugins,
new HtmlWebpackPlugin({
template: path.join(__dirname, "./public/index.html"),
template: path.join(__dirname, './public/index.html'),
}),
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
Expand All @@ -31,32 +31,32 @@ module.exports = {
process: 'process/browser',
}),
new webpack.DefinePlugin({
process: {
env: {},
},
process: {
env: {},
},
}),
];
config.ignoreWarnings = [/Failed to parse source map/];

return config;
},

// Function to customize the devServer
// Function to customize the devServer
devServer: function (configFunction) {
return function (proxy, allowedHost) {
// Get the default config and modify it
const config = configFunction(proxy, allowedHost);
const config = configFunction(proxy, allowedHost);

// Update devServer settings here
config.static = [
path.join(__dirname, "public"),
path.join(__dirname, "node_modules", "@heliaxdev", "namada-sdk", "dist"),
];
config.compress = true;
config.port = 9000;
// Update devServer settings here
config.static = [
path.join(__dirname, 'public'),
path.join(__dirname, 'node_modules', '@heliaxdev', 'namada-sdk', 'dist'),
];
config.compress = true;
config.port = 9000;

// Return the modified configuration
return config;
// Return the modified configuration
return config;
};
},
};
71 changes: 58 additions & 13 deletions src/actions/accounts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import {
DELEGATIONS_FETCH_IN_PROGRESS,
DELEGATIONS_FETCH_SUCCESS,
DISCONNECT_SET,
REVEALED_PUB_KEY_FETCH_ERROR,
REVEALED_PUB_KEY_FETCH_IN_PROGRESS,
REVEALED_PUB_KEY_FETCH_SUCCESS,
REWARDS_FETCH_ERROR,
REWARDS_FETCH_IN_PROGRESS,
REWARDS_FETCH_SUCCESS,
Expand All @@ -22,12 +25,12 @@ import {
VESTING_BALANCE_FETCH_SUCCESS,
} from '../../constants/accounts';
import Axios from 'axios';
import { urlFetchRewards, urlFetchUnBondingDelegations, urlFetchVestingBalance } from '../../constants/url';
import { urlFetchRevealedPubkey, urlFetchRewards, urlFetchUnBondingDelegations, urlFetchVestingBalance } from '../../constants/url';
// import { Query } from '@namada/shared';
import { config } from '../../config';
// import { init as initShared } from '@namada/shared/dist/init-inline';
import { Sdk, getSdk } from "@heliaxdev/namada-sdk/web";
import init from "@heliaxdev/namada-sdk/web-init";
import { Sdk, getSdk } from '@heliaxdev/namada-sdk/web';
import init from '@heliaxdev/namada-sdk/web-init';
// import { Tokens } from '@namada/types';

export const setAccountAddress = (value) => {
Expand Down Expand Up @@ -69,11 +72,11 @@ export const getDelegations = (address) => (dispatch) => {
(async () => {
const { cryptoMemory } = await init();
const sdk = getSdk(
cryptoMemory,
config.RPC_URL,
config.MAPS_REST_URL,
"",
config.TOKEN_ADDRESS
cryptoMemory,
config.RPC_URL,
config.MAPS_REST_URL,
'',
config.TOKEN_ADDRESS,
);

const { rpc } = sdk;
Expand Down Expand Up @@ -134,11 +137,11 @@ export const getBalance = (address, cb) => (dispatch) => {
// }
const { cryptoMemory } = await init();
const sdk = getSdk(
cryptoMemory,
config.RPC_URL,
config.MAPS_REST_URL,
"",
config.TOKEN_ADDRESS
cryptoMemory,
config.RPC_URL,
config.MAPS_REST_URL,
'',
config.TOKEN_ADDRESS,
);

const { rpc } = sdk;
Expand Down Expand Up @@ -310,6 +313,48 @@ export const fetchRewards = (address) => (dispatch) => {
});
};

const fetchRevealedPubKeyInProgress = () => {
return {
type: REVEALED_PUB_KEY_FETCH_IN_PROGRESS,
};
};

const fetchRevealedPubKeySuccess = (value) => {
return {
type: REVEALED_PUB_KEY_FETCH_SUCCESS,
value,
};
};

const fetchRevealedPubKeyError = (message) => {
return {
type: REVEALED_PUB_KEY_FETCH_ERROR,
message,
};
};

export const fetchRevealedPubKey = (address) => (dispatch) => {
dispatch(fetchRevealedPubKeyInProgress());
const url = urlFetchRevealedPubkey(address);
Axios.get(url, {
headers: {
Accept: 'application/json, text/plain, */*',
},
})
.then((res) => {
dispatch(fetchRevealedPubKeySuccess(res.data));
})
.catch((error) => {
dispatch(fetchRevealedPubKeyError(
error.response &&
error.response.data &&
error.response.data.message
? error.response.data.message
: 'Failed!',
));
});
};

export const disconnectSet = () => {
return {
type: DISCONNECT_SET,
Expand Down
6 changes: 4 additions & 2 deletions src/actions/stake.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
} from '../constants/url';
import { config } from '../config';
import { calculateNominalAPR, calculateRealAPR, getBlocksPerYearReal, getParams } from '../utils/aprCalculation';
import { randomNoRepeats } from 'utils/array';

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

Expand Down Expand Up @@ -84,8 +85,9 @@ export const getValidators = (page, cb) => (dispatch) => {
},
})
.then((res) => {
dispatch(fetchValidatorsSuccess(res.data, res.data && res.data.length, page));
cb(res.data, res.data && res.data.length, page, res.data && res.data.length);
const data = randomNoRepeats(res.data);
dispatch(fetchValidatorsSuccess(data, data && data.length, page));
cb(data, data && data.length, page, data && data.length);
})
.catch((error) => {
dispatch(fetchValidatorsError(
Expand Down
6 changes: 3 additions & 3 deletions src/assets/userDetails/rewards.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/constants/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ export const REWARDS_FETCH_IN_PROGRESS = 'REWARDS_FETCH_IN_PROGRESS';
export const REWARDS_FETCH_SUCCESS = 'REWARDS_FETCH_SUCCESS';
export const REWARDS_FETCH_ERROR = 'REWARDS_FETCH_ERROR';

export const REVEALED_PUB_KEY_FETCH_IN_PROGRESS = 'REVEALED_PUB_KEY_FETCH_IN_PROGRESS';
export const REVEALED_PUB_KEY_FETCH_SUCCESS = 'REVEALED_PUB_KEY_FETCH_SUCCESS';
export const REVEALED_PUB_KEY_FETCH_ERROR = 'REVEALED_PUB_KEY_FETCH_ERROR';

export const DISCONNECT_SET = 'DISCONNECT_SET';
3 changes: 2 additions & 1 deletion src/constants/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ export const urlFetchBalance = (address) => `${REST_URL}/cosmos/bank/v1beta1/bal
export const urlFetchVestingBalance = (address) => `${REST_URL}/cosmos/auth/v1beta1/accounts/${address}`;
export const urlFetchUnBondingDelegations = (address) => `${REST_URL}/cosmos/staking/v1beta1/delegators/${address}/unbonding_delegations`;

export const urlFetchRewards = (address) => `${REST_URL}/cosmos/distribution/v1beta1/delegators/${address}/rewards`;
export const urlFetchRewards = (address) => `${REST_URL}/api/v1/pos/reward/${address}`;
export const urlFetchVoteDetails = (proposalId, address) => `${REST_URL}/cosmos/gov/v1beta1/proposals/${proposalId}/votes/${address}`;
export const urlFetchRevealedPubkey = (address) => `${REST_URL}/api/v1/revealed-public-key/${address}`;

export const VALIDATORS_LIST_URL = () => `${REST_URL}/api/v1/pos/validator/all`;
export const GENESIS_VALIDATORS_LIST_URL = 'https://namada.info/shielded-expedition.88f17d1d14/output/genesis_tm_address_to_alias.json';
Expand Down
47 changes: 16 additions & 31 deletions src/containers/Home/ClaimDialog/ValidatorsSelectField.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@ const ValidatorSelectField = (props) => {

let total = 0;

const totalRewards = props.rewards && props.rewards.rewards &&
props.rewards.rewards.length &&
props.rewards.rewards.map((value) => {
let rewards = value.reward && value.reward.length &&
value.reward.find((val) => val.denom === config.COIN_MINIMAL_DENOM);
rewards = rewards && rewards.amount ? rewards.amount / 10 ** config.COIN_DECIMALS : 0;
const totalRewards = props.rewards && props.rewards.length &&
props.rewards.map((value) => {
const rewards = value && value.minDenomAmount ? value.minDenomAmount / 10 ** config.COIN_DECIMALS : 0;
total = rewards + total;

return total;
Expand All @@ -34,28 +31,26 @@ const ValidatorSelectField = (props) => {
return (
<SelectField
id="claim_validator_select_field"
items={props.rewards && props.rewards.rewards}
items={props.rewards}
name="validators"
value={props.value}
onChange={handleChange}>
<MenuItem disabled value="none">
Select the validator
</MenuItem>
{props.rewards && props.rewards.rewards &&
props.rewards.rewards.length &&
props.rewards.rewards.map((item, index) => {
const validator = item && item.validator_address && props.validatorList && props.validatorList.length &&
props.validatorList.filter((value) => value.operator_address === item.validator_address);

{props.rewards && props.rewards.length &&
props.rewards.map((item, index) => {
const validator = item && item.validator;
const rewards = item && item.minDenomAmount ? item.minDenomAmount / 10 ** config.COIN_DECIMALS : 0;
const image = validator && validator.length && validator[0] &&
validator[0].description && validator[0].description.identity &&
props.validatorImages && props.validatorImages.length &&
props.validatorImages.filter((value) => value._id === validator[0].description.identity.toString());

return (
<MenuItem
key={item.validator_address}
value={item.validator_address}>
key={validator.address}
value={validator.address}>
{image && image.length && image[0] && image[0].them && image[0].them.length &&
image[0].them[0] && image[0].them[0].pictures && image[0].them[0].pictures.primary &&
image[0].them[0].pictures.primary.url
Expand All @@ -65,22 +60,12 @@ const ValidatorSelectField = (props) => {
className="image"
src={image[0].them[0].pictures.primary.url}/>
: <span className="image" style={{ background: colors[index % 6] }}/>}
{props.validatorList && props.validatorList.map((value) => {
let rewards = item.reward && item.reward.length &&
item.reward.find((val) => val.denom === config.COIN_MINIMAL_DENOM);
rewards = rewards && rewards.amount ? rewards.amount / 10 ** config.COIN_DECIMALS : 0;

if (value.operator_address === item.validator_address) {
return <span key={value.operator_address}>
{value.description && value.description.moniker}
{rewards && rewards > 0
? <b>&nbsp;({rewards.toFixed(4)})</b>
: null}
</span>;
}

return null;
})}
<span key={validator.address}>
{validator.name || validator.address}
{rewards && rewards > 0
? <b>&nbsp;({rewards.toFixed(4)})</b>
: null}
</span>
</MenuItem>
);
},
Expand Down
Loading

0 comments on commit 237062a

Please sign in to comment.