@@ -15,7 +15,7 @@ export function WalletLogs ({ wallet, embedded }) {
1515 const { logs, setLogs, hasMore, loadMore, loadLogs, loading } = useWalletLogs ( wallet )
1616 useEffect ( ( ) => {
1717 loadLogs ( )
18- } , [ wallet ] )
18+ } , [ loadLogs ] )
1919
2020 const showModal = useShowModal ( )
2121
@@ -93,22 +93,26 @@ function useWalletLogDB () {
9393 const { me } = useMe ( )
9494 const dbName = `app:storage${ me ? `:${ me . id } ` : '' } `
9595 const idbStoreName = 'wallet_logs'
96- const { add, getPage, clear, error : idbError } = useIndexedDB ( dbName , idbStoreName , 1 , INDICES )
97- return { add, getPage, clear, error : idbError }
96+ const { add, getPage, clear, error, notSupported } = useIndexedDB ( dbName , idbStoreName , 1 , INDICES )
97+ return { add, getPage, clear, error, notSupported }
9898}
9999
100100export function useWalletLogger ( wallet , setLogs ) {
101- const { add, clear } = useWalletLogDB ( )
101+ const { add, clear, notSupported } = useWalletLogDB ( )
102102
103103 const appendLog = useCallback ( async ( wallet , level , message ) => {
104104 const log = { wallet : tag ( wallet ) , level, message, ts : + new Date ( ) }
105105 try {
106- await add ( log )
106+ if ( notSupported ) {
107+ console . log ( 'cannot persist wallet log: indexeddb not supported' )
108+ } else {
109+ await add ( log )
110+ }
107111 setLogs ?. ( prevLogs => [ log , ...prevLogs ] )
108112 } catch ( error ) {
109- console . error ( 'Failed to append log:' , error )
113+ console . error ( 'Failed to append wallet log:' , error )
110114 }
111- } , [ add ] )
115+ } , [ add , notSupported ] )
112116
113117 const [ deleteServerWalletLogs ] = useMutation (
114118 gql `
@@ -130,13 +134,17 @@ export function useWalletLogger (wallet, setLogs) {
130134 if ( ! wallet || wallet . sendPayment ) {
131135 try {
132136 const walletTag = wallet ? tag ( wallet ) : null
133- await clear ( 'wallet_ts' , walletTag ? window . IDBKeyRange . bound ( [ walletTag , 0 ] , [ walletTag , Infinity ] ) : null )
137+ if ( notSupported ) {
138+ console . log ( 'cannot clear wallet logs: indexeddb not supported' )
139+ } else {
140+ await clear ( 'wallet_ts' , walletTag ? window . IDBKeyRange . bound ( [ walletTag , 0 ] , [ walletTag , Infinity ] ) : null )
141+ }
134142 setLogs ?. ( logs => logs . filter ( l => wallet ? l . wallet !== tag ( wallet ) : false ) )
135143 } catch ( e ) {
136144 console . error ( 'failed to delete logs' , e )
137145 }
138146 }
139- } , [ clear , deleteServerWalletLogs , setLogs ] )
147+ } , [ clear , deleteServerWalletLogs , setLogs , notSupported ] )
140148
141149 const log = useCallback ( level => message => {
142150 if ( ! wallet ) {
@@ -169,20 +177,24 @@ export function useWalletLogs (wallet, initialPage = 1, logsPerPage = 10) {
169177 const [ cursor , setCursor ] = useState ( null )
170178 const [ loading , setLoading ] = useState ( true )
171179
172- const { getPage, error : idbError } = useWalletLogDB ( )
180+ const { getPage, error, notSupported } = useWalletLogDB ( )
173181 const [ getWalletLogs ] = useLazyQuery ( WALLET_LOGS , SSR ? { } : { fetchPolicy : 'cache-and-network' } )
174182
175183 const loadLogsPage = useCallback ( async ( page , pageSize , wallet ) => {
176184 try {
177185 let result = { data : [ ] , hasMore : false }
178- const indexName = wallet ? 'wallet_ts' : 'ts'
179- const query = wallet ? window . IDBKeyRange . bound ( [ tag ( wallet ) , - Infinity ] , [ tag ( wallet ) , Infinity ] ) : null
180- result = await getPage ( page , pageSize , indexName , query , 'prev' )
181- // no walletType means we're using the local IDB
182- if ( wallet && ! wallet . walletType ) {
183- return result
186+ if ( notSupported ) {
187+ console . log ( 'cannot get client wallet logs: indexeddb not supported' )
188+ } else {
189+ const indexName = wallet ? 'wallet_ts' : 'ts'
190+ const query = wallet ? window . IDBKeyRange . bound ( [ tag ( wallet ) , - Infinity ] , [ tag ( wallet ) , Infinity ] ) : null
191+
192+ result = await getPage ( page , pageSize , indexName , query , 'prev' )
193+ // no walletType means we're using the local IDB
194+ if ( wallet && ! wallet . walletType ) {
195+ return result
196+ }
184197 }
185-
186198 const { data } = await getWalletLogs ( {
187199 variables : {
188200 type : wallet ?. walletType ,
@@ -207,10 +219,10 @@ export function useWalletLogs (wallet, initialPage = 1, logsPerPage = 10) {
207219 console . error ( 'Error loading logs from IndexedDB:' , error )
208220 return { data : [ ] , total : 0 , hasMore : false }
209221 }
210- } , [ getPage , setCursor , cursor ] )
222+ } , [ getPage , setCursor , cursor , notSupported ] )
211223
212- if ( idbError ) {
213- console . error ( 'IndexedDB error:' , idbError )
224+ if ( error ) {
225+ console . error ( 'IndexedDB error:' , error )
214226 }
215227
216228 const loadMore = useCallback ( async ( ) => {
0 commit comments