-
Notifications
You must be signed in to change notification settings - Fork 21
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
Changes from all commits
529593c
73d958e
d19b797
64d4d00
a1e2cf0
b4f4fb0
88b81bb
e4213e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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" | ||
} |
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(.*)*', | ||
|
@@ -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]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we match only if the space doesn't have Updated code handles both URLs with There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, else all existing URLs will break, users reference these URLs on their forums or blogs or Twitter, etc. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}`; | ||
} | ||
} | ||
|
||
|
@@ -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(); | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)