diff --git a/src/renderer/widgets/DelegateDetails/ui/YourDelegation.tsx b/src/renderer/widgets/DelegateDetails/ui/YourDelegation.tsx index 34dd577f50..b0ef3c0893 100644 --- a/src/renderer/widgets/DelegateDetails/ui/YourDelegation.tsx +++ b/src/renderer/widgets/DelegateDetails/ui/YourDelegation.tsx @@ -1,4 +1,3 @@ -import { BN } from '@polkadot/util'; import { useUnit } from 'effector-react'; import { Trans } from 'react-i18next'; @@ -61,13 +60,10 @@ export const YourDelegation = () => { components={{ votes: ( diff --git a/src/renderer/widgets/DelegateDetails/ui/YourDelegations.tsx b/src/renderer/widgets/DelegateDetails/ui/YourDelegations.tsx index 6b616f4f98..525ba04788 100644 --- a/src/renderer/widgets/DelegateDetails/ui/YourDelegations.tsx +++ b/src/renderer/widgets/DelegateDetails/ui/YourDelegations.tsx @@ -1,4 +1,3 @@ -import { BN } from '@polkadot/util'; import { useUnit } from 'effector-react'; import { Trans } from 'react-i18next'; @@ -51,8 +50,6 @@ export const YourDelegations = () => { if (!account || !activeDelegation) return null; - const convictionMultiplier = votingService.getConvictionMultiplier(activeDelegation.conviction); - return (
@@ -80,7 +77,10 @@ export const YourDelegations = () => { components={{ votes: ( @@ -92,7 +92,7 @@ export const YourDelegations = () => { , }} diff --git a/src/renderer/widgets/DelegateModal/lib/helpers.ts b/src/renderer/widgets/DelegateModal/lib/helpers.ts index 5d2f7d6084..da6088d9b1 100644 --- a/src/renderer/widgets/DelegateModal/lib/helpers.ts +++ b/src/renderer/widgets/DelegateModal/lib/helpers.ts @@ -4,6 +4,7 @@ import { type Asset } from '@/shared/core'; import { nonNullable } from '@shared/lib/utils'; import { treasurySpendsDescription } from './constants'; +import { type Track } from './types'; export const getTreasuryTrackDescription = (asset: Asset | null, description: string, t: TFunction) => { if (nonNullable(asset) && treasurySpendsDescription[description]?.[asset.symbol]) { @@ -12,3 +13,7 @@ export const getTreasuryTrackDescription = (asset: Asset | null, description: st return t(`${description}General`); }; + +export const getTrackIds = (tracks: Track[], votedTracks: string[]): number[] => { + return tracks.filter((t) => !votedTracks.includes(t.id)).map((track) => Number(track.id)); +}; diff --git a/src/renderer/widgets/DelegateModal/lib/types.ts b/src/renderer/widgets/DelegateModal/lib/types.ts index f632e453c2..0ab0adaa64 100644 --- a/src/renderer/widgets/DelegateModal/lib/types.ts +++ b/src/renderer/widgets/DelegateModal/lib/types.ts @@ -20,3 +20,9 @@ export type FeeData = { totalFee: string; multisigDeposit: string; }; + +export type Track = { + id: string; + value: string; + description: string; +}; diff --git a/src/renderer/widgets/DelegateModal/model/select-tracks-model.ts b/src/renderer/widgets/DelegateModal/model/select-tracks-model.ts index 57c5052ba9..48f7c609a2 100644 --- a/src/renderer/widgets/DelegateModal/model/select-tracks-model.ts +++ b/src/renderer/widgets/DelegateModal/model/select-tracks-model.ts @@ -111,6 +111,9 @@ export const selectTracksModel = { $availableTracks, $votedTracks, $tracksGroup, + $allTracks: $tracksGroup.map(({ adminTracks, governanceTracks, treasuryTracks, fellowshipTracks }) => { + return [...adminTracks, ...governanceTracks, ...treasuryTracks, ...fellowshipTracks]; + }), $accounts, $availableAccounts, diff --git a/src/renderer/widgets/DelegateModal/ui/SelectTracksForm.tsx b/src/renderer/widgets/DelegateModal/ui/SelectTracksForm.tsx index fdbb8456ce..39cd152440 100644 --- a/src/renderer/widgets/DelegateModal/ui/SelectTracksForm.tsx +++ b/src/renderer/widgets/DelegateModal/ui/SelectTracksForm.tsx @@ -6,7 +6,7 @@ import { BaseModal, Button, Checkbox, FootnoteText, Icon, MultiSelect, SmallTitl import { OperationTitle } from '@/entities/chain'; import { AccountAddress, accountUtils } from '@/entities/wallet'; import { votingAssetModel } from '@/features/governance'; -import { getTreasuryTrackDescription } from '../lib/helpers'; +import { getTrackIds, getTreasuryTrackDescription } from '../lib/helpers'; import { delegateModel } from '../model/delegate-model'; import { selectTracksModel } from '../model/select-tracks-model'; @@ -21,9 +21,9 @@ export const SelectTrackForm = ({ isOpen, onClose }: Props) => { const chain = useUnit(selectTracksModel.$chain); const tracks = useUnit(selectTracksModel.$tracks); const accounts = useUnit(selectTracksModel.$accounts); - const availableTracks = useUnit(selectTracksModel.$availableTracks); const votedTracks = useUnit(selectTracksModel.$votedTracks); const tracksGroup = useUnit(selectTracksModel.$tracksGroup); + const allTracks = useUnit(selectTracksModel.$allTracks); const asset = useUnit(votingAssetModel.$votingAsset); const { adminTracks, governanceTracks, treasuryTracks, fellowshipTracks } = tracksGroup; @@ -47,37 +47,41 @@ export const SelectTrackForm = ({ isOpen, onClose }: Props) => {
diff --git a/src/renderer/widgets/DelegationModal/components/AddCustomDelegationModal.tsx b/src/renderer/widgets/DelegationModal/components/AddCustomDelegationModal.tsx index 0652ccafc8..1c0fc686ce 100644 --- a/src/renderer/widgets/DelegationModal/components/AddCustomDelegationModal.tsx +++ b/src/renderer/widgets/DelegationModal/components/AddCustomDelegationModal.tsx @@ -63,7 +63,7 @@ export const AddCustomDelegationModel = () => {
-
diff --git a/src/renderer/widgets/DelegationModal/model/delegation-model.ts b/src/renderer/widgets/DelegationModal/model/delegation-model.ts index 6b8899b7c0..9e89e3377a 100644 --- a/src/renderer/widgets/DelegationModal/model/delegation-model.ts +++ b/src/renderer/widgets/DelegationModal/model/delegation-model.ts @@ -5,7 +5,7 @@ import { readonly } from 'patronum'; import { type DelegateAccount } from '@/shared/api/governance'; import { type Address } from '@/shared/core'; -import { Step, includesMultiple, toAccountId, toAddress, validateAddress } from '@/shared/lib/utils'; +import { Step, includesMultiple, toAccountId, validateAddress } from '@/shared/lib/utils'; import { votingService } from '@/entities/governance'; import { walletModel } from '@/entities/wallet'; import { @@ -89,22 +89,18 @@ const $customError = combine( wallet: walletModel.$activeWallet, chain: delegationAggregate.$chain, }, - ({ delegate, votes, wallet, chain }): DelegationErrors | undefined => { + ({ delegate, votes, wallet, chain }): DelegationErrors | null => { if (!wallet || !chain || !delegate || !validateAddress(delegate)) return DelegationErrors.INVALID_ADDRESS; const isSameAccount = wallet.accounts.some((a) => a.accountId === toAccountId(delegate)); if (isSameAccount) return DelegationErrors.YOUR_ACCOUNT; - const isAlreadyDelegated = wallet.accounts.some((a) => { - const address = toAddress(a.accountId, { prefix: chain.addressPrefix }); - - return Object.keys(votes[address]).length > 0; - }); + const isAlreadyDelegated = delegate && votes[delegate] && Object.keys(votes[delegate]).length > 0; if (isAlreadyDelegated) return DelegationErrors.ALREADY_DELEGATED; - return; + return null; }, );