Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
8fd381cb
Commit
8fd381cb
authored
Nov 04, 2024
by
Max Alekseenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add fix for localhost
parent
7a85c0ab
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
8 deletions
+13
-8
rewards.tsx
lib/contexts/rewards.tsx
+13
-8
No files found.
lib/contexts/rewards.tsx
View file @
8fd381cb
...
@@ -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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment