-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3139 from near/master
Release 2024-05-29
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
packages/frontend/src/components/wallet-migration/RecoveryRedirect.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useEffect } from 'react'; | ||
import { useLocation } from 'react-router-dom'; | ||
|
||
import { IS_MAINNET } from '../../config'; | ||
|
||
const RedirectToTestnet = () => { | ||
const location = useLocation(); | ||
|
||
useEffect(() => { | ||
// Function to reconstruct the URL | ||
const reconstructUrl = (url) => { | ||
const urlObj = new URL(url); | ||
const myNearWalletUrl = IS_MAINNET ? 'https://app.mynearwallet.com/' : 'https://testnet.mynearwallet.com'; | ||
const newUrl = new URL(myNearWalletUrl); | ||
newUrl.pathname = urlObj.pathname; | ||
newUrl.search = urlObj.search; | ||
newUrl.hash = urlObj.hash; | ||
return newUrl.toString(); | ||
}; | ||
|
||
// Get the current URL | ||
const currentUrl = window.location.href; | ||
|
||
// Reconstruct the URL | ||
const newUrl = reconstructUrl(currentUrl); | ||
|
||
// Redirect to the new URL | ||
window.location.replace(newUrl); | ||
}, [location]); | ||
|
||
return null; | ||
}; | ||
|
||
export default RedirectToTestnet; |