ac45fdc234
* Use HODL invoices * Fix expiry check comparing string with Date * Fix unconfirmed user balance for HODL invoices This is done by syncing the data from LND to the Invoice table. If the columns is_held and msatsReceived are set, the frontend is told that we're ready to execute the action. We then update the user balance in the same tx as the action. We need to still keep checking the invoice for expiration though. * Fix worker acting upon deleted invoices * Prevent usage of invoice after expiration * Use onComplete from <Countdown> to show expired status * Remove unused lnd argument * Fix item destructuring from query * Fix balance added to every stacker * Fix hmac required * Fix invoices not used when logged in * refactor: move invoiceable code into form * renamed invoiceHash, invoiceHmac to hash, hmac since it's less verbose all over the place * form now supports `invoiceable` in its props * form then wraps `onSubmit` with `useInvoiceable` and passes optional invoice options * Show expired if expired and canceled * Also use useCallback for zapping * Always expire modal invoices after 3m * little styling thing --------- Co-authored-by: ekzyis <ek@stacker.news> Co-authored-by: keyan <keyan.kousha+huumn@gmail.com> Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com>
110 lines
3.6 KiB
JavaScript
110 lines
3.6 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'
|
|
import { PriceProvider } from '../components/price'
|
|
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'
|
|
|
|
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
|
|
})
|
|
}
|
|
}
|
|
|
|
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])
|
|
|
|
/*
|
|
If we are on the client, we populate the apollo cache with the
|
|
ssr data
|
|
*/
|
|
const { apollo, ssrData, me, price, ...otherProps } = props
|
|
useEffect(() => {
|
|
writeQuery(client, apollo, ssrData)
|
|
}, [client, apollo, ssrData])
|
|
|
|
return (
|
|
<>
|
|
<Head>
|
|
<meta name='viewport' content='initial-scale=1.0, width=device-width' />
|
|
</Head>
|
|
<ErrorBoundary>
|
|
<PlausibleProvider domain='stacker.news' trackOutboundLinks>
|
|
<ApolloProvider client={client}>
|
|
<MeProvider me={me}>
|
|
<ServiceWorkerProvider>
|
|
<PriceProvider price={price}>
|
|
<LightningProvider>
|
|
<ToastProvider>
|
|
<ShowModalProvider>
|
|
<Component ssrData={ssrData} {...otherProps} />
|
|
</ShowModalProvider>
|
|
</ToastProvider>
|
|
</LightningProvider>
|
|
</PriceProvider>
|
|
</ServiceWorkerProvider>
|
|
</MeProvider>
|
|
</ApolloProvider>
|
|
</PlausibleProvider>
|
|
</ErrorBoundary>
|
|
</>
|
|
)
|
|
}
|
|
|
|
export default MyApp
|