Files
pezkuwi-apps/packages/page-staking-legacy/src/Actions/Account/SetRewardDestination.tsx
T
Kurdistan Tech MinistryandClaude Opus 4.5 7a4bbeac25 fix: update extension packages and fix type compatibility for pezkuwi-sdk
- Update @pezkuwi/extension-inject to ^0.62.13 with proper /types exports
- Update @pezkuwi/extension-dapp to ^0.62.13
- Update @pezkuwi/extension-compat-metamask to ^0.62.13
- Fix IconTheme type to include 'bizinikiwi' and 'pezkuwi' themes
- Fix endpoint array issues (getTeleports -> direct array references)
- Add type assertions for external package compatibility (acala, moonbeam, parallel)
- Fix subspace.ts dynamic class typing
- Fix conviction type in page-referenda
- Update Pallet type names to Pezpallet prefix across codebase
- Define InjectedExtension types locally for module resolution
- Add styled-components DefaultTheme augmentation
- Add react-copy-to-clipboard type declaration for React 18

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-08 16:24:19 +03:00

91 lines
3.2 KiB
TypeScript

// Copyright 2017-2026 @pezkuwi/app-staking authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { DeriveBalancesAll } from '@pezkuwi/api-derive/types';
import type { PezpalletStakingRewardDestination } 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?: PezpalletStakingRewardDestination | null;
controllerId: string;
onClose: () => void;
stashId: string;
}
function SetRewardDestination ({ controllerId, defaultDestination, onClose, stashId }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const { api } = useApi();
const [destination, setDestination] = useState<DestinationType>(() => ((defaultDestination?.isAccount ? 'Account' : defaultDestination?.toString()) || 'Staked') as 'Staked');
const [destAccount, setDestAccount] = useState<string | null>(() => defaultDestination?.isAccount ? defaultDestination.asAccount.toString() : null);
const destBalance = useCall<DeriveBalancesAll>(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 (
<Modal
header={t('Bonding Preferences')}
onClose={onClose}
size='large'
>
<Modal.Content>
<SenderInfo
controllerId={controllerId}
stashId={stashId}
/>
<Modal.Columns hint={t('All rewards will go towards the selected output destination when a payout is made.')}>
<Dropdown
defaultValue={defaultDestination?.toString()}
label={t('payment destination')}
onChange={setDestination}
options={options}
value={destination}
/>
{isAccount && (
<InputAddress
label={t('the payment account')}
onChange={setDestAccount}
type='account'
value={destAccount}
/>
)}
{isDestError && (
<MarkError content={t('The selected destination account does not exist and cannot be used to receive rewards')} />
)}
</Modal.Columns>
</Modal.Content>
<Modal.Actions>
<TxButton
accountId={controllerId}
icon='sign-in-alt'
isDisabled={!controllerId || (isAccount && (!destAccount || isDestError))}
label={t('Set reward destination')}
onStart={onClose}
params={[
isAccount
? { Account: destAccount }
: destination
]}
tx={api.tx.staking.setPayee}
/>
</Modal.Actions>
</Modal>
);
}
export default React.memo(SetRewardDestination);