Skip to content

Commit

Permalink
fix: redirect to assets page after changing the network
Browse files Browse the repository at this point in the history
  • Loading branch information
impelcrypto committed Jan 3, 2025
1 parent 04bd37c commit 376272d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.DS_Store
.thumbs.db
node_modules
.env

# Quasar core related directories
.quasar
Expand Down Expand Up @@ -52,3 +53,4 @@ astar-collator

# Chopstick binaries
db.sqlite*
.vercel
20 changes: 5 additions & 15 deletions src/router/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,15 @@ export const buildXvmTransferPageLink = (symbol: string): string => {
};

/**
* A helper function to replace the network params to the selected network
* EX: `http://localhost:8080/shiden/assets` -> `http://localhost:8080/astar/assets`
* A helper function to build the URL and redirect to the selected network's assets page
* EX: `http://localhost:8080/shiden/bridge` -> `http://localhost:8080/astar/assets`
* @param network networkAlias in providerEndpoints
* @returns URL
*/
export const buildNetworkUrl = (network: string) => {
const href = window.location.href;
const hrefArray = href.split('/');
const networkIndex = 3;

const url = hrefArray
.slice(0, hrefArray.length)
.map((it: string, index: number) => (index === networkIndex ? network : it))
.join('/');

// Memo: `window.open(url, '_self')` won't work with `#`
if (url.includes('#staking')) {
return url.replace('#staking', '');
}

// Memo: Extract the protocol + host
const host = hrefArray.slice(0, 3).join('/');
const url = `${host}/${network}${Path.Assets}`;
return url;
};

0 comments on commit 376272d

Please sign in to comment.