Skip to content

Commit

Permalink
Fix email version checkbox and react hook error (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
tolgahan-arikan authored Jul 17, 2024
1 parent 5dac3d8 commit 1620646
Showing 1 changed file with 34 additions and 22 deletions.
56 changes: 34 additions & 22 deletions src/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function Login() {
const [showEmailWarning, setEmailWarning] = useState(false)
const [code, setCode] = useState<string[]>([])

const [v2EmailLoginEnabled, setV2EmailLoginEnabled] = useState(true)
const [isEmailV2Enabled, setIsEmailV2Enabled] = useState(true)

const [isEmailConflictModalOpen, setIsEmailConflictModalOpen] = useState(false)
const forceCreateFuncRef = useRef<(() => Promise<void>) | null>(null)
Expand Down Expand Up @@ -66,25 +66,35 @@ function Login() {
})

const {
inProgress: emailAuthInProgress,
loading: emailAuthLoading,
initiateAuth: initiateEmailAuth,
sendChallengeAnswer
} = v2EmailLoginEnabled
? useEmailAuthV2({
sessionName: randomName(),
onSuccess: async ({ wallet }) => {
console.log(`Wallet address: ${wallet}`)
router.navigate('/')
}
})
: useEmailAuth({
onSuccess: async idToken => {
const walletAddress = await sequence.signIn({ idToken }, randomName())
console.log(`Wallet address: ${walletAddress}`)
router.navigate('/')
}
})
inProgress: emailV2AuthInProgress,
loading: emailV2AuthLoading,
initiateAuth: initiateEmailV2Auth,
sendChallengeAnswer: sendChallengeAnswerV2
} = useEmailAuthV2({
sessionName: randomName(),
onSuccess: async ({ wallet }) => {
console.log(`Wallet address: ${wallet}`)
router.navigate('/')
}
})

const {
inProgress: emailV1AuthInProgress,
loading: emailV1AuthLoading,
initiateAuth: initiateEmailV1Auth,
sendChallengeAnswer: sendChallengeAnswerV1
} = useEmailAuth({
onSuccess: async idToken => {
const walletAddress = await sequence.signIn({ idToken }, randomName())
console.log(`Wallet address: ${walletAddress}`)
router.navigate('/')
}
})

const emailAuthInProgress = isEmailV2Enabled ? emailV2AuthInProgress : emailV1AuthInProgress
const emailAuthLoading = isEmailV2Enabled ? emailV2AuthLoading : emailV1AuthLoading
const initiateEmailAuth = isEmailV2Enabled ? initiateEmailV2Auth : initiateEmailV1Auth
const sendChallengeAnswer = isEmailV2Enabled ? sendChallengeAnswerV2 : sendChallengeAnswerV1

useEffect(() => {
;(async () => {
Expand Down Expand Up @@ -169,8 +179,10 @@ function Login() {
<Box marginTop="4">
<Checkbox
label="Use v2 email login"
checked={v2EmailLoginEnabled}
onChange={() => setV2EmailLoginEnabled(!v2EmailLoginEnabled)}
checked={isEmailV2Enabled}
onCheckedChange={() => {
setIsEmailV2Enabled(!isEmailV2Enabled)
}}
/>
</Box>
</Box>
Expand Down

0 comments on commit 1620646

Please sign in to comment.