Skip to content

Commit

Permalink
fix: wrong call data from chain (#2867)
Browse files Browse the repository at this point in the history
  • Loading branch information
Asmadek authored Dec 17, 2024
1 parent 407cba1 commit 6d2a233
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const MultisigChainProvider = ({ children }: PropsWithChildren) => {
const account = activeAccount && accountUtils.isMultisigAccount(activeAccount) ? activeAccount : undefined;

const txs = getLiveAccountMultisigTxs(account?.accountId ? [account.accountId] : []);
const events = getLiveEventsByKeys(txs.filter((tx) => !tx.dateCreated));
const events = getLiveEventsByKeys(txs);

useGate(operationsModel.gate.flow, {
transactions: txs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
MultisigTxInitStatus,
} from '@/shared/core';
import { type Task } from '@/shared/lib/hooks/useTaskQueue';
import { getCurrentBlockNumber, getExpectedBlockTime, toAddress } from '@/shared/lib/utils';
import { getCurrentBlockNumber, getExpectedBlockTime, toAddress, validateCallData } from '@/shared/lib/utils';
import { useCallDataDecoder } from '@/entities/transaction';
import { useMultisigEvent } from '../multisigEvent/multisigEventService';

Expand Down Expand Up @@ -241,6 +241,8 @@ export const useMultisigTx = ({ addTask }: Props): IMultisigTxService => {

const callData = extrinsic.args[MULTISIG_EXTRINSIC_CALL_INDEX].toHex();

if (!validateCallData(callData, tx.callHash)) return;

updateCallData(api, tx, callData);
} catch (e) {
console.log('Error during update call data from chain', e);
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/entities/signatory/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const signatoryUtils = {

function getSignatoryWallet(wallets: Wallet[], accountId: AccountId): Wallet | undefined {
return wallets.find((wallet) => {
const hasMatch = wallet.accounts.some((account) => account.accountId === accountId);
const hasMatch = wallet.accounts?.some((account) => account.accountId === accountId);

return hasMatch && walletUtils.isValidSignatory(wallet);
});
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/pages/Operations/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const getSignatoryName = (
addressPrefix?: number,
): string => {
const finderFn = <T extends { accountId: AccountId }>(collection: T[]): T | undefined => {
return collection.find((c) => c.accountId === signatoryId);
return collection.find((c) => c?.accountId === signatoryId);
};

// signatory data source priority: transaction -> contacts -> wallets -> address
Expand Down
33 changes: 29 additions & 4 deletions src/renderer/pages/Operations/components/OperationFullInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { useUnit } from 'effector-react';
import { useStoreMap, useUnit } from 'effector-react';

import { useMultisigChainContext } from '@/app/providers';
import { type MultisigTransactionDS } from '@/shared/api/storage';
import { type CallData, type MultisigAccount } from '@/shared/core';
import { useI18n } from '@/shared/i18n';
import { useToggle } from '@/shared/lib/hooks';
import { validateCallData } from '@/shared/lib/utils';
import { Button, Icon, InfoLink, SmallTitleText } from '@/shared/ui';
import { useMultisigTx } from '@/entities/multisig';
import { useNetworkData } from '@/entities/network';
import { permissionUtils, walletModel } from '@/entities/wallet';
import { operationsModel } from '@/entities/operations';
import { permissionUtils, walletModel, walletUtils } from '@/entities/wallet';
import { getMultisigExtrinsicLink } from '../common/utils';

import { OperationCardDetails } from './OperationCardDetails';
Expand All @@ -27,6 +29,24 @@ export const OperationFullInfo = ({ tx, account }: Props) => {
const { api, chain, connection, extendedChain } = useNetworkData(tx.chainId);

const wallets = useUnit(walletModel.$wallets);
const activeWallet = useUnit(walletModel.$activeWallet);

const events = useStoreMap({
store: operationsModel.$multisigEvents,
keys: [tx],
fn: (events, [tx]) => {
return events.filter((e) => {
return (
e.txAccountId === tx.accountId &&
e.txChainId === tx.chainId &&
e.txCallHash === tx.callHash &&
e.txBlock === tx.blockCreated &&
e.txIndex === tx.indexCreated &&
e.status === 'SIGNED'
);
});
},
});

const { addTask } = useMultisigChainContext();
const { updateCallData } = useMultisigTx({ addTask });
Expand All @@ -41,12 +61,17 @@ export const OperationFullInfo = ({ tx, account }: Props) => {
updateCallData(api, tx, callData as CallData);
};

if (!walletUtils.isMultisig(activeWallet)) return null;

const isRejectAvailable = wallets.some((wallet) => {
const hasDepositor = wallet.accounts.some((account) => account.accountId === tx.depositor);
const hasDepositor = wallet.accounts?.some((account) => account.accountId === tx.depositor);

return hasDepositor && permissionUtils.canRejectMultisigTx(wallet);
});

const isFinalSigning = events.length === activeWallet.accounts[0].threshold - 1;
const isApproveAvailable = !isFinalSigning || (tx.callData && validateCallData(tx.callData, tx.callHash));

return (
<div className="flex flex-1">
<div className="flex w-[416px] flex-col border-r border-r-divider p-4">
Expand Down Expand Up @@ -80,7 +105,7 @@ export const OperationFullInfo = ({ tx, account }: Props) => {
</Button>
</RejectTxModal>
)}
{account && connection && (
{account && isApproveAvailable && connection && (
<ApproveTxModal tx={tx} account={account} connection={extendedChain}>
<Button className="ml-auto">{t('operation.approveButton')}</Button>
</ApproveTxModal>
Expand Down
6 changes: 4 additions & 2 deletions src/renderer/pages/Operations/components/modals/ApproveTx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { TransactionType } from '@/shared/core';
import { useI18n } from '@/shared/i18n';
import { useToggle } from '@/shared/lib/hooks';
import { TEST_ADDRESS, getAssetById, toAddress, transferableAmount } from '@/shared/lib/utils';
import { TEST_ADDRESS, getAssetById, toAddress, transferableAmount, validateCallData } from '@/shared/lib/utils';
import { Button } from '@/shared/ui';
import { Modal } from '@/shared/ui-kit';
import { balanceModel, balanceUtils } from '@/entities/balance';
Expand Down Expand Up @@ -155,10 +155,12 @@ const ApproveTxModal = ({ tx, account, connection, children }: Props) => {
return acc;
}, []);

const hasCallData = tx.callData && validateCallData(tx.callData, tx.callHash);

return {
chainId: tx.chainId,
address: signerAddress,
type: tx.callData ? TransactionType.MULTISIG_AS_MULTI : TransactionType.MULTISIG_APPROVE_AS_MULTI,
type: hasCallData ? TransactionType.MULTISIG_AS_MULTI : TransactionType.MULTISIG_APPROVE_AS_MULTI,
args: {
threshold: account.threshold,
otherSignatories: otherSignatories.sort(),
Expand Down

0 comments on commit 6d2a233

Please sign in to comment.