Skip to content

Commit

Permalink
chore: fix celo networks
Browse files Browse the repository at this point in the history
  • Loading branch information
Another-DevX authored and fabianschu committed Apr 21, 2024
1 parent 6203489 commit e3b5010
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/navs/AppNav/AppNavNetworkSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const appNetworkSupported = computed((): boolean => {
const activeNetwork = computed((): NetworkOption | undefined =>
allNetworks.value.find(network => {
if (!appNetworkSupported.value && network.id === 'ethereum') return true;
if (!appNetworkSupported.value && network.id === 'celo') return true;
return isActive(network);
})
);
Expand Down
3 changes: 2 additions & 1 deletion src/composables/useNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,13 @@ export function handleNetworkSlug(
) {
const networkFromUrl = networkFromSlug(networkSlug);
const localStorageNetwork = networkFor(
localStorage.getItem('networkId') ?? '1'
localStorage.getItem('networkId') ?? '42220'
);
if (!networkFromUrl) {
// missing or incorrect network name -> next() withtout network change
return noNetworkChangeCallback();
}

if (localStorageNetwork === networkFromUrl) {
// if on the correct network -> next()
return noNetworkChangeCallback();
Expand Down
12 changes: 11 additions & 1 deletion src/plugins/router/nav-guards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ function applyNetworkSubdomainRedirect(router: Router): Router {
*/
function applyNetworkPathRedirects(router: Router): Router {
router.beforeEach((to, from, next) => {
const networkSlugFromUrl = to.params.networkSlug?.toString() ?? '';

if (
networkSlugFromUrl !== config[Network.CELO].slug &&
networkSlugFromUrl !== config[Network.ALFAJORES].slug
) {
console.debug(networkSlugFromUrl, config[Network.CELO].slug);
router.push({ path: `/${config[Network.CELO].slug}${to.fullPath}` });
}
if (redirecting.value) {
next();
} else {
Expand All @@ -106,6 +115,7 @@ function applyNetworkPathRedirects(router: Router): Router {
'/risks',
];
const routerHandledRedirects = ['not-found', 'trade-redirect'];

if (
to.redirectedFrom?.fullPath &&
to.redirectedFrom?.fullPath.includes('/pool')
Expand All @@ -121,7 +131,7 @@ function applyNetworkPathRedirects(router: Router): Router {
} else {
const newPath = to.redirectedFrom?.fullPath ?? to.fullPath;
const newNetwork = newPath.includes('/pool')
? config[Network.MAINNET].slug
? config[Network.CELO].slug
: networkSlug;
router.push({ path: `/${newNetwork}${newPath}` });
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/router/route-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ export interface RouteTo {

export function resolveRoute(to: RouteTo) {
if (!to?.name) throw new Error(`Provided route (${to}) must have name`);
return router.resolve({ name: to.name, params: { networkSlug: 'ethereum' } })
return router.resolve({ name: to.name, params: { networkSlug: 'celo' } })
.matched[0].components?.default;
}

0 comments on commit e3b5010

Please sign in to comment.