diff --git a/package.json b/package.json index 990d4f51..8e805aed 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "eslint": "8.36.0", "eslint-config-react-app": "7.0.1", "ext-name": "5.0.0", + "json-stringify-pretty-compact": "^4.0.0", "lodash": "4.17.21", "mock-require": "3.0.3", "postcss": "8.4.21", diff --git a/src/components/modals/SettingsModal.jsx b/src/components/modals/SettingsModal.jsx index ff0be20f..9aee5831 100755 --- a/src/components/modals/SettingsModal.jsx +++ b/src/components/modals/SettingsModal.jsx @@ -2,6 +2,7 @@ import React, { useState, useEffect, useRef } from "react"; import { Link, useLocation, useNavigate } from "react-router-dom"; import Modal from "react-modal"; import { deleteAccount, deleteCaches, exportAccount, importAccount, setAccount, setActiveAccount, useAccount, useAccounts, useResolvedAuthorAddress } from "@plebbit/plebbit-react-hooks"; +import stringify from "json-stringify-pretty-compact" import { StyledModal } from "../styled/modals/SettingsModal.styled"; import useError from "../../hooks/useError"; import useSuccess from "../../hooks/useSuccess"; @@ -74,18 +75,31 @@ const SettingsModal = ({ isOpen, closeModal }) => { if (account) { const fetchAccountData = async () => { const data = await exportAccount(); - setAccountJson(data); + try { + const parsedData = JSON.parse(data); + setAccountJson(stringify(parsedData)); + } catch (error) { + console.error("Failed to pretty-print the JSON:", error); + setAccountJson(data); + } }; - fetchAccountData(); } - }, [account]); + }, [account]); + const handleAccountJsonChange = (e) => { - setAccountJson(e.target.value); + try { + const parsedData = JSON.parse(e.target.value); + setAccountJson(stringify(parsedData)); + } catch (error) { + console.error("Failed to pretty-print the JSON:", error); + setAccountJson(e.target.value); + } }; + useEffect(() => { if (checkedENS && resolvedAddress && state === 'succeeded') { @@ -502,7 +516,10 @@ const SettingsModal = ({ isOpen, closeModal }) => {