1- import React , { useEffect } from 'react' ;
1+ import React , { useEffect , useState } from 'react' ;
22import { ZcashYellowPNG , FormTransferSvg , MetaMaskLogoPNG } from '../assets' ;
33import { useNavigate } from 'react-router-dom' ;
44import { useWebZjsContext } from '../context/WebzjsContext' ;
55import { useMetaMask , useWebZjsActions } from '../hooks' ;
6- import { useMetaMaskContext } from 'src/context/MetamaskContext' ;
7- import { useGetSnapState } from 'src/hooks/snaps/useGetSnapState' ;
86
97const Home : React . FC = ( ) => {
108 const navigate = useNavigate ( ) ;
11- const { state } = useWebZjsContext ( ) ;
9+ const { state, dispatch } = useWebZjsContext ( ) ;
1210 const { getAccountData, connectWebZjsSnap } = useWebZjsActions ( ) ;
1311 const { installedSnap } = useMetaMask ( ) ;
14- const { getSnapState } = useGetSnapState ( ) ;
15- const { setSnapState } = useMetaMaskContext ( ) ;
12+ const [ showResetInstructions , setShowResetInstructions ] = useState ( false ) ;
13+ const isFirefox = typeof navigator !== 'undefined' && / f i r e f o x / i. test ( navigator . userAgent ) ;
14+
1615
1716 const handleConnectButton : React . MouseEventHandler <
1817 HTMLButtonElement
@@ -22,20 +21,33 @@ const Home: React.FC = () => {
2221 } ;
2322
2423 useEffect ( ( ) => {
24+ if ( state . loading ) {
25+ return ;
26+ }
2527 if ( installedSnap ) {
2628 const homeReload = async ( ) => {
2729 if ( state . activeAccount !== null && state . activeAccount !== undefined ) {
28- const accountData = await getAccountData ( ) ;
29-
30- if ( accountData ?. unifiedAddress ) {
31- navigate ( '/dashboard/account-summary' ) ;
30+ try {
31+ const accountData = await getAccountData ( ) ;
32+ if ( accountData ?. unifiedAddress ) {
33+ navigate ( '/dashboard/account-summary' ) ;
34+ } else {
35+ dispatch ( { type : 'set-error' , payload : 'Unified address not available for the active account' } ) ;
36+ setShowResetInstructions ( true ) ;
37+ }
38+ } catch ( err ) {
39+ dispatch ( { type : 'set-error' , payload : err instanceof Error ? err : new Error ( String ( err ) ) } ) ;
40+ setShowResetInstructions ( true ) ;
3241 }
42+ } else {
43+ dispatch ( { type : 'set-error' , payload : 'Active account is not set' } ) ;
44+ setShowResetInstructions ( true ) ;
3345 }
3446
3547 } ;
3648 homeReload ( ) ;
3749 } ;
38- } , [ navigate , getAccountData , state . activeAccount , installedSnap ] ) ;
50+ } , [ navigate , getAccountData , state . activeAccount , state . loading ] ) ;
3951
4052 return (
4153 < div className = "home-page flex items-start md:items-center justify-center px-4 overflow-y-hidden" >
@@ -53,17 +65,34 @@ const Home: React.FC = () => {
5365 Access the Zcash network from your web browser with the Zcash
5466 MetaMask Snap
5567 </ p >
56- { ! ! installedSnap && (
57- < div className = "bg-yellow-100 border border-yellow-400 text-yellow-700 px-4 py-3 rounded-xl" >
58- Make sure your MetaMask is unlocked to continue
68+ { isFirefox && (
69+ < div className = "w-full bg-yellow-50 border border-yellow-200 text-yellow-800 px-4 py-3 rounded-xl" >
70+ < div > Zcash Web Wallet currently does not support Firefox.</ div >
71+ </ div >
72+ ) }
73+ { showResetInstructions && (
74+ < div className = "w-full space-y-2 bg-red-50 border border-red-200 text-red-800 px-4 py-4 rounded-xl" >
75+ < div > Error occurred while loading the wallet data, please reset the wallet</ div >
76+ < div > To reset manually:</ div >
77+ < ul className = "list-disc pl-6 space-y-1" >
78+ < li > Open DevTools ➛ Application ➛ IndexedDB ➛ keyval-store ➛ Delete database</ li >
79+ < li > Opem Metamask ➛ ⋮ ➛ Snaps ➛ Zcash Shielded Wallet ➛ Remove Zcash Shielded Wallet ➛ Remove Snap</ li >
80+ < li > Refresh the page and start installation again</ li >
81+ </ ul >
82+ < details className = "mt-2" >
83+ < summary className = "cursor-pointer underline" > Show error details</ summary >
84+ < div className = "mt-2 whitespace-pre-wrap break-words text-sm text-red-700" >
85+ { typeof state . error === 'string' ? state . error : ( state . error ? state . error . toString ( ) : 'No additional error details' ) }
86+ </ div >
87+ </ details >
5988 </ div >
6089 ) }
6190 < button
62- disabled = { ! ! installedSnap }
91+ disabled = { state . loading }
6392 onClick = { handleConnectButton }
64- className = { `flex items-center bg-button-black-gradient hover:bg-button-black-gradient-hover text-white px-6 py-3 rounded-[2rem] ${ ! ! installedSnap ? 'cursor-not-allowed' : 'cursor-pointer' } ` }
93+ className = { `flex items-center bg-button-black-gradient hover:bg-button-black-gradient-hover text-white px-6 py-3 rounded-[2rem] ${ state . loading ? 'cursor-not-allowed' : 'cursor-pointer' } ` }
6594 >
66- < span > { ! ! installedSnap ? 'Loading Web Wallet...' : 'Connect MetaMask Snap' } </ span >
95+ < span > { state . loading ? 'Wallet Initializing ...' : 'Connect MetaMask Snap' } </ span >
6796 < div className = "ml-3" >
6897 < img
6998 src = { MetaMaskLogoPNG }
0 commit comments