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
89d2af32
Commit
89d2af32
authored
Oct 18, 2024
by
Max Alekseenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
login to account before rewards program
parent
5a3e8723
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
4 deletions
+31
-4
LoginStepContent.tsx
ui/rewards/steps/LoginStepContent.tsx
+31
-4
No files found.
ui/rewards/steps/LoginStepContent.tsx
View file @
89d2af32
import
{
Text
,
Button
,
useColorModeValue
,
Image
,
Box
,
Flex
,
Switch
,
useBoolean
,
Input
,
FormControl
}
from
'
@chakra-ui/react
'
;
import
{
Text
,
Button
,
useColorModeValue
,
Image
,
Box
,
Flex
,
Switch
,
useBoolean
,
Input
,
FormControl
,
Alert
}
from
'
@chakra-ui/react
'
;
import
{
useRouter
}
from
'
next/router
'
;
import
{
useRouter
}
from
'
next/router
'
;
import
type
{
ChangeEvent
}
from
'
react
'
;
import
type
{
ChangeEvent
}
from
'
react
'
;
import
React
,
{
useCallback
,
useState
,
useEffect
}
from
'
react
'
;
import
React
,
{
useCallback
,
useState
,
useEffect
}
from
'
react
'
;
import
{
useRewardsContext
}
from
'
lib/contexts/rewards
'
;
import
{
useRewardsContext
}
from
'
lib/contexts/rewards
'
;
import
*
as
cookies
from
'
lib/cookies
'
;
import
*
as
cookies
from
'
lib/cookies
'
;
import
{
apos
}
from
'
lib/html-entities
'
;
import
useWallet
from
'
lib/web3/useWallet
'
;
import
useWallet
from
'
lib/web3/useWallet
'
;
import
InputPlaceholder
from
'
ui/shared/InputPlaceholder
'
;
import
InputPlaceholder
from
'
ui/shared/InputPlaceholder
'
;
import
LinkExternal
from
'
ui/shared/links/LinkExternal
'
;
import
LinkExternal
from
'
ui/shared/links/LinkExternal
'
;
import
useProfileQuery
from
'
ui/snippets/auth/useProfileQuery
'
;
import
useSignInWithWallet
from
'
ui/snippets/auth/useSignInWithWallet
'
;
type
Props
=
{
type
Props
=
{
goNext
:
(
isReferral
:
boolean
)
=>
void
;
goNext
:
(
isReferral
:
boolean
)
=>
void
;
...
@@ -16,7 +19,7 @@ type Props = {
...
@@ -16,7 +19,7 @@ type Props = {
const
LoginStepContent
=
({
goNext
,
closeModal
}:
Props
)
=>
{
const
LoginStepContent
=
({
goNext
,
closeModal
}:
Props
)
=>
{
const
router
=
useRouter
();
const
router
=
useRouter
();
const
{
connect
,
isConnected
}
=
useWallet
({
source
:
'
Merits
'
});
const
{
connect
,
isConnected
,
address
}
=
useWallet
({
source
:
'
Merits
'
});
const
savedRefCode
=
cookies
.
get
(
cookies
.
NAMES
.
REWARDS_REFERRAL_CODE
);
const
savedRefCode
=
cookies
.
get
(
cookies
.
NAMES
.
REWARDS_REFERRAL_CODE
);
const
[
isRefCodeUsed
,
setIsRefCodeUsed
]
=
useBoolean
(
Boolean
(
savedRefCode
));
const
[
isRefCodeUsed
,
setIsRefCodeUsed
]
=
useBoolean
(
Boolean
(
savedRefCode
));
const
[
isLoading
,
setIsLoading
]
=
useBoolean
(
false
);
const
[
isLoading
,
setIsLoading
]
=
useBoolean
(
false
);
...
@@ -24,12 +27,13 @@ const LoginStepContent = ({ goNext, closeModal }: Props) => {
...
@@ -24,12 +27,13 @@ const LoginStepContent = ({ goNext, closeModal }: Props) => {
const
[
refCodeError
,
setRefCodeError
]
=
useBoolean
(
false
);
const
[
refCodeError
,
setRefCodeError
]
=
useBoolean
(
false
);
const
dividerColor
=
useColorModeValue
(
'
blackAlpha.200
'
,
'
whiteAlpha.200
'
);
const
dividerColor
=
useColorModeValue
(
'
blackAlpha.200
'
,
'
whiteAlpha.200
'
);
const
{
login
}
=
useRewardsContext
();
const
{
login
}
=
useRewardsContext
();
const
profileQuery
=
useProfileQuery
();
const
handleRefCodeChange
=
React
.
useCallback
((
event
:
ChangeEvent
<
HTMLInputElement
>
)
=>
{
const
handleRefCodeChange
=
React
.
useCallback
((
event
:
ChangeEvent
<
HTMLInputElement
>
)
=>
{
setRefCode
(
event
.
target
.
value
);
setRefCode
(
event
.
target
.
value
);
},
[]);
},
[]);
const
handleLogin
=
useCallback
(
async
()
=>
{
const
loginToRewardsProgram
=
useCallback
(
async
()
=>
{
try
{
try
{
setRefCodeError
.
off
();
setRefCodeError
.
off
();
setIsLoading
.
on
();
setIsLoading
.
on
();
...
@@ -52,6 +56,22 @@ const LoginStepContent = ({ goNext, closeModal }: Props) => {
...
@@ -52,6 +56,22 @@ const LoginStepContent = ({ goNext, closeModal }: Props) => {
setRefCodeError
.
off
();
setRefCodeError
.
off
();
},
[
refCode
]);
// eslint-disable-line react-hooks/exhaustive-deps
},
[
refCode
]);
// eslint-disable-line react-hooks/exhaustive-deps
const
{
start
:
loginToAccount
}
=
useSignInWithWallet
({
isAuth
:
Boolean
(
!
profileQuery
.
isLoading
&&
profileQuery
.
data
?.
email
),
onSuccess
:
loginToRewardsProgram
,
onError
:
setIsLoading
.
off
,
});
const
handleLogin
=
useCallback
(
async
()
=>
{
if
(
!
profileQuery
.
isLoading
&&
!
profileQuery
.
data
?.
address_hash
)
{
loginToAccount
();
return
;
}
loginToRewardsProgram
();
},
[
loginToAccount
,
loginToRewardsProgram
,
profileQuery
]);
const
isAddressMismatch
=
isConnected
&&
profileQuery
.
data
?.
address_hash
!==
address
;
return
(
return
(
<>
<>
<
Image
src=
"/static/merits_program.png"
alt=
"Rewards program"
mb=
{
3
}
/>
<
Image
src=
"/static/merits_program.png"
alt=
"Rewards program"
mb=
{
3
}
/>
...
@@ -88,14 +108,21 @@ const LoginStepContent = ({ goNext, closeModal }: Props) => {
...
@@ -88,14 +108,21 @@ const LoginStepContent = ({ goNext, closeModal }: Props) => {
)
}
)
}
</>
</>
)
}
)
}
{
isAddressMismatch
&&
(
<
Alert
status=
"warning"
mt=
{
4
}
>
Your wallet address doesn
{
apos
}
t match the one in your Blockscout account. Please connect the correct wallet.
</
Alert
>
)
}
<
Button
<
Button
variant=
"solid"
variant=
"solid"
colorScheme=
"blue"
colorScheme=
"blue"
w=
"full"
w=
"full"
whiteSpace=
"normal"
mt=
{
isConnected
?
6
:
0
}
mt=
{
isConnected
?
6
:
0
}
mb=
{
4
}
mb=
{
4
}
onClick=
{
isConnected
?
handleLogin
:
connect
}
onClick=
{
isConnected
?
handleLogin
:
connect
}
isLoading=
{
isLoading
}
isLoading=
{
isLoading
||
profileQuery
.
isLoading
}
isDisabled=
{
isAddressMismatch
}
>
>
{
isConnected
?
'
Get started
'
:
'
Connect wallet
'
}
{
isConnected
?
'
Get started
'
:
'
Connect wallet
'
}
</
Button
>
</
Button
>
...
...
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