Skip to content

Commit

Permalink
feat: wip add payload arg to auth modal
Browse files Browse the repository at this point in the history
  • Loading branch information
simodrws committed Aug 9, 2023
1 parent 1106848 commit 8d496fc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
Expand Up @@ -9,7 +9,10 @@ import { useAuthenticateModal } from './use-authenticate-modal';
import { ModalLoading } from '../ModalLoading';

export interface AuthenticateProps {
onAuthenticateSuccess?: () => void;
onAuthenticateSuccess?: (payload: {
address?: string;
walletType?: string;
}) => void;
onAuthenticateError?: () => void;
onAuthenticateFinish?: () => void;
}
Expand Down
Expand Up @@ -8,12 +8,14 @@ export const useAuthenticateModal = ({
onAuthenticateSuccess,
onAuthenticateError,
}: {
onAuthenticateSuccess?: () => void;
onAuthenticateSuccess?: (payload: {
address?: string;
walletType?: string;
}) => void;
onAuthenticateError?: () => void;
onClose?: () => void;
}) => {
const { hasAddress, isConnected, signer } = useWallet();

const { hasAddress, isConnected, signer, connector } = useWallet();
const { hasSession, loginSession } = useSession();
const { company } = useConfig();

Expand Down Expand Up @@ -70,11 +72,14 @@ export const useAuthenticateModal = ({
console.log('should be here onAuthenticatESuccess', {
onAuthenticateSuccess,
});
onAuthenticateSuccess?.();
onAuthenticateSuccess?.({
address: result.address,
walletType: connector?.name,
});
}

return result;
}, [loginSession, onAuthenticateError, onAuthenticateSuccess]);
}, [loginSession, onAuthenticateError, onAuthenticateSuccess, connector]);

const showSwitchWalletButton = useMemo(
() => !hasSession && isConnected,
Expand Down
18 changes: 14 additions & 4 deletions src/refactor/ui/components/modals/authenticate/use-authenticate.ts
Expand Up @@ -14,16 +14,19 @@ export const useAuthenticate = ({
onSuccess,
onError,
}: {
onAuthenticateSuccess?: () => void;
onAuthenticateSuccess?: (payload: {
address?: string;
walletType?: string;
}) => void;
onAuthenticateError?: () => void;
onMintSuccess?: () => void;
onMintError?: () => void;
onRegisterFinish?: () => void;
onSuccess?: () => void;
onError?: () => void;
}) => {
const { openConnectModal, isDisconnected } = useWallet();
const { hasSession, checkLogin } = useSession();
const { openConnectModal, isDisconnected, connector } = useWallet();
const { hasSession, checkLogin, getSession } = useSession();
const { reloadIdentity } = useIdentity();

const openSoulnameModal = useCallback(
Expand Down Expand Up @@ -59,7 +62,12 @@ export const useAuthenticate = ({
const { data: hasSessionCheck } = await checkLogin();
console.log('ONAUTHENTICATE FINSIH', { hasSessionCheck });
if (hasSessionCheck) {
onAuthenticateSuccess?.();
const { data: session } = await getSession();
console.log('BEFORE AUTH SUCCESS', { session });
onAuthenticateSuccess?.({
address: session?.user.address,
walletType: connector?.name,
});
}

if (!identityRefetched || !identityRefetched.identityId)
Expand All @@ -75,6 +83,8 @@ export const useAuthenticate = ({
onAuthenticateError,
checkLogin,
hasSession,
getSession,
connector?.name,
]);

return {
Expand Down

0 comments on commit 8d496fc

Please sign in to comment.