diff --git a/components/banners.js b/components/banners.js index 5b45526b..3527d474 100644 --- a/components/banners.js +++ b/components/banners.js @@ -35,8 +35,8 @@ export default function WelcomeBanner () { } }) useEffect(() => { - setHidden(me?.hideWelcomeBanner || (!me && window.localStorage.getItem('hideWelcomeBanner'))) - }, [me?.hideWelcomeBanner]) + setHidden(me?.privates?.hideWelcomeBanner || (!me && window.localStorage.getItem('hideWelcomeBanner'))) + }, [me?.privates?.hideWelcomeBanner]) if (hidden) return diff --git a/components/comment.js b/components/comment.js index 04e7d536..9955efe6 100644 --- a/components/comment.js +++ b/components/comment.js @@ -99,7 +99,7 @@ export default function Comment ({ }) { const [edit, setEdit] = useState() const me = useMe() - const isHiddenFreebie = !me?.wildWestMode && !me?.greeterMode && !item.mine && item.freebie && item.wvotes <= 0 + const isHiddenFreebie = !me?.privates?.wildWestMode && !me?.privates?.greeterMode && !item.mine && item.freebie && item.wvotes <= 0 const [collapse, setCollapse] = useState( isHiddenFreebie || item?.user?.meMute ? 'yep' diff --git a/components/discussion-form.js b/components/discussion-form.js index 5ef05bf7..d2c29997 100644 --- a/components/discussion-form.js +++ b/components/discussion-form.js @@ -99,7 +99,7 @@ export function DiscussionForm ({ initial={{ title: item?.title || shareTitle || '', text: item?.text || '', - crosspost: me?.nostrCrossposting, + crosspost: me?.privates?.nostrCrossposting, ...AdvPostInitial({ forward: normalizeForwards(item?.forwards), boost: item?.boost }), ...SubSelectInitial({ sub: item?.subName || sub?.name }) }} diff --git a/components/fee-button.js b/components/fee-button.js index 35c8ed61..1096fbfc 100644 --- a/components/fee-button.js +++ b/components/fee-button.js @@ -115,7 +115,7 @@ export default function FeeButton ({ ChildButton = SubmitButton, variant, text, // freebies: there's only a base cost, it's less than 10, and we have less than 10 sats const free = total === lines.baseCost?.modifier(0) && total <= FREEBIE_BASE_COST_THRESHOLD && - me?.sats < FREEBIE_BASE_COST_THRESHOLD + me?.privates?.sats < FREEBIE_BASE_COST_THRESHOLD const feeText = free ? 'free' : total > 1 diff --git a/components/header.js b/components/header.js index 255a04ef..1c0cf5b0 100644 --- a/components/header.js +++ b/components/header.js @@ -29,10 +29,10 @@ import { clearNotifications } from '../lib/badge' function WalletSummary ({ me }) { if (!me) return null - if (me.hideWalletBalance) { + if (me.privates?.hideWalletBalance) { return } - return `${abbrNum(me.sats)}` + return `${abbrNum(me.privates?.sats)}` } function Back () { diff --git a/components/hidden-wallet-summary.js b/components/hidden-wallet-summary.js index c28cba2b..161f03b3 100644 --- a/components/hidden-wallet-summary.js +++ b/components/hidden-wallet-summary.js @@ -18,7 +18,7 @@ export default function HiddenWalletSummary ({ abbreviate, fixedWidth }) { ref={ref} style={{ width: fixedWidth ? width : undefined }} className='d-inline-block text-monospace' align='right' onPointerEnter={() => setHover(true)} onPointerLeave={() => setHover(false)} > - {hover ? (abbreviate ? abbrNum(me.sats) : numWithUnits(me.sats, { abbreviate: false, format: true })) : '******'} + {hover ? (abbreviate ? abbrNum(me.privates?.sats) : numWithUnits(me.privates?.sats, { abbreviate: false, format: true })) : '******'} ) } diff --git a/components/image.js b/components/image.js index c896fd58..695f4a33 100644 --- a/components/image.js +++ b/components/image.js @@ -23,7 +23,7 @@ function ImageOriginal ({ src, topLevel, nofollow, tab, children, onClick, ...pr const [showImage, setShowImage] = useState(false) useEffect(() => { - if (me?.imgproxyOnly && tab !== 'preview') return + if (me?.privates?.imgproxyOnly && tab !== 'preview') return // make sure it's not a false negative by trying to load URL as const img = new window.Image() img.onload = () => setShowImage(true) diff --git a/components/item-act.js b/components/item-act.js index d249074d..62881551 100644 --- a/components/item-act.js +++ b/components/item-act.js @@ -67,7 +67,7 @@ export default function ItemAct ({ onClose, itemId, act, down, strike }) { return (
{ return async (message, context) => { - if (!me || !me.diagnostics) return + if (!me || !me.privates?.diagnostics) return const env = { userAgent: window.navigator.userAgent, // os may not be initialized yet @@ -78,7 +78,7 @@ export function LoggerProvider ({ children }) { body: JSON.stringify(body) }).catch(console.error) } - }, [me?.diagnostics, name, os]) + }, [me?.privates?.diagnostics, name, os]) const logger = useMemo(() => ({ info: log('info'), diff --git a/components/me.js b/components/me.js index 0db92c86..d3d61fae 100644 --- a/components/me.js +++ b/components/me.js @@ -1,4 +1,4 @@ -import React, { useContext, useMemo } from 'react' +import React, { useContext } from 'react' import { useQuery } from '@apollo/client' import { ME } from '../fragments/users' import { SSR } from '../lib/constants' @@ -9,22 +9,14 @@ 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 - - const contextValue = useMemo(() => ({ - me: futureMe - ? { ...futureMe, ...futureMe.privates, ...futureMe.optional } - : null - }), [me, data]) return ( - + {children} ) } export function useMe () { - const { me } = useContext(MeContext) - return me + return useContext(MeContext) } diff --git a/components/price.js b/components/price.js index 98eb8da8..1cce362b 100644 --- a/components/price.js +++ b/components/price.js @@ -18,7 +18,7 @@ export function usePrice () { export function PriceProvider ({ price, children }) { const me = useMe() - const fiatCurrency = me?.fiatCurrency + const fiatCurrency = me?.privates?.fiatCurrency const { data } = useQuery(PRICE, { variables: { fiatCurrency }, ...(SSR @@ -32,7 +32,7 @@ export function PriceProvider ({ price, children }) { const contextValue = useMemo(() => ({ price: data?.price || price, fiatSymbol: CURRENCY_SYMBOLS[fiatCurrency] || '$' - }), [data?.price, price, me?.fiatCurrency]) + }), [data?.price, price, me?.privates?.fiatCurrency]) return ( diff --git a/components/upvote.js b/components/upvote.js index 960b55fa..61987ebd 100644 --- a/components/upvote.js +++ b/components/upvote.js @@ -39,7 +39,7 @@ const UpvotePopover = ({ target, show, handleClose }) => { -
Press the bolt again to zap {me?.tipDefault || 1} more sat{me?.tipDefault > 1 ? 's' : ''}.
+
Press the bolt again to zap {me?.privates?.tipDefault || 1} more sat{me?.privates?.tipDefault > 1 ? 's' : ''}.
Repeatedly press the bolt to zap more sats.
@@ -83,7 +83,7 @@ export default function UpVote ({ item, className, pendingSats, setPendingSats } if (!me) return // if they haven't seen the walkthrough and they have sats - if (yes && !me.upvotePopover && me.sats) { + if (yes && !me.privates?.upvotePopover && me.privates?.sats) { _setVoteShow(true) } @@ -97,7 +97,7 @@ export default function UpVote ({ item, className, pendingSats, setPendingSats } if (!me) return // if we want to show it, yet we still haven't shown - if (yes && !me.tipPopover && me.sats) { + if (yes && !me.privates?.tipPopover && me.privates?.sats) { _setTipShow(true) } @@ -124,7 +124,7 @@ export default function UpVote ({ item, className, pendingSats, setPendingSats } }, meSats: me ? (existingSats = 0) => { - if (sats <= me.sats) { + if (sats <= me.privates?.sats) { if (existingSats === 0) { setVoteShow(true) } else { @@ -186,8 +186,8 @@ export default function UpVote ({ item, className, pendingSats, setPendingSats } const meSats = (item?.meSats || item?.meAnonSats || 0) + pendingSats // what should our next tip be? - let sats = me?.tipDefault || 1 - if (me?.turboTipping) { + let sats = me?.privates?.tipDefault || 1 + if (me?.privates?.turboTipping) { let raiseTip = sats while (meSats >= raiseTip) { raiseTip *= 10 @@ -197,7 +197,7 @@ export default function UpVote ({ item, className, pendingSats, setPendingSats } } return [meSats, sats, me ? numWithUnits(sats, { abbreviate: false }) : 'zap it', getColor(meSats)] - }, [item?.meSats, item?.meAnonSats, pendingSats, me?.tipDefault, me?.turboDefault]) + }, [item?.meSats, item?.meAnonSats, pendingSats, me?.privates?.tipDefault, me?.privates?.turboDefault]) return ( diff --git a/lib/apollo.js b/lib/apollo.js index ce82d9e8..dbd39ae8 100644 --- a/lib/apollo.js +++ b/lib/apollo.js @@ -33,6 +33,17 @@ function getClient (uri) { cache: new InMemoryCache({ freezeResults: true, typePolicies: { + User: { + // https://www.apollographql.com/docs/react/caching/cache-field-behavior/#merging-non-normalized-objects + fields: { + privates: { + merge: true + }, + optional: { + merge: true + } + } + }, Query: { fields: { sub: { diff --git a/pages/settings.js b/pages/settings.js index 8bee79a2..7aeb54e7 100644 --- a/pages/settings.js +++ b/pages/settings.js @@ -277,7 +277,7 @@ export default function Settings ({ ssrData }) { name='hideBookmarks' groupClassName='mb-0' /> - {me.isContributor && + {me.optional?.isContributor && hide that I'm a stacker.news contributor} name='hideIsContributor' diff --git a/pages/wallet.js b/pages/wallet.js index 57216017..11e68374 100644 --- a/pages/wallet.js +++ b/pages/wallet.js @@ -62,9 +62,9 @@ function YouHaveSats () {

you have{' '} {me && ( - me.hideWalletBalance + me.privates?.hideWalletBalance ? - : numWithUnits(me.sats, { abbreviate: false, format: true }) + : numWithUnits(me.privates?.sats, { abbreviate: false, format: true }) )}

@@ -201,7 +201,7 @@ export function InvWithdrawal () { const [createWithdrawl, { called, error }] = useMutation(CREATE_WITHDRAWL) - const maxFeeDefault = me?.withdrawMaxFeeDefault + const maxFeeDefault = me?.privates?.withdrawMaxFeeDefault useEffect(() => { async function effect () { @@ -209,7 +209,7 @@ export function InvWithdrawal () { const provider = await requestProvider() const { paymentRequest: invoice } = await provider.makeInvoice({ defaultMemo: `Withdrawal for @${me.name} on SN`, - maximumAmount: Math.max(me.sats - maxFeeDefault, 0) + maximumAmount: Math.max(me.privates?.sats - maxFeeDefault, 0) }) const { data } = await createWithdrawl({ variables: { invoice, maxFee: maxFeeDefault } }) router.push(`/withdrawals/${data.createWithdrawl.id}`) @@ -340,7 +340,7 @@ export function LnAddrWithdrawal () { const defaultOptions = { min: 1 } const [addrOptions, setAddrOptions] = useState(defaultOptions) const [formSchema, setFormSchema] = useState(lnAddrSchema()) - const maxFeeDefault = me?.withdrawMaxFeeDefault + const maxFeeDefault = me?.privates?.withdrawMaxFeeDefault const onAddrChange = useDebounceCallback(async (formik, e) => { if (!e?.target?.value) { diff --git a/pages/withdrawals/[id].js b/pages/withdrawals/[id].js index 9c4d0bde..37e2fea2 100644 --- a/pages/withdrawals/[id].js +++ b/pages/withdrawals/[id].js @@ -120,7 +120,7 @@ function PrivacyOption ({ wd }) { if (!oldEnough) { return ( - {`this invoice ${me.autoDropBolt11s ? 'will be auto-deleted' : 'can be deleted'} in ${timeLeft(keepUntil)}`} + {`this invoice ${me.privates?.autoDropBolt11s ? 'will be auto-deleted' : 'can be deleted'} in ${timeLeft(keepUntil)}`} ) }