diff --git a/Aztec-Passport/apps/www/src/app/-components/social-verify/github.tsx b/Aztec-Passport/apps/www/src/app/-components/social-verify/github.tsx index 5a455301d..3247e7bfa 100644 --- a/Aztec-Passport/apps/www/src/app/-components/social-verify/github.tsx +++ b/Aztec-Passport/apps/www/src/app/-components/social-verify/github.tsx @@ -10,71 +10,97 @@ import { StepButton } from '~/components/ui/step-button'; import { Loader2Icon } from 'lucide-react'; -export const GitHubVerify = () => { +export const GitHubVerify: React.FC = () => { const [status, setStatus] = useState< 'idle' | 'loading' | 'complete' | 'error' >('idle'); const { verifyGithub } = usePassport(); + /** + * Handles GitHub account verification process + */ const onVerify = async () => { try { setStatus('loading'); + + // Simulate API call to verify GitHub account const tx = await verifyGithub(); + + // Notify user of success toast.success('GitHub verification successful', { description: `Transaction ID: ${truncate(tx.txHash.to0xString())}`, }); + + // Simulate transitions between states await sleep(3000); setStatus('complete'); await sleep(1000); - } catch (error) { + } catch (error: unknown) { setStatus('error'); - console.error(error); + + // Handle errors with user-friendly messages + const errorMessage = + error instanceof Error ? error.message : 'An unexpected error occurred'; + toast.error(`GitHub Verification Failed: ${errorMessage}`); + console.error('Verification Error:', error); + await sleep(3000); } finally { setStatus('idle'); } }; + // Reusable content for button states + const buttonContent = { + error: ( +
+
Error +
+ ), + success: ( +
+
Verified +
+ ), + initial: ( +
+ Verify +
+ ), + loading: ( +
+ + Verifying... +
+ ), + }; + return ( -
+
+ {/* GitHub Logo */}
GitHub

Verify your GitHub account.

+ + {/* StepButton with dynamic state-based content */} -
Error -
- } - finalContent={ -
-
Verified -
- } - initialContent={ -
- Verify -
- } - loadingContent={ -
- - Verifying... -
- } - variants={{ - initial: { y: '-120%' }, - animate: { y: '0%' }, - exit: { y: '120%' }, - }} + errorContent={buttonContent.error} + finalContent={buttonContent.success} + initialContent={buttonContent.initial} + loadingContent={buttonContent.loading} onClick={onVerify} />
diff --git a/Aztec-Passport/apps/www/src/app/-components/social-verify/google.tsx b/Aztec-Passport/apps/www/src/app/-components/social-verify/google.tsx index 133c57e71..493d5f798 100644 --- a/Aztec-Passport/apps/www/src/app/-components/social-verify/google.tsx +++ b/Aztec-Passport/apps/www/src/app/-components/social-verify/google.tsx @@ -4,77 +4,104 @@ import { usePassport } from '~/lib/hooks'; import { sleep, truncate } from '~/lib/utils'; import GoogleLogo from 'public/assets/google.svg'; +import { toast } from 'sonner'; import { StepButton } from '~/components/ui/step-button'; import { Loader2Icon } from 'lucide-react'; -import { toast } from 'sonner'; -export const GoogleVerify = () => { +export const GoogleVerify: React.FC = () => { const [status, setStatus] = useState< 'idle' | 'loading' | 'complete' | 'error' >('idle'); const { verifyGoogle } = usePassport(); + /** + * Handles the Google account verification process + */ const onVerify = async () => { try { setStatus('loading'); + + // Call verifyGoogle and process the result const tx = await verifyGoogle(); + const txHash = tx?.txHash?.to0xString?.() ?? 'N/A'; + + // Notify success with transaction details toast.success('Google verification successful', { - description: `Transaction ID: ${truncate(tx.txHash.to0xString())}`, + description: `Transaction ID: ${truncate(txHash)}`, }); + + // Simulate transition delay for feedback await sleep(3000); setStatus('complete'); await sleep(1000); - } catch (error) { + } catch (error: unknown) { + // Handle errors and provide user feedback setStatus('error'); - console.error(error); + + const errorMessage = + error instanceof Error ? error.message : 'An unexpected error occurred'; + toast.error(`Verification failed: ${errorMessage}`); + console.error('Verification failed:', error); + await sleep(3000); } finally { setStatus('idle'); } }; + // Reusable content for button states + const buttonContent = { + error: ( +
+
Error +
+ ), + success: ( +
+
Verified +
+ ), + initial: ( +
+ Verify +
+ ), + loading: ( +
+ + Verifying... +
+ ), + }; + return ( -
+
+ {/* Google Logo */}
Google

Verify your Google account.

+ + {/* StepButton with dynamic state-based content */} -
Error -
- } - finalContent={ -
-
Verified -
- } - initialContent={ -
- Verify -
- } - loadingContent={ -
- - Verifying... -
- } - variants={{ - initial: { y: '-120%' }, - animate: { y: '0%' }, - exit: { y: '120%' }, - }} + errorContent={buttonContent.error} + finalContent={buttonContent.success} + initialContent={buttonContent.initial} + loadingContent={buttonContent.loading} onClick={onVerify} />