Skip to content

Commit

Permalink
refetch user balance after unified login
Browse files Browse the repository at this point in the history
  • Loading branch information
tom2drum committed Feb 3, 2025
1 parent 4c42918 commit a8738a8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 2 additions & 3 deletions ui/rewards/login/RewardsLoginModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const MIXPANEL_CONFIG = {
const RewardsLoginModal = () => {
const { isOpen: isWalletModalOpen } = useWallet({ source: 'Merits' });
const isMobile = useIsMobile();
const { isLoginModalOpen, closeLoginModal, saveApiToken } = useRewardsContext();
const { isLoginModalOpen, closeLoginModal } = useRewardsContext();

const [ isLoginStep, setIsLoginStep ] = useBoolean(true);
const [ isReferral, setIsReferral ] = useBoolean(false);
Expand Down Expand Up @@ -51,12 +51,11 @@ const RewardsLoginModal = () => {

const handleAuthModalClose = useCallback((isSuccess?: boolean, rewardsApiToken?: string) => {
if (isSuccess && rewardsApiToken) {
saveApiToken(rewardsApiToken);
goNext(false);
}
setAuthModalInitialScreen(undefined);
authModal.onClose();
}, [ authModal, setAuthModalInitialScreen, goNext, saveApiToken ]);
}, [ authModal, setAuthModalInitialScreen, goNext ]);

return (
<>
Expand Down
8 changes: 5 additions & 3 deletions ui/snippets/auth/AuthModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { Screen, ScreenSuccess } from './types';

import config from 'configs/app';
import { getResourceKey } from 'lib/api/useApiQuery';
import * as cookies from 'lib/cookies';
import { useRewardsContext } from 'lib/contexts/rewards';
import useGetCsrfToken from 'lib/hooks/useGetCsrfToken';
import * as mixpanel from 'lib/mixpanel';
import IconSvg from 'ui/shared/IconSvg';
Expand Down Expand Up @@ -40,6 +40,8 @@ const AuthModal = ({ initialScreen, onClose, mixpanelConfig, closeOnError }: Pro
const [ isSuccess, setIsSuccess ] = React.useState(false);
const [ rewardsApiToken, setRewardsApiToken ] = React.useState<string | undefined>(undefined);

const { saveApiToken } = useRewardsContext();

const router = useRouter();
const csrfQuery = useGetCsrfToken();
const queryClient = useQueryClient();
Expand Down Expand Up @@ -92,11 +94,11 @@ const AuthModal = ({ initialScreen, onClose, mixpanelConfig, closeOnError }: Pro

if ('rewardsToken' in screen && screen.rewardsToken) {
setRewardsApiToken(screen.rewardsToken);
cookies.set(cookies.NAMES.REWARDS_API_TOKEN, screen.rewardsToken, { expires: 365 });
saveApiToken(screen.rewardsToken);
}

onNextStep(screen);
}, [ initialScreen, mixpanelConfig?.account_link_info.source, onNextStep, csrfQuery, queryClient ]);
}, [ initialScreen, mixpanelConfig?.account_link_info.source, onNextStep, csrfQuery, queryClient, saveApiToken ]);

const onModalClose = React.useCallback(() => {
onClose(isSuccess, rewardsApiToken);
Expand Down

0 comments on commit a8738a8

Please sign in to comment.