Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: handle alias redirection #1121

Merged
merged 8 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' } },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed? This already direct me to space overview: https://snapshot.org/#/fabien.eth/about

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was handled in the previous code (which is changed now to make it more readable)

redirectPath = `/${metadataNetwork}:${domain}`;
if (rest && !/^\/about$/.test(rest)) {
  redirectPath += rest;
}

{ path: 'proposals', name: 'space-proposals', component: SpaceProposals },
{
path: 'proposal/:proposal?',
Expand Down
25 changes: 15 additions & 10 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,16 +36,20 @@ const router = createRouter({

// Add a global navigation guard for URL redirection
router.beforeEach((to, _from, next) => {
if (isWhiteLabel.value) 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];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we just replace the domain here and not change the whole logic? There is plenty of case to test if we change the logic.

Copy link
Member Author

@ChaituVR ChaituVR Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we match only if the space doesn't have s: for example URLs like /safe.eth/settings,

Updated code handles both URLs with s:safe.eth and safe.eth and redirects to new aliased space

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit afraid of rewriting the logic like this, it might be hard to find out if we are breaking anything.

Do we need to redirect safe.eth to s:safe.eth? Space should have single canonical URL (aside from hardcoded redirects).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to redirect safe.eth to s:safe.eth

Yes, else all existing URLs will break, users reference these URLs on their forums or blogs or Twitter, etc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tested most of the cases (also mentioned them in the description)

Also, this is not a complete rewrite but adds one more case to handle aliases and moving /about to routes instead of handling it in this function

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm mostly concerned by whitelist functionality as this code was used for this as well.

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"
// Also handle aliases
if (to.matched[0]?.name === 'space') {
const [, space, ...rest] = to.path.split('/');
let spaceName = space.replace(`${metadataNetwork}:`, '');
spaceName = aliases[spaceName] || spaceName;
const restPath = rest.join('/');

redirectPath = `/${metadataNetwork}:${spaceName}`;
if (restPath) {
redirectPath += `/${restPath}`;
}
}

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