94cce9155d
* Replace useInvoiceable with usePayment hook * Show WebLnError in QR code fallback * Fix missing removal of old zap undo code * Fix payment timeout message * Fix unused arg in super() * Also bail if invoice expired * Fix revert on reply error * Use JIT_INVOICE_TIMEOUT_MS constant * Remove unnecessary PaymentContext * Fix me as a dependency in FeeButtonContext * Fix anon sats added before act success * Optimistic updates for zaps * Fix modal not closed after custom zap * Optimistic update for custom zaps * Optimistic update for bounty payments * Consistent error handling for zaps and bounty payments * Optimistic update for poll votes * Use var balance in payment.request * Rename invoiceable to prepaid * Log cancelled invoices * Client notifications We now show notifications that are stored on the client to inform the user about following errors in the prepaid payment flow: - if a payment fails - if an invoice expires before it is paid - if a payment was interrupted (for example via page refresh) - if the action fails after payment * Remove unnecessary passing of act * Use AbortController for zap undos * Fix anon zap update not updating bolt color * Fix zap counted towards anon sats even if logged in * Fix duplicate onComplete call * Fix downzap type error * Fix "missing field 'path' while writing result" error * Pass full item in downzap props The previous commit fixed cache updates for downzaps but then the cache update for custom zaps failed because 'path' wasn't included in the server response. This commit is the proper fix. * Parse lnc rpc error messages * Add hash to InvoiceExpiredError
140 lines
5.5 KiB
JavaScript
140 lines
5.5 KiB
JavaScript
import '@/styles/globals.scss'
|
|
import { ApolloProvider, gql } from '@apollo/client'
|
|
import { MeProvider } from '@/components/me'
|
|
import PlausibleProvider from 'next-plausible'
|
|
import getApolloClient from '@/lib/apollo.js'
|
|
import { PriceProvider } from '@/components/price'
|
|
import { BlockHeightProvider } from '@/components/block-height'
|
|
import Head from 'next/head'
|
|
import { useRouter } from 'next/dist/client/router'
|
|
import { useEffect } from 'react'
|
|
import { ShowModalProvider } from '@/components/modal'
|
|
import ErrorBoundary from '@/components/error-boundary'
|
|
import { LightningProvider } from '@/components/lightning'
|
|
import { ToastProvider } from '@/components/toast'
|
|
import { ServiceWorkerProvider } from '@/components/serviceworker'
|
|
import { SSR } from '@/lib/constants'
|
|
import NProgress from 'nprogress'
|
|
import 'nprogress/nprogress.css'
|
|
import { LoggerProvider } from '@/components/logger'
|
|
import { ChainFeeProvider } from '@/components/chain-fee.js'
|
|
import { WebLNProvider } from '@/components/webln'
|
|
import dynamic from 'next/dynamic'
|
|
import { HasNewNotesProvider } from '@/components/use-has-new-notes'
|
|
import { ClientNotificationProvider } from '@/components/client-notifications'
|
|
|
|
const PWAPrompt = dynamic(() => import('react-ios-pwa-prompt'), { ssr: false })
|
|
|
|
NProgress.configure({
|
|
showSpinner: false
|
|
})
|
|
|
|
function writeQuery (client, apollo, data) {
|
|
if (apollo && data) {
|
|
client.writeQuery({
|
|
query: gql`${apollo.query}`,
|
|
data,
|
|
variables: apollo.variables,
|
|
overwrite: SSR,
|
|
broadcast: false
|
|
})
|
|
}
|
|
}
|
|
|
|
export default function MyApp ({ Component, pageProps: { ...props } }) {
|
|
const client = getApolloClient()
|
|
const router = useRouter()
|
|
|
|
useEffect(() => {
|
|
const nprogressStart = (_, { shallow }) => !shallow && NProgress.start()
|
|
const nprogressDone = (_, { shallow }) => !shallow && NProgress.done()
|
|
|
|
router.events.on('routeChangeStart', nprogressStart)
|
|
router.events.on('routeChangeComplete', nprogressDone)
|
|
router.events.on('routeChangeError', nprogressDone)
|
|
|
|
if (!props?.apollo) return
|
|
// HACK: 'cause there's no way to tell Next to skip SSR
|
|
// So every page load, we modify the route in browser history
|
|
// to point to the same page but without SSR, ie ?nodata=true
|
|
// this nodata var will get passed to the server on back/foward and
|
|
// 1. prevent data from reloading and 2. perserve scroll
|
|
// (2) is not possible while intercepting nav with beforePopState
|
|
router.replace({
|
|
pathname: router.pathname,
|
|
query: { ...router.query, nodata: true }
|
|
}, router.asPath, { ...router.options, shallow: true }).catch((e) => {
|
|
// workaround for https://github.com/vercel/next.js/issues/37362
|
|
if (!e.cancelled) {
|
|
console.log(e)
|
|
throw e
|
|
}
|
|
})
|
|
|
|
return () => {
|
|
router.events.off('routeChangeStart', nprogressStart)
|
|
router.events.off('routeChangeComplete', nprogressDone)
|
|
router.events.off('routeChangeError', nprogressDone)
|
|
}
|
|
}, [router.asPath, props?.apollo])
|
|
|
|
useEffect(() => {
|
|
// hack to disable ios pwa prompt for https://github.com/stackernews/stacker.news/issues/953
|
|
// see https://github.com/chrisdancee/react-ios-pwa-prompt/blob/66e91c4f033b740cff42c3220cf13ebdf39e3078/src/index.js#L30
|
|
if (router?.query?.disablePrompt) {
|
|
window.localStorage.setItem('iosPwaPrompt', JSON.stringify({ isiOS: false, visits: 0 }))
|
|
}
|
|
}, [router?.query?.disablePrompt])
|
|
|
|
/*
|
|
If we are on the client, we populate the apollo cache with the
|
|
ssr data
|
|
*/
|
|
const { apollo, ssrData, me, price, blockHeight, chainFee, ...otherProps } = props
|
|
useEffect(() => {
|
|
writeQuery(client, apollo, ssrData)
|
|
}, [client, apollo, ssrData])
|
|
|
|
return (
|
|
<>
|
|
<Head>
|
|
<meta name='viewport' content='initial-scale=1.0, width=device-width, viewport-fit=cover' />
|
|
</Head>
|
|
<ErrorBoundary>
|
|
<PlausibleProvider domain='stacker.news' trackOutboundLinks>
|
|
<ApolloProvider client={client}>
|
|
<MeProvider me={me}>
|
|
<HasNewNotesProvider>
|
|
<ClientNotificationProvider>
|
|
<LoggerProvider>
|
|
<ServiceWorkerProvider>
|
|
<PriceProvider price={price}>
|
|
<LightningProvider>
|
|
<ToastProvider>
|
|
<WebLNProvider>
|
|
<ShowModalProvider>
|
|
<BlockHeightProvider blockHeight={blockHeight}>
|
|
<ChainFeeProvider chainFee={chainFee}>
|
|
<ErrorBoundary>
|
|
<Component ssrData={ssrData} {...otherProps} />
|
|
{!router?.query?.disablePrompt && <PWAPrompt copyBody='This website has app functionality. Add it to your home screen to use it in fullscreen and receive notifications. In Safari:' promptOnVisit={2} />}
|
|
</ErrorBoundary>
|
|
</ChainFeeProvider>
|
|
</BlockHeightProvider>
|
|
</ShowModalProvider>
|
|
</WebLNProvider>
|
|
</ToastProvider>
|
|
</LightningProvider>
|
|
</PriceProvider>
|
|
</ServiceWorkerProvider>
|
|
</LoggerProvider>
|
|
</ClientNotificationProvider>
|
|
</HasNewNotesProvider>
|
|
</MeProvider>
|
|
</ApolloProvider>
|
|
</PlausibleProvider>
|
|
</ErrorBoundary>
|
|
</>
|
|
)
|
|
}
|