Skip to content

Commit

Permalink
fix: already delegated state (#2182)
Browse files Browse the repository at this point in the history
  • Loading branch information
Asmadek authored Aug 22, 2024
1 parent 7a1946f commit ee67896
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ export const Confirmation = ({
? formatAmount(confirmStore.balance, confirmStore.asset.precision)
: confirmStore.balance;

const convictionValue = new BN(votingService.getConvictionMultiplier(confirmStore.conviction));
const votesValue = new BN(amountValue).mul(convictionValue).toString();
const convictionValue = votingService.getConvictionMultiplier(confirmStore.conviction);
const votesValue = votingService.calculateVotingPower(new BN(amountValue), confirmStore.conviction);

return (
<div className="flex w-modal flex-col items-center gap-y-4 px-5 pb-4 pt-4">
Expand Down
10 changes: 7 additions & 3 deletions src/renderer/widgets/DelegationModal/model/delegation-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, validateAddress } from '@/shared/lib/utils';
import { Step, includesMultiple, toAccountId, toAddress, validateAddress } from '@/shared/lib/utils';
import { votingService } from '@/entities/governance';
import { walletModel } from '@/entities/wallet';
import {
Expand Down Expand Up @@ -85,7 +85,7 @@ const $delegateList = combine(
const $customError = combine(
{
delegate: $customDelegate,
votes: votingAggregate.$activeWalletVotes,
votes: delegationAggregate.$activeDelegations,
wallet: walletModel.$activeWallet,
chain: delegationAggregate.$chain,
},
Expand All @@ -96,7 +96,11 @@ const $customError = combine(

if (isSameAccount) return DelegationErrors.YOUR_ACCOUNT;

const isAlreadyDelegated = delegate && votes[delegate] && Object.keys(votes[delegate]).length > 0;
const delegations = delegate && votes[delegate] ? Object.keys(votes[delegate]) : [];

const isAlreadyDelegated = wallet.accounts.every((a) =>
delegations.some((d) => d === toAddress(a.accountId, { prefix: chain.addressPrefix })),
);

if (isAlreadyDelegated) return DelegationErrors.ALREADY_DELEGATED;

Expand Down

0 comments on commit ee67896

Please sign in to comment.