Skip to content
Snippets Groups Projects
Commit 7da5746c authored by Lukas's avatar Lukas Committed by mcfarhat
Browse files

Update account search url build function

parent da6a9b62
No related branches found
No related tags found
1 merge request!499#392_part2_simplify_URL_route_build
import { convertIdsToBooleanArray, getPageUrlParams } from "@/lib/utils";
import { dataToURL } from "@/utils/URLutils";
import Explorer from "@/types/Explorer";
import { convertIdsToBooleanArray } from "@/lib/utils";
import { setParamIfPositive } from "./globalSearchHelpers";
export function startAccountOperationsSearch(
accountOperationsSearchProps: Explorer.AccountSearchOperationsProps,
......@@ -29,57 +28,47 @@ export function getAccountPageLink(
): string {
if (!accountOperationsSearchProps) return "#";
const urlParams: Explorer.UrlParam[] = [
{
paramName: "fromBlock",
paramValue: dataToURL(accountOperationsSearchProps.fromBlock),
},
{
paramName: "toBlock",
paramValue: dataToURL(accountOperationsSearchProps.toBlock),
},
{
paramName: "fromDate",
paramValue: dataToURL(accountOperationsSearchProps.startDate),
},
{
paramName: "toDate",
paramValue: dataToURL(accountOperationsSearchProps.endDate),
},
{
paramName: "rangeSelectKey",
paramValue: dataToURL(searchRanges.rangeSelectKey),
},
];
const {
fromBlock,
toBlock,
startDate,
endDate,
operationTypes,
accountName,
} = accountOperationsSearchProps;
if (accountOperationsSearchProps.operationTypes) {
urlParams.push({
paramName: "filters",
paramValue: dataToURL(
convertIdsToBooleanArray(accountOperationsSearchProps.operationTypes)
),
});
}
const {
rangeSelectKey,
lastTimeUnitValue,
timeUnitSelectKey,
lastBlocksValue,
} = searchRanges;
const searchParams = new URLSearchParams();
if (searchRanges.rangeSelectKey === "lastTime") {
urlParams.push({
paramName: "lastTime",
paramValue: dataToURL(searchRanges.lastTimeUnitValue),
});
urlParams.push({
paramName: "timeUnit",
paramValue: dataToURL(searchRanges.timeUnitSelectKey),
});
setParamIfPositive(searchParams, "fromBlock", fromBlock);
setParamIfPositive(searchParams, "toBlock", toBlock);
setParamIfPositive(searchParams, "fromDate", startDate);
setParamIfPositive(searchParams, "toDate", endDate);
setParamIfPositive(searchParams, "rangeSelectKey", rangeSelectKey);
if (operationTypes) {
setParamIfPositive(
searchParams,
"filters",
convertIdsToBooleanArray(operationTypes)
);
}
if (searchRanges.rangeSelectKey === "lastBlocks") {
urlParams.push({
paramName: "lastBlocks",
paramValue: dataToURL(searchRanges.lastBlocksValue),
});
if (rangeSelectKey === "lastTime") {
setParamIfPositive(searchParams, "lastTime", lastTimeUnitValue);
setParamIfPositive(searchParams, "timeUnit", timeUnitSelectKey);
} else if (rangeSelectKey === "lastBlocks") {
setParamIfPositive(searchParams, "lastBlocks", lastBlocksValue);
}
return `/@${accountOperationsSearchProps.accountName}${getPageUrlParams(
urlParams
)}`;
const queryString = searchParams.toString();
const urlPath = `/@${accountName}${queryString ? `?${queryString}` : ""}`;
return urlPath;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment