From 5e7129038359c3d9843c12e4adfc821ec499930e Mon Sep 17 00:00:00 2001 From: Viterbo Date: Wed, 11 Dec 2024 11:55:31 -0300 Subject: [PATCH] refactoring the multichain and network selection utils to a specific file --- src/components/header/AppHeaderLinks.vue | 68 ++-------------- src/components/header/AppHeaderTopBar.vue | 85 ++----------------- src/layouts/MainLayout.vue | 10 ++- src/lib/multichain-utils.ts | 99 +++++++++++++++++++++++ 4 files changed, 120 insertions(+), 142 deletions(-) create mode 100644 src/lib/multichain-utils.ts diff --git a/src/components/header/AppHeaderLinks.vue b/src/components/header/AppHeaderLinks.vue index d2b7fd62..79c2cf83 100644 --- a/src/components/header/AppHeaderLinks.vue +++ b/src/components/header/AppHeaderLinks.vue @@ -4,15 +4,11 @@ import { useRoute, useRouter } from 'vue-router'; import { useQuasar } from 'quasar'; import { useI18n } from 'vue-i18n'; -import { - TELOSCAN_MAINNET_URL, - TELOSCAN_TESTNET_URL, -} from 'src/lib/chain-utils'; - import LanguageSwitcherModal from 'components/header/LanguageSwitcherModal.vue'; import OutlineButton from 'components/OutlineButton.vue'; import { useChainStore } from 'src/core'; import { HeaderMenuEntry } from 'src/core/types'; +import { chains, multichainSelectedNetwork, switchChain } from 'src/lib/multichain-utils'; const $route = useRoute(); const $router = useRouter(); @@ -24,17 +20,6 @@ defineProps<{ }>(); const emit = defineEmits(['close-menu']); -const networksMenuItems = { - mainnet: [{ - url: TELOSCAN_MAINNET_URL, - label: 'Telos Mainnet', - }], - testnet: [{ - url: TELOSCAN_TESTNET_URL, - label: 'Telos Testnet', - }], -}; - const blockchainMenuExpandedMobile = ref(false); const developersMenuExpandedMobile = ref(false); const moreMenuExpandedMobile = ref(false); @@ -105,28 +90,6 @@ function toggleDarkMode() { $q.dark.toggle(); localStorage.setItem('darkModeEnabled', $q.dark.isActive.toString()); } - -function getIsCurrentNetworkMenuItem(url: string) { - networksMenuItems.mainnet.forEach((item) => { - if (item.url === url) { - return true; - } - }); - return false; -} - -function goTo(to: string | { name: string }) { - blurActiveElement(); - closeAllMenus(); - - const httpsRegex = /^https/; - if (typeof to === 'string' && httpsRegex.test(to)) { - window.open(to, '_blank'); - return; - } - - $router.push(to); -}