From 9bd7392d73caf95043336028aca2919d38e3d536 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Wed, 27 Mar 2019 18:26:35 +0100 Subject: [PATCH] More informative staking page (buttons based on actions) (#855) * WIP * Render nominees * Staking statics & buttons --- package.json | 4 +- .../app-staking/src/Account/Nominating.tsx | 7 +- .../app-staking/src/Account/Validating.tsx | 7 +- packages/app-staking/src/Account/index.tsx | 188 ++++++++++-------- .../app-staking/src/Overview/CurrentList.tsx | 4 +- packages/app-staking/src/StakeList.tsx | 3 +- packages/app-staking/src/index.css | 14 +- packages/app-staking/src/index.tsx | 31 ++- packages/app-staking/src/types.ts | 6 + packages/ui-api/package.json | 2 +- packages/ui-api/src/with/call.tsx | 4 +- yarn.lock | 104 +++++----- 12 files changed, 212 insertions(+), 162 deletions(-) diff --git a/package.json b/package.json index 652303db3a..d56483a22e 100644 --- a/package.json +++ b/package.json @@ -10,9 +10,9 @@ "packages/*" ], "resolutions": { - "@polkadot/api": "^0.52.0-beta.1", + "@polkadot/api": "^0.52.0-beta.3", "@polkadot/keyring": "^0.42.0-beta.1", - "@polkadot/types": "^0.52.0-beta.1", + "@polkadot/types": "^0.52.0-beta.3", "@polkadot/util": "^0.42.0-beta.1", "@polkadot/util-crypto": "^0.42.0-beta.1", "babel-core": "^7.0.0-bridge.0", diff --git a/packages/app-staking/src/Account/Nominating.tsx b/packages/app-staking/src/Account/Nominating.tsx index 86c02ec562..4b81ca0474 100644 --- a/packages/app-staking/src/Account/Nominating.tsx +++ b/packages/app-staking/src/Account/Nominating.tsx @@ -15,8 +15,7 @@ type Props = I18nProps & { isOpen: boolean, onClose: () => void, intentions: Array, - stashId: string, - validators: Array + stashId: string }; type State = { @@ -141,7 +140,7 @@ class Nominating extends React.PureComponent { } private onChangeNominee = (nominee: string) => { - const { intentions, validators } = this.props; + // const { intentions } = this.props; let isAddressFormatValid = false; @@ -154,7 +153,7 @@ class Nominating extends React.PureComponent { } this.setState({ - isNomineeValid: validators.includes(nominee) || intentions.includes(nominee), + isNomineeValid: isAddressFormatValid, // intentions.includes(nominee), isAddressFormatValid, nominees: [nominee] }); diff --git a/packages/app-staking/src/Account/Validating.tsx b/packages/app-staking/src/Account/Validating.tsx index 42d580a0ca..049841987c 100644 --- a/packages/app-staking/src/Account/Validating.tsx +++ b/packages/app-staking/src/Account/Validating.tsx @@ -25,7 +25,10 @@ type State = { }; class Staking extends React.PureComponent { - state: State = {}; + state: State = { + unstakeThreshold: new BN(3), + validatorPayment: new BN(0) + }; // inject the preferences are returned via RPC once into the state (from this // point forward it will be entirely managed by the actual inputs) @@ -34,6 +37,8 @@ class Staking extends React.PureComponent { return null; } + console.error('preferences', props.preferences); + const { unstakeThreshold, validatorPayment } = props.preferences; return { diff --git a/packages/app-staking/src/Account/index.tsx b/packages/app-staking/src/Account/index.tsx index a283f00028..8e24388e55 100644 --- a/packages/app-staking/src/Account/index.tsx +++ b/packages/app-staking/src/Account/index.tsx @@ -5,9 +5,10 @@ import { DerivedBalancesMap } from '@polkadot/api-derive/types'; import { I18nProps } from '@polkadot/ui-app/types'; import { ApiProps } from '@polkadot/ui-api/types'; +import { Nominators } from '../types'; import React from 'react'; -import { AccountId, Balance, Option, StakingLedger, ValidatorPrefs } from '@polkadot/types'; +import { AccountId, Balance, Exposure, Option, StakingLedger, ValidatorPrefs } from '@polkadot/types'; import { AddressMini, AddressSummary, Button, TxButton } from '@polkadot/ui-app'; import { withCalls } from '@polkadot/ui-api'; @@ -25,15 +26,16 @@ type Props = ApiProps & I18nProps & { session_nextKeyFor?: Option, staking_bonded?: Option, staking_ledger?: Option, - staking_nominating?: Option, - staking_nominatorsFor?: Array, - staking_validators?: ValidatorPrefs, + staking_stakers?: Exposure, + staking_validators?: [ValidatorPrefs], intentions: Array, + nominators: Nominators, isValidator: boolean, validators: Array }; type State = { + isAccountValidating: boolean, isBondingOpen: boolean, isNominateOpen: boolean, isSessionKeyOpen: boolean, @@ -41,12 +43,12 @@ type State = { isUnbondOpen: boolean, bondedId: string | null, sessionId: string | null, - nomineeId: string | null, stashId: string | null }; class Account extends React.PureComponent { state: State = { + isAccountValidating: false, isBondingOpen: false, isSessionKeyOpen: false, isNominateOpen: false, @@ -54,21 +56,21 @@ class Account extends React.PureComponent { isUnbondOpen: false, bondedId: null, sessionId: null, - nomineeId: null, stashId: null }; - static getDerivedStateFromProps ({ session_nextKeyFor, staking_bonded, staking_ledger, staking_nominating }: Props): Partial { + static getDerivedStateFromProps ({ accountId, session_nextKeyFor, staking_bonded, staking_ledger, validators }: Props): Partial { + + // console.error('staking_stakers', JSON.stringify(staking_stakers)); + return { + isAccountValidating: validators.indexOf(accountId) !== -1, bondedId: staking_bonded && staking_bonded.isSome ? staking_bonded.unwrap().toString() : null, sessionId: session_nextKeyFor && session_nextKeyFor.isSome ? session_nextKeyFor.unwrap().toString() : null, - nomineeId: staking_nominating && staking_nominating.isSome - ? staking_nominating.unwrap().toString() - : null, stashId: staking_ledger && staking_ledger.isSome ? staking_ledger.unwrap().stash.toString() : null @@ -129,7 +131,7 @@ class Account extends React.PureComponent { accountId={accountId} isOpen onClose={this.toggleValidating} - preferences={staking_validators} + preferences={staking_validators[0]} stashId={stashId} /> ); @@ -166,48 +168,58 @@ class Account extends React.PureComponent { // ); // } - private renderNominee () { - const { balanceArray } = this.props; - const { nomineeId } = this.state; + private getNominees () { + const { nominators } = this.props; + const { stashId } = this.state; - if (!nomineeId) { + return stashId ? nominators[stashId] : null; + } + + private renderNominee () { + const nominees = this.getNominees(); + + if (!nominees || !nominees.length) { return null; } return (
- + { + nominees.map((nomineeId, index) => ( + + )) + }
); } private renderNominators () { - const { staking_nominatorsFor } = this.props; + // const { staking_nominatorsFor } = this.props; - if (!staking_nominatorsFor) { - return null; - } + // if (!staking_nominatorsFor) { + // return null; + // } - return ( -
- -
- {staking_nominatorsFor.map((nominator) => ( - - ))} -
-
- ); + // return ( + //
+ // + //
+ // {staking_nominatorsFor.map((nominator) => ( + // + // ))} + //
+ //
+ // ); } private renderBondedId () { @@ -247,7 +259,7 @@ class Account extends React.PureComponent { } private renderNominating () { - const { accountId, intentions, validators } = this.props; + const { accountId, intentions } = this.props; const { isNominateOpen, stashId } = this.state; if (!stashId) { @@ -261,14 +273,13 @@ class Account extends React.PureComponent { onClose={this.toggleNominate} intentions={intentions} stashId={stashId} - validators={validators} /> ); } private renderButtons () { - const { accountId, t } = this.props; - const { sessionId, stashId } = this.state; + const { accountId, intentions, t } = this.props; + const { isAccountValidating, sessionId, stashId } = this.state; const buttons = []; if (!stashId) { @@ -292,42 +303,58 @@ class Account extends React.PureComponent { ); } } else { - // buttons.push( - //