Skip to content
Merged
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
18 changes: 13 additions & 5 deletions src/components/FormElements/FetchContractMethodPickerWithQuery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,22 @@ export const FetchContractMethodPickerWithQuery = ({
}
}, [contractClientError, sacDataError]);

// Auto-fetch contract methods when remounting with a saved contract_id
// Auto-fetch contract methods once a valid contract id is filled in.
// Debounced so we only fetch after the user stops typing/pasting, and
// gated on validation so we never fetch an incomplete/invalid id. This also
// covers remounting with a saved contract_id.
useEffect(() => {
if (contractIdInput && value?.function_name && !contractMethods.length) {
fetchContractData();
if (!contractIdInput || validate.getContractIdError(contractIdInput)) {
return;
}
// Run only on mount

Comment thread
jeesunikim marked this conversation as resolved.
const timeoutId = setTimeout(() => {
fetchContractData();
}, 500);

return () => clearTimeout(timeoutId);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [contractIdInput]);
Comment thread
jeesunikim marked this conversation as resolved.

const handleContractIdChange = (e: React.ChangeEvent<HTMLInputElement>) => {
// reset the error
Expand Down
Loading