Skip to content

Commit

Permalink
refactor(popup): move ConnectWallet route out of Settings (#656)
Browse files Browse the repository at this point in the history
  • Loading branch information
sidvishnoi authored Oct 14, 2024
1 parent fd44364 commit 7244a3d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 37 deletions.
5 changes: 5 additions & 0 deletions src/popup/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {

export const ROUTES_PATH = {
HOME: '/',
CONNECT_WALLET: '/connect-wallet',
SETTINGS: '/settings',
MISSING_HOST_PERMISSION: '/missing-host-permission',
OUT_OF_FUNDS: '/out-of-funds',
Expand Down Expand Up @@ -59,6 +60,10 @@ export const routes = [
path: ROUTES_PATH.SETTINGS,
lazy: () => import('./pages/Settings'),
},
{
path: ROUTES_PATH.CONNECT_WALLET,
lazy: () => import('./pages/ConnectWallet'),
},
],
},
],
Expand Down
2 changes: 1 addition & 1 deletion src/popup/components/ProtectedRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const ProtectedRoute = () => {
return <Navigate to={ROUTES_PATH.OUT_OF_FUNDS} />;
}
if (state.connected === false) {
return <Navigate to={ROUTES_PATH.SETTINGS} />;
return <Navigate to={ROUTES_PATH.CONNECT_WALLET} />;
}

return <Outlet />;
Expand Down
38 changes: 38 additions & 0 deletions src/popup/pages/ConnectWallet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react';
import { ConnectWalletForm } from '@/popup/components/ConnectWalletForm';
import { useMessage, usePopupState } from '@/popup/lib/context';
import { getWalletInformation } from '@/shared/helpers';

export const Component = () => {
const { state } = usePopupState();
const message = useMessage();

const connectState = state.transientState['connect'];
return (
<ConnectWalletForm
publicKey={state.publicKey}
state={connectState}
defaultValues={{
recurring:
localStorage?.getItem('connect.recurring') === 'true' || false,
amount: localStorage?.getItem('connect.amount') || undefined,
walletAddressUrl:
localStorage?.getItem('connect.walletAddressUrl') || undefined,
autoKeyAddConsent:
localStorage?.getItem('connect.autoKeyAddConsent') === 'true',
}}
saveValue={(key, val) => {
localStorage?.setItem(`connect.${key}`, val.toString());
}}
getWalletInfo={getWalletInformation}
connectWallet={(data) => message.send('CONNECT_WALLET', data)}
onConnect={() => {
// The popup closes due to redirects on connect, so we don't need to
// update any state manually.
// But we reload it, as it's open all-time when running E2E tests
window.location.reload();
}}
clearConnectState={() => message.send('CONNECT_WALLET', null)}
/>
);
};
38 changes: 2 additions & 36 deletions src/popup/pages/Settings.tsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,9 @@
import React from 'react';
import { ConnectWalletForm } from '@/popup/components/ConnectWalletForm';
import { WalletInformation } from '@/popup/components/WalletInformation';
import { useMessage, usePopupState } from '@/popup/lib/context';
import { getWalletInformation } from '@/shared/helpers';
import { usePopupState } from '@/popup/lib/context';

export const Component = () => {
const { state } = usePopupState();
const message = useMessage();

if (state.connected) {
return <WalletInformation info={state} />;
} else {
const connectState = state.transientState['connect'];
return (
<ConnectWalletForm
publicKey={state.publicKey}
state={connectState}
defaultValues={{
recurring:
localStorage?.getItem('connect.recurring') === 'true' || false,
amount: localStorage?.getItem('connect.amount') || undefined,
walletAddressUrl:
localStorage?.getItem('connect.walletAddressUrl') || undefined,
autoKeyAddConsent:
localStorage?.getItem('connect.autoKeyAddConsent') === 'true',
}}
saveValue={(key, val) => {
localStorage?.setItem(`connect.${key}`, val.toString());
}}
getWalletInfo={getWalletInformation}
connectWallet={(data) => message.send('CONNECT_WALLET', data)}
onConnect={() => {
// The popup closes due to redirects on connect, so we don't need to
// update any state manually.
// But we reload it, as it's open all-time when running E2E tests
window.location.reload();
}}
clearConnectState={() => message.send('CONNECT_WALLET', null)}
/>
);
}
return <WalletInformation info={state} />;
};

0 comments on commit 7244a3d

Please sign in to comment.