mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
some fixes
This commit is contained in:
+23
-16
@@ -53,7 +53,7 @@ const defaultQueryResult = {
|
||||
refetch: () => Promise.resolve({} as never),
|
||||
};
|
||||
|
||||
const RewardsContext = createContext<TRewardsContext>({
|
||||
const initialState = {
|
||||
balancesQuery: defaultQueryResult,
|
||||
dailyRewardQuery: defaultQueryResult,
|
||||
referralsQuery: defaultQueryResult,
|
||||
@@ -66,7 +66,9 @@ const RewardsContext = createContext<TRewardsContext>({
|
||||
closeLoginModal: () => {},
|
||||
login: async() => ({}),
|
||||
claim: async() => {},
|
||||
});
|
||||
};
|
||||
|
||||
const RewardsContext = createContext<TRewardsContext>(initialState);
|
||||
|
||||
// Message to sign for the rewards program
|
||||
function getMessageToSign(address: string, nonce: string, isLogin?: boolean, refCode?: string) {
|
||||
@@ -245,20 +247,25 @@ export function RewardsContextProvider({ children }: Props) {
|
||||
}
|
||||
}, [ apiFetch, errorToast, fetchParams ]);
|
||||
|
||||
const value = useMemo(() => ({
|
||||
balancesQuery,
|
||||
dailyRewardQuery,
|
||||
referralsQuery,
|
||||
rewardsConfigQuery,
|
||||
checkUserQuery,
|
||||
apiToken,
|
||||
isInitialized,
|
||||
isLoginModalOpen,
|
||||
openLoginModal: setIsLoginModalOpen.on,
|
||||
closeLoginModal: setIsLoginModalOpen.off,
|
||||
login,
|
||||
claim,
|
||||
}), [
|
||||
const value = useMemo(() => {
|
||||
if (!isEnabled) {
|
||||
return initialState;
|
||||
}
|
||||
return {
|
||||
balancesQuery,
|
||||
dailyRewardQuery,
|
||||
referralsQuery,
|
||||
rewardsConfigQuery,
|
||||
checkUserQuery,
|
||||
apiToken,
|
||||
isInitialized,
|
||||
isLoginModalOpen,
|
||||
openLoginModal: setIsLoginModalOpen.on,
|
||||
closeLoginModal: setIsLoginModalOpen.off,
|
||||
login,
|
||||
claim,
|
||||
};
|
||||
}, [
|
||||
isLoginModalOpen, setIsLoginModalOpen, balancesQuery, dailyRewardQuery, checkUserQuery,
|
||||
apiToken, login, claim, referralsQuery, rewardsConfigQuery, isInitialized,
|
||||
]);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Flex, Skeleton, Image } from '@chakra-ui/react';
|
||||
import { useRouter } from 'next/router';
|
||||
import React, { useEffect } from 'react';
|
||||
|
||||
import config from 'configs/app';
|
||||
import { useRewardsContext } from 'lib/contexts/rewards';
|
||||
import { apos } from 'lib/html-entities';
|
||||
import DailyRewardClaimButton from 'ui/rewards/DailyRewardClaimButton';
|
||||
@@ -13,19 +13,22 @@ import PageTitle from 'ui/shared/Page/PageTitle';
|
||||
import useRedirectForInvalidAuthToken from 'ui/snippets/auth/useRedirectForInvalidAuthToken';
|
||||
|
||||
const RewardsDashboard = () => {
|
||||
const router = useRouter();
|
||||
const { balancesQuery, apiToken, referralsQuery, rewardsConfigQuery, isInitialized } = useRewardsContext();
|
||||
|
||||
useRedirectForInvalidAuthToken();
|
||||
|
||||
useEffect(() => {
|
||||
if (isInitialized && !apiToken) {
|
||||
router.replace({ pathname: '/' }, undefined, { shallow: true });
|
||||
if (!config.features.rewards.isEnabled || (isInitialized && !apiToken)) {
|
||||
window.location.assign('/');
|
||||
}
|
||||
}, [ isInitialized, apiToken, router ]);
|
||||
}, [ isInitialized, apiToken ]);
|
||||
|
||||
const numberOfReferrals = Number(referralsQuery.data?.referrals || 0);
|
||||
|
||||
if (!config.features.rewards.isEnabled) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageTitle
|
||||
|
||||
@@ -8,6 +8,7 @@ import type { NavItem } from 'types/client/navigation';
|
||||
import { route } from 'nextjs-routes';
|
||||
import type { Route } from 'nextjs-routes';
|
||||
|
||||
import config from 'configs/app';
|
||||
import { useRewardsContext } from 'lib/contexts/rewards';
|
||||
import useIsMobile from 'lib/hooks/useIsMobile';
|
||||
import LightningLabel, { LIGHTNING_LABEL_CLASS_NAME } from 'ui/snippets/navigation/LightningLabel';
|
||||
@@ -43,6 +44,10 @@ const RewardsNavLink = ({ isCollapsed, onClick }: Props) => {
|
||||
onClick?.();
|
||||
}, [ onClick, isInitialized, apiToken, openLoginModal ]);
|
||||
|
||||
if (!config.features.rewards.isEnabled) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const content = (
|
||||
<Link
|
||||
href={ isInitialized && apiToken ? route(nextRoute) : undefined }
|
||||
|
||||
Reference in New Issue
Block a user