Skip to content

support Paseo #1401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"@polkadot/types-support": "^11.2.1",
"@polkadot/util": "^12.6.2",
"@polkadot/util-crypto": "^12.6.2",
"@polkagate/apps-config": "^0.133.87",
"@polkagate/apps-config": "^0.140.1",
"@substrate/connect": "^0.7.32",
"@vaadin/icons": "^23.2.3",
"babel-plugin-transform-import-meta": "^2.1.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright 2019-2024 @polkadot/extension-polkagate authors & contributors
// SPDX-License-Identifier: Apache-2.0
// @ts-nocheck

/* eslint-disable react/jsx-max-props-per-line */

Expand All @@ -18,6 +17,7 @@
import { amountToHuman, amountToMachine } from '../../../util/utils';
import type { Inputs } from '../Entry';
import { STEPS } from '..';
import { POLKAGATE_POOL_IDS } from '../../../util/constants';

interface Props {
address: string
Expand All @@ -27,22 +27,16 @@
setInputs: React.Dispatch<React.SetStateAction<Inputs | undefined>>
}

const POLKAGATE_POOL_IDS = {
Kusama: 18,
Polkadot: 8,
Westend: 6
};

export default function EasyMode({ address, balances, inputs, setInputs, setStep }: Props): React.ReactElement {
const { t } = useTranslation();
const theme = useTheme();
const { api, chainName, decimal, formatted } = useInfo(address);
const pool = usePool(address, POLKAGATE_POOL_IDS[chainName] as number);
const pool = usePool(address, POLKAGATE_POOL_IDS[chainName as string] as number);

const poolConsts = usePoolConsts(address);
const stakingConsts = useStakingConsts(address);

const [amount, setAmount] = useState<string>(inputs?.extraInfo?.amount);
const [amount, setAmount] = useState<string>(inputs?.extraInfo?.['amount'] as string);
const [amountAsBN, setAmountAsBN] = useState<BN>(BN_ZERO);
const [isNextClicked, setNextIsClicked] = useState<boolean>();
const [topStakingLimit, setTopStakingLimit] = useState<BN>();
Expand All @@ -55,7 +49,7 @@
return !amount || !amountAsBN || !topStakingLimit || parseFloat(amount) === 0 || amountAsBN.gt(topStakingLimit);
}, [amount, amountAsBN, topStakingLimit]);

const isBusy = !inputs?.extraInfo?.amount && isNextClicked;
const isBusy = !inputs?.extraInfo?.['amount'] && isNextClicked;

useEffect(() => {
if (!amountAsBN || !amount) {
Expand All @@ -75,11 +69,11 @@
}

if (!api?.call?.['transactionPaymentApi']) {
return setEstimatedMaxFee(api.createType('Balance', BN_ONE));

Check failure on line 72 in packages/extension-polkagate/src/fullscreen/stake/easyMode/index.tsx

View workflow job for this annotation

GitHub Actions / build

Argument of type 'Codec' is not assignable to parameter of type 'SetStateAction<Balance | undefined>'.
}

amountAsBN && api.tx['nominationPools']['bondExtra']({ FreeBalance: availableBalance.toString() }).paymentInfo(formatted).then((i) => {
setEstimatedMaxFee(api.createType('Balance', i?.partialFee));

Check failure on line 76 in packages/extension-polkagate/src/fullscreen/stake/easyMode/index.tsx

View workflow job for this annotation

GitHub Actions / build

Argument of type 'Codec' is not assignable to parameter of type 'SetStateAction<Balance | undefined>'.
});
}, [formatted, api, availableBalance, amount, decimal, amountAsBN]);

