From a6aba2481973a61336615f0c65b9acf2df5c0ea2 Mon Sep 17 00:00:00 2001 From: ae_atrofimov Date: Mon, 29 Jul 2024 13:54:12 +0200 Subject: [PATCH] fix(reference): act-1487 - fixes for new reference pages --- .../ParserOpenRPC/InteractiveBox/index.tsx | 32 ++++++++++--------- .../ParserOpenRPC/RequestBox/index.tsx | 3 +- src/plugins/plugin-json-rpc.ts | 2 +- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/components/ParserOpenRPC/InteractiveBox/index.tsx b/src/components/ParserOpenRPC/InteractiveBox/index.tsx index 65a85bb9bec..b3c42d264c6 100644 --- a/src/components/ParserOpenRPC/InteractiveBox/index.tsx +++ b/src/components/ParserOpenRPC/InteractiveBox/index.tsx @@ -44,16 +44,21 @@ export default function InteractiveBox({ }: InteractiveBoxProps) { const [parsedSchema, setParsedSchema] = useState(null); const [defaultFormData, setDefaultFormData] = useState({}); + const [currentFormData, setCurrentFormData] = useState({}); 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, @@ -85,7 +90,8 @@ export default function InteractiveBox({ }; const handleResetForm = (e) => { e.preventDefault(); - setDefaultFormData(defaultExampleFormData); + setCurrentFormData({...defaultFormData}); + onParamChange({...defaultFormData}); setIsFormReseted(true); }; const handleClearForm = (e) => { @@ -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) => { @@ -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(); }; @@ -151,7 +153,7 @@ export default function InteractiveBox({
{ 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]); diff --git a/src/plugins/plugin-json-rpc.ts b/src/plugins/plugin-json-rpc.ts index 2cb8574fab2..505d3c23d0e 100644 --- a/src/plugins/plugin-json-rpc.ts +++ b/src/plugins/plugin-json-rpc.ts @@ -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, }, ];