Skip to content

Commit

Permalink
feat: handle alias redirection (#1128)
Browse files Browse the repository at this point in the history
* feat: handle alias redirection

* fix variable name

* fix: ignore redirection for whitelabel

* Update apps/ui/src/helpers/aliases.json

Co-authored-by: Less <[email protected]>

* ignore non metadataNetworks to redirect

* Update apps/ui/src/routes/index.ts

Co-authored-by: Wan <[email protected]>

* Update apps/ui/src/routes/index.ts

---------

Co-authored-by: Less <[email protected]>
Co-authored-by: Wan <[email protected]>
  • Loading branch information
3 people authored Jan 29, 2025
1 parent 8186f40 commit 6196993
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 11 deletions.
80 changes: 80 additions & 0 deletions apps/ui/src/helpers/aliases.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"treasuredao.eth": "treasuregaming.eth",
"cryptopugz": "cryptopugz.eth",
"aave": "aave.eth",
"aavegotchi": "aavegotchi.eth",
"airswap": "vote.airswap.eth",
"dhedge": "gov.dhedge.eth",
"unfederalreserve": "unfederalreserve.eth",
"andrewladdusaw.eth": "everydaydao.eth",
"sushi": "sushigov.eth",
"sushipowah": "sushigov.eth",
"yam": "yam.eth",
"yamv2": "yam.eth",
"velotoken": "velotoken.eth",
"cream": "cream-finance.eth",
"bzx": "bzx.eth",
"metafactory": "metafactory.eth",
"stabilize": "stabilize-governance.eth",
"diadata": "diadao.eth",
"gnosis": "gnosis.eth",
"farm": "harvestfi.eth",
"tokenlon": "tokenlon.eth",
"synthetixcouncil": "spartancouncil.eth",
"synthetixproposal": "snxgov.eth",
"synthetixgrants": "snxgrants.eth",
"cover": "cover-protocol.eth",
"iwan": "iwan.eth",
"oceandao": "officialoceandao.eth",
"macaronswap": "macaronswap.eth",
"pepemon": "pepedontdump.eth",
"akropolis-delphi": "akropolis.eth",
"rally": "rallygov.eth",
"debaseonomics": "debaseonomics.eth",
"pickle": "pickle.eth",
"index": "index-coop.eth",
"streamr": "streamr.eth",
"rarible": "rarible.eth",
"curve": "curve.eth",
"sil": "sister-in-law.eth",
"digital-reserve-currency": "drctoken.eth",
"web3-api": "polywrap.eth",
"mstable": "mstablegovernance.eth",
"adex": "adex.eth",
"balancer": "balancer.eth",
"peripheralist.eth": "tiledao.eth",
"seen": "seenhaus.eth",
"kleros": "kleros.eth",
"piedao": "piedao.eth",
"dracula": "draculasucks.eth",
"pillar": "pillarwallet.eth",
"yaxis": "yaxis.eth",
"spaceswap": "spaceswap.eth",
"descience.eth": "people-dao.eth",
"dforce": "dforcenet.eth",
"rari": "fuse.eth",
"nft20.eth": "musedao.eth",
"tripscommunity": "tripscommunity.eth",
"deversifi.eth": "rhinofi.vote",
"cake.eth": "cakevote.eth",
"project-galaxy.eth": "gal.eth",
"epns.eth": "pushdao.eth",
"tptdao.eth": "itokenpocket.eth",
"tallyhodao.eth": "tahodao.eth",
"goodghosting.eth": "halofi.eth",
"arbitrum-odyssey.eth": "arbitrumfoundation.eth",
"pokt-network": "poktdao.eth",
"lensterapp.eth": "lenster.xyz",
"nexondao.eth": "eralend.eth",
"pancake": "cakevote.eth",
"gov.radicle.eth": "gov.radworks.eth",
"daoge.eth": "ownthedoge.eth",
"ownthedaoge.eth": "ownthedoge.eth",
"uniswap": "uniswapgovernance.eth",
"popcorn-snapshot.eth": "vaultcraft-snapshot.eth",
"kuma-inu.eth": "kumatokens.eth",
"x7community.eth": "x7finance.eth",
"redactedcartel.eth": "dinero.xyz",
"gal.eth": "g-dao.eth",
"bzr.eth": "rwg.eth"
}
1 change: 1 addition & 0 deletions apps/ui/src/routes/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const spaceChildrenRoutes: RouteRecordRaw[] = [
component: SpaceEditor
},
{ path: '', name: 'space-overview', component: SpaceOverview },
{ path: 'about', redirect: { name: 'space-overview' } },
{ path: 'proposals', name: 'space-proposals', component: SpaceProposals },
{
path: 'proposal/:proposal?',
Expand Down
27 changes: 16 additions & 11 deletions apps/ui/src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { createRouter, createWebHashHistory } from 'vue-router';
import SplashScreen from '@/components/Layout/SplashScreen.vue';
import aliases from '@/helpers/aliases.json';
import { metadataNetwork } from '@/networks';
import defaultRoutes from '@/routes/default';

const { resolved } = useWhiteLabel();
const { resolved, isWhiteLabel } = useWhiteLabel();

const splashScreenRoute = {
path: '/:catchAll(.*)*',
Expand Down Expand Up @@ -35,17 +36,21 @@ const router = createRouter({

// Add a global navigation guard for URL redirection
router.beforeEach((to, _from, next) => {
if (isWhiteLabel.value) return next();

const [, space, ...rest] = to.path.split('/');
let spaceName = space.replace(`${metadataNetwork}:`, '');
// skip if network is not metadataNetwork
if (spaceName.includes(':')) return 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;
}
// Redirect paths like "/safe.eth/settings" to "/s:safe.eth/settings"
if (to.matched[0]?.name === 'space') {
// if space has alias, change url to it
spaceName = aliases[spaceName] || spaceName;
const restPath = rest.length ? `/${rest.join('/')}` : '';
redirectPath = `/${metadataNetwork}:${spaceName}${restPath}`;
}

// Match and redirect paths like "/delegate/safe.eth" to "/s:safe.eth/delegates"
Expand All @@ -63,7 +68,7 @@ router.beforeEach((to, _from, next) => {
}

// Perform the redirection if a match is found
if (redirectPath) {
if (redirectPath && redirectPath !== to.path) {
next({ path: redirectPath, replace: true });
} else {
next();
Expand Down

0 comments on commit 6196993

Please sign in to comment.