Skip to content

Commit

Permalink
update formatting
Browse files Browse the repository at this point in the history
resolve errors

update dev hasura uri and loosen filters for active validators

fix apollo error and console issues with accounts

update compare BN

test remove account sorting

fix lint

update filters; remove parachain validators from nominations; update BN comparison

add missig filters

update icons, remove console statements and commented out code
  • Loading branch information
Raid5594 committed Jan 18, 2024
1 parent 8a6803b commit ddb02f4
Show file tree
Hide file tree
Showing 29 changed files with 264 additions and 391 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Refactored testnet inclusion condition in build-and-deploy job
- Updated branches for Stage and Prod
- Updated information about Inflation
- Fixed HTML page formatting, ChangeNominations, and CERE_URL
- Fixed HTML page formatting, ChangeNominations, and CereUrl
- Updated README.md, prod.yaml, Favicons, units, and URI Prefix
- Adjusted constants and networks for Cere
- Updated default Network and active networks fields
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"date-fns": "^2.29.3",
"downshift": "^6.1.7",
"framer-motion": "^7.6.7",
"graphql": "^16.6.0",

This comment has been minimized.

Copy link
@MRamanenkau

MRamanenkau Jan 18, 2024

Where is it used?

"i18next": "^22.0.6",
"i18next-browser-languagedetector": "^7.0.1",
"lodash.throttle": "^4.1.1",
Expand Down
Binary file modified public/favicons/android-chrome-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/favicons/android-chrome-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/favicons/apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/favicons/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/favicons/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/favicons/favicon.ico
Binary file not shown.
113 changes: 28 additions & 85 deletions src/config/help.ts
Original file line number Diff line number Diff line change
@@ -1,97 +1,40 @@
// Copyright 2022 @paritytech/polkadot-staking-dashboard authors & contributors
// SPDX-License-Identifier: Apache-2.0

import { HelpContentRaw } from 'contexts/Help/types';
// ToDo: update

This comment has been minimized.

Copy link
@MRamanenkau

MRamanenkau Jan 18, 2024

Is it still relevant?

import { HelpItems } from 'contexts/Help/types';

