From d17efb4014788907f64a74d8f58478be9d3e2258 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Wed, 9 Sep 2020 16:21:59 +0200 Subject: [PATCH] Display reward destination for isAccount (#3646) * Display reward desitnation for isAccount * Allow adjustment of destination --- .../Actions/Account/SetRewardDestination.tsx | 38 +++++++++++++++---- .../src/Actions/Account/index.tsx | 11 ++++-- .../page-staking/src/Actions/constants.tsx | 7 +++- packages/page-staking/src/Actions/index.tsx | 2 +- .../src/Actions/partials/Bond.tsx | 8 ++-- packages/page-staking/src/Actions/types.ts | 2 + packages/page-treasury/src/Tips/Tips.tsx | 2 +- packages/react-hooks/src/types.ts | 5 +-- packages/react-hooks/src/useOwnStashInfos.ts | 3 +- 9 files changed, 54 insertions(+), 24 deletions(-) diff --git a/packages/page-staking/src/Actions/Account/SetRewardDestination.tsx b/packages/page-staking/src/Actions/Account/SetRewardDestination.tsx index 3222977e69..4657db636b 100644 --- a/packages/page-staking/src/Actions/Account/SetRewardDestination.tsx +++ b/packages/page-staking/src/Actions/Account/SetRewardDestination.tsx @@ -2,14 +2,17 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { RewardDestination } from '@polkadot/types/interfaces'; +import { DestinationType } from '../types'; + import React, { useState } from 'react'; import { Dropdown, InputAddress, Modal, TxButton } from '@polkadot/react-components'; import { useTranslation } from '../../translate'; -import { rewardDestinationOptions } from '../constants'; +import { rewardDestinationOptions, rewardDestinationOptionsPrev } from '../constants'; interface Props { - defaultDestination?: number; + defaultDestination?: RewardDestination; controllerId: string; onClose: () => void; stashId: string; @@ -17,7 +20,13 @@ interface Props { function SetRewardDestination ({ controllerId, defaultDestination, onClose, stashId }: Props): React.ReactElement { const { t } = useTranslation(); - const [destination, setDestination] = useState(0); + const [destination, setDestination] = useState(((defaultDestination?.isAccount ? 'Account' : defaultDestination?.toString()) || 'Staked') as 'Staked'); + const [destAccount, setDestAccount] = useState(defaultDestination?.isAccount ? defaultDestination.asAccount.toString() : null); + + const options = defaultDestination?.isAccount + ? rewardDestinationOptions + : rewardDestinationOptionsPrev; + const isAccount = destination === 'Account'; return ( ('The destination account for any payments as either a nominator or validator')} label={t('payment destination')} onChange={setDestination} - options={rewardDestinationOptions} + options={options} value={destination} /> + {isAccount && ( + + )}

{t('All rewards will go towards the selected output destination when a payout is made.')}

@@ -63,11 +81,15 @@ function SetRewardDestination ({ controllerId, defaultDestination, onClose, stas ('Set reward destination')} onStart={onClose} - params={[destination]} - tx={'staking.setPayee'} + params={[ + isAccount + ? { Account: destAccount } + : destination + ]} + tx='staking.setPayee' />
diff --git a/packages/page-staking/src/Actions/Account/index.tsx b/packages/page-staking/src/Actions/Account/index.tsx index 1804c5a7f1..3cf2cd4f46 100644 --- a/packages/page-staking/src/Actions/Account/index.tsx +++ b/packages/page-staking/src/Actions/Account/index.tsx @@ -66,7 +66,7 @@ function useStashCalls (api: ApiPromise, stashId: string) { return { balancesAll, spanCount, stakingAccount }; } -function Account ({ allSlashes, className = '', info: { controllerId, destination, destinationId, hexSessionIdNext, hexSessionIdQueue, isLoading, isOwnController, isOwnStash, isStashNominating, isStashValidating, nominating, sessionIds, stakingLedger, stashId }, isDisabled, targets }: Props): React.ReactElement { +function Account ({ allSlashes, className = '', info: { controllerId, destination, hexSessionIdNext, hexSessionIdQueue, isLoading, isOwnController, isOwnStash, isStashNominating, isStashValidating, nominating, sessionIds, stakingLedger, stashId }, isDisabled, targets }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); const { queueExtrinsic } = useContext(StatusContext); @@ -149,7 +149,7 @@ function Account ({ allSlashes, className = '', info: { controllerId, destinatio {isRewardDestinationOpen && controllerId && ( @@ -180,7 +180,12 @@ function Account ({ allSlashes, className = '', info: { controllerId, destinatio - {destination} + + {destination?.isAccount + ? + : destination?.toString() + } + diff --git a/packages/page-staking/src/Actions/constants.tsx b/packages/page-staking/src/Actions/constants.tsx index 33112baf16..86280f3a4f 100644 --- a/packages/page-staking/src/Actions/constants.tsx +++ b/packages/page-staking/src/Actions/constants.tsx @@ -2,8 +2,13 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -export const rewardDestinationOptions = [ +export const rewardDestinationOptionsPrev = [ { text: 'Stash account (increase the amount at stake)', value: 'Staked' }, { text: 'Stash account (do not increase the amount at stake)', value: 'Stash' }, { text: 'Controller account', value: 'Controller' } ]; + +export const rewardDestinationOptions = [ + ...rewardDestinationOptionsPrev, + { text: 'Payment account', value: 'Account' } +]; diff --git a/packages/page-staking/src/Actions/index.tsx b/packages/page-staking/src/Actions/index.tsx index be40fdea73..9605398660 100644 --- a/packages/page-staking/src/Actions/index.tsx +++ b/packages/page-staking/src/Actions/index.tsx @@ -59,7 +59,7 @@ function Actions ({ className = '', isInElection, ownStashes, targets }: Props): const headerRef = useRef([ [t('stashes'), 'start', 2], [t('controller'), 'address'], - [t('rewards'), 'number media--1200'], + [t('rewards'), 'start media--1200'], [t('bonded'), 'number'], [undefined, undefined, 2] ]); diff --git a/packages/page-staking/src/Actions/partials/Bond.tsx b/packages/page-staking/src/Actions/partials/Bond.tsx index 6cd89ef353..f615f9cfa5 100644 --- a/packages/page-staking/src/Actions/partials/Bond.tsx +++ b/packages/page-staking/src/Actions/partials/Bond.tsx @@ -3,7 +3,7 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { DeriveBalancesAll } from '@polkadot/api-derive/types'; -import { AmountValidateState } from '../types'; +import { AmountValidateState, DestinationType } from '../types'; import { BondInfo } from './types'; import BN from 'bn.js'; @@ -16,7 +16,7 @@ import { BN_ZERO } from '@polkadot/util'; import { useTranslation } from '../../translate'; import InputValidateAmount from '../Account/InputValidateAmount'; import InputValidationController from '../Account/InputValidationController'; -import { rewardDestinationOptions } from '../constants'; +import { rewardDestinationOptionsPrev } from '../constants'; import useUnbondDuration from '../useUnbondDuration'; interface Props { @@ -24,8 +24,6 @@ interface Props { onChange: (info: BondInfo) => void; } -type DestinationType = 'Staked' | 'Stash' | 'Controller' | 'Account'; - function Bond ({ className = '', onChange }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); @@ -152,7 +150,7 @@ function Bond ({ className = '', onChange }: Props): React.ReactElement { help={t('The destination account for any payments as either a nominator or validator')} label={t('payment destination')} onChange={setDestination} - options={rewardDestinationOptions} + options={rewardDestinationOptionsPrev} value={destination} /> diff --git a/packages/page-staking/src/Actions/types.ts b/packages/page-staking/src/Actions/types.ts index 564539bcd1..704ac25d8b 100644 --- a/packages/page-staking/src/Actions/types.ts +++ b/packages/page-staking/src/Actions/types.ts @@ -23,3 +23,5 @@ export interface Slash { era: BN; slashes: Unapplied[]; } + +export type DestinationType = 'Staked' | 'Stash' | 'Controller' | 'Account'; diff --git a/packages/page-treasury/src/Tips/Tips.tsx b/packages/page-treasury/src/Tips/Tips.tsx index 07a7ed1bb1..f244c8fcf0 100644 --- a/packages/page-treasury/src/Tips/Tips.tsx +++ b/packages/page-treasury/src/Tips/Tips.tsx @@ -105,7 +105,7 @@ export default React.memo(styled(Tips)` .ui--Toggle { margin-right: 1rem; - margin-top: 0.5rem; + margin-top: 0.75rem; } } `); diff --git a/packages/react-hooks/src/types.ts b/packages/react-hooks/src/types.ts index 55a5139cb6..3b78cef8b0 100644 --- a/packages/react-hooks/src/types.ts +++ b/packages/react-hooks/src/types.ts @@ -5,7 +5,7 @@ import { SubmittableExtrinsic } from '@polkadot/api/promise/types'; import { DeriveAccountFlags, DeriveAccountRegistration } from '@polkadot/api-derive/types'; import { ConstructTxFn, StringOrNull, VoidFn } from '@polkadot/react-components/types'; -import { AccountId, Balance, BlockNumber, Call, Exposure, Hash, SessionIndex, StakingLedger, ValidatorPrefs } from '@polkadot/types/interfaces'; +import { AccountId, Balance, BlockNumber, Call, Exposure, Hash, RewardDestination, SessionIndex, StakingLedger, ValidatorPrefs } from '@polkadot/types/interfaces'; import { IExtrinsic } from '@polkadot/types/types'; import { KeyringJson$Meta } from '@polkadot/ui-keyring/types'; @@ -122,8 +122,7 @@ export interface UseAccountInfo { export interface StakerState { controllerId: string | null; - destination?: string; - destinationId: number; + destination?: RewardDestination; exposure?: Exposure; hexSessionIdNext: string | null; hexSessionIdQueue: string | null; diff --git a/packages/react-hooks/src/useOwnStashInfos.ts b/packages/react-hooks/src/useOwnStashInfos.ts index 4de89cf0cc..0d92b80087 100644 --- a/packages/react-hooks/src/useOwnStashInfos.ts +++ b/packages/react-hooks/src/useOwnStashInfos.ts @@ -34,8 +34,7 @@ function getStakerState (stashId: string, allAccounts: string[], allStashes: str return { controllerId, - destination: rewardDestination?.toString().toLowerCase(), - destinationId: rewardDestination?.toNumber() || 0, + destination: rewardDestination, exposure, hexSessionIdNext: u8aToHex(nextConcat, 48), hexSessionIdQueue: u8aToHex(currConcat.length ? currConcat : nextConcat, 48),