diff --git a/packages/page-staking/src/Actions/Account/BondExtra.tsx b/packages/page-staking/src/Actions/Account/BondExtra.tsx index 592a3c8621..212c33765b 100644 --- a/packages/page-staking/src/Actions/Account/BondExtra.tsx +++ b/packages/page-staking/src/Actions/Account/BondExtra.tsx @@ -55,7 +55,6 @@ function BondExtra ({ controllerId, onClose, stakingInfo, stashId }: Props): Rea return ( ('Bond more funds')} onClose={onClose} size='large' diff --git a/packages/page-staking/src/Actions/Account/Rebond.tsx b/packages/page-staking/src/Actions/Account/Rebond.tsx new file mode 100644 index 0000000000..c77089dde3 --- /dev/null +++ b/packages/page-staking/src/Actions/Account/Rebond.tsx @@ -0,0 +1,75 @@ +// Copyright 2017-2021 @polkadot/app-staking authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { DeriveStakingAccount } from '@polkadot/api-derive/types'; + +import BN from 'bn.js'; +import React, { useMemo, useState } from 'react'; + +import { InputBalance, Modal, TxButton } from '@polkadot/react-components'; +import { useApi } from '@polkadot/react-hooks'; +import { BN_ZERO } from '@polkadot/util'; + +import { useTranslation } from '../../translate'; +import SenderInfo from '../partials/SenderInfo'; + +interface Props { + controllerId: string | null; + onClose: () => void; + stakingInfo?: DeriveStakingAccount; + stashId: string; +} + +// TODO we should check that the bonded amoutn, after the operation is >= ED +function Rebond ({ controllerId, onClose, stakingInfo, stashId }: Props): React.ReactElement { + const { t } = useTranslation(); + const { api } = useApi(); + const [maxAdditional, setMaxAdditional] = useState(); + + const startBalance = useMemo( + () => stakingInfo && stakingInfo.unlocking + ? stakingInfo.unlocking.reduce((total, { value }) => total.iadd(value), new BN(0)) + : BN_ZERO, + [stakingInfo] + ); + + return ( + ('Bond more funds')} + onClose={onClose} + size='large' + > + + + {startBalance && ( + ('The amount the is to be rebonded from the value currently unlocking, i.e. previously unbonded')}> + ('Amount to add to the currently bonded funds. This is adjusted using the funds currently unlocking.')} + isError={!maxAdditional || maxAdditional.eqn(0) || maxAdditional.gt(startBalance)} + label={t('rebonded amount')} + onChange={setMaxAdditional} + /> + + )} + + + ('Rebond')} + onStart={onClose} + params={[maxAdditional]} + tx={api.tx.staking.rebond} + /> + + + ); +} + +export default React.memo(Rebond); diff --git a/packages/page-staking/src/Actions/Account/Unbond.tsx b/packages/page-staking/src/Actions/Account/Unbond.tsx index 3aa69761e1..038e856ffe 100644 --- a/packages/page-staking/src/Actions/Account/Unbond.tsx +++ b/packages/page-staking/src/Actions/Account/Unbond.tsx @@ -15,14 +15,13 @@ import { useTranslation } from '../../translate'; import useUnbondDuration from '../useUnbondDuration'; interface Props { - className?: string; controllerId?: AccountId | null; onClose: () => void; stakingLedger?: StakingLedger; stashId: string; } -function Unbond ({ className = '', controllerId, onClose, stakingLedger, stashId }: Props): React.ReactElement { +function Unbond ({ controllerId, onClose, stakingLedger, stashId }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); const bondedBlocks = useUnbondDuration(); @@ -32,7 +31,6 @@ function Unbond ({ className = '', controllerId, onClose, stakingLedger, stashId return ( ('Unbond funds')} onClose={onClose} size='large' diff --git a/packages/page-staking/src/Actions/Account/index.tsx b/packages/page-staking/src/Actions/Account/index.tsx index 3d6fa13e23..187ca20470 100644 --- a/packages/page-staking/src/Actions/Account/index.tsx +++ b/packages/page-staking/src/Actions/Account/index.tsx @@ -23,6 +23,7 @@ import InjectKeys from './InjectKeys'; import KickNominees from './KickNominees'; import ListNominees from './ListNominees'; import Nominate from './Nominate'; +import Rebond from './Rebond'; import SetControllerAccount from './SetControllerAccount'; import SetRewardDestination from './SetRewardDestination'; import SetSessionKey from './SetSessionKey'; @@ -76,6 +77,7 @@ function Account ({ allSlashes, className = '', info: { controllerId, destinatio const [isInjectOpen, toggleInject] = useToggle(); const [isKickOpen, toggleKick] = useToggle(); const [isNominateOpen, toggleNominate] = useToggle(); + const [isRebondOpen, toggleRebond] = useToggle(); const [isRewardDestinationOpen, toggleRewardDestination] = useToggle(); const [isSetControllerOpen, toggleSetController] = useToggle(); const [isSetSessionOpen, toggleSetSession] = useToggle(); @@ -148,6 +150,14 @@ function Account ({ allSlashes, className = '', info: { controllerId, destinatio targets={targets} /> )} + {isRebondOpen && ( + + )} {isSetControllerOpen && controllerId && ( {t('Unbond funds')} + + {t('Rebond funds')} + { +function SenderInfo ({ className = '', controllerId, stashId }: Props): React.ReactElement | null { const { t } = useTranslation(); + if (!stashId || !controllerId) { + return null; + } + return (