Skip to content

Commit

Permalink
Merge pull request #3138 from near/email-recovery-redirect
Browse files Browse the repository at this point in the history
feat: email recovery link to redirect to my near wallet
  • Loading branch information
andy-haynes committed May 28, 2024
2 parents f9c7f5a + 41bb5f1 commit ed4b0a0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/frontend/src/components/Routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import { PageNotFound } from './page-not-found/PageNotFound';
import Privacy from './privacy/Privacy';
import Terms from './terms/Terms';
import { initAnalytics } from './wallet-migration/metrics';
import RecoveryRedirect from './wallet-migration/RecoveryRedirect';
import { getMigrationStep } from './wallet-migration/utils';
import WalletMigration, { WALLET_MIGRATION_VIEWS } from './wallet-migration/WalletMigration';
import '../index.css';
Expand Down Expand Up @@ -420,6 +421,11 @@ class Routing extends Component {
component={VerifyOwnerWrapper}
/>
)}
<Route
exact
path="/recover-with-link/:accountId/:seedPhrase"
component={RecoveryRedirect}
/>
<PrivateRoute component={PageNotFound} />
</Switch>
<Footer />
Expand Down
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;

0 comments on commit ed4b0a0

Please sign in to comment.