diff --git a/src/renderer/widgets/DelegateDetails/model/delegate-details-model.ts b/src/renderer/widgets/DelegateDetails/model/delegate-details-model.ts index fd1e51995..b6e2aa3cb 100644 --- a/src/renderer/widgets/DelegateDetails/model/delegate-details-model.ts +++ b/src/renderer/widgets/DelegateDetails/model/delegate-details-model.ts @@ -157,13 +157,11 @@ export const delegateDetailsModel = { $delegate, $activeAccounts, $activeTracks, - $uniqueTracks: $activeTracks.map((tracks) => - uniq( - Object.values(tracks) - .map((tracks) => [...tracks]) - .flat(), - ), - ), + $uniqueTracks: $activeTracks.map((tracks) => { + const flatTracks = Object.values(tracks).flatMap((tracks) => [...tracks]); + + return uniq(flatTracks); + }), $activeDelegations, $isAddAvailable, diff --git a/src/renderer/widgets/EditDelegationModal/model/edit-delegation-model.ts b/src/renderer/widgets/EditDelegationModal/model/edit-delegation-model.ts index d537c9108..9b03848c4 100644 --- a/src/renderer/widgets/EditDelegationModal/model/edit-delegation-model.ts +++ b/src/renderer/widgets/EditDelegationModal/model/edit-delegation-model.ts @@ -91,9 +91,10 @@ const $api = combine( walletData: $walletData, }, ({ apis, walletData }) => { - return walletData?.chain ? apis[walletData.chain.chainId] : undefined; + if (!walletData.chain) return null; + + return apis[walletData.chain.chainId] || null; }, - { skipVoid: false }, ); const $transactions = combine( @@ -104,7 +105,7 @@ const $transactions = combine( txWrappers: $txWrappers, }, ({ api, walletData, coreTxs, txWrappers }) => { - if (!api || !walletData.chain) return undefined; + if (!api || !walletData.chain) return null; return coreTxs.map((tx) => transactionService.getWrappedTransaction({ @@ -115,7 +116,6 @@ const $transactions = combine( }), ); }, - { skipVoid: false }, ); // Transaction & Form @@ -475,17 +475,14 @@ sample({ return Boolean(walletData.wallet) && Boolean(coreTxs) && Boolean(txWrappers); }, fn: ({ walletData, coreTxs, txWrappers }) => { - const txs = coreTxs!.map( - (coreTx) => - ({ - initiatorWallet: walletData.wallet!.id, - coreTx, - txWrappers, - groupId: Date.now(), - }) as BasketTransaction, - ); - - return txs; + return coreTxs!.map((coreTx) => { + return { + initiatorWallet: walletData.wallet!.id, + coreTx, + txWrappers, + groupId: Date.now(), + } as BasketTransaction; + }); }, target: basketModel.events.transactionsCreated, }); diff --git a/src/renderer/widgets/EditDelegationModal/model/select-tracks-model.ts b/src/renderer/widgets/EditDelegationModal/model/select-tracks-model.ts index 8fbb15b7d..b029699d9 100644 --- a/src/renderer/widgets/EditDelegationModal/model/select-tracks-model.ts +++ b/src/renderer/widgets/EditDelegationModal/model/select-tracks-model.ts @@ -34,8 +34,8 @@ const tracksSelected = createEvent(); const accountsChanged = createEvent(); const $tracks = createStore([]).reset(formInitiated); -const $delegatedTracks = createStore([]).reset(formInitiated); const $votedTracks = createStore([]).reset(formInitiated); +const $delegatedTracks = createStore([]).reset(formInitiated); const $votesToRemove = createStore([]).reset(formInitiated); const $accounts = createStore([]); @@ -122,27 +122,34 @@ sample({ sample({ clock: [votingAggregate.$activeWalletVotes, $addresses], source: { + tracks: $tracks, votes: votingAggregate.$activeWalletVotes, addresses: $addresses, delegate: $delegate, }, - fn: ({ addresses, votes, delegate }) => { + fn: ({ tracks, addresses, votes, delegate }) => { const activeTracks = new Set(); - const delegatedTracks = new Set(); + const otherDelegatedTracks = new Set(); + const currentDelegatedTracks = new Set(); const votesToRemove = []; for (const [address, voteList] of Object.entries(votes)) { if (!addresses.includes(address)) continue; for (const [track, vote] of Object.entries(voteList)) { - const isNotCurrentDelegate = - votingService.isDelegating(vote) && delegate && toAccountId(delegate.accountId) !== toAccountId(vote.target); + const isDelegateExist = votingService.isDelegating(vote) && delegate; + const isCurrentDelegate = isDelegateExist && toAccountId(delegate.accountId) === toAccountId(vote.target); + const isOtherDelegate = isDelegateExist && toAccountId(delegate.accountId) !== toAccountId(vote.target); - if ((votingService.isCasting(vote) && !votingService.isUnlockingDelegation(vote)) || isNotCurrentDelegate) { + if ((votingService.isCasting(vote) && !votingService.isUnlockingDelegation(vote)) || isOtherDelegate) { activeTracks.add(track); } - if (isNotCurrentDelegate) { - delegatedTracks.add(track); + if (isOtherDelegate) { + otherDelegatedTracks.add(track); + } + + if (isCurrentDelegate) { + currentDelegatedTracks.add(Number(track)); } if (votingService.isCasting(vote) && !votingService.isUnlockingDelegation(vote)) { @@ -154,12 +161,14 @@ sample({ } return { + tracks: [...tracks, ...currentDelegatedTracks], votedTracks: [...activeTracks], - delegatedTracks: [...delegatedTracks], + delegatedTracks: [...otherDelegatedTracks], votesToRemove: [...votesToRemove], }; }, target: spread({ + tracks: $tracks, votedTracks: $votedTracks, delegatedTracks: $delegatedTracks, votesToRemove: $votesToRemove, @@ -191,7 +200,10 @@ sample({ sample({ clock: tracksSelected, - source: { tracks: $tracks, votedTracks: $votedTracks }, + source: { + tracks: $tracks, + votedTracks: $votedTracks, + }, fn: ({ tracks, votedTracks }, newTracks) => { const resultArray = newTracks.filter((num) => !votedTracks.includes(num.toString())); diff --git a/src/renderer/widgets/EditDelegationModal/ui/EditDelegation.tsx b/src/renderer/widgets/EditDelegationModal/ui/EditDelegation.tsx index 51da3d909..5ce87fc7c 100644 --- a/src/renderer/widgets/EditDelegationModal/ui/EditDelegation.tsx +++ b/src/renderer/widgets/EditDelegationModal/ui/EditDelegation.tsx @@ -2,7 +2,7 @@ import { useUnit } from 'effector-react'; import { useI18n } from '@/shared/i18n'; import { useModalClose } from '@/shared/lib/hooks'; -import { Step, isStep } from '@/shared/lib/utils'; +import { Step, isStep, nullable } from '@/shared/lib/utils'; import { BaseModal, Button } from '@/shared/ui'; import { OperationTitle } from '@/entities/chain'; import { SignButton } from '@/entities/operations'; @@ -32,12 +32,18 @@ export const EditDelegation = () => { editDelegationModel.output.flowFinished, ); - if (!walletData) { - return null; + if (isStep(step, Step.INIT)) { + return ( + editDelegationModel.events.stepChanged(Step.SELECT_TRACK)} + /> + ); } - if (isStep(step, Step.SUBMIT)) { - return ; + if (isStep(step, Step.SELECT_TRACK)) { + return ; } if (isStep(step, Step.BASKET)) { @@ -52,21 +58,11 @@ export const EditDelegation = () => { ); } - if (isStep(step, Step.SELECT_TRACK)) { - return ; - } - - if (isStep(step, Step.INIT)) { - return ( - editDelegationModel.events.stepChanged(Step.SELECT_TRACK)} - /> - ); + if (isStep(step, Step.SUBMIT)) { + return ; } - if (transactions === undefined) { + if (nullable(transactions)) { return null; } @@ -109,7 +105,7 @@ export const EditDelegation = () => { } > - {transactions?.map((t, index) => ( + {transactions.map((_, index) => (