From 8fd381cb477a0bdf5df7a01bad1df27989b8e28f Mon Sep 17 00:00:00 2001 From: Max Alekseenko Date: Mon, 4 Nov 2024 14:31:28 +0100 Subject: [PATCH] add fix for localhost --- lib/contexts/rewards.tsx | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/contexts/rewards.tsx b/lib/contexts/rewards.tsx index bf91aa9fd9..1061f530bb 100644 --- a/lib/contexts/rewards.tsx +++ b/lib/contexts/rewards.tsx @@ -28,6 +28,8 @@ import removeQueryParam from 'lib/router/removeQueryParam'; import useAccount from 'lib/web3/useAccount'; import useProfileQuery from 'ui/snippets/auth/useProfileQuery'; +const feature = config.features.rewards; + type ContextQueryResult = Pick>, 'data' | 'isLoading' | 'refetch' | 'isPending' | 'isFetching' | 'isError'>; @@ -78,13 +80,18 @@ function getMessageToSign(address: string, nonce: string, isLogin?: boolean, ref const signUpText = 'Sign-Up for the Blockscout Merits program. I accept Terms of Service: https://merits.blockscout.com/tos. I love capybaras.'; const referralText = refCode ? ` Referral code: ${ refCode }` : ''; const body = isLogin ? signInText : signUpText + referralText; + + const urlObj = window.location.hostname === 'localhost' && feature.isEnabled ? + new URL(feature.api.endpoint) : + window.location; + return [ - `${ window.location.hostname } wants you to sign in with your Ethereum account:`, + `${ urlObj.hostname } wants you to sign in with your Ethereum account:`, address, '', body, '', - `URI: ${ window.location.origin }`, + `URI: ${ urlObj.origin }`, 'Version: 1', `Chain ID: ${ config.chain.id }`, `Nonce: ${ nonce }`, @@ -99,8 +106,6 @@ function getRegisteredAddress(token: string) { return decodedToken?.payload.sub; } -const isEnabled = config.features.rewards.isEnabled; - type Props = { children: React.ReactNode; } @@ -141,15 +146,15 @@ export function RewardsContextProvider({ children }: Props) { }, []); const [ queryOptions, fetchParams ] = useMemo(() => [ - { enabled: Boolean(apiToken) && isEnabled }, + { enabled: Boolean(apiToken) && feature.isEnabled }, { headers: { Authorization: `Bearer ${ apiToken }` } }, ], [ apiToken ]); const balancesQuery = useApiQuery('rewards_user_balances', { queryOptions, fetchParams }); const dailyRewardQuery = useApiQuery('rewards_user_daily_check', { queryOptions, fetchParams }); const referralsQuery = useApiQuery('rewards_user_referrals', { queryOptions, fetchParams }); - const rewardsConfigQuery = useApiQuery('rewards_config', { queryOptions: { enabled: isEnabled } }); - const checkUserQuery = useApiQuery('rewards_check_user', { queryOptions: { enabled: isEnabled }, pathParams: { address } }); + const rewardsConfigQuery = useApiQuery('rewards_config', { queryOptions: { enabled: feature.isEnabled } }); + const checkUserQuery = useApiQuery('rewards_check_user', { queryOptions: { enabled: feature.isEnabled }, pathParams: { address } }); // Reset queries when the API token is removed useEffect(() => { @@ -250,7 +255,7 @@ export function RewardsContextProvider({ children }: Props) { }, [ apiFetch, errorToast, fetchParams ]); const value = useMemo(() => { - if (!isEnabled) { + if (!feature.isEnabled) { return initialState; } return {