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
2d92ce21
Commit
2d92ce21
authored
Oct 30, 2024
by
Max Alekseenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some fixes
parent
1797669f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
21 deletions
+36
-21
rewards.tsx
lib/contexts/rewards.tsx
+23
-16
RewardsDashboard.tsx
ui/pages/RewardsDashboard.tsx
+8
-5
RewardsNavLink.tsx
ui/rewards/RewardsNavLink.tsx
+5
-0
No files found.
lib/contexts/rewards.tsx
View file @
2d92ce21
...
...
@@ -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
,
]);
...
...
ui/pages/RewardsDashboard.tsx
View file @
2d92ce21
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
...
...
ui/rewards/RewardsNavLink.tsx
View file @
2d92ce21
...
...
@@ -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
}
...
...
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