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(reference): act-1487 - fixes for new reference pages #1459

Merged
merged 1 commit into from
Jul 29, 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
32 changes: 17 additions & 15 deletions src/components/ParserOpenRPC/InteractiveBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,21 @@ export default function InteractiveBox({
}: InteractiveBoxProps) {
const [parsedSchema, setParsedSchema] = useState<RJSFSchema>(null);
const [defaultFormData, setDefaultFormData] = useState<any>({});
const [currentFormData, setCurrentFormData] = useState<any>({});
const [isFormReseted, setIsFormReseted] = useState(false);
const formRef = useRef(null);
const { colorMode } = useColorMode();
const { isComplexTypeView } = useContext(ParserOpenRPCContext);

const defaultExampleFormData = examples
? Object.fromEntries(
examples[0].params.map(({ name, value }) => [name, value])
)
: {};
useEffect(() => {
if (examples && examples.length > 0 && examples[0].params) {
const defaultValues = Object.fromEntries(examples[0].params.map(({ name, value }) => [name, value]));
setDefaultFormData({...defaultValues});
setCurrentFormData({...defaultValues});
onParamChange({...defaultValues});
}
}, [examples]);

const schema: RJSFSchema = {
components: {
schemas: components,
Expand Down Expand Up @@ -85,7 +90,8 @@ export default function InteractiveBox({
};
const handleResetForm = (e) => {
e.preventDefault();
setDefaultFormData(defaultExampleFormData);
setCurrentFormData({...defaultFormData});
onParamChange({...defaultFormData});
setIsFormReseted(true);
};
const handleClearForm = (e) => {
Expand All @@ -107,15 +113,11 @@ export default function InteractiveBox({
}
};
dereferenceSchema();
if (examples) {
setDefaultFormData(defaultExampleFormData);
onParamChange(defaultExampleFormData);
}
}, []);

const onChangeHandler = (data) => {
onParamChange(data);
setDefaultFormData(data);
setCurrentFormData({...data});
onParamChange({...data});
};

const cloneAndSetNullIfExists = (obj, key) => {
Expand All @@ -137,8 +139,8 @@ export default function InteractiveBox({

const handleCancelClick = () => {
if (drawerLabel) {
const upData = cloneAndSetNullIfExists(defaultFormData, drawerLabel);
setDefaultFormData(upData);
const upData = cloneAndSetNullIfExists(currentFormData, drawerLabel);
setCurrentFormData(upData);
}
closeComplexTypeView();
};
Expand All @@ -151,7 +153,7 @@ export default function InteractiveBox({
</div>
<Form
schema={parsedSchema}
formData={defaultFormData}
formData={currentFormData}
formContext={{ isFormReseted }}
validator={validator}
liveValidate
Expand Down
3 changes: 1 addition & 2 deletions src/components/ParserOpenRPC/RequestBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ export default function RequestBox({
}: RequestBoxProps) {
const exampleRequest = useMemo(() => {
const preparedParams = JSON.stringify(paramsData, null, 2);
return `await window.ethereum.request({\n "method": "${method}",\n "params": ${preparedParams},\n});`;
return `await window.ethereum.request({\n "method": "${method}",\n "params": ${preparedParams.replace(/"([^"]+)":/g, '$1:')},\n});`;
}, [method, paramsData]);

const exampleResponse = useMemo(() => {
if (!response || response === null) return false;
return JSON.stringify(response, null, 2);
}, [response]);

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/plugin-json-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const requests = [
name: NETWORK_NAMES.linea,
},
{
url: "https://metamask.github.io/api-specs/0.9.3/openrpc.json",
url: "https://metamask.github.io/api-specs/latest/openrpc.json",
name: NETWORK_NAMES.metamask,
},
];
Expand Down
Loading