Expand All @@ -103,8 +97,7 @@
pool
});
} else {
console.log('waiting!');
console.log('waiting:', amount, amountAsBN, poolConsts, pool, api, poolConsts?.minJoinBond && amountAsBN?.gte(poolConsts?.minJoinBond));
console.log('waiting for pool:', pool);
}
}, [amount, amountAsBN, api, pool, poolConsts, setInputs]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function ShowValidator({ accountInfo, allInOneRow = true, api, chain, check, dec
{t('Nominators')}:
</Grid>
<Grid fontSize='14px' fontWeight={400} item lineHeight='22px' pl='3px'>
{v.exposure.others.length || t('N/A')}
{v.exposure.others?.length || t('N/A')}
</Grid>
</Grid>
<Grid alignItems='center' container item justifyContent='flex-end' sx={{ lineHeight: '23px', pl: '2px' }} width='fit-content'>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// Copyright 2019-2024 @polkadot/extension-polkagate authors & contributors
// SPDX-License-Identifier: Apache-2.0
// @ts-nocheck

/* eslint-disable react/jsx-max-props-per-line */

import type { AccountId } from '@polkadot/types/interfaces';

import { alpha, Grid, type SxProps, type Theme, useTheme } from '@mui/material';
import React, { useCallback, useEffect, useRef, useState } from 'react';
// @ts-ignore
import { FixedSizeList as List } from 'react-window';

import { DeriveAccountInfo } from '@polkadot/api-derive/types';
import type { DeriveAccountInfo } from '@polkadot/api-derive/types';
import { useInfo } from '@polkadot/extension-polkagate/src/hooks';
import ValidatorInfoPage from '@polkadot/extension-polkagate/src/popup/staking/partial/ValidatorInfo';
import { BN, hexToBn, isHex } from '@polkadot/util';
Expand Down Expand Up @@ -55,18 +55,18 @@ export default function ValidatorsTable({ activeValidators, address, allValidato
}

const threshold = stakingConsts.maxNominatorRewardedPerValidator;
const sortedNominators = v.exposure.others.sort((a, b) => b.value - a.value);
const maybeMyIndex = staked ? sortedNominators.findIndex((n) => new BN(isHex(n.value) ? hexToBn(n.value) : String(n.value)).lt(staked)) : -1;
const sortedNominators = v.exposure.others?.sort((a:any, b:any) => b.value - a.value);
const maybeMyIndex = staked ? sortedNominators?.findIndex((n:any) => new BN(isHex(n.value) ? hexToBn(n.value) : String(n.value)).lt(staked)) : -1;

return {
notSafe: v.exposure.others.length > threshold && (maybeMyIndex > threshold || maybeMyIndex === -1),
safe: v.exposure.others.length > threshold && (maybeMyIndex < threshold || maybeMyIndex === -1)
notSafe: v.exposure.others?.length > threshold && (maybeMyIndex > threshold || maybeMyIndex === -1),
safe: v.exposure.others?.length > threshold && (maybeMyIndex < threshold || maybeMyIndex === -1)
};
}, [staked, stakingConsts]);

useEffect(() => {
if (maxSelected) {
ref.current.scrollTop = 0;
if (maxSelected && ref?.current) {
(ref?.current as any).scrollTop = 0;
}
}, [maxSelected]);

Expand All @@ -93,8 +93,8 @@ export default function ValidatorsTable({ activeValidators, address, allValidato
ref={ref}
width={'100%'}
>
{({ index, key, style }) => {
const v = validatorsToList[index];
{({ index, key, style }: { index: number, key:number, style:any }) => {
const v = validatorsToList![index];
const isActive = !!activeValidators?.find((av) => v.accountId === av?.accountId);
const isOversubscribed = overSubscribed(v);
const accountInfo = allValidatorsIdentities?.find((a) => a.accountId === v?.accountId);
Expand Down
7 changes: 4 additions & 3 deletions packages/extension-polkagate/src/hooks/usePeopleChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useMemo } from 'react';
import type { Chain } from '@polkadot/extension-chains/types';


import { KUSAMA_PEOPLE_GENESIS_HASH, POLKADOT_GENESIS_HASH, WESTEND_PEOPLE_GENESIS_HASH } from '../util/constants';
import { KUSAMA_PEOPLE_GENESIS_HASH, PASEO_GENESIS_HASH, POLKADOT_GENESIS_HASH, RELAY_CHAINS_NAMES, WESTEND_PEOPLE_GENESIS_HASH } from '../util/constants';
import getChain from '../util/getChain';
import { sanitizeChainName } from '../util/utils';
import { useInfo, useMetadata } from '.';
Expand All @@ -24,8 +24,7 @@ interface PeopleChainInfo {
*/

const getPeopleChainGenesisHash = (chainName: string | undefined) => {
const relayChainNames = ['Westend', 'Kusama', 'Polkadot'];
const startWith = relayChainNames.find((name) => chainName?.startsWith(name)) || undefined;
const startWith = RELAY_CHAINS_NAMES.find((name) => chainName?.startsWith(name)) || undefined;

switch (startWith) {
case 'Westend':
Expand All @@ -34,6 +33,8 @@ const getPeopleChainGenesisHash = (chainName: string | undefined) => {
return KUSAMA_PEOPLE_GENESIS_HASH;
case 'Polkadot':
return POLKADOT_GENESIS_HASH; // should be changed to POLKADOT_PEOPLE_GENESIS_HASH in the future
case 'Paseo':
return PASEO_GENESIS_HASH;
default:
return undefined;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright 2019-2024 @polkadot/extension-polkagate authors & contributors
// SPDX-License-Identifier: Apache-2.0
// @ts-nocheck

import type { StakingConsts, ValidatorInfo, ValidatorInfoWithIdentity } from '../util/types';

Expand All @@ -23,7 +22,7 @@ export default function useValidatorSuggestion(address: string): ValidatorInfo[]

const [selected, setSelected] = useState<ValidatorInfo[] | undefined>();

const allValidators = useMemo(() => allValidatorsInfo?.current?.concat(allValidatorsInfo.waiting)?.filter((v) => v.validatorPrefs.blocked === false || v.validatorPrefs.blocked.isFalse), [allValidatorsInfo]);
const allValidators = useMemo(() => allValidatorsInfo?.current?.concat(allValidatorsInfo.waiting)?.filter((v) => v.validatorPrefs.blocked as unknown as boolean === false || v.validatorPrefs.blocked.isFalse), [allValidatorsInfo]);

const onLimitValidatorsPerOperator = useCallback((validators: ValidatorInfoWithIdentity[] | undefined, limit: number): ValidatorInfoWithIdentity[] => {
if (!validators?.length) {
Expand All @@ -38,7 +37,7 @@ export default function useValidatorSuggestion(address: string): ValidatorInfo[]
v.identity = vId?.identity;
});

aDeepCopyOfValidators.sort((v1, v2) => ('' + v1?.identity?.displayParent).localeCompare(v2?.identity?.displayParent));
aDeepCopyOfValidators.sort((v1, v2) => ('' + v1?.identity?.displayParent).localeCompare(v2?.identity?.displayParent || ''));

let counter = 1;
let indicator = aDeepCopyOfValidators[0];
Expand All @@ -65,7 +64,7 @@ export default function useValidatorSuggestion(address: string): ValidatorInfo[]
// !v.validatorPrefs.blocked && // filter blocked validators
Number(v.validatorPrefs.commission) !== 0 && // filter 0 commission validators, to exclude new and chilled validators
(Number(v.validatorPrefs.commission) / (10 ** 7)) < DEFAULT_FILTERS.maxCommission.value && // filter high commission validators
v.exposure.others.length && v.exposure.others.length < stakingConsts?.maxNominatorRewardedPerValidator// filter oversubscribed
v.exposure.others?.length && v.exposure.others.length < stakingConsts?.maxNominatorRewardedPerValidator// filter oversubscribed
// && v.exposure.others.length > stakingConsts?.maxNominatorRewardedPerValidator / 4 // filter validators with very low nominators
);
const filtered2 = onLimitValidatorsPerOperator(filtered1, DEFAULT_FILTERS.limitOfValidatorsPerOperator.value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function ShowValidator({ accountInfo, api, chain, check, decimal, handleCheck, i
<Grid alignItems='end' container item sx={{ fontSize: '12px', fontWeight: 300, lineHeight: '23px' }} width='fit-content'>
{t<string>('Nominators:')}
<Grid fontSize='12px' fontWeight={400} item lineHeight='22px' pl='3px'>
{v.exposure.others.length || t('N/A')}
{v.exposure.others?.length || t('N/A')}
</Grid>
</Grid>
<Grid alignItems='center' container item justifyContent='flex-end' sx={{ lineHeight: '23px', pl: '2px' }} width='fit-content'>
Expand Down
50 changes: 28 additions & 22 deletions packages/extension-polkagate/src/util/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ export const EXTENSION_NAME = 'Polkagate';
export const NEW_VERSION_ALERT = 'alert_v0.5.8';
export const PREFERRED_POOL_NAME = EXTENSION_NAME;

export const POLKAGATE_POOL_IDS: { [key: string]: number } = {
Kusama: 18,
Polkadot: 8,
Westend: 6,
Paseo: 3
};

// export const EXTENSION_FEEDBACK_FORM_URL = 'https://docs.google.com/forms/d/e/1FAIpQLSf2WHD0oVR0NS7tW6C1U025H1XBEZXqwxvFvPhcoFa18eHQiA/viewform';

export const BALANCES_VALIDITY_PERIOD = 5 * 60 * 1000; // to show outdated balance in grey
Expand All @@ -26,56 +33,54 @@ export const CHAINS_WITH_BLACK_LOGO = ['statescan', 'Centrifuge', 'Centrifuge Ch
export const TOKENS_WITH_BLACK_LOGO = ['KSM', 'PEN', 'ZTG'];
export const CHAINS_ON_POLKAHOLIC = ['Pendulum', 'Pendulum chain', 'Amplitude', 'Amplitude chain'];
export const DISABLED_NETWORKS = ['3DP network', 'xx network', 'Polkadex Mainnet', 'Stafi'];
export const RELAY_CHAINS = [
{
name: 'Polkadot',
symbol: 'DOT'
},
{
name: 'Kusama',
symbol: 'KSM'
},
{
name: 'Westend',
symbol: 'WND'
}
];

export const POLKADOT_GENESIS_HASH = '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3';
export const KUSAMA_GENESIS_HASH = '0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe';
export const WESTEND_GENESIS_HASH = '0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e';
export const ACALA_GENESIS_HASH = '0xfc41b9bd8ef8fe53d58c7ea67c794c7ec9a73daf05e6d54b14ff6342c99ba64c';

export const WESTMINT_GENESIS_HASH = '0x67f9723393ef76214df0118c34bbbd3dbebc8ed46a10973a8c969d48fe7598c9';
export const STATEMINE_GENESIS_HASH = '0x48239ef607d7928874027a43a67689209727dfb3d3dc5e5b03a39bdc2eda771a'; // KUSAMA ASSET HUB
export const STATEMINT_GENESIS_HASH = '0x68d56f15f85d3136970ec16946040bc1752654e906147f7e43e9d539d7c3de2f';
export const PASEO_ASSET_HUB_GENESIS_HASH = '0x862ce2fa5abfdc3d29ead85a9472071efc69433b0128db1d6f009967fae87952';

export const WESTEND_PEOPLE_GENESIS_HASH = '0x1eb6fb0ba5187434de017a70cb84d4f47142df1d571d0ef9e7e1407f2b80b93c';
export const KUSAMA_PEOPLE_GENESIS_HASH = '0xc1af4cb4eb3918e5db15086c0cc5ec17fb334f728b7c65dd44bfe1e174ff8b3f';
export const POLKADOT_PEOPLE_GENESIS_HASH = '';


/** relay chains info */
export const RELAY_CHAINS_NAMES = ['Polkadot', 'Kusama', 'Westend', 'Paseo'];

export const POLKADOT_GENESIS_HASH = '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3';
export const KUSAMA_GENESIS_HASH = '0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe';
export const WESTEND_GENESIS_HASH = '0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e';
export const PASEO_GENESIS_HASH = '0x77afd6190f1554ad45fd0d31aee62aacc33c6db0ea801129acb813f913e0764f';

export const RELAY_CHAINS_GENESISHASH = [
POLKADOT_GENESIS_HASH,
KUSAMA_GENESIS_HASH,
WESTEND_GENESIS_HASH
WESTEND_GENESIS_HASH,
PASEO_GENESIS_HASH
];

export const ASSET_HUBS = [
WESTMINT_GENESIS_HASH,
STATEMINE_GENESIS_HASH,
STATEMINT_GENESIS_HASH
STATEMINT_GENESIS_HASH,
PASEO_ASSET_HUB_GENESIS_HASH
];

export const TEST_NETS = [
WESTEND_GENESIS_HASH,
WESTMINT_GENESIS_HASH,
WESTEND_PEOPLE_GENESIS_HASH
WESTEND_PEOPLE_GENESIS_HASH,
PASEO_GENESIS_HASH,
PASEO_ASSET_HUB_GENESIS_HASH
];

export const PROXY_CHAINS = [
POLKADOT_GENESIS_HASH,
KUSAMA_GENESIS_HASH,
WESTEND_GENESIS_HASH,
PASEO_GENESIS_HASH,
...ASSET_HUBS
];

Expand All @@ -98,8 +103,9 @@ export const SOCIAL_RECOVERY_CHAINS = [
// used to enable/disable staking icon in account page
export const STAKING_CHAINS = [
POLKADOT_GENESIS_HASH,
KUSAMA_GENESIS_HASH,
WESTEND_GENESIS_HASH,
KUSAMA_GENESIS_HASH
PASEO_GENESIS_HASH
];

export const PEOPLE_CHAINS = ['Kusama', 'Westend', 'KusamaPeople', 'WestendPeople'];
Expand Down Expand Up @@ -144,7 +150,7 @@ const PROXY_TYPE_KUSAMA = ['Any', 'NonTransfer', 'Staking', 'Society', 'Governan
const PROXY_TYPE_WESTEND = ['Any', 'NonTransfer', 'Staking', 'Governance', 'SudoBalances', 'IdentityJudgement', 'CancelProxy', 'Auction', 'NominationPools'];
const PROXY_TYPE_ASSET_HUBS = ['Any', 'NonTransfer', 'CancelProxy', 'Assets', 'AssetOwner', 'AssetManager', 'Collator'];

export const CHAIN_PROXY_TYPES = { Kusama: PROXY_TYPE_KUSAMA, Polkadot: PROXY_TYPE_POLKADOT, Westend: PROXY_TYPE_WESTEND, AssetHubs: PROXY_TYPE_ASSET_HUBS};
export const CHAIN_PROXY_TYPES = { Kusama: PROXY_TYPE_KUSAMA, Polkadot: PROXY_TYPE_POLKADOT, Westend: PROXY_TYPE_WESTEND, AssetHubs: PROXY_TYPE_ASSET_HUBS };

export const VOTE_MAP = {
AYE: 1,
Expand Down
2 changes: 1 addition & 1 deletion packages/extension-polkagate/src/util/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ export async function getHistoryFromStorage(formatted: string): Promise<Transact
export const isHexToBn = (i: string): BN => isHex(i) ? hexToBn(i) : new BN(i);
export const toBN = (i: any): BN => isHexToBn(String(i));

export const sanitizeChainName = (chainName: string | undefined) => (chainName?.replace(' Relay Chain', '')?.replace(' Network', '')?.replace(' chain', '')?.replace(' Chain', '')?.replace(' Finance', '')?.replace(/\s/g, ''));
export const sanitizeChainName = (chainName: string | undefined) => (chainName?.replace(' Relay Chain', '')?.replace(' Network', '')?.replace(' chain', '')?.replace(' Chain', '')?.replace(' Finance', '')?.replace(' Testnet', '')?.replace(/\s/g, ''));

export const isEmail = (input: string | undefined) => {
if (!input) {
Expand Down
Loading
Loading