Skip to content

Commit

Permalink
Don't fetch logs as anon
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzyis committed Nov 22, 2024
1 parent 83341d5 commit 64957c9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
10 changes: 0 additions & 10 deletions components/use-interval.js

This file was deleted.

15 changes: 10 additions & 5 deletions components/wallet-logger.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import LogMessage from './log-message'
import { useCallback, useMemo, useState } from 'react'
import { useCallback, useEffect, useMemo, useState } from 'react'
import styles from '@/styles/log.module.css'
import { Button } from 'react-bootstrap'
import { useToast } from './toast'
Expand All @@ -10,7 +10,6 @@ import { gql, useLazyQuery, useMutation } from '@apollo/client'
import { useMe } from './me'
import useIndexedDB, { getDbName } from './use-indexeddb'
import { SSR } from '@/lib/constants'
import useInterval from './use-interval'
import { decode as bolt11Decode } from 'bolt11'
import { formatMsats } from '@/lib/format'

Expand Down Expand Up @@ -204,6 +203,7 @@ export function useWalletLogs (wallet, initialPage = 1, logsPerPage = 10) {
const [hasMore, setHasMore] = useState(true)
const [cursor, setCursor] = useState(null)
const [loading, setLoading] = useState(true)
const { me } = useMe()

const { getPage, error, notSupported } = useWalletLogDB()
const [getWalletLogs] = useLazyQuery(WALLET_LOGS, SSR ? {} : { fetchPolicy: 'cache-and-network' })
Expand Down Expand Up @@ -313,9 +313,14 @@ export function useWalletLogs (wallet, initialPage = 1, logsPerPage = 10) {
}
}, [logs, wallet?.def, loadLogsPage])

useInterval(() => {
loadNew().catch(console.error)
}, 1_000, [loadNew])
useEffect(() => {
if (me) {
const interval = setInterval(() => {
loadNew().catch(console.error)
}, 1_000)
return () => clearInterval(interval)
}
}, [me?.id, loadNew])

return { logs, hasMore: !loading && hasMore, loadMore, setLogs, loading }
}
Expand Down

0 comments on commit 64957c9

Please sign in to comment.