Skip to content

Commit

Permalink
Merge pull request #3 from 0xsequence/opt_refactor
Browse files Browse the repository at this point in the history
waas: otp refactor changes
  • Loading branch information
marino39 authored Nov 21, 2023
2 parents 9a6c1f0 + 83870f0 commit f6e2307
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@0xsequence/design-system": "^1.0.13",
"@0xsequence/indexer": "^1.1.3",
"@0xsequence/network": "^1.1.3",
"@0xsequence/waas": "0.0.0-20231113164400",
"@0xsequence/waas": "0.0.0-20231121142317",
"@react-oauth/google": "^0.11.1",
"@vanilla-extract/css": "^1.12.0",
"axios": "^1.6.0",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 19 additions & 14 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ function App() {
const [walletAddress, setWalletAddress] = useState<string>()
const [fetchWalletAddressError, setFetchWalletAddressError] = useState<string>()

const [sessionValidationSalt, setSessionValidationSalt] = useState<string | undefined>()
const [sessionValidationCode, setSessionValidationCode] = useState<string[]>([])
const [isValidateSessionPending, setIsValidateSessionPending] = useState(false)
const [isFinishValidateSessionPending, setIsFinishValidateSessionPending] = useState(false)

useEffect(() => {
Expand All @@ -47,28 +47,33 @@ function App() {

useEffect(() => {
const code = sessionValidationCode.join('')
if (code.length === 6 && sessionValidationSalt) {
sequence.finishValidateSession(sessionValidationSalt, code)
if (code.length === 6) {
setIsFinishValidateSessionPending(true)
sequence.finishValidateSession(code)
}
}, [sessionValidationCode])

sequence.onValidationRequired(salt => {
setSessionValidationSalt(salt)
sequence.waitForSessionValid(600 * 1000, 4000).then((isValid: boolean) => {
console.log('isValid', isValid)
if (isValid) {
setSessionValidationSalt(undefined)
}
setSessionValidationCode([])
setIsFinishValidateSessionPending(false)
useEffect(() => {
const removeCallback = sequence.onValidationRequired(() => {
setIsValidateSessionPending(true)

sequence.waitForSessionValid(600 * 1000, 4000).then((isValid: boolean) => {
console.log('isValid', isValid)
setSessionValidationCode([])
setIsValidateSessionPending(false)
setIsFinishValidateSessionPending(false)
})
})
})
return () => {
removeCallback.then((cb: any) => cb())
}
}, []);


return (
<>
<AnimatePresence>
{sessionValidationSalt && (
{isValidateSessionPending && (
<Modal>
<div
style={{
Expand Down

0 comments on commit f6e2307

Please sign in to comment.