diff --git a/.env.development b/.env.development index b358f2b6..fd2d9c44 100644 --- a/.env.development +++ b/.env.development @@ -107,10 +107,10 @@ DB_WORKER_CONNECTION_LIMIT=2 DB_TRANSACTION_TIMEOUT=5000 # polling intervals -NEXT_PUBLIC_FAST_POLL_INTERVAL=1000 -NEXT_PUBLIC_NORMAL_POLL_INTERVAL=30000 -NEXT_PUBLIC_LONG_POLL_INTERVAL=60000 -NEXT_PUBLIC_EXTRA_LONG_POLL_INTERVAL=300000 +NEXT_PUBLIC_FAST_POLL_INTERVAL_MS=1000 +NEXT_PUBLIC_NORMAL_POLL_INTERVAL_MS=30000 +NEXT_PUBLIC_LONG_POLL_INTERVAL_MS=60000 +NEXT_PUBLIC_EXTRA_LONG_POLL_INTERVAL_MS=300000 # containers can't use localhost, so we need to use the container name IMGPROXY_URL_DOCKER=http://imgproxy:8080 diff --git a/.env.production b/.env.production index 78e66ab8..5e873124 100644 --- a/.env.production +++ b/.env.production @@ -11,10 +11,10 @@ NEXT_PUBLIC_MEDIA_DOMAIN=m.stacker.news PUBLIC_URL=https://stacker.news SELF_URL=http://127.0.0.1:8080 grpc_proxy=http://127.0.0.1:7050 -NEXT_PUBLIC_FAST_POLL_INTERVAL=1000 -NEXT_PUBLIC_NORMAL_POLL_INTERVAL=30000 -NEXT_PUBLIC_LONG_POLL_INTERVAL=60000 -NEXT_PUBLIC_EXTRA_LONG_POLL_INTERVAL=300000 +NEXT_PUBLIC_FAST_POLL_INTERVAL_MS=1000 +NEXT_PUBLIC_NORMAL_POLL_INTERVAL_MS=30000 +NEXT_PUBLIC_LONG_POLL_INTERVAL_MS=60000 +NEXT_PUBLIC_EXTRA_LONG_POLL_INTERVAL_MS=300000 NEXT_PUBLIC_URL=https://stacker.news TOR_PROXY=http://127.0.0.1:7050/ PRISMA_SLOW_LOGS_MS=50 diff --git a/components/block-height.js b/components/block-height.js index 3e3a48cc..4c69e3f6 100644 --- a/components/block-height.js +++ b/components/block-height.js @@ -1,6 +1,6 @@ import { createContext, useContext, useMemo } from 'react' import { useQuery } from '@apollo/client' -import { NORMAL_POLL_INTERVAL, SSR } from '@/lib/constants' +import { NORMAL_POLL_INTERVAL_MS, SSR } from '@/lib/constants' import { BLOCK_HEIGHT } from '@/fragments/blockHeight' import { datePivot } from '@/lib/time' @@ -18,7 +18,7 @@ export const BlockHeightProvider = ({ blockHeight, children }) => { ...(SSR ? {} : { - pollInterval: NORMAL_POLL_INTERVAL, + pollInterval: NORMAL_POLL_INTERVAL_MS, nextFetchPolicy: 'cache-and-network' }) }) diff --git a/components/chain-fee.js b/components/chain-fee.js index 8bd7805b..1925b07c 100644 --- a/components/chain-fee.js +++ b/components/chain-fee.js @@ -1,6 +1,6 @@ import { createContext, useContext, useMemo } from 'react' import { useQuery } from '@apollo/client' -import { NORMAL_POLL_INTERVAL, SSR } from '@/lib/constants' +import { NORMAL_POLL_INTERVAL_MS, SSR } from '@/lib/constants' import { CHAIN_FEE } from '@/fragments/chainFee' export const ChainFeeContext = createContext({ @@ -14,7 +14,7 @@ export const ChainFeeProvider = ({ chainFee, children }) => { ...(SSR ? {} : { - pollInterval: NORMAL_POLL_INTERVAL, + pollInterval: NORMAL_POLL_INTERVAL_MS, nextFetchPolicy: 'cache-and-network' }) }) diff --git a/components/fee-button.js b/components/fee-button.js index 5f01a9ed..abd3871a 100644 --- a/components/fee-button.js +++ b/components/fee-button.js @@ -4,7 +4,7 @@ import ActionTooltip from './action-tooltip' import Info from './info' import styles from './fee-button.module.css' import { gql, useQuery } from '@apollo/client' -import { ANON_FEE_MULTIPLIER, FAST_POLL_INTERVAL, SSR } from '@/lib/constants' +import { ANON_FEE_MULTIPLIER, FAST_POLL_INTERVAL_MS, SSR } from '@/lib/constants' import { numWithUnits } from '@/lib/format' import { useMe } from './me' import AnonIcon from '@/svgs/spy-fill.svg' @@ -45,7 +45,7 @@ export function postCommentUseRemoteLineItems ({ parentId } = {}) { return function useRemoteLineItems () { const [line, setLine] = useState({}) - const { data } = useQuery(query, SSR ? {} : { pollInterval: FAST_POLL_INTERVAL, nextFetchPolicy: 'cache-and-network' }) + const { data } = useQuery(query, SSR ? {} : { pollInterval: FAST_POLL_INTERVAL_MS, nextFetchPolicy: 'cache-and-network' }) useEffect(() => { const repetition = data?.itemRepetition diff --git a/components/footer-rewards.js b/components/footer-rewards.js index 7e99423c..5d9b76cf 100644 --- a/components/footer-rewards.js +++ b/components/footer-rewards.js @@ -1,7 +1,7 @@ import { gql, useQuery } from '@apollo/client' import Link from 'next/link' import { RewardLine } from '@/pages/rewards' -import { LONG_POLL_INTERVAL, SSR } from '@/lib/constants' +import { LONG_POLL_INTERVAL_MS, SSR } from '@/lib/constants' const REWARDS = gql` { @@ -12,7 +12,7 @@ const REWARDS = gql` }` export default function Rewards () { - const { data } = useQuery(REWARDS, SSR ? { ssr: false } : { pollInterval: LONG_POLL_INTERVAL, nextFetchPolicy: 'cache-and-network' }) + const { data } = useQuery(REWARDS, SSR ? { ssr: false } : { pollInterval: LONG_POLL_INTERVAL_MS, nextFetchPolicy: 'cache-and-network' }) const total = data?.rewards?.[0]?.total const time = data?.rewards?.[0]?.time return ( diff --git a/components/invoice.js b/components/invoice.js index cdc984ed..fa6f76c2 100644 --- a/components/invoice.js +++ b/components/invoice.js @@ -7,7 +7,7 @@ import PayerData from './payer-data' import Bolt11Info from './bolt11-info' import { useQuery } from '@apollo/client' import { INVOICE } from '@/fragments/invoice' -import { FAST_POLL_INTERVAL, SSR } from '@/lib/constants' +import { FAST_POLL_INTERVAL_MS, SSR } from '@/lib/constants' import { WalletConfigurationError, WalletPaymentAggregateError } from '@/wallets/client/errors' import ItemJob from './item-job' import Item from './item' @@ -24,7 +24,7 @@ export default function Invoice ({ const { data, error } = useQuery(query, SSR ? {} : { - pollInterval: FAST_POLL_INTERVAL, + pollInterval: FAST_POLL_INTERVAL_MS, variables: { id }, nextFetchPolicy: 'cache-and-network', skip: !poll diff --git a/components/lightning-auth.js b/components/lightning-auth.js index bfb3c928..a3787b59 100644 --- a/components/lightning-auth.js +++ b/components/lightning-auth.js @@ -9,7 +9,7 @@ import Qr, { QrSkeleton } from './qr' import styles from './lightning-auth.module.css' import BackIcon from '@/svgs/arrow-left-line.svg' import { useRouter } from 'next/router' -import { FAST_POLL_INTERVAL, SSR } from '@/lib/constants' +import { FAST_POLL_INTERVAL_MS, SSR } from '@/lib/constants' function QrAuth ({ k1, encodedUrl, callbackUrl, multiAuth }) { const query = gql` @@ -19,7 +19,7 @@ function QrAuth ({ k1, encodedUrl, callbackUrl, multiAuth }) { k1 } }` - const { data } = useQuery(query, SSR ? {} : { pollInterval: FAST_POLL_INTERVAL, nextFetchPolicy: 'cache-and-network' }) + const { data } = useQuery(query, SSR ? {} : { pollInterval: FAST_POLL_INTERVAL_MS, nextFetchPolicy: 'cache-and-network' }) useEffect(() => { if (data?.lnAuth?.pubkey) { diff --git a/components/me.js b/components/me.js index faf76e9c..7a82485d 100644 --- a/components/me.js +++ b/components/me.js @@ -1,14 +1,14 @@ import React, { useContext } from 'react' import { useQuery } from '@apollo/client' import { ME } from '@/fragments/users' -import { FAST_POLL_INTERVAL, SSR } from '@/lib/constants' +import { FAST_POLL_INTERVAL_MS, SSR } from '@/lib/constants' export const MeContext = React.createContext({ me: null }) export function MeProvider ({ me, children }) { - const { data, refetch } = useQuery(ME, SSR ? {} : { pollInterval: FAST_POLL_INTERVAL, nextFetchPolicy: 'cache-and-network' }) + const { data, refetch } = useQuery(ME, SSR ? {} : { pollInterval: FAST_POLL_INTERVAL_MS, nextFetchPolicy: 'cache-and-network' }) // this makes sure that we always use the fetched data if it's null. // without this, we would always fallback to the `me` object // which was passed during page load which (visually) breaks switching to anon diff --git a/components/price.js b/components/price.js index 01dd9f7a..75b60bac 100644 --- a/components/price.js +++ b/components/price.js @@ -4,7 +4,7 @@ import { fixedDecimal } from '@/lib/format' import { useMe } from './me' import { PRICE } from '@/fragments/price' import { CURRENCY_SYMBOLS } from '@/lib/currency' -import { NORMAL_POLL_INTERVAL, SSR } from '@/lib/constants' +import { NORMAL_POLL_INTERVAL_MS, SSR } from '@/lib/constants' import { useBlockHeight } from './block-height' import { useChainFee } from './chain-fee' import { CompactLongCountdown } from './countdown' @@ -27,7 +27,7 @@ export function PriceProvider ({ price, children }) { ...(SSR ? {} : { - pollInterval: NORMAL_POLL_INTERVAL, + pollInterval: NORMAL_POLL_INTERVAL_MS, nextFetchPolicy: 'cache-and-network' }) }) diff --git a/components/sub-select.js b/components/sub-select.js index c6a136dd..6a3c80e8 100644 --- a/components/sub-select.js +++ b/components/sub-select.js @@ -1,7 +1,7 @@ import { useEffect, useState } from 'react' import { useRouter } from 'next/router' import { Select } from './form' -import { EXTRA_LONG_POLL_INTERVAL, SSR } from '@/lib/constants' +import { EXTRA_LONG_POLL_INTERVAL_MS, SSR } from '@/lib/constants' import { SUBS } from '@/fragments/subs' import { useQuery } from '@apollo/client' import styles from './sub-select.module.css' @@ -24,7 +24,7 @@ export function useSubs ({ prependSubs = DEFAULT_PREPEND_SUBS, sub, filterSubs = const { data, refetch } = useQuery(SUBS, SSR ? {} : { - pollInterval: EXTRA_LONG_POLL_INTERVAL, + pollInterval: EXTRA_LONG_POLL_INTERVAL_MS, nextFetchPolicy: 'cache-and-network' }) diff --git a/components/use-has-new-notes.js b/components/use-has-new-notes.js index d24aa7ed..2b01577e 100644 --- a/components/use-has-new-notes.js +++ b/components/use-has-new-notes.js @@ -1,5 +1,5 @@ import { HAS_NOTIFICATIONS } from '@/fragments/notifications' -import { NORMAL_POLL_INTERVAL, SSR } from '@/lib/constants' +import { NORMAL_POLL_INTERVAL_MS, SSR } from '@/lib/constants' import { useQuery } from '@apollo/client' import React, { useContext } from 'react' import { clearNotifications } from '@/components/serviceworker' @@ -11,7 +11,7 @@ export function HasNewNotesProvider ({ me, children }) { SSR ? {} : { - pollInterval: NORMAL_POLL_INTERVAL, + pollInterval: NORMAL_POLL_INTERVAL_MS, nextFetchPolicy: 'cache-and-network', onCompleted: ({ hasNewNotes }) => { if (!hasNewNotes) { diff --git a/lib/constants.js b/lib/constants.js index 5e5d5693..e6b0450d 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -192,10 +192,10 @@ export const ADMIN_ITEMS = [ export const INVOICE_RETENTION_DAYS = 7 export const JIT_INVOICE_TIMEOUT_MS = 180_000 -export const FAST_POLL_INTERVAL = Number(process.env.NEXT_PUBLIC_FAST_POLL_INTERVAL) -export const NORMAL_POLL_INTERVAL = Number(process.env.NEXT_PUBLIC_NORMAL_POLL_INTERVAL) -export const LONG_POLL_INTERVAL = Number(process.env.NEXT_PUBLIC_LONG_POLL_INTERVAL) -export const EXTRA_LONG_POLL_INTERVAL = Number(process.env.NEXT_PUBLIC_EXTRA_LONG_POLL_INTERVAL) +export const FAST_POLL_INTERVAL_MS = Number(process.env.NEXT_PUBLIC_FAST_POLL_INTERVAL_MS) +export const NORMAL_POLL_INTERVAL_MS = Number(process.env.NEXT_PUBLIC_NORMAL_POLL_INTERVAL_MS) +export const LONG_POLL_INTERVAL_MS = Number(process.env.NEXT_PUBLIC_LONG_POLL_INTERVAL_MS) +export const EXTRA_LONG_POLL_INTERVAL_MS = Number(process.env.NEXT_PUBLIC_EXTRA_LONG_POLL_INTERVAL_MS) export const ZAP_UNDO_DELAY_MS = 5_000 diff --git a/next.config.js b/next.config.js index 08b95806..f5c3c463 100644 --- a/next.config.js +++ b/next.config.js @@ -241,10 +241,10 @@ module.exports = withPlausibleProxy()({ 'process.env.NEXT_PUBLIC_MEDIA_URL': JSON.stringify(process.env.NEXT_PUBLIC_MEDIA_URL), 'process.env.NEXT_PUBLIC_MEDIA_DOMAIN': JSON.stringify(process.env.NEXT_PUBLIC_MEDIA_DOMAIN), 'process.env.NEXT_PUBLIC_URL': JSON.stringify(process.env.NEXT_PUBLIC_URL), - 'process.env.NEXT_PUBLIC_FAST_POLL_INTERVAL': JSON.stringify(process.env.NEXT_PUBLIC_FAST_POLL_INTERVAL), - 'process.env.NEXT_PUBLIC_NORMAL_POLL_INTERVAL': JSON.stringify(process.env.NEXT_PUBLIC_NORMAL_POLL_INTERVAL), - 'process.env.NEXT_PUBLIC_LONG_POLL_INTERVAL': JSON.stringify(process.env.NEXT_PUBLIC_LONG_POLL_INTERVAL), - 'process.env.NEXT_PUBLIC_EXTRA_LONG_POLL_INTERVAL': JSON.stringify(process.env.NEXT_PUBLIC_EXTRA_LONG_POLL_INTERVAL), + 'process.env.NEXT_PUBLIC_FAST_POLL_INTERVAL_MS': JSON.stringify(process.env.NEXT_PUBLIC_FAST_POLL_INTERVAL_MS), + 'process.env.NEXT_PUBLIC_NORMAL_POLL_INTERVAL_MS': JSON.stringify(process.env.NEXT_PUBLIC_NORMAL_POLL_INTERVAL_MS), + 'process.env.NEXT_PUBLIC_LONG_POLL_INTERVAL_MS': JSON.stringify(process.env.NEXT_PUBLIC_LONG_POLL_INTERVAL_MS), + 'process.env.NEXT_PUBLIC_EXTRA_LONG_POLL_INTERVAL_MS': JSON.stringify(process.env.NEXT_PUBLIC_EXTRA_LONG_POLL_INTERVAL_MS), 'process.env.SANCTIONED_COUNTRY_CODES': JSON.stringify(process.env.SANCTIONED_COUNTRY_CODES), 'process.env.NEXT_IS_EXPORT_WORKER': 'true' }) diff --git a/pages/directs/[id].js b/pages/directs/[id].js index b7adcd1a..f62ac5d0 100644 --- a/pages/directs/[id].js +++ b/pages/directs/[id].js @@ -2,7 +2,7 @@ import { useQuery } from '@apollo/client' import { CenterLayout } from '@/components/layout' import { useRouter } from 'next/router' import { DIRECT } from '@/fragments/invoice' -import { SSR, FAST_POLL_INTERVAL } from '@/lib/constants' +import { SSR, FAST_POLL_INTERVAL_MS } from '@/lib/constants' import Bolt11Info from '@/components/bolt11-info' import { getGetServerSideProps } from '@/api/ssrApollo' import { PrivacyOption } from '../withdrawals/[id]' @@ -39,7 +39,7 @@ function LoadDirect () { ? {} : { variables: { id: router.query.id }, - pollInterval: FAST_POLL_INTERVAL, + pollInterval: FAST_POLL_INTERVAL_MS, nextFetchPolicy: 'cache-and-network' }) if (error) return
error
diff --git a/pages/rewards/index.js b/pages/rewards/index.js index a8b654c1..590b7f21 100644 --- a/pages/rewards/index.js +++ b/pages/rewards/index.js @@ -11,7 +11,7 @@ import { numWithUnits } from '@/lib/format' import PageLoading from '@/components/page-loading' import { useShowModal } from '@/components/modal' import dynamic from 'next/dynamic' -import { FAST_POLL_INTERVAL, SSR } from '@/lib/constants' +import { FAST_POLL_INTERVAL_MS, SSR } from '@/lib/constants' import { useToast } from '@/components/toast' import { useAnimation } from '@/components/animation' import { Col, Row } from 'react-bootstrap' @@ -81,7 +81,7 @@ export default function Rewards ({ ssrData }) { // only poll for updates to rewards const { data: rewardsData } = useQuery( REWARDS, - SSR ? {} : { pollInterval: FAST_POLL_INTERVAL, nextFetchPolicy: 'cache-and-network' }) + SSR ? {} : { pollInterval: FAST_POLL_INTERVAL_MS, nextFetchPolicy: 'cache-and-network' }) const { data } = useQuery(REWARDS_FULL) const dat = useData(data, ssrData) diff --git a/pages/withdraw.js b/pages/withdraw.js index cb31bcfe..2dd3b4ce 100644 --- a/pages/withdraw.js +++ b/pages/withdraw.js @@ -17,7 +17,7 @@ import { useField } from 'formik' import { useToast } from '@/components/toast' import { decode } from 'bolt11' import CameraIcon from '@/svgs/camera-line.svg' -import { FAST_POLL_INTERVAL, SSR } from '@/lib/constants' +import { FAST_POLL_INTERVAL_MS, SSR } from '@/lib/constants' import Qr, { QrSkeleton } from '@/components/qr' import useDebounceCallback from '@/components/use-debounce-callback' import { lnAddrOptions } from '@/lib/lnurl' @@ -215,7 +215,7 @@ function LnQRWith ({ k1, encodedUrl }) { k1 } }` - const { data } = useQuery(query, SSR ? {} : { pollInterval: FAST_POLL_INTERVAL, nextFetchPolicy: 'cache-and-network' }) + const { data } = useQuery(query, SSR ? {} : { pollInterval: FAST_POLL_INTERVAL_MS, nextFetchPolicy: 'cache-and-network' }) if (data?.lnWith?.withdrawalId) { router.push(`/withdrawals/${data.lnWith.withdrawalId}`) diff --git a/pages/withdrawals/[id].js b/pages/withdrawals/[id].js index 569e4653..86e9bb4d 100644 --- a/pages/withdrawals/[id].js +++ b/pages/withdrawals/[id].js @@ -6,7 +6,7 @@ import InvoiceStatus from '@/components/invoice-status' import { useRouter } from 'next/router' import { WITHDRAWL } from '@/fragments/invoice' import Link from 'next/link' -import { SSR, INVOICE_RETENTION_DAYS, FAST_POLL_INTERVAL } from '@/lib/constants' +import { SSR, INVOICE_RETENTION_DAYS, FAST_POLL_INTERVAL_MS } from '@/lib/constants' import { numWithUnits } from '@/lib/format' import Bolt11Info from '@/components/bolt11-info' import { datePivot, timeLeft } from '@/lib/time' @@ -52,7 +52,7 @@ function LoadWithdrawl () { ? {} : { variables: { id: router.query.id }, - pollInterval: FAST_POLL_INTERVAL, + pollInterval: FAST_POLL_INTERVAL_MS, nextFetchPolicy: 'cache-and-network' }) if (error) return
error
diff --git a/wallets/client/context/hooks.js b/wallets/client/context/hooks.js index 3841cd0b..505bb50c 100644 --- a/wallets/client/context/hooks.js +++ b/wallets/client/context/hooks.js @@ -1,7 +1,7 @@ import { useCallback, useEffect, useState } from 'react' import { useLazyQuery } from '@apollo/client' import { FAILED_INVOICES } from '@/fragments/invoice' -import { NORMAL_POLL_INTERVAL } from '@/lib/constants' +import { NORMAL_POLL_INTERVAL_MS } from '@/lib/constants' import useInvoice from '@/components/use-invoice' import { useMe } from '@/components/me' import { @@ -87,7 +87,7 @@ export function useAutomatedRetries () { console.error('retry poll failed:', err) } if (!stopped) queuePoll() - }, NORMAL_POLL_INTERVAL) + }, NORMAL_POLL_INTERVAL_MS) } const stopPolling = () => { diff --git a/wallets/client/hooks/logger.js b/wallets/client/hooks/logger.js index c0a26000..5cce1947 100644 --- a/wallets/client/hooks/logger.js +++ b/wallets/client/hooks/logger.js @@ -4,7 +4,7 @@ import { createContext, useCallback, useContext, useMemo, useState, useEffect } import { Button } from 'react-bootstrap' import { ModalClosedError, useShowModal } from '@/components/modal' import { useToast } from '@/components/toast' -import { FAST_POLL_INTERVAL } from '@/lib/constants' +import { FAST_POLL_INTERVAL_MS } from '@/lib/constants' import { isTemplate } from '@/wallets/lib/util' import { useDiagnostics } from '@/wallets/client/hooks/diagnostics' @@ -115,7 +115,7 @@ export function useWalletLogs (protocol, debug) { if (!called) { setCursor(cursor) } - }, FAST_POLL_INTERVAL) + }, FAST_POLL_INTERVAL_MS) return () => clearInterval(interval) }, [fetchLogs, protocolId, called, noFetch, debug]) diff --git a/wallets/client/hooks/payment.js b/wallets/client/hooks/payment.js index fd8c3592..b0896b86 100644 --- a/wallets/client/hooks/payment.js +++ b/wallets/client/hooks/payment.js @@ -1,7 +1,7 @@ import { useCallback } from 'react' import { useSendProtocols, useWalletLoggerFactory } from '@/wallets/client/hooks' import useInvoice from '@/components/use-invoice' -import { FAST_POLL_INTERVAL, WALLET_SEND_PAYMENT_TIMEOUT_MS } from '@/lib/constants' +import { FAST_POLL_INTERVAL_MS, WALLET_SEND_PAYMENT_TIMEOUT_MS } from '@/lib/constants' import { AnonWalletError, WalletsNotAvailableError, WalletSenderError, WalletAggregateError, WalletPaymentAggregateError, WalletPaymentError, WalletError, WalletReceiverError @@ -125,7 +125,7 @@ function invoiceController (inv, isInvoice) { clearInterval(interval) signal.removeEventListener('abort', abort) } - }, FAST_POLL_INTERVAL) + }, FAST_POLL_INTERVAL_MS) const abort = () => { console.info(`invoice #${inv.id}: stopped waiting`)