Commit 8fd381cb authored by Max Alekseenko's avatar Max Alekseenko

add fix for localhost

parent 7a85c0ab
...@@ -28,6 +28,8 @@ import removeQueryParam from 'lib/router/removeQueryParam'; ...@@ -28,6 +28,8 @@ import removeQueryParam from 'lib/router/removeQueryParam';
import useAccount from 'lib/web3/useAccount'; import useAccount from 'lib/web3/useAccount';
import useProfileQuery from 'ui/snippets/auth/useProfileQuery'; import useProfileQuery from 'ui/snippets/auth/useProfileQuery';
const feature = config.features.rewards;
type ContextQueryResult<Response> = type ContextQueryResult<Response> =
Pick<UseQueryResult<Response, ResourceError<unknown>>, 'data' | 'isLoading' | 'refetch' | 'isPending' | 'isFetching' | 'isError'>; Pick<UseQueryResult<Response, ResourceError<unknown>>, 'data' | 'isLoading' | 'refetch' | 'isPending' | 'isFetching' | 'isError'>;
...@@ -78,13 +80,18 @@ function getMessageToSign(address: string, nonce: string, isLogin?: boolean, ref ...@@ -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 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 referralText = refCode ? ` Referral code: ${ refCode }` : '';
const body = isLogin ? signInText : signUpText + referralText; const body = isLogin ? signInText : signUpText + referralText;
const urlObj = window.location.hostname === 'localhost' && feature.isEnabled ?
new URL(feature.api.endpoint) :
window.location;
return [ 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, address,
'', '',
body, body,
'', '',
`URI: ${ window.location.origin }`, `URI: ${ urlObj.origin }`,
'Version: 1', 'Version: 1',
`Chain ID: ${ config.chain.id }`, `Chain ID: ${ config.chain.id }`,
`Nonce: ${ nonce }`, `Nonce: ${ nonce }`,
...@@ -99,8 +106,6 @@ function getRegisteredAddress(token: string) { ...@@ -99,8 +106,6 @@ function getRegisteredAddress(token: string) {
return decodedToken?.payload.sub; return decodedToken?.payload.sub;
} }
const isEnabled = config.features.rewards.isEnabled;
type Props = { type Props = {
children: React.ReactNode; children: React.ReactNode;
} }
...@@ -141,15 +146,15 @@ export function RewardsContextProvider({ children }: Props) { ...@@ -141,15 +146,15 @@ export function RewardsContextProvider({ children }: Props) {
}, []); }, []);
const [ queryOptions, fetchParams ] = useMemo(() => [ const [ queryOptions, fetchParams ] = useMemo(() => [
{ enabled: Boolean(apiToken) && isEnabled }, { enabled: Boolean(apiToken) && feature.isEnabled },
{ headers: { Authorization: `Bearer ${ apiToken }` } }, { headers: { Authorization: `Bearer ${ apiToken }` } },
], [ apiToken ]); ], [ apiToken ]);
const balancesQuery = useApiQuery('rewards_user_balances', { queryOptions, fetchParams }); const balancesQuery = useApiQuery('rewards_user_balances', { queryOptions, fetchParams });
const dailyRewardQuery = useApiQuery('rewards_user_daily_check', { queryOptions, fetchParams }); const dailyRewardQuery = useApiQuery('rewards_user_daily_check', { queryOptions, fetchParams });
const referralsQuery = useApiQuery('rewards_user_referrals', { queryOptions, fetchParams }); const referralsQuery = useApiQuery('rewards_user_referrals', { queryOptions, fetchParams });
const rewardsConfigQuery = useApiQuery('rewards_config', { queryOptions: { enabled: isEnabled } }); const rewardsConfigQuery = useApiQuery('rewards_config', { queryOptions: { enabled: feature.isEnabled } });
const checkUserQuery = useApiQuery('rewards_check_user', { queryOptions: { enabled: isEnabled }, pathParams: { address } }); const checkUserQuery = useApiQuery('rewards_check_user', { queryOptions: { enabled: feature.isEnabled }, pathParams: { address } });
// Reset queries when the API token is removed // Reset queries when the API token is removed
useEffect(() => { useEffect(() => {
...@@ -250,7 +255,7 @@ export function RewardsContextProvider({ children }: Props) { ...@@ -250,7 +255,7 @@ export function RewardsContextProvider({ children }: Props) {
}, [ apiFetch, errorToast, fetchParams ]); }, [ apiFetch, errorToast, fetchParams ]);
const value = useMemo(() => { const value = useMemo(() => {
if (!isEnabled) { if (!feature.isEnabled) {
return initialState; return initialState;
} }
return { return {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment