Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(website): queue drawer issues #1574

Merged
merged 3 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/website/src/features/Packages/Abi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ export const Abi: FC<{
address: viem.Address;
cannonOutputs: ChainArtifacts;
chainId: number;
contractName?: string;
contractSource?: string;
onDrawerOpen?: () => void;
packageUrl?: string;
}> = ({
isLoading,
abi,
contractSource,
contractName,
address,
cannonOutputs,
chainId,
Expand Down Expand Up @@ -313,6 +315,7 @@ export const Abi: FC<{
cannonOutputs={cannonOutputs}
chainId={chainId}
contractSource={contractSource}
contractName={contractName}
onDrawerOpen={onDrawerOpen}
collapsible
showFunctionSelector={false}
Expand Down
5 changes: 2 additions & 3 deletions packages/website/src/features/Packages/Function.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const Function: FC<{
address: Address;
cannonOutputs: ChainArtifacts;
chainId: number;
contractName?: string;
contractSource?: string;
onDrawerOpen?: () => void;
collapsible?: boolean;
Expand All @@ -86,6 +87,7 @@ export const Function: FC<{
abi /*, cannonOutputs */,
address,
chainId,
contractName,
contractSource,
onDrawerOpen,
collapsible,
Expand Down Expand Up @@ -295,9 +297,6 @@ export const Function: FC<{
}
}

const regex = /\/([^/]+)\.sol$/;
const contractName = contractSource?.match(regex)?.[1] || 'Unknown';

setQueuedIdentifiableTxns({
queuedIdentifiableTxns: [
...queuedIdentifiableTxns,
Expand Down
9 changes: 7 additions & 2 deletions packages/website/src/features/Packages/FunctionInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,13 @@ export const FunctionInput: FC<Props> = ({
/>
);
case input.type.startsWith('tuple'):
// TODO: implement value prop for TupleInput
return <TupleInput input={input} handleUpdate={_handleUpdate} />;
return (
<TupleInput
input={input}
handleUpdate={_handleUpdate}
value={_initialValue}
/>
);
default:
return (
<DefaultInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,25 @@ import { FunctionInput } from '../FunctionInput';
const TupleInput = ({
input,
handleUpdate,
value,
}: {
input: any;
handleUpdate: (value: any) => void;
value?: Record<string, any>;
}) => {
const getDefaultValueForType = (component: AbiParameter) => {
if (component.type.startsWith('bool')) return false;
if (component.type.startsWith('int')) return '0';
if (component.type.startsWith('uint')) return '0';
return '';
};

// Initialize the tuple state as an object, with keys corresponding to tuple property names
const [tupleState, setTupleState] = useState(() =>
input.components.reduce((acc: any, component: any) => {
acc[component.name] = getDefaultValueForType(component);
// Use value prop if available, otherwise use default value
acc[component.name] =
value?.[component.name] ?? getDefaultValueForType(component);
return acc;
}, {})
);
Expand Down Expand Up @@ -60,6 +65,7 @@ const TupleInput = ({
}
updateTupleValue(component.name, value);
}}
initialValue={tupleState[component.name]}
/>
</FormControl>
))}
Expand Down
1 change: 1 addition & 0 deletions packages/website/src/features/Packages/Interact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ const Interact: FC = () => {
<Abi
isLoading={isLoadingData}
abi={contract?.abi}
contractName={contract?.contractName ?? 'Unknown'}
contractSource={contract?.sourceName}
address={contractAddress!}
cannonOutputs={cannonOutputs}
Expand Down
Loading