Skip to content

Commit

Permalink
chore: small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
benmalcom committed Feb 13, 2024
1 parent 5534975 commit 4e5e265
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/components/vm/VmInitializer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import {
signInContractId,
} from '@/utils/config';
import { KEYPOM_OPTIONS } from '@/utils/keypom-options';
import { useSearchParams } from 'next/navigation';
import { useRouter } from 'next/router';

export default function VmInitializer() {
Expand All @@ -61,7 +60,6 @@ export default function VmInitializer() {
const setAuthStore = useAuthStore((state) => state.set);
const setVmStore = useVmStore((store) => store.set);
const { requestAuthentication, saveCurrentUrl } = useSignInRedirect();
const searchParams = useSearchParams();
const idOS = useIdOS();
const router = useRouter();
const idosSDK = useIdosStore((state) => state.idOS);
Expand Down Expand Up @@ -146,18 +144,22 @@ export default function VmInitializer() {
});
}, [idOS, near]);

const handleWalletSelectorMessage = useCallback(
(e: MessageEvent<{ showWalletSelector: boolean }>) => {
if (e.data.showWalletSelector) {
// Show wallet selector
walletModal?.show();
}
},
[walletModal],
);

useEffect(() => {
// Show wallet selector
window.addEventListener(
'message',
(e: MessageEvent<{ showWalletSelector: boolean }>) => {
if (e.data.showWalletSelector) {
walletModal?.show();
}
},
false,
);
}, [walletModal]);
window.addEventListener('message', handleWalletSelectorMessage, false);
return () => {
window.removeEventListener('message', handleWalletSelectorMessage, false);
};
}, []);

const requestSignMessage = useCallback(
async (message: string) => {
Expand Down

0 comments on commit 4e5e265

Please sign in to comment.