Skip to content

Commit

Permalink
feat: redirect v1 URL paths to v2 (#1024)
Browse files Browse the repository at this point in the history
* feat: redirect v1 URL paths to v2

* chore: update v1 URLs to .box

* chore: redirect strategy and playground to v1 site
  • Loading branch information
bonustrack authored Dec 9, 2024
1 parent d8dd2c1 commit 657759e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 6 deletions.
2 changes: 1 addition & 1 deletion apps/ui/src/components/Site/Footer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const SOCIALS = [
<AppLink :to="{ name: 'my-explore' }"> Explore spaces </AppLink>
</div>
<div>
<a href="https://snapshot.org/#/setup?step=0" target="_blank">
<a href="https://v1.snapshot.box/#/setup" target="_blank">
Create a space
<IH-arrow-sm-right class="inline-block -rotate-45" />
</a>
Expand Down
4 changes: 2 additions & 2 deletions apps/ui/src/networks/offchain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const HUB_URLS: Partial<Record<NetworkID, string | undefined>> = {
's-tn': 'https://testnet.hub.snapshot.org/graphql'
};
const SNAPSHOT_URLS: Partial<Record<NetworkID, string | undefined>> = {
s: 'https://snapshot.org',
's-tn': 'https://testnet.snapshot.org'
s: 'https://v1.snapshot.box',
's-tn': 'https://testnet.v1.snapshot.box'
};
const CHAIN_IDS: Partial<Record<NetworkID, 1 | 11155111>> = {
s: 1,
Expand Down
40 changes: 39 additions & 1 deletion apps/ui/src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createRouter, createWebHashHistory } from 'vue-router';
import SplashScreen from '@/components/Layout/SplashScreen.vue';
import defaultRoutes from './default';
import { metadataNetwork } from '@/networks';
import defaultRoutes from '@/routes/default';

const { resolved } = useWhiteLabel();

Expand Down Expand Up @@ -32,4 +33,41 @@ const router = createRouter({
}
});

// Add a global navigation guard for URL redirection
router.beforeEach((to, _from, next) => {
let redirectPath: string | null = null;

// Match and redirect paths like "/safe.eth/settings" to "/s:safe.eth/settings"
const domainMatch = to.path.match(/^\/([^:\/]+?\.[^:\/]+)(\/.*)?$/);
if (domainMatch) {
const domain = domainMatch[1];
const rest = domainMatch[2] || '';
redirectPath = `/${metadataNetwork}:${domain}`;
if (rest && !/^\/about$/.test(rest)) {
redirectPath += rest;
}
}

// Match and redirect paths like "/delegate/safe.eth" to "/s:safe.eth/delegates"
const delegateMatch = to.path.match(/^\/delegate\/([^:\/]+?\.[^:\/]+)$/);
if (delegateMatch) {
const domain = delegateMatch[1];
redirectPath = `/${metadataNetwork}:${domain}/delegates`;
}

// Match and redirect "/strategy/*" or "/playground/*" to v1.snapshot.box
if (to.path.startsWith('/strategy/') || to.path.startsWith('/playground/')) {
const newPath = to.path.replace(/^\/(strategy|playground)/, '/#$1');
window.location.href = `https://v1.snapshot.box${newPath}`;
return;
}

// Perform the redirection if a match is found
if (redirectPath) {
next({ path: redirectPath, replace: true });
} else {
next();
}
});

export default router;
4 changes: 3 additions & 1 deletion apps/ui/src/views/My/Explore.vue
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ onMounted(() => {
<UiTooltip title="Create new space">
<UiButton
:to="
protocol === 'snapshot' ? 'https://snapshot.org/#/setup' : 'create'
protocol === 'snapshot'
? 'https://v1.snapshot.box/#/setup'
: 'create'
"
class="!px-0 w-[46px]"
>
Expand Down
2 changes: 1 addition & 1 deletion apps/ui/src/views/Settings/Spaces.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ watch(
<UiButton
:to="
spacesStore.protocol === 'snapshot'
? 'https://snapshot.org/#/setup'
? 'https://v1.snapshot.box/#/setup'
: 'create'
"
class="!px-0 w-[46px]"
Expand Down

0 comments on commit 657759e

Please sign in to comment.