From 286e83e0385636b055b28d170eba5ca4f1bb1f2c Mon Sep 17 00:00:00 2001 From: Monoblade <157546326+Monobladegg@users.noreply.github.com> Date: Sun, 18 Aug 2024 09:39:36 +0300 Subject: [PATCH] fixed handle net --- package-lock.json | 133 ------------------ src/pages/Layout/layout.tsx | 1 + src/pages/public/account/publicnet.tsx | 3 +- .../shared/layouts/Header/ui/index.tsx | 29 ++-- 4 files changed, 18 insertions(+), 148 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2e7b900..d608bf3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -367,126 +367,6 @@ "node": ">=16 || 14 >=14.17" } }, - "node_modules/@next/swc-darwin-arm64": { - "version": "14.2.5", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.5.tgz", - "integrity": "sha512-/9zVxJ+K9lrzSGli1///ujyRfon/ZneeZ+v4ptpiPoOU+GKZnm8Wj8ELWU1Pm7GHltYRBklmXMTUqM/DqQ99FQ==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-darwin-x64": { - "version": "14.2.5", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.5.tgz", - "integrity": "sha512-vXHOPCwfDe9qLDuq7U1OYM2wUY+KQ4Ex6ozwsKxp26BlJ6XXbHleOUldenM67JRyBfVjv371oneEvYd3H2gNSA==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-linux-arm64-gnu": { - "version": "14.2.5", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.5.tgz", - "integrity": "sha512-vlhB8wI+lj8q1ExFW8lbWutA4M2ZazQNvMWuEDqZcuJJc78iUnLdPPunBPX8rC4IgT6lIx/adB+Cwrl99MzNaA==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-linux-arm64-musl": { - "version": "14.2.5", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.5.tgz", - "integrity": "sha512-NpDB9NUR2t0hXzJJwQSGu1IAOYybsfeB+LxpGsXrRIb7QOrYmidJz3shzY8cM6+rO4Aojuef0N/PEaX18pi9OA==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-linux-x64-gnu": { - "version": "14.2.5", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.5.tgz", - "integrity": "sha512-8XFikMSxWleYNryWIjiCX+gU201YS+erTUidKdyOVYi5qUQo/gRxv/3N1oZFCgqpesN6FPeqGM72Zve+nReVXQ==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-linux-x64-musl": { - "version": "14.2.5", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.5.tgz", - "integrity": "sha512-6QLwi7RaYiQDcRDSU/os40r5o06b5ue7Jsk5JgdRBGGp8l37RZEh9JsLSM8QF0YDsgcosSeHjglgqi25+m04IQ==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-win32-arm64-msvc": { - "version": "14.2.5", - "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.5.tgz", - "integrity": "sha512-1GpG2VhbspO+aYoMOQPQiqc/tG3LzmsdBH0LhnDS3JrtDx2QmzXe0B6mSZZiN3Bq7IOMXxv1nlsjzoS1+9mzZw==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-win32-ia32-msvc": { - "version": "14.2.5", - "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.5.tgz", - "integrity": "sha512-Igh9ZlxwvCDsu6438FXlQTHlRno4gFpJzqPjSIBZooD22tKeI4fE/YMRoHVJHmrQ2P5YL1DoZ0qaOKkbeFWeMg==", - "cpu": [ - "ia32" - ], - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">= 10" - } - }, "node_modules/@next/swc-win32-x64-msvc": { "version": "14.2.5", "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.5.tgz", @@ -3307,19 +3187,6 @@ "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" }, - "node_modules/fsevents": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", - "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", - "hasInstallScript": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, "node_modules/function-bind": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", diff --git a/src/pages/Layout/layout.tsx b/src/pages/Layout/layout.tsx index 61040b3..4727d9d 100644 --- a/src/pages/Layout/layout.tsx +++ b/src/pages/Layout/layout.tsx @@ -51,6 +51,7 @@ const PageLayout: FC = ({ children }) => { ); }, [accounts, net, setIsAuth]); + const themeLS: string | undefined | null = isWindowDefined ? window.localStorage.getItem("theme") ? window.localStorage.getItem("theme") diff --git a/src/pages/public/account/publicnet.tsx b/src/pages/public/account/publicnet.tsx index 9b557db..f7d0fc1 100644 --- a/src/pages/public/account/publicnet.tsx +++ b/src/pages/public/account/publicnet.tsx @@ -157,7 +157,7 @@ const PublicNet: FC = ({ id }) => { * Logic to create an array of strings where item is an accountID * that is not fake in the home_domain set by the account * - * example: newAccounts: string[] = ['GCGLKWJX5BPX2BOCOHYA6KUBZ67FR23DAHLG7VD3YRTGEYGZX57KUGFP', + * example: newAccounts: string[] = ['GBR2RQKJY6S5JXKZVJYK6YH5CQXN5KUWQXKQO6G7XK5E5WQ4', * 'GBEUDKANIFPTFHPWJ5T3R6RIO36RQBFGHYPAQ6STH7KMNDHAT36LHOLD', * 'GA2T6GR7VXXXBETTERSAFETHANSORRYXXXPROTECTEDBYLOBSTRVAULT'] */ @@ -900,7 +900,6 @@ const PublicNet: FC = ({ id }) => {

) : ( {errorvalid} - )} diff --git a/src/widgets/shared/layouts/Header/ui/index.tsx b/src/widgets/shared/layouts/Header/ui/index.tsx index 5138a9c..fc578c2 100644 --- a/src/widgets/shared/layouts/Header/ui/index.tsx +++ b/src/widgets/shared/layouts/Header/ui/index.tsx @@ -12,6 +12,7 @@ import AccountItem from "./AccountItem"; import { collapseAccount } from "@/pages/public/account/publicnet"; export const Header: FC = () => { + const { net, setNet, @@ -72,28 +73,30 @@ export const Header: FC = () => { return () => { document.removeEventListener("mousedown", handleClickOutside); }; - }, [isOpenAddAccountModal, setIsOpenAddAccountModal]); // Добавляем зависимость + }, [isOpenAddAccountModal, setIsOpenAddAccountModal]); const toggleDropdownNet = () => setIsOpenNet(!isOpenNet); const toggleDropdownAccount = () => setIsOpenAccount(!isOpenAccount); const handleSelectNet = (network: string) => { setNet(network); - localStorage.setItem("net", network); + localStorage.setItem('net', network); setIsOpenNet(false); - const currentPath = window.location.pathname; - if (currentPath === "/public" || currentPath === "/testnet") { - const newPath = `/${network}`; - router.push(newPath); - } else if ( - currentPath.includes("/public/") || - currentPath.includes("/testnet/") - ) { - // Construct the new path with updated network segment - const newPath = `/${network}` - router.push(newPath); + const currentUrl = new URL(window.location.href); + const pathSegments = currentUrl.pathname.split('/').filter(Boolean); + + let newPath: string; + + if (pathSegments[0] === 'public' || pathSegments[0] === 'testnet') { + newPath = `/${network}${pathSegments.length > 1 ? '/' + pathSegments.slice(1).join('/') : ''}`; + } else { + newPath = `/${network}${currentUrl.pathname}`; } + + const newUrl = `${newPath}${currentUrl.search}`; + + router.push(newUrl); }; // const handleSelectAccount = (account: IAccount) => {