Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"packages/*"
],
"resolutions": {
"@polkadot/api": "^0.99.0-beta.6",
"@polkadot/api-contract": "^0.99.0-beta.6",
"@polkadot/api": "^0.99.0-beta.7",
"@polkadot/api-contract": "^0.99.0-beta.7",
"@polkadot/keyring": "^1.7.1",
"@polkadot/types": "^0.99.0-beta.6",
"@polkadot/types": "^0.99.0-beta.7",
"@polkadot/util": "^1.7.1",
"@polkadot/util-crypto": "^1.7.1",
"babel-core": "^7.0.0-bridge.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/app-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.7.5",
"@polkadot/api-contract": "^0.99.0-beta.6",
"@polkadot/api-contract": "^0.99.0-beta.7",
"@polkadot/react-components": "^0.38.0-beta.49"
}
}
25 changes: 8 additions & 17 deletions packages/app-staking/src/Actions/Account/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.

import { DerivedBalances, DerivedStaking, DerivedStakingOnlineStatus, DerivedHeartbeats } from '@polkadot/api-derive/types';
import { DerivedBalances, DerivedStakingAccount, DerivedHeartbeats } from '@polkadot/api-derive/types';
import { ApiProps } from '@polkadot/react-api/types';
import { I18nProps } from '@polkadot/react-components/types';
import { AccountId, Exposure, StakingLedger, ValidatorPrefs } from '@polkadot/types/interfaces';
import { KeyringSectionOption } from '@polkadot/ui-keyring/options/types';

import React from 'react';
import styled from 'styled-components';
import { AddressCard, AddressInfo, AddressMini, AddressRow, Button, Menu, OnlineStatus, Popup, TxButton } from '@polkadot/react-components';
import { AddressCard, AddressInfo, AddressMini, AddressRow, Button, Menu, Popup, TxButton } from '@polkadot/react-components';
import { withCalls, withMulti } from '@polkadot/react-api';

