// Copyright 2017-2026 @pezkuwi/app-staking authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { DeriveBalancesAll } from '@pezkuwi/api-derive/types'; import type { PalletStakingRewardDestination } from '@pezkuwi/types/lookup'; import type { DestinationType } from '../types.js'; import React, { useMemo, useState } from 'react'; import { Dropdown, InputAddress, MarkError, Modal, TxButton } from '@pezkuwi/react-components'; import { useApi, useCall } from '@pezkuwi/react-hooks'; import { useTranslation } from '../../translate.js'; import { createDestCurr } from '../destOptions.js'; import SenderInfo from '../partials/SenderInfo.js'; interface Props { defaultDestination?: PalletStakingRewardDestination | null; controllerId: string; onClose: () => void; stashId: string; } function SetRewardDestination ({ controllerId, defaultDestination, onClose, stashId }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); const [destination, setDestination] = useState(() => ((defaultDestination?.isAccount ? 'Account' : defaultDestination?.toString()) || 'Staked') as 'Staked'); const [destAccount, setDestAccount] = useState(() => defaultDestination?.isAccount ? defaultDestination.asAccount.toString() : null); const destBalance = useCall(api.derive.balances?.all, [destAccount]); const options = useMemo( () => createDestCurr(t), [t] ); const isAccount = destination === 'Account'; const isDestError = isAccount && destBalance && destBalance.accountId.eq(destAccount) && destBalance.freeBalance.isZero(); return ( {isAccount && ( )} {isDestError && ( )} ); } export default React.memo(SetRewardDestination);