diff --git a/packages/page-staking/src/Bags/Stash.tsx b/packages/page-staking/src/Bags/Stash.tsx index 61a39a478a..f97da5b6fa 100644 --- a/packages/page-staking/src/Bags/Stash.tsx +++ b/packages/page-staking/src/Bags/Stash.tsx @@ -4,6 +4,7 @@ import type { ListNode } from './types'; import React, { useMemo } from 'react'; +import styled from 'styled-components'; import { AddressMini, TxButton } from '@polkadot/react-components'; import { useApi } from '@polkadot/react-hooks'; @@ -11,37 +12,53 @@ import { useApi } from '@polkadot/react-hooks'; import { useTranslation } from '../translate'; interface Props { + className?: string; list?: ListNode[]; stashId: string; } -function findEntry (stashId: string, list: ListNode[] = []): ListNode | null { - return list.find((o) => o.stashId === stashId) || null; +function findEntry (stashId: string, list: ListNode[] = []): [ListNode | null, boolean, number] { + const entry = list.find((o) => o.stashId === stashId) || null; + const other = (entry && entry.jump && list.find((o) => o.stashId === entry.jump)) || null; + + return [entry, !!other, entry && other ? entry.index - other.index : 0]; } -export default function Stash ({ list, stashId }: Props): React.ReactElement { +function Stash ({ className, list, stashId }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); - const stashInfo = useMemo( + const [stashInfo, canJump, jumpCount] = useMemo( () => findEntry(stashId, list), [list, stashId] ); + // FIXME The button should disappear when we have moved to the correct position + return ( -
+
- {stashInfo && stashInfo.jump && ( - ('Jump')} - params={[stashInfo?.jump]} - tx={api.tx.bagsList.putInFrontOf} - /> - )} + ('Move up {{jumpCount}}', { replace: { jumpCount } })} + params={[stashInfo?.jump]} + tx={api.tx.bagsList.putInFrontOf} + />
); } + +export default styled(Stash)` + .ui--AddressMini { + vertical-align: middle; + } + + .ui--Button.isDisabled { + cursor: default; + opacity: 0; + } +`;