diff --git a/src/renderer/entities/governance/lib/voteTransactionService.ts b/src/renderer/entities/governance/lib/voteTransactionService.ts index a4111f201c..52a43402d0 100644 --- a/src/renderer/entities/governance/lib/voteTransactionService.ts +++ b/src/renderer/entities/governance/lib/voteTransactionService.ts @@ -2,17 +2,29 @@ import { BN, BN_ZERO } from '@polkadot/util'; import { type Conviction, type Transaction, TransactionType } from '@/shared/core'; import { toSerializable } from '@/shared/lib/utils'; +import { isProxyTransaction } from '@/entities/transaction'; import { - type RemoveVoteTransaction, - type RevoteTransaction, type TransactionSplitAbstainVote, type TransactionStandardVote, type TransactionVote, - type VoteTransaction, } from '../types/voteTransaction'; import { votingService } from './votingService'; +const getVote = (tx: Transaction): TransactionVote => { + const coreTx = getCoreTx(tx); + + return coreTx?.args.vote; +}; + +const getCoreTx = (tx: Transaction): Transaction => { + if (isProxyTransaction(tx)) { + return tx.args.transaction; + } + + return tx; +}; + const isStandardVote = (vote: TransactionVote): vote is TransactionStandardVote => { return 'Standard' in vote; }; @@ -21,20 +33,26 @@ const isSplitAbstainVote = (vote: TransactionVote): vote is TransactionSplitAbst return 'Standard' in vote; }; -const isVoteTransaction = (t: Transaction): t is VoteTransaction => { - return t.type === TransactionType.VOTE; +const isVoteTransaction = (t: Transaction): boolean => { + const coreTx = getCoreTx(t); + + return coreTx.type === TransactionType.VOTE; }; -const isRevoteTransaction = (t: Transaction): t is RevoteTransaction => { - return t.type === TransactionType.REVOTE; +const isRevoteTransaction = (t: Transaction): boolean => { + const coreTx = getCoreTx(t); + + return coreTx.type === TransactionType.REVOTE; }; -const isRemoveVoteTransaction = (t: Transaction): t is RemoveVoteTransaction => { +const isRemoveVoteTransaction = (t: Transaction): boolean => { if (t.type === TransactionType.BATCH_ALL) { return t.args.transactions?.some(isRemoveVoteTransaction); } - return t.type === TransactionType.REMOVE_VOTE; + const coreTx = getCoreTx(t); + + return coreTx.type === TransactionType.REMOVE_VOTE; }; const createTransactionVote = ( @@ -65,9 +83,6 @@ const createTransactionVote = ( }); }; -const getVoteAmount = (vote: TransactionVote) => - new BN(isStandardVote(vote) ? vote.Standard.balance : vote.SplitAbstain.abstain); - const getDecision = (vote: TransactionVote): 'aye' | 'nay' | 'abstain' => { if (isStandardVote(vote)) { return vote.Standard.vote.vote === 'Aye' || vote.Standard.vote.aye ? 'aye' : 'nay'; @@ -87,9 +102,9 @@ const getVotes = (vote: TransactionVote): BN => { }; export const voteTransactionService = { - getVoteAmount, getDecision, getVotes, + getVote, isVoteTransaction, isRevoteTransaction, diff --git a/src/renderer/features/operations/OperationsConfirm/Referendum/RemoveVote/ui/Confirmation.tsx b/src/renderer/features/operations/OperationsConfirm/Referendum/RemoveVote/ui/Confirmation.tsx index 2ee53add00..0c6523de5a 100644 --- a/src/renderer/features/operations/OperationsConfirm/Referendum/RemoveVote/ui/Confirmation.tsx +++ b/src/renderer/features/operations/OperationsConfirm/Referendum/RemoveVote/ui/Confirmation.tsx @@ -106,6 +106,7 @@ export const Confirmation = ({ id = 0, secondaryActionButton, hideSignButton }: wallets={wallets} initiator={[confirm.accounts.initiator]} signatory={confirm.accounts.signer} + proxied={confirm.accounts.proxied || undefined} > {votingPower && amount && conviction ? ( <> diff --git a/src/renderer/features/operations/OperationsConfirm/Referendum/Vote/ui/Confirmation.tsx b/src/renderer/features/operations/OperationsConfirm/Referendum/Vote/ui/Confirmation.tsx index 0ceb401c22..ca6f69a32e 100644 --- a/src/renderer/features/operations/OperationsConfirm/Referendum/Vote/ui/Confirmation.tsx +++ b/src/renderer/features/operations/OperationsConfirm/Referendum/Vote/ui/Confirmation.tsx @@ -64,7 +64,7 @@ export const Confirmation = ({ id = 0, secondaryActionButton, hideSignButton, on return null; } - const { vote } = wrappedTransactions.coreTx.args; + const vote = voteTransactionService.getVote(wrappedTransactions.coreTx); const decision = voteTransactionService.isStandardVote(vote) ? (vote.Standard.vote.aye ? 'aye' : 'nay') : 'abstain'; const conviction = voteTransactionService.isStandardVote(vote) ? vote.Standard.vote.conviction : 'None'; @@ -110,7 +110,7 @@ export const Confirmation = ({ id = 0, secondaryActionButton, hideSignButton, on wallets={wallets} initiator={[confirm.accounts.initiator]} signatory={confirm.accounts.signer} - proxied={confirm.accounts.proxy || undefined} + proxied={confirm.accounts.proxied || undefined} > {t(`governance.referendum.${decision}`)} diff --git a/src/renderer/features/operations/OperationsConfirm/lib/createTransactionConfirmStore.ts b/src/renderer/features/operations/OperationsConfirm/lib/createTransactionConfirmStore.ts index 57f1c7767c..75c3169174 100644 --- a/src/renderer/features/operations/OperationsConfirm/lib/createTransactionConfirmStore.ts +++ b/src/renderer/features/operations/OperationsConfirm/lib/createTransactionConfirmStore.ts @@ -13,7 +13,7 @@ import { import { toAddress } from '@/shared/lib/utils'; import { operationsUtils } from '@/entities/operations'; import { type WrappedTransactions, isProxyTransaction } from '@/entities/transaction'; -import { walletUtils } from '@/entities/wallet'; +import { accountUtils, walletUtils } from '@/entities/wallet'; export type ConfirmInfo = { id?: number; @@ -27,12 +27,12 @@ export type ConfirmItem = { meta: Input; wallets: { initiator: Wallet; - proxy: Wallet | null; + proxied: Wallet | null; signer: Wallet | null; }; accounts: { initiator: Account; - proxy?: ProxiedAccount | null; + proxied?: ProxiedAccount | null; signer: Account | null; }; }; @@ -61,60 +61,42 @@ export const createTransactionConfirmStore = ({ if (!wallets.length) return {}; return store.reduce((acc, meta, index) => { - const { wrappedTransactions, chain } = meta; + const { wrappedTransactions, chain, account } = meta; const { wrappedTx, coreTx } = wrappedTransactions; const { addressPrefix } = chain; - const initiatorAccount = walletUtils.getAccountBy(wallets, (account, wallet) => { - const isSameAccount = coreTx.address === toAddress(account.accountId, { prefix: addressPrefix }); - - if (isProxyTransaction(wrappedTx)) { - return walletUtils.isProxied(wallet) && isSameAccount; + const isProxyTx = isProxyTransaction(wrappedTx) || isProxyTransaction(coreTx); + const initiatorAccount = walletUtils.getAccountBy(wallets, (acc) => { + if (accountUtils.isProxiedAccount(account)) { + return acc.accountId == account.proxyAccountId; } + const isSameAccount = coreTx.address === toAddress(acc.accountId, { prefix: addressPrefix }); + return isSameAccount; }); + if (!initiatorAccount) return acc; - const initiatorWallet = walletUtils.getWalletFilteredAccounts(wallets, { - walletFn: (wallet) => !isProxyTransaction(wrappedTx) || walletUtils.isProxied(wallet), - accountFn: (account) => initiatorAccount.accountId === account.accountId, - }); + const initiatorWallet = walletUtils.getWalletById(wallets, initiatorAccount.walletId); if (!initiatorWallet) return acc; - const signerAccount = walletUtils.getAccountBy( - wallets, - (account, wallet) => - walletUtils.isValidSignSignatory(wallet) && - wrappedTx.address === toAddress(account.accountId, { prefix: addressPrefix }), - ); - const signerWallet = walletUtils.getWalletFilteredAccounts(wallets, { - walletFn: walletUtils.isValidSignSignatory, - accountFn: (account) => signerAccount?.accountId === account.accountId, - }); + const signerWallet = meta.signatory && walletUtils.getWalletById(wallets, meta.signatory?.walletId); - const proxyAccount = walletUtils.getAccountBy( - wallets, - (account, wallet) => - !walletUtils.isProxied(wallet) && - isProxyTransaction(wrappedTx) && - wrappedTx.address === toAddress(account.accountId, { prefix: addressPrefix }), - ) as ProxiedAccount | null; - const proxyWallet = walletUtils.getWalletFilteredAccounts(wallets, { - accountFn: (account) => proxyAccount?.accountId === account.accountId, - }); + const proxiedAccount = isProxyTx && accountUtils.isProxiedAccount(account) ? account : null; + const proxiedWallet = proxiedAccount && walletUtils.getWalletById(wallets, proxiedAccount.walletId); acc[meta.id ?? index] = { meta, wallets: { signer: signerWallet || null, initiator: initiatorWallet, - proxy: proxyWallet || null, + proxied: proxiedWallet || null, }, accounts: { - signer: signerAccount, + signer: meta.signatory, initiator: initiatorAccount, - proxy: proxyAccount, + proxied: proxiedAccount, }, }; diff --git a/src/renderer/widgets/RemoveVotesModal/aggregates/removeVotesModal.ts b/src/renderer/widgets/RemoveVotesModal/aggregates/removeVotesModal.ts index 1d63c0c92c..0a5c76121a 100644 --- a/src/renderer/widgets/RemoveVotesModal/aggregates/removeVotesModal.ts +++ b/src/renderer/widgets/RemoveVotesModal/aggregates/removeVotesModal.ts @@ -79,15 +79,22 @@ const selectSignatory = createEvent(); const $signatory = createStore(null); const $signatories = combine($accounts, walletModel.$wallets, (accounts, wallets) => { - if (!accounts[0] || !accountUtils.isMultisigAccount(accounts[0])) { + const account = accounts.at(0); + if (nullable(account)) return []; + + const multisigAcc = accountUtils.isProxiedAccount(account) + ? walletUtils.getAccountBy(wallets, (a) => a.accountId === account.proxyAccountId) + : account; + + if (nullable(multisigAcc) || !accountUtils.isMultisigAccount(multisigAcc)) { return []; } - const a = accounts[0].signatories.map((signatory) => + const acc = multisigAcc.signatories.map((signatory) => walletUtils.getAccountBy(wallets, (a) => a.accountId === signatory.accountId), ); - return a.filter((option) => option !== null); + return acc.filter((option) => option !== null); }); const $votesList = combine($accounts, flow.state, (accounts, { votes, chain }) => { @@ -241,7 +248,7 @@ sample({ return { signingPayloads: Object.values(confirms).map(({ meta, accounts }) => ({ - account: accounts.proxy || accounts.initiator, + account: accounts.initiator, chain: meta.chain, transaction: meta.wrappedTransactions.wrappedTx, signatory: accounts.signer, diff --git a/src/renderer/widgets/VoteModal/aggregates/voteModal.ts b/src/renderer/widgets/VoteModal/aggregates/voteModal.ts index 3a47c351ce..2fd094b7c8 100644 --- a/src/renderer/widgets/VoteModal/aggregates/voteModal.ts +++ b/src/renderer/widgets/VoteModal/aggregates/voteModal.ts @@ -204,7 +204,7 @@ sample({ return { signingPayloads: Object.values(confirms).map(({ meta, accounts }) => ({ - account: accounts.proxy || accounts.initiator, + account: accounts.initiator, chain: meta.chain, transaction: meta.wrappedTransactions.wrappedTx, signatory: accounts.signer,