import BondExtra from './BondExtra';
Expand All @@ -31,7 +31,7 @@ interface Props extends ApiProps, I18nProps {
className?: string;
isOwnStash: boolean;
recentlyOnline?: DerivedHeartbeats;
staking_info?: DerivedStaking;
staking_account?: DerivedStakingAccount;
stashId: string;
stashOptions: KeyringSectionOption[];
}
Expand All @@ -53,7 +53,6 @@ interface State {
isUnbondOpen: boolean;
isValidateOpen: boolean;
nominees?: string[];
onlineStatus: DerivedStakingOnlineStatus;
sessionIds: string[];
stakers?: Exposure;
stakingLedger?: StakingLedger;
Expand Down Expand Up @@ -99,16 +98,15 @@ class Account extends React.PureComponent<Props, State> {
isStashValidating: false,
isUnbondOpen: false,
isValidateOpen: false,
onlineStatus: {},
sessionIds: []
};

public static getDerivedStateFromProps ({ allStashes, staking_info, stashId }: Props): Pick<State, never> | null {
if (!staking_info) {
public static getDerivedStateFromProps ({ allStashes, staking_account, stashId }: Props): Pick<State, never> | null {
if (!staking_account) {
return null;
}

const { controllerId, nextSessionIds, nominators, rewardDestination, sessionIds, stakers, stakingLedger, validatorPrefs } = staking_info;
const { controllerId, nextSessionIds, nominators, rewardDestination, sessionIds, stakers, stakingLedger, validatorPrefs } = staking_account;
const isStashNominating = nominators && !!nominators.length;
const isStashValidating = !!allStashes && !!stashId && allStashes.includes(stashId);
const nextConcat = u8aConcat(...nextSessionIds.map((id): Uint8Array => id.toU8a()));
Expand All @@ -135,7 +133,7 @@ class Account extends React.PureComponent<Props, State> {

public render (): React.ReactNode {
const { className, isSubstrateV2, stashId, t } = this.props;
const { controllerId, hexSessionIdNext, hexSessionIdQueue, isBondExtraOpen, isInjectOpen, isStashValidating, isUnbondOpen, nominees, onlineStatus, sessionIds } = this.state;
const { controllerId, hexSessionIdNext, hexSessionIdQueue, isBondExtraOpen, isInjectOpen, isStashValidating, isUnbondOpen, nominees, sessionIds } = this.state;

// Each component is rendered and gets a `is[Component]Open` passed in a `isOpen` props.
// These components will be loaded and return null at the first load (because is[Component]Open === false).
Expand All @@ -145,13 +143,6 @@ class Account extends React.PureComponent<Props, State> {
<AddressCard
buttons={this.renderButtons()}
className={className}
iconInfo={onlineStatus && (
<OnlineStatus
isTooltip
value={onlineStatus}
/>
)}
// label={t('stash')}
type='account'
value={stashId}
withAddressOrName
Expand Down Expand Up @@ -612,7 +603,7 @@ export default withMulti(
`,
translate,
withCalls<Props>(
['derive.staking.info', { paramName: 'stashId' }],
['derive.staking.account', { paramName: 'stashId' }],
['derive.balances.all', { paramName: 'stashId' }]
)
);
4 changes: 2 additions & 2 deletions packages/app-staking/src/Overview/Address.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.

import { AccountId, Balance, Points, ValidatorPrefsTo196 } from '@polkadot/types/interfaces';
import { DerivedStaking, DerivedHeartbeats } from '@polkadot/api-derive/types';
import { DerivedStakingQuery, DerivedHeartbeats } from '@polkadot/api-derive/types';
import { I18nProps } from '@polkadot/react-components/types';
import { ValidatorFilter } from '../types';

Expand Down Expand Up @@ -51,7 +51,7 @@ interface StakingState {
function Address ({ address, authorsMap, className, filter, hasQueries, isElected, isFavorite, lastAuthors, myAccounts, points, recentlyOnline, t, toggleFavorite, withNominations = true }: Props): React.ReactElement<Props> | null {
const { api } = useApi();
// FIXME Any horrors, caused by derive type mismatches
const stakingInfo = useCall<DerivedStaking>(api.derive.staking.info as any, [address]);
const stakingInfo = useCall<DerivedStakingQuery>(api.derive.staking.query as any, [address]);
const [hasActivity, setHasActivity] = useState(true);
const [{ commission, hasNominators, isNominatorMe, nominators, stashId, stakeOwn, stakeOther, validatorPayment }, setStakingState] = useState<StakingState>({
hasNominators: false,
Expand Down
33 changes: 8 additions & 25 deletions packages/app-staking/src/Targets/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { DerivedStakingElected } from '@polkadot/api-derive/types';
import { I18nProps } from '@polkadot/react-components/types';
import { AccountId, Exposure, ValidatorPrefs, ValidatorPrefsTo196 } from '@polkadot/types/interfaces';
import { ValidatorPrefs, ValidatorPrefsTo196 } from '@polkadot/types/interfaces';
import { SessionRewards } from '../types';
import { ValidatorInfo } from './types';

Expand Down Expand Up @@ -32,12 +32,6 @@ interface AllInfo {
validators: ValidatorInfo[];
}

interface BaseInfo {
accountId: AccountId;
stakers?: Exposure;
validatorPrefs?: ValidatorPrefs;
}

function sortValidators (list: ValidatorInfo[]): ValidatorInfo[] {
return list
.sort((a, b): number => b.bondTotal.cmp(a.bondTotal))
Expand Down Expand Up @@ -91,10 +85,11 @@ function sortValidators (list: ValidatorInfo[]): ValidatorInfo[] {
);
}

function extractInfo (allAccounts: string[], amount: BN = new BN(0), baseInfo: BaseInfo[], favorites: string[], lastReward: BN): AllInfo {
function extractInfo (allAccounts: string[], amount: BN = new BN(0), electedInfo: DerivedStakingElected, favorites: string[], lastReward: BN): AllInfo {
let totalStaked = new BN(0);
const perValidatorReward = lastReward.divn(electedInfo.info.length);
const validators = sortValidators(
baseInfo.map(({ accountId, stakers, validatorPrefs }): ValidatorInfo => {
electedInfo.info.map(({ accountId, stakers, validatorPrefs }): ValidatorInfo => {
const exposure = stakers || {
total: createType(registry, 'Compact<Balance>'),
own: createType(registry, 'Compact<Balance>'),
Expand All @@ -105,7 +100,6 @@ function extractInfo (allAccounts: string[], amount: BN = new BN(0), baseInfo: B
};
const bondOwn = exposure.own.unwrap();
const bondTotal = exposure.total.unwrap();
const perValidatorReward = lastReward.divn(baseInfo.length);
const validatorPayment = (prefs as ValidatorPrefsTo196).validatorPayment
? (prefs as ValidatorPrefsTo196).validatorPayment.unwrap() as BN
: (prefs as ValidatorPrefs).commission.unwrap().mul(perValidatorReward).div(PERBILL);
Expand Down Expand Up @@ -150,23 +144,12 @@ function Targets ({ className, sessionRewards, t }: Props): React.ReactElement<P
const { api } = useApi();
const { allAccounts } = useAccounts();
const [_amount, setAmount] = useState<BN | undefined>(new BN(1000));
const electedInfo = useCall<DerivedStakingElected>(api.derive.staking.electedInfo, [], { isSingle: true });
const electedInfo = useCall<DerivedStakingElected>(api.derive.staking.electedInfo, []);
const [favorites, toggleFavorite] = useFavorites(STORE_FAVS_BASE);
const [lastReward, setLastReward] = useState(new BN(0));
const [baseInfo, setBaseInfo] = useState<BaseInfo[] | undefined>();
const [{ validators, totalStaked }, setWorkable] = useState<AllInfo>({ totalStaked: new BN(0), validators: [] });
const amount = useDebounce(_amount);

useEffect((): void => {
if (electedInfo) {
setBaseInfo(
electedInfo.info.map(({ accountId, stakers, validatorPrefs }) => ({
accountId, stakers, validatorPrefs
}))
);
}
}, [electedInfo]);

useEffect((): void => {
if (sessionRewards && sessionRewards.length) {
const lastRewardSession = sessionRewards.filter(({ reward }): boolean => reward.gtn(0));
Expand All @@ -180,10 +163,10 @@ function Targets ({ className, sessionRewards, t }: Props): React.ReactElement<P
}, [sessionRewards]);

useEffect((): void => {
if (baseInfo) {
setWorkable(extractInfo(allAccounts, amount, baseInfo, favorites, lastReward));
if (electedInfo) {
setWorkable(extractInfo(allAccounts, amount, electedInfo, favorites, lastReward));
}
}, [allAccounts, amount, baseInfo, favorites, lastReward]);
}, [allAccounts, amount, electedInfo, favorites, lastReward]);

return (
<div className={className}>
Expand Down
2 changes: 1 addition & 1 deletion packages/react-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"homepage": "https://github.com/polkadot-js/ui/tree/master/packages/ui-reactive#readme",
"dependencies": {
"@babel/runtime": "^7.7.5",
"@polkadot/api": "^0.99.0-beta.6",
"@polkadot/api": "^0.99.0-beta.7",
"@polkadot/extension-dapp": "^0.14.0-beta.9",
"edgeware-node-types": "^1.0.10",
"rxjs-compat": "^6.5.3"
Expand Down
8 changes: 4 additions & 4 deletions packages/react-components/src/AddressInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.

import { DerivedBalances, DerivedStaking } from '@polkadot/api-derive/types';
import { DerivedBalances, DerivedStakingAccount } from '@polkadot/api-derive/types';
import { ValidatorPrefsTo145 } from '@polkadot/types/interfaces';
import { BareProps, I18nProps } from './types';

Expand Down Expand Up @@ -49,7 +49,7 @@ interface Props extends BareProps, I18nProps {
balancesAll?: DerivedBalances;
children?: React.ReactNode;
extraInfo?: [string, string][];
stakingInfo?: DerivedStaking;
stakingInfo?: DerivedStakingAccount;
withBalance?: boolean | BalanceActiveType;
withBalanceToggle?: false;
withExtended?: boolean | CryptoActiveType;
Expand Down Expand Up @@ -112,7 +112,7 @@ function skipStakingIf ({ stakingInfo, withBalance = true, withRewardDestination
}

// calculates the bonded, first being the own, the second being nominated
function calcBonded (stakingInfo?: DerivedStaking, bonded?: boolean | BN[]): [BN, BN[]] {
function calcBonded (stakingInfo?: DerivedStakingAccount, bonded?: boolean | BN[]): [BN, BN[]] {
let other: BN[] = [];
let own = new BN(0);

Expand Down Expand Up @@ -494,7 +494,7 @@ export default withMulti(
propName: 'balancesAll',
skipIf: skipBalancesIf
}],
['derive.staking.info', {
['derive.staking.account', {
paramName: 'address',
propName: 'stakingInfo',
skipIf: skipStakingIf
Expand Down
4 changes: 2 additions & 2 deletions packages/react-components/src/AddressRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.

import { DeriveAccountInfo, DerivedStaking } from '@polkadot/api-derive/types';
import { DeriveAccountInfo, DerivedStakingAccount } from '@polkadot/api-derive/types';
import { ApiProps } from '@polkadot/react-api/types';
import { I18nProps } from '@polkadot/react-components/types';
import { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces';
Expand Down Expand Up @@ -32,7 +32,7 @@ export interface Props extends I18nProps, RowProps {
accounts_info?: DeriveAccountInfo;
noDefaultNameOpacity?: boolean;
overlay?: React.ReactNode;
stakingInfo?: DerivedStaking;
stakingInfo?: DerivedStakingAccount;
value: AccountId | AccountIndex | Address | string | null;
withAddressOrName?: boolean;
withBalance?: boolean | BalanceActiveType;
Expand Down
75 changes: 0 additions & 75 deletions packages/react-components/src/OnlineStatus.tsx

This file was deleted.

1 change: 0 additions & 1 deletion packages/react-components/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export { default as Password } from './Password';
export { default as Popup } from './Popup';
export { default as Progress } from './Progress';
export { default as ProposedAction } from './ProposedAction';
export { default as OnlineStatus } from './OnlineStatus';
export { default as Row } from './Row';
export { default as Static } from './Static';
export { default as Status, StatusContext } from './Status';
Expand Down
Loading