Skip to content

Commit

Permalink
Merge pull request #491 from HausDAO/develop
Browse files Browse the repository at this point in the history
deploy
  • Loading branch information
skuhlmann authored Apr 3, 2024
2 parents ae80c8a + d7a5f63 commit 186d148
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ReactNode, useState } from 'react';
import { isValidNetwork } from '@daohaus/keychain-utils';
import { ValidNetwork, isValidNetwork } from '@daohaus/keychain-utils';
import { MolochV3Proposal } from '@daohaus/moloch-v3-data';
import {
ActionError,
Expand All @@ -18,6 +18,7 @@ import {
useBreakpoint,
widthQuery,
ParLg,
DataMd,
} from '@daohaus/ui';
import {
DAO_METHOD_TO_PROPOSAL_TYPE,
Expand Down Expand Up @@ -210,20 +211,52 @@ const ActionToggle = ({

const ActionSectionError = ({
action,
actionHeader,
daoChain,
index,
isMobile,
}: {
action: ActionError;
actionHeader: string;
daoChain?: ValidNetwork;
index: number;
isMobile?: boolean;
}) => {
return (
<div className="display-segment data" key={`${action.message}-${index}`}>
<H4 className="space">Action {index + 1}: Error</H4>
<DataSm className="space">{action.message}</DataSm>
<Divider className="space" />
<DataSm className="space">
<Bold>HEX DATA:</Bold>
</DataSm>
<DataSm className="space">{action.data}</DataSm>
<ActionToggle actionHeader={actionHeader} action={action}>
<>
<DataMd className="space">Action {index + 1}</DataMd>
<DataSm className="space">Error: {action.message}</DataSm>
<Divider className="space" />
{action.contractAddress && (
<>
<DataSm className="space">
<Bold>TARGET</Bold>
</DataSm>
<AddressDisplay
className="space"
address={action.contractAddress}
copy
explorerNetworkId={daoChain}
truncate={isMobile}
/>
</>
)}
<DataSm className="space">
<Bold>HEX DATA:</Bold>
</DataSm>
<DataSm className="space">{action.data}</DataSm>
{action.value && (
<>
<DataSm className="space">
<Bold>VALUE</Bold>
</DataSm>
<DataSm className="space">{action.value}</DataSm>
</>
)}
</>
</ActionToggle>
</div>
);
};
Expand All @@ -249,7 +282,15 @@ const ActionSection = ({
const isMobile = useBreakpoint(widthQuery.sm);

if (isActionError(action)) {
return <ActionSectionError index={index} action={action} />;
return (
<ActionSectionError
index={index}
action={action}
actionHeader={actionHeader}
daoChain={network}
isMobile={isMobile}
/>
);
}

return (
Expand Down
2 changes: 2 additions & 0 deletions libs/tx-builder/src/utils/decoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export type ActionError = {
error: boolean;
message: string;
data: string;
contractAddress?: string;
value?: string;
};

export type DecodedMultiTX = (DecodedAction | ActionError)[];
Expand Down
47 changes: 36 additions & 11 deletions libs/tx-builder/src/utils/deepDecoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,17 @@ export const deepDecodeProposalActions = async ({
return decodeMultiCall(options, actionData as `0x${string}`);
};

const createActionError = (data: string, message: string): ActionError => ({
const createActionError = (
data: string,
message: string,
contractAddress?: string,
value?: string
): ActionError => ({
error: true,
message,
data,
contractAddress,
value,
});

const decodeMultiCall = async (
Expand Down Expand Up @@ -192,15 +199,17 @@ const actionDecoders: Record<
) {
return createActionError(
action.data,
'Could not decode action: multiSend'
'Could not decode action: multiSend',
action.to
);
}
const input = decodedMethod.inputs[0];

if (input.type !== 'bytes') {
return createActionError(
action.data,
'Could not decode action: multiSend'
'Could not decode action: multiSend',
action.to
);
}

Expand All @@ -227,7 +236,8 @@ const actionDecoders: Record<
) {
return createActionError(
action.data,
'Could not decode action: execTransactionFromModule'
'Could not decode action: execTransactionFromModule',
action.to
);
}
const inputTo = decodedMethod.inputs[0];
Expand All @@ -243,7 +253,8 @@ const actionDecoders: Record<
) {
return createActionError(
action.data,
'Could not decode action: execTransactionFromModule'
'Could not decode action: execTransactionFromModule',
action.to
);
}

Expand Down Expand Up @@ -274,7 +285,8 @@ const actionDecoders: Record<
) {
return createActionError(
action.data,
'Could not decode action: executeAsBaal'
'Could not decode action: executeAsBaal',
action.to
);
}
const inputTo = decodedMethod.inputs[0];
Expand All @@ -288,7 +300,8 @@ const actionDecoders: Record<
) {
return createActionError(
action.data,
'Could not decode action: executeAsBaal'
'Could not decode action: executeAsBaal',
action.to
);
}

Expand Down Expand Up @@ -349,15 +362,17 @@ const actionDecoders: Record<
) {
return createActionError(
action.data,
'Could not decode action: multiSend'
'Could not decode action: multiSend',
action.to
);
}
const input = decodedMethod.inputs[0];

if (input.type !== 'bytes[]') {
return createActionError(
action.data,
'Could not decode action: multicall'
'Could not decode action: multicall',
action.to
);
}

Expand Down Expand Up @@ -420,7 +435,12 @@ const decodeAction = async (
});

if (!abi || !abi?.length) {
return createActionError(data, 'Could not decode action: abi not found');
return createActionError(
data,
'Could not decode action: abi not found',
to,
decodeValue(value)
);
}

const decodedMethod = decodeMethod({
Expand All @@ -429,7 +449,12 @@ const decodeAction = async (
});

if (!decodedMethod) {
return createActionError(data, 'Could not decode action: method not found');
return createActionError(
data,
'Could not decode action: method not found',
to,
decodeValue(value)
);
}

const methodSignature = data.slice(0, 10);
Expand Down
9 changes: 7 additions & 2 deletions libs/tx-builder/src/utils/multicall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,13 @@ const handleMulticallFormActions = ({
if (!validTxs.length) {
throw new Error('No actions found');
}
// TODO: sort by tx.actionId.index
return validTxs.map((actionId: string) => {
const sortedTxs = validTxs.sort((actionA: string, actionB: string) =>
Number(appState.formValues.tx[actionA].index) >
Number(appState.formValues.tx[actionB].index)
? 1
: -1
);
return sortedTxs.map((actionId: string) => {
const action = appState.formValues.tx[actionId];
const { to, data, value, operation } = action;
return {
Expand Down

0 comments on commit 186d148

Please sign in to comment.