Skip to content

Commit 3194f3c

Browse files
authored
feat(APP-4476): Remove calculation of function selectors internally (#549)
1 parent 6d634e3 commit 3194f3c

7 files changed

Lines changed: 27 additions & 20 deletions

File tree

.changeset/vast-socks-carry.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@aragon/gov-ui-kit': patch
3+
---
4+
5+
**BREAKING CHANGE:** Update `ProposalActionsItem` and `SmartContractFunctionDataListItemStructure` to accept
6+
`functionSelector` as a prop, instead of calculating it internally

src/modules/components/proposal/proposalActions/proposalActionsItem/proposalActionsItem.api.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export interface IProposalActionsItemProps<TAction extends IProposalAction = IPr
2626
* Proposal action to be rendered.
2727
*/
2828
action: TAction;
29+
/**
30+
* Function selector of the action to be displayed optionally.
31+
*/
32+
actionFunctionSelector?: string;
2933
/**
3034
* Index of the action injected by the <ProposalActions.Container /> component.
3135
*/

src/modules/components/proposal/proposalActions/proposalActionsItem/proposalActionsItem.stories.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export const VerifiedDecoded: Story = {
7878
],
7979
},
8080
}),
81+
actionFunctionSelector: '0x7ff36ab5',
8182
},
8283
};
8384

@@ -98,6 +99,7 @@ export const VerifiedRaw: Story = {
9899
parameters: [],
99100
},
100101
}),
102+
actionFunctionSelector: '0x7ff36ab5',
101103
},
102104
};
103105

src/modules/components/proposal/proposalActions/proposalActionsItem/proposalActionsItem.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const ProposalActionsItem = <TAction extends IProposalAction = IProposalA
2222
) => {
2323
const {
2424
action,
25+
actionFunctionSelector,
2526
index,
2627
value,
2728
CustomComponent,
@@ -81,10 +82,10 @@ export const ProposalActionsItem = <TAction extends IProposalAction = IProposalA
8182
<Accordion.Item value={value ?? index.toString()} ref={itemRef}>
8283
<Accordion.ItemHeader className="min-w-0">
8384
<SmartContractFunctionDataListItem.Structure
84-
functionName={action.inputData?.function}
8585
contractName={action.inputData?.contract}
8686
contractAddress={action.to}
87-
functionParameters={action.inputData?.parameters}
87+
functionName={action.inputData?.function}
88+
functionSelector={actionFunctionSelector}
8889
chainId={chainId}
8990
className="w-full bg-transparent"
9091
asChild={true}

src/modules/components/smartContract/smartContractFunctionDataListItem/smartContractFunctionDataListItemStructure/smartContractFunctionDataListItemStructure.stories.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,14 @@ export const Unverified: Story = {
3636
};
3737

3838
/**
39-
* Usage example of the SmartContractFunctionDataListItem.Structure component with a function signature.
39+
* Usage example of the SmartContractFunctionDataListItem.Structure component with a function selector.
4040
*/
41-
export const WithFunctionSignature: Story = {
41+
export const WithFunctionSelector: Story = {
4242
args: {
4343
contractAddress: '0x1234567890abcdef1234567890abcdef12345678',
4444
contractName: 'Uniswap V2 Router',
4545
functionName: 'addLiquidity',
46-
functionParameters: [
47-
{ name: 'tokenA', type: 'address', value: 0 },
48-
{ name: 'tokenB', type: 'address', value: 0 },
49-
],
46+
functionSelector: '0x7ff36ab5',
5047
},
5148
};
5249

src/modules/components/smartContract/smartContractFunctionDataListItem/smartContractFunctionDataListItemStructure/smartContractFunctionDataListItemStructure.test.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ describe('<SmartContractFunctionDataListItem.Structure /> component', () => {
2828
expect(screen.getByText(functionName)).toBeInTheDocument();
2929
});
3030

31+
it('renders the function selector when smart contract is verified', () => {
32+
const functionSelector = '0xFunSelector';
33+
render(createTestComponent({ functionSelector }));
34+
expect(screen.getByText(functionSelector)).toBeInTheDocument();
35+
});
36+
3137
it('renders a not-verified label for function name and contract name when smart contract is not verified', () => {
3238
render(createTestComponent());
3339
expect(

src/modules/components/smartContract/smartContractFunctionDataListItem/smartContractFunctionDataListItemStructure/smartContractFunctionDataListItemStructure.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import classNames from 'classnames';
2-
import { toFunctionSelector } from 'viem';
32
import { mainnet } from 'viem/chains';
4-
import type { IProposalActionInputDataParameter } from '../../..';
53
import {
64
Button,
75
DataList,
@@ -30,9 +28,9 @@ export type ISmartContractFunctionDataListItemProps = IDataListItemProps & {
3028
*/
3129
contractAddress: string;
3230
/**
33-
* The parameters to pass to the function.
31+
* Function selector of the given smart contract function.
3432
*/
35-
functionParameters?: IProposalActionInputDataParameter[];
33+
functionSelector?: string;
3634
/**
3735
* Callback when function is removed.
3836
*/
@@ -58,7 +56,7 @@ export const SmartContractFunctionDataListItemStructure: React.FC<ISmartContract
5856
) => {
5957
const {
6058
functionName,
61-
functionParameters,
59+
functionSelector,
6260
contractName,
6361
contractAddress,
6462
chainId = mainnet.id,
@@ -77,13 +75,6 @@ export const SmartContractFunctionDataListItemStructure: React.FC<ISmartContract
7775
const functionLabel = functionName ?? copy.smartContractFunctionDataListItemStructure.notVerified.function;
7876
const contractLabel = contractName ?? copy.smartContractFunctionDataListItemStructure.notVerified.contract;
7977

80-
const functionSignature =
81-
functionName && functionParameters
82-
? `${functionName}(${functionParameters.map((param) => param.type).join(',')})`
83-
: undefined;
84-
85-
const functionSelector = functionSignature ? toFunctionSelector(functionSignature) : undefined;
86-
8778
const hasVerifiedNames = !!functionName && !!contractName;
8879
const displayWarningFeedback = displayWarning || !hasVerifiedNames;
8980

0 commit comments

Comments
 (0)