Skip to content

Commit

Permalink
feat: improve animation
Browse files Browse the repository at this point in the history
  • Loading branch information
sripwoud committed Sep 6, 2024
1 parent 5d85b4c commit a32db76
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
13 changes: 1 addition & 12 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,9 @@ import { Header } from 'c/Header'
import { Landing } from 'c/Landing'
import { Login } from 'c/Login'
import { X } from 'c/X'
import { useVerify } from 'h/useVerify'
import { useEffect } from 'react'
import { Navigate, Route, Routes, useNavigate } from 'react-router-dom'
import { Navigate, Route, Routes } from 'react-router-dom'

function App() {
const navigate = useNavigate()
const { error, valid } = useVerify()

useEffect(() => {
if (valid === true) navigate('/x')
if (error)
alert('Error')
}, [error, navigate, valid])

return (
<div className='flex flex-col min-h-screen'>
<Header />
Expand Down
16 changes: 11 additions & 5 deletions client/src/components/QrCode/OpenPassportQrCode.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
'use client'
import { useProofSocket } from 'h/useProofSocket'
import { useQRCode } from 'h/useQRCode'
import { useStore } from 'h/useStore'
import { useVerify } from 'h/useVerify'
import { ProofStep } from 'l/constants'
import type { Id } from 'l/types'
import { type FC, useState } from 'react'
import { type FC, useEffect, useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { BounceLoader } from 'react-spinners'
import LED from './LED'
import { ProofAnimation } from './ProofAnimation'
Expand All @@ -18,17 +19,22 @@ export const OpenPassportQRCode: FC<OpenPassportQRcodeProps> = ({
userId,
}) => {
const [sessionId, setSessionId] = useState(crypto.randomUUID())
const { proof } = useStore()

const { valid, error } = useVerify()
const navigate = useNavigate()
const qrElement = useQRCode({ userId, sessionId })
const { proofStep, connectionStatus } = useProofSocket(sessionId)

const handleAnimationComplete = () => {
setSessionId(crypto.randomUUID())
navigate('/x')
}

useEffect(() => {
if (error) alert(error)
}, [error])

const renderProofStatus = () => {
if (proof !== null) return <ProofAnimation onComplete={handleAnimationComplete} />
if (valid) return <ProofAnimation onComplete={handleAnimationComplete} />

switch (proofStep) {
case ProofStep.WAITING_FOR_MOBILE:
Expand Down

0 comments on commit a32db76

Please sign in to comment.