diff --git a/src/pages/public/account/publicnet.tsx b/src/pages/public/account/publicnet.tsx index 101574a..c28d0a5 100644 --- a/src/pages/public/account/publicnet.tsx +++ b/src/pages/public/account/publicnet.tsx @@ -17,7 +17,7 @@ import { Balance, Information, Signer } from "@/shared/types"; import { DocumentInfo, Issuer } from "@/shared/types"; import { processKeys } from "@/shared/lib"; import BalanceItem from "@/pages/public/account/(BalanceItem)"; -import ignoredHomeDomains from "@/shared/configs/ignored-home-domains.json"; +import { ignoredHomeDomains, cacheConfig } from "@/shared/configs"; interface Props { id: string; @@ -47,6 +47,51 @@ const PublicNet: FC = ({ id }) => { const [isVisibleHomeDomainInfo, setIsVisibleHomeDomainInfo] = useState(true); + const FetchData = async () => { + setLoading(true); + if (account !== "") { + const horizonInfo = await getMainInformation(account); + const accountIssuer = await getAccountIssuerInformation(account); + let tomlInformation = ""; + if (horizonInfo.home_domain != undefined) + tomlInformation = await getDomainInformation(horizonInfo.home_domain); + const splittedInformation = tomlInformation.split("\n"); + let document = false; + const documentInfo: DocumentInfo = {}; + for (const i in splittedInformation) { + if (splittedInformation[i] == "[DOCUMENTATION]") { + document = true; + continue; + } + + if (!document) { + continue; + } + + if (splittedInformation[i] == "" && document) { + document = false; + continue; + } + + const _pattern = splittedInformation[i].split("="); + documentInfo[_pattern[0].trim()] = _pattern[1].replace(/"/g, "").trim(); + } + setInformation({ + home_domain: horizonInfo.home_domain, + created_at: horizonInfo.last_modified_time, + thresholds: horizonInfo.thresholds, + flags: horizonInfo.flags, + signers: horizonInfo.signers, + entries: horizonInfo.data_attr, + balances: horizonInfo.balances, + meta_data: documentInfo, + issuers: accountIssuer.records, + tomlInfo: tomlInformation, + }); + } + setLoading(false); + }; + useEffect(() => { const checkAccount = async () => { const serverUrl = @@ -84,61 +129,12 @@ const PublicNet: FC = ({ id }) => { }, [net, account]); useEffect(() => { - const handler = async () => { - setLoading(true); - if (account != "") { - const horizonInfo = await getMainInformation(account as string); - const accountIssuer = await getAccountIssuerInformation( - account as string - ); - - let tomlInformation = ""; - - if (horizonInfo.home_domain != undefined) { - tomlInformation = await getDomainInformation(horizonInfo.home_domain); - } - - const splittedInformation = tomlInformation.split("\n"); - let document = false; - const documentInfo: DocumentInfo = {}; - - for (const i in splittedInformation) { - if (splittedInformation[i] == "[DOCUMENTATION]") { - document = true; - continue; - } - - if (!document) { - continue; - } - - if (splittedInformation[i] == "" && document) { - document = false; - continue; - } - - const _pattern = splittedInformation[i].split("="); - documentInfo[_pattern[0].trim()] = _pattern[1] - .replace(/"/g, "") - .trim(); - } - setInformation({ - home_domain: horizonInfo.home_domain, - created_at: horizonInfo.last_modified_time, - thresholds: horizonInfo.thresholds, - flags: horizonInfo.flags, - signers: horizonInfo.signers, - entries: horizonInfo.data_attr, - balances: horizonInfo.balances, - meta_data: documentInfo, - issuers: accountIssuer.records, - tomlInfo: tomlInformation, - }); - } - setLoading(false); - }; - handler(); - }, [account]); + FetchData(); + const intervalID = setInterval(() => { + FetchData(); + }, cacheConfig.stellarDataCacheDurationMs); + return () => clearInterval(intervalID); + }, []); useEffect(() => { if (information.tomlInfo) { @@ -219,17 +215,18 @@ const PublicNet: FC = ({ id }) => {
{information?.home_domain !== undefined && - isVisibleHomeDomainInfo && - information.home_domain && - !ignoredHomeDomains.includes(information.home_domain) ? ( + isVisibleHomeDomainInfo && + information.home_domain && + !ignoredHomeDomains.includes(information.home_domain) ? ( <>
Home domain:
@@ -352,9 +349,9 @@ const PublicNet: FC = ({ id }) => { ? "immutable, " : ""} {information?.flags?.auth_required == false && - information?.flags?.auth_revocable == false && - information?.flags?.auth_clawback_enabled == false && - information?.flags?.auth_immutable == false + information?.flags?.auth_revocable == false && + information?.flags?.auth_clawback_enabled == false && + information?.flags?.auth_immutable == false ? "none" : ""} @@ -408,7 +405,7 @@ const PublicNet: FC = ({ id }) => {
{information?.issuers?.length && - information?.issuers?.length > 0 ? ( + information?.issuers?.length > 0 ? (

= ({ id }) => { )} {information?.entries && - Object.keys(information?.entries).length ? ( + Object.keys(information?.entries).length ? ( <>

= ({ id }) => {

{information?.meta_data && - information?.meta_data["ORG_NAME"] !== undefined && - ignoredHomeDomains && - information?.home_domain && - !ignoredHomeDomains.includes(information.home_domain) && - isVisibleHomeDomainInfo ? ( + information?.meta_data["ORG_NAME"] !== undefined && + ignoredHomeDomains && + information?.home_domain && + !ignoredHomeDomains.includes(information.home_domain) && + isVisibleHomeDomainInfo ? (
{ e.preventDefault(); setTabIndex(1); @@ -686,8 +684,9 @@ const PublicNet: FC = ({ id }) => { { e.preventDefault(); setTabIndex(2); @@ -702,7 +701,7 @@ const PublicNet: FC = ({ id }) => { {tabIndex == 1 ? (
{information?.meta_data && - information.meta_data?.["ORG_NAME"] == undefined ? ( + information.meta_data?.["ORG_NAME"] == undefined ? ( +
) : (
 = ({ id }) => {
                           
)} -
-
-
+
+ + ) : null} ) : (

Search results for {account}

@@ -904,9 +905,9 @@ const PublicNet: FC = ({ id }) => {
)} - - - + + + ); }; diff --git a/src/shared/configs/index.ts b/src/shared/configs/index.ts new file mode 100644 index 0000000..1742828 --- /dev/null +++ b/src/shared/configs/index.ts @@ -0,0 +1,4 @@ +export {default as trustedMtlAssets} from './trusted-mtl-assets.json'; +export {default as ignoredHomeDomains} from './ignored-home-domains.json'; +export {default as dataKeys} from './data-keys.json'; +export {default as cacheConfig} from './cache-config.json' \ No newline at end of file