diff --git a/components/header.js b/components/header.js index bedb8810a..079ee0998 100644 --- a/components/header.js +++ b/components/header.js @@ -33,8 +33,7 @@ function WalletSummary ({ me }) { if (me.privates?.hideWalletBalance) { return } - const sats = me.privates?.sats + me.weblnSats - return `${abbrNum(sats)}` + return `${abbrNum(me.privates?.sats)}` } function Back () { diff --git a/components/hidden-wallet-summary.js b/components/hidden-wallet-summary.js index 59ee1e7c5..161f03b31 100644 --- a/components/hidden-wallet-summary.js +++ b/components/hidden-wallet-summary.js @@ -13,14 +13,12 @@ export default function HiddenWalletSummary ({ abbreviate, fixedWidth }) { setWidth(ref.current?.offsetWidth) }, []) - const sats = me.privates?.sats + me.weblnSats - return ( setHover(true)} onPointerLeave={() => setHover(false)} > - {hover ? (abbreviate ? abbrNum(sats) : numWithUnits(sats, { abbreviate: false, format: true })) : '******'} + {hover ? (abbreviate ? abbrNum(me.privates?.sats) : numWithUnits(me.privates?.sats, { abbreviate: false, format: true })) : '******'} ) } diff --git a/components/me.js b/components/me.js index 686846848..d3d61fae2 100644 --- a/components/me.js +++ b/components/me.js @@ -10,10 +10,6 @@ export const MeContext = React.createContext({ export function MeProvider ({ me, children }) { const { data } = useQuery(ME, SSR ? {} : { pollInterval: 1000, nextFetchPolicy: 'cache-and-network' }) - const futureMe = data?.me || me - // weblnSats is initially undefined on page load for some reason - if (futureMe.weblnSats === undefined) futureMe.weblnSats = 0 - return ( {children} diff --git a/components/webln.js b/components/webln.js index 72f4c52de..b1835485a 100644 --- a/components/webln.js +++ b/components/webln.js @@ -1,7 +1,6 @@ -import { createContext, createRef, useContext, useEffect, useImperativeHandle, useState } from 'react' +import { createContext, useContext, useEffect, useState } from 'react' const WebLNContext = createContext({}) -export const WebLNContextRef = createRef() const fetchWebLNProvider = async () => { // sync provider from local storage @@ -18,7 +17,6 @@ const fetchWebLNProvider = async () => { export function WebLNProvider ({ children }) { const [provider, setProvider] = useState(null) const [info, setInfo] = useState(null) - const [balance, setBalance] = useState(0) const initProvider = async (provider) => { const WebLNProviders = await import('@getalby/bitcoin-connect').then((mod) => mod.WebLNProviders) @@ -33,14 +31,11 @@ export function WebLNProvider ({ children }) { setProvider(provider) const info = await provider.getInfo() setInfo(o => ({ ...o, ...info })) - const { balance } = await provider.getBalance() - setBalance(balance) } const clearProvider = () => { setProvider(null) setInfo(null) - setBalance(0) } useEffect(() => { @@ -80,23 +75,7 @@ export function WebLNProvider ({ children }) { } }, []) - // poll balance - // TODO is there a better way? - useEffect(() => { - if (!provider) return - // TODO check rate limiting of services - is every 15 seconds too often? (it probably is) - const BALANCE_POLL = 15000 // 15 seconds - const interval = setInterval(() => { - provider?.getBalance().then(({ balance }) => setBalance(balance)).catch(console.error) - }, BALANCE_POLL) - return () => clearInterval(interval) - }, [provider]) - - const value = { provider, setProvider, info, balance } - - // required to resolve fields marked with @client using values from WebLN context - useImperativeHandle(WebLNContextRef, () => value) - + const value = { provider, setProvider, info } return ( {children} diff --git a/fragments/users.js b/fragments/users.js index 166731efc..0aee792c9 100644 --- a/fragments/users.js +++ b/fragments/users.js @@ -8,7 +8,6 @@ export const ME = gql` id name bioId - weblnSats @client privates { autoDropBolt11s diagnostics diff --git a/lib/apollo.js b/lib/apollo.js index ce385dc2b..d8f45a2fb 100644 --- a/lib/apollo.js +++ b/lib/apollo.js @@ -1,7 +1,6 @@ import { ApolloClient, InMemoryCache, HttpLink } from '@apollo/client' import { decodeCursor, LIMIT } from './cursor' import { SSR } from './constants' -import { WebLNContextRef } from '../components/webln' function isFirstPage (cursor, existingThings, limit = LIMIT) { if (cursor) { @@ -189,14 +188,6 @@ function getClient (uri) { } } }), - resolvers: { - User: { - weblnSats: (user, args, { cache }) => { - const balance = WebLNContextRef.current?.balance - return balance - } - } - }, assumeImmutableResults: true, defaultOptions: { watchQuery: { diff --git a/pages/wallet.js b/pages/wallet.js index 53cd17aa3..e951b8092 100644 --- a/pages/wallet.js +++ b/pages/wallet.js @@ -68,7 +68,7 @@ function YouHaveSats () { {me && ( me.privates?.hideWalletBalance ? - : numWithUnits(me.privates?.sats + me.weblnSats, { abbreviate: false, format: true }) + : numWithUnits(me.privates?.sats, { abbreviate: false, format: true }) )}