@@ -15,7 +15,7 @@ export function WalletLogs ({ wallet, embedded }) {
15
15
const { logs, setLogs, hasMore, loadMore, loadLogs, loading } = useWalletLogs ( wallet )
16
16
useEffect ( ( ) => {
17
17
loadLogs ( )
18
- } , [ wallet ] )
18
+ } , [ loadLogs ] )
19
19
20
20
const showModal = useShowModal ( )
21
21
@@ -93,22 +93,26 @@ function useWalletLogDB () {
93
93
const { me } = useMe ( )
94
94
const dbName = `app:storage${ me ? `:${ me . id } ` : '' } `
95
95
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 }
98
98
}
99
99
100
100
export function useWalletLogger ( wallet , setLogs ) {
101
- const { add, clear } = useWalletLogDB ( )
101
+ const { add, clear, notSupported } = useWalletLogDB ( )
102
102
103
103
const appendLog = useCallback ( async ( wallet , level , message ) => {
104
104
const log = { wallet : tag ( wallet ) , level, message, ts : + new Date ( ) }
105
105
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
+ }
107
111
setLogs ?. ( prevLogs => [ log , ...prevLogs ] )
108
112
} catch ( error ) {
109
- console . error ( 'Failed to append log:' , error )
113
+ console . error ( 'Failed to append wallet log:' , error )
110
114
}
111
- } , [ add ] )
115
+ } , [ add , notSupported ] )
112
116
113
117
const [ deleteServerWalletLogs ] = useMutation (
114
118
gql `
@@ -130,13 +134,17 @@ export function useWalletLogger (wallet, setLogs) {
130
134
if ( ! wallet || wallet . sendPayment ) {
131
135
try {
132
136
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
+ }
134
142
setLogs ?. ( logs => logs . filter ( l => wallet ? l . wallet !== tag ( wallet ) : false ) )
135
143
} catch ( e ) {
136
144
console . error ( 'failed to delete logs' , e )
137
145
}
138
146
}
139
- } , [ clear , deleteServerWalletLogs , setLogs ] )
147
+ } , [ clear , deleteServerWalletLogs , setLogs , notSupported ] )
140
148
141
149
const log = useCallback ( level => message => {
142
150
if ( ! wallet ) {
@@ -169,20 +177,24 @@ export function useWalletLogs (wallet, initialPage = 1, logsPerPage = 10) {
169
177
const [ cursor , setCursor ] = useState ( null )
170
178
const [ loading , setLoading ] = useState ( true )
171
179
172
- const { getPage, error : idbError } = useWalletLogDB ( )
180
+ const { getPage, error, notSupported } = useWalletLogDB ( )
173
181
const [ getWalletLogs ] = useLazyQuery ( WALLET_LOGS , SSR ? { } : { fetchPolicy : 'cache-and-network' } )
174
182
175
183
const loadLogsPage = useCallback ( async ( page , pageSize , wallet ) => {
176
184
try {
177
185
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
+ }
184
197
}
185
-
186
198
const { data } = await getWalletLogs ( {
187
199
variables : {
188
200
type : wallet ?. walletType ,
@@ -207,10 +219,10 @@ export function useWalletLogs (wallet, initialPage = 1, logsPerPage = 10) {
207
219
console . error ( 'Error loading logs from IndexedDB:' , error )
208
220
return { data : [ ] , total : 0 , hasMore : false }
209
221
}
210
- } , [ getPage , setCursor , cursor ] )
222
+ } , [ getPage , setCursor , cursor , notSupported ] )
211
223
212
- if ( idbError ) {
213
- console . error ( 'IndexedDB error:' , idbError )
224
+ if ( error ) {
225
+ console . error ( 'IndexedDB error:' , error )
214
226
}
215
227
216
228
const loadMore = useCallback ( async ( ) => {
0 commit comments