From a019e33b42ed41636edeadcd24774aa3dd29de08 Mon Sep 17 00:00:00 2001 From: Iveta Date: Wed, 23 Oct 2024 14:10:17 -0400 Subject: [PATCH] Fix generated links (#1115) --- src/helpers/buildEndpointHref.ts | 42 ++++++++++++++++---------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/helpers/buildEndpointHref.ts b/src/helpers/buildEndpointHref.ts index 3c2e6c00..b8524f4a 100644 --- a/src/helpers/buildEndpointHref.ts +++ b/src/helpers/buildEndpointHref.ts @@ -1,7 +1,7 @@ -import { stringify } from "zustand-querystring"; +import { stringify, parse } from "zustand-querystring"; import { Routes } from "@/constants/routes"; import { isEmptyObject } from "@/helpers/isEmptyObject"; -import { sanitizeArray } from "@/helpers/sanitizeArray"; +import { Store } from "@/store/createStore"; import { AnyObject } from "@/types/types"; export const buildEndpointHref = ( @@ -12,30 +12,30 @@ export const buildEndpointHref = ( return ""; } - const SPLIT_CHAR = ";&"; - const END_CHAR = ";;"; + const trimmedSearch = window.location.search.substring(3); + const parsedParams = parse(trimmedSearch) as Store; - const storeParams = window.location.search - .replace(END_CHAR, "") - .split(SPLIT_CHAR) - .map((i) => { - // Remove existing Endpoints or XDR params - if (i.startsWith("endpoints$") || i.startsWith("xdr$")) { - return ""; - } + const buildParams = Object.entries(parsedParams).reduce((res, cur) => { + const [key, value] = cur; - return i; - }); + // Only need to keep network params + if (key === "network") { + return { ...res, [key]: value }; + } - // Add XDR params - if (route.startsWith("/xdr")) { - storeParams.push(`xdr$${stringify(params)}`); - } + return res; + }, {} as AnyObject); - // Add Endpoints params + // Endpoints params if (route.startsWith("/endpoints") && !isEmptyObject(params)) { - storeParams.push(`endpoints$params$${stringify(params)}`); + // Endpoints params need a "params" key + buildParams["endpoints"] = { params }; + } + + // XDR params + if (route.startsWith("/xdr")) { + buildParams["xdr"] = params; } - return `${route}${sanitizeArray(storeParams).join(SPLIT_CHAR)}${END_CHAR}`; + return `${route}?$=${stringify(buildParams)};;`; };