export const HELP_CONFIG: HelpContentRaw = [
export const HELP_CONFIG: HelpItems = [
{
key: 'overview',
definitions: [
{
title: 'Dashboard Tips',
description: [
'Staking dashboard will present you tips to help you along each step of staking on Polkadot.',
'Tips can be turned off or re-enabled from dashboard settings, that can be accessed via the cog icon in the bottom left corner of the side menu.',
],
},
{
title: 'Supply Staked',
description: [
'The current cumulative supply of {NETWORK_UNIT} being staked globally.',
'The percentage of staked {NETWORK_UNIT} is relative to the total supply of {NETWORK_UNIT}.',
],
},
{
title: 'Total Nominators',
description: [
'Accounts who are staking in the network, regardless of whether they are active or inactive in the current session.',
'In order to stake {NETWORK_UNIT}, you must be a nominator.',
],
},
{
title: 'Active Nominators',
description: [
'Nominators who are active in the current session.',
'Being an active nominator does not guarantee rewards, as your nominees may be oversubscribed.',
],
},
{
title: 'Your Balance',
description: [
'Your balance represents the total {NETWORK_UNIT} you have available in addition to your total staked amount, that includes the amount you have bonded in a Pool.',
'Unlike your staked balance, your bonded pool balance is held and locked in the pool itself.',
],
},
{
title: 'Reserve Balance',
description: [
'In {NETWORK_NAME}, you must have a balance above a certain amount for your account to exist on-chain. This amount is called your "existential deposit".',
'Staking dashboard ensures that this amount of {NETWORK_UNIT} is never touched.',
],
},
{
title: 'Network Stats',
description: [
'Real time network statistics that may affect your staking positions.',
'Keep up to date on the state of the network from your overview.',
],
},
{
title: 'Inflation',
description: [
'CERE is inflationary; there is no maximum number of CERE.',
'Inflation is designed to be in the range of 0.01% to 5% annually, with validator rewards being a function of the amount staked and the remainder going to treasury.',
],
},
{
title: 'Historical Rewards Rate',
description: [
'An estimated annual yield based on the {NETWORK_NAME} reward distribution model.',
],
},
{
title: 'Ideal Staked',
description: [
'The percentage of staked total supply in ideal network conditions.',
],
},
'Dashboard Tips',
'Total Nominators',
'Active Nominators',
'Your Balance',
'Reserve Balance',
'Network Stats',
'Inflation',
'Historical Rewards Rate',
'Ideal Staked',
'Supply Staked',
],
external: [
{
title: 'How to Connect Your Accounts',
url: 'https://support.polkadot.network/support/solutions/articles/65000182121-how-to-use-the-staking-dashboard-connecting-your-account',
website: 'polkadot.network',
},
{
title: 'How to Use the Staking Dashboard: Overview',
url: 'https://support.polkadot.network/support/solutions/articles/65000182104-how-to-use-the-staking-dashboard-overview',
website: 'polkadot.network',
},
{
title: 'Staking your DOT',
url: 'https://support.polkadot.network/support/solutions/articles/65000182104-how-to-use-the-staking-dashboard-overview',
website: 'polkadot.network',
},
[
'connect_your_accounts',
'https://support.polkadot.network/support/solutions/articles/65000182121-how-to-use-the-staking-dashboard-connecting-your-account',
'polkadot.network',
],
[
'how_to_use',
'https://support.polkadot.network/support/solutions/articles/65000182104-how-to-use-the-staking-dashboard-overview',
'polkadot.network',
],
[
'stake_cere',
'https://support.polkadot.network/support/solutions/articles/65000182104-how-to-use-the-staking-dashboard-overview',
'polkadot.network',
],

This comment has been minimized.

Copy link
@MRamanenkau

MRamanenkau Jan 18, 2024

Why do we keep links to Polkadot?

],
},
{
Expand Down
10 changes: 5 additions & 5 deletions src/config/networks.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: Apache-2.0
import { Networks } from 'types';
import { WellKnownChain } from '@polkadot/rpc-provider/substrate-connect';
import { DefaultParams } from 'consts';
import { ReactComponent as CereLogoSvg } from 'img/cere_logo.svg';
import { ReactComponent as CereIconSvg } from 'img/cere_icon.svg';
import { ReactComponent as CereLogoSvg } from 'img/cere_logo.svg';
import { Networks } from 'types';

const cereMainnet = {
name: 'Cere',
Expand Down Expand Up @@ -63,7 +63,7 @@ const cereTestnet = {
rpc: 'wss://archive.testnet.cere.network/ws',
lightClient: WellKnownChain.polkadot,
},
cereStatsEndpoint: 'wss://hasura.stats.dev.cere.network/v1/graphql',
cereStatsEndpoint: 'wss://stats-hasura.network-dev.aws.cere.io/v1/graphql',
};

const cereDevnet = {
Expand All @@ -73,7 +73,7 @@ const cereDevnet = {
rpc: 'wss://archive.devnet.cere.network/ws',
lightClient: WellKnownChain.polkadot,
},
cereStatsEndpoint: 'wss://hasura.stats.dev.cere.network/v1/graphql',
cereStatsEndpoint: 'wss://stats-hasura.network-dev.aws.cere.io/v1/graphql',
};

const cereQAnet = {
Expand All @@ -83,7 +83,7 @@ const cereQAnet = {
rpc: 'wss://archive.qanet.cere.network/ws',
lightClient: WellKnownChain.polkadot,
},
cereStatsEndpoint: 'wss://hasura.stats.dev.cere.network/v1/graphql',
cereStatsEndpoint: 'wss://stats-hasura.network-dev.aws.cere.io/v1/graphql',
};

// Determine if the testnet should be included based on the REACT_APP_INCLUDE_TESTNET environment variable
Expand Down
5 changes: 5 additions & 0 deletions src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,8 @@ export const DefaultParams = {
maxInflation: 0.05,
minInflation: 0.0001,
};

/*
* locale
*/
export const DefaultLocale = 'en';
2 changes: 1 addition & 1 deletion src/contexts/CereStats/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const usePayouts = (
data: { _like: $activeAccount }
}
) {
blockNumber
block_number
data
timestamp
}
Expand Down
4 changes: 2 additions & 2 deletions src/contexts/Network/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export const metrics: NetworkMetrics = {
start: 0,
},
totalIssuance: new BN(0),
auctionCounter: new BN(0),
earliestStoredSession: new BN(0),
// auctionCounter: new BN(0),
// earliestStoredSession: new BN(0),
};

export const defaultNetworkContext: NetworkMetricsContextInterface = {
Expand Down
22 changes: 9 additions & 13 deletions src/contexts/Network/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2022 @paritytech/polkadot-staking-dashboard authors & contributors
// SPDX-License-Identifier: Apache-2.0

import { BN } from 'bn.js';
import React, { useEffect, useState } from 'react';
import { AnyApi } from 'types';
import { useApi } from '../Api';
Expand Down Expand Up @@ -53,15 +52,12 @@ export const NetworkMetricsProvider = ({
[
api.query.staking.activeEra,
api.query.balances.totalIssuance,
api.query.auctions.auctionCounter,
api.query.paraSessionInfo.earliestStoredSession,
// api.query.auctions.auctionCounter,
// api.query.paraSessionInfo.earliestStoredSession,
],
([
activeEra,
_totalIssuance,
_auctionCounter,
_earliestStoredSession,
]: AnyApi) => {
([activeEra, _totalIssuance]: // _auctionCounter,
// _earliestStoredSession,
AnyApi) => {
// determine activeEra: toString used as alternative to `toHuman`, that puts commas in numbers
let _activeEra = activeEra
.unwrapOrDefault({
Expand All @@ -76,8 +72,8 @@ export const NetworkMetricsProvider = ({
const _metrics = {
activeEra: _activeEra,
totalIssuance: _totalIssuance.toBn(),
auctionCounter: new BN(_auctionCounter.toString()),
earliestStoredSession: new BN(_earliestStoredSession.toString()),
// auctionCounter: new BN(_auctionCounter.toString()),
// earliestStoredSession: new BN(_earliestStoredSession.toString()),
};
setMetrics(_metrics);
}
Expand All @@ -92,8 +88,8 @@ export const NetworkMetricsProvider = ({
metrics: {
activeEra: metrics.activeEra,
totalIssuance: metrics.totalIssuance,
auctionCounter: metrics.auctionCounter,
earliestStoredSession: metrics.earliestStoredSession,
// auctionCounter: metrics.auctionCounter,
// earliestStoredSession: metrics.earliestStoredSession,

This comment has been minimized.

Copy link
@MRamanenkau

MRamanenkau Jan 18, 2024

Why do we keep it commented?

},
}}
>
Expand Down
4 changes: 2 additions & 2 deletions src/contexts/Network/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ export interface NetworkMetrics {
start: number;
};
totalIssuance: BN;
auctionCounter: BN;
earliestStoredSession: BN;
// auctionCounter: BN;
// earliestStoredSession: BN;
}
19 changes: 14 additions & 5 deletions src/contexts/Validators/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const ValidatorsProvider = ({
const { poolNominations } = useActivePools();
const { units } = network;
const { maxNominatorRewardedPerValidator } = consts;
const { activeEra, earliestStoredSession } = metrics;
const { activeEra } = metrics;

// stores the total validator entries
const [validators, setValidators] = useState<Array<Validator>>([]);
Expand Down Expand Up @@ -138,10 +138,10 @@ export const ValidatorsProvider = ({

// fetch parachain session validators when earliestStoredSession ready
useEffect(() => {
if (isReady && earliestStoredSession.gt(new BN(0))) {

This comment has been minimized.

Copy link
@MRamanenkau

MRamanenkau Jan 18, 2024

Why do we need earliestStoredSession? Probably we don't need to fetch parachain validators at all.

if (isReady) {
subscribeParachainValidators(api);
}
}, [isReady, earliestStoredSession]);
}, [isReady]);

// pre-populating validator meta batches. Needed for generating nominations
useEffect(() => {
Expand All @@ -161,13 +161,17 @@ export const ValidatorsProvider = ({
if (!activeAccount) {
return;
}

console.log(`Active account: ${activeAccount}`);
// get raw targets list
const targets = getAccountNominations(activeAccount);

// format to list format
const targetsFormatted = targets.map((item: any) => {
return { address: item };
});
console.log(`Fetching validators from nominated list:`);
console.log(targetsFormatted);
// fetch preferences
const nominationsWithPrefs = await fetchValidatorPrefs(targetsFormatted);

Expand All @@ -188,11 +192,14 @@ export const ValidatorsProvider = ({
const fetchPoolNominatedList = async () => {
// get raw nominations list
let n = poolNominations.targets;
console.log(`Raw nominations list:`);
console.log(n);
// format to list format
n = n.map((item: string) => {
return { address: item };
});
// fetch preferences
console.log(`Fetching validators from pool nominated list: ${n}`);
const nominationsWithPrefs = await fetchValidatorPrefs(n);
if (nominationsWithPrefs) {
setPoolNominated(nominationsWithPrefs);
Expand All @@ -218,6 +225,8 @@ export const ValidatorsProvider = ({
const _favorites = [...favorites].map((item: string) => {
return { address: item };
});
console.log(`Favourite validators:`);
console.log(_favorites);

This comment has been minimized.

Copy link
@MRamanenkau

MRamanenkau Jan 18, 2024

Leaving console.log is usually considered a bad practice. Why do we need them?

// // fetch preferences
const favoritesWithPrefs = await fetchValidatorPrefs(_favorites);
if (favoritesWithPrefs) {
Expand Down Expand Up @@ -305,8 +314,8 @@ export const ValidatorsProvider = ({
*/
const subscribeParachainValidators = async (_api: AnyApi) => {
if (isReady) {
const unsub = await _api.query.paraSessionInfo.accountKeys(
earliestStoredSession.toString(),
const unsub = await _api.query.session.validators(
// earliestStoredSession.toString(),
(_validators: AnyApi) => {
setSessionParachainValidators({
...sessionParachainValidators,
Expand Down
8 changes: 7 additions & 1 deletion src/library/Form/Utils/getEligibleControllers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ export const getEligibleControllers = (): Array<InputItem> => {
_accountsAsInput = _accountsAsInput.sort((a: InputItem, b: InputItem) => {
const aFree = a?.balance?.free ?? new BN(0);
const bFree = b?.balance?.free ?? new BN(0);
return bFree.sub(aFree).toNumber();

if (bFree.lt(aFree)) {
return -1;
// eslint-disable-next-line no-else-return
} else {
return bFree.sub(aFree).toNumber();
}

This comment has been minimized.

Copy link
@MRamanenkau

MRamanenkau Jan 18, 2024

  1. Eslint suggests a good thing here. You don't need additional braces. The next code will work the same
  if (bFree.lt(aFree)) {
        return -1;
      } 

      return bFree.sub(aFree).toNumber();
  1. Why do we need this if?
});

return _accountsAsInput;
Expand Down
9 changes: 0 additions & 9 deletions src/library/GenerateNominations/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,6 @@ export const GenerateNominations = (props: GenerateNominationsInnerProps) => {
onSelected: true,
isDisabled: () => false,
},
{
title: 'Parachain Validator',
onClick: () => addNominationByType('Parachain Validator'),
onSelected: false,
icon: faPlus,
isDisabled: () =>
disabledMaxNominations() ||
!availableToNominate(nominations).parachainValidators.length,
},
{
title: 'Active Validator',
onClick: () => addNominationByType('Active Validator'),
Expand Down
Loading

0 comments on commit ddb02f4

Please sign in to comment.