Skip to content

Commit

Permalink
feat: implement redo arbitrary for activity table
Browse files Browse the repository at this point in the history
  • Loading branch information
Nortsova committed Jan 24, 2025
1 parent ea0c1dd commit 184472a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 46 deletions.
16 changes: 16 additions & 0 deletions src/components/v5/common/ActionSidebar/hooks/useGetActionData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useGetAllTokens } from '~hooks/useGetAllTokens.ts';
import { convertRolesToArray } from '~transformers/index.ts';
import { DecisionMethod, ExtendedColonyActionType } from '~types/actions.ts';
import { Authority } from '~types/authority.ts';
import { getDecodedArbitraryTransactions } from '~utils/arbitraryTxs.ts';
import { getExtendedActionType } from '~utils/colonyActions.ts';
import { convertToDecimal } from '~utils/convertToDecimal.ts';
import { convertPeriodToHours } from '~utils/extensions.ts';
Expand All @@ -23,6 +24,7 @@ import {
import {
ACTION_TYPE_FIELD_NAME,
AMOUNT_FIELD_NAME,
ARBITRARY_TRANSACTIONS_FIELD_NAME,
FROM_FIELD_NAME,
RECIPIENT_FIELD_NAME,
TEAM_FIELD_NAME,
Expand Down Expand Up @@ -70,6 +72,7 @@ const useGetActionData = (transactionId: string | undefined) => {
isMotion,
roles,
colony,
arbitraryTransactions,
} = action;

const { metadata: expenditureMetadata, slots } = expenditure || {};
Expand Down Expand Up @@ -384,6 +387,19 @@ const useGetActionData = (transactionId: string | undefined) => {
...repeatableFields,
};
}
case ColonyActionType.MakeArbitraryTransaction:
case ColonyActionType.MakeArbitraryTransactionsMotion:
case ColonyActionType.MakeArbitraryTransactionsMultisig: {
const decodedArbitraryTransactions = getDecodedArbitraryTransactions(
arbitraryTransactions || [],
action,
);
return {
[ACTION_TYPE_FIELD_NAME]: Action.ArbitraryTxs,
[ARBITRARY_TRANSACTIONS_FIELD_NAME]: decodedArbitraryTransactions,
...repeatableFields,
};
}
default:
return undefined;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
type ColonyActionArbitraryTransaction,
} from '~gql';
import {
decodeArbitraryTransaction,
getDecodedArbitraryTransactions,
type DecodedArbitraryTransaction,
} from '~utils/arbitraryTxs.ts';

Expand All @@ -18,35 +18,5 @@ export const useTransformArbitraryTransactions = (
data: ColonyActionArbitraryTransaction[],
action: ColonyActionFragment,
): CompletedArbitraryTransactions[] => {
const decodedArbitraryTransactions = data?.map(
({ contractAddress, encodedFunction }) => {
const abi = action.metadata?.arbitraryTxAbis?.find(
(abiItem) => abiItem.contractAddress === contractAddress,
);
if (!abi) {
return {
contractAddress,
encodedFunction,
};
}

const decodedTx = decodeArbitraryTransaction(
abi.jsonAbi,
encodedFunction,
);
if (!decodedTx) {
return {
contractAddress,
encodedFunction,
jsonAbi: JSON.stringify(JSON.parse(abi.jsonAbi)),
};
}
return {
contractAddress,
jsonAbi: JSON.stringify(JSON.parse(abi.jsonAbi)),
...decodedTx,
};
},
);
return decodedArbitraryTransactions;
return getDecodedArbitraryTransactions(data, action);
};
51 changes: 37 additions & 14 deletions src/utils/arbitraryTxs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Interface } from 'ethers/lib/utils';

import { type ColonyActionFragment } from '~gql';
import {
type ColonyActionArbitraryTransaction,
type ColonyActionFragment,
} from '~gql';

import { type ActionTitleMessageKeys } from '../components/common/ColonyActions/helpers/getActionTitleValues.ts';

Expand Down Expand Up @@ -48,21 +51,41 @@ export const decodeArbitraryTransaction = (
}
};

export const getDecodedArbitraryTransaction = (transaction) => {
const abi = transaction.action.metadata?.arbitraryTxAbis?.find(
(abiItem) => abiItem.contractAddress === transaction.contractAddress,
);

if (!abi) {
return {};
}
export const getDecodedArbitraryTransactions = (
data: ColonyActionArbitraryTransaction[],
action: ColonyActionFragment,
) => {
const decodedArbitraryTransactions = data?.map(
({ contractAddress, encodedFunction }) => {
const abi = action.metadata?.arbitraryTxAbis?.find(
(abiItem) => abiItem.contractAddress === contractAddress,
);
if (!abi) {
return {
contractAddress,
encodedFunction,
};
}

const decodedTx = decodeArbitraryTransaction(
abi.jsonAbi,
transaction.encodedFunction,
const decodedTx = decodeArbitraryTransaction(
abi.jsonAbi,
encodedFunction,
);
if (!decodedTx) {
return {
contractAddress,
encodedFunction,
jsonAbi: JSON.stringify(JSON.parse(abi.jsonAbi)),
};
}
return {
contractAddress,
jsonAbi: JSON.stringify(JSON.parse(abi.jsonAbi)),
...decodedTx,
};
},
);

return decodedTx;
return decodedArbitraryTransactions;
};

type ArbitraryFormatMessageValues = {
Expand Down

0 comments on commit 184472a

Please sign in to comment.