merge non-normalized user subtypes fixing #645

This commit is contained in:
keyan 2023-11-20 09:04:38 -06:00
parent 44e12a4b44
commit af59e3ef54
16 changed files with 42 additions and 39 deletions

View File

@ -35,8 +35,8 @@ export default function WelcomeBanner () {
} }
}) })
useEffect(() => { useEffect(() => {
setHidden(me?.hideWelcomeBanner || (!me && window.localStorage.getItem('hideWelcomeBanner'))) setHidden(me?.privates?.hideWelcomeBanner || (!me && window.localStorage.getItem('hideWelcomeBanner')))
}, [me?.hideWelcomeBanner]) }, [me?.privates?.hideWelcomeBanner])
if (hidden) return if (hidden) return

View File

@ -99,7 +99,7 @@ export default function Comment ({
}) { }) {
const [edit, setEdit] = useState() const [edit, setEdit] = useState()
const me = useMe() 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( const [collapse, setCollapse] = useState(
isHiddenFreebie || item?.user?.meMute isHiddenFreebie || item?.user?.meMute
? 'yep' ? 'yep'

View File

@ -99,7 +99,7 @@ export function DiscussionForm ({
initial={{ initial={{
title: item?.title || shareTitle || '', title: item?.title || shareTitle || '',
text: item?.text || '', text: item?.text || '',
crosspost: me?.nostrCrossposting, crosspost: me?.privates?.nostrCrossposting,
...AdvPostInitial({ forward: normalizeForwards(item?.forwards), boost: item?.boost }), ...AdvPostInitial({ forward: normalizeForwards(item?.forwards), boost: item?.boost }),
...SubSelectInitial({ sub: item?.subName || sub?.name }) ...SubSelectInitial({ sub: item?.subName || sub?.name })
}} }}

View File

@ -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 // 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) && const free = total === lines.baseCost?.modifier(0) &&
total <= FREEBIE_BASE_COST_THRESHOLD && total <= FREEBIE_BASE_COST_THRESHOLD &&
me?.sats < FREEBIE_BASE_COST_THRESHOLD me?.privates?.sats < FREEBIE_BASE_COST_THRESHOLD
const feeText = free const feeText = free
? 'free' ? 'free'
: total > 1 : total > 1

View File

@ -29,10 +29,10 @@ import { clearNotifications } from '../lib/badge'
function WalletSummary ({ me }) { function WalletSummary ({ me }) {
if (!me) return null if (!me) return null
if (me.hideWalletBalance) { if (me.privates?.hideWalletBalance) {
return <HiddenWalletSummary abbreviate fixedWidth /> return <HiddenWalletSummary abbreviate fixedWidth />
} }
return `${abbrNum(me.sats)}` return `${abbrNum(me.privates?.sats)}`
} }
function Back () { function Back () {

View File

@ -18,7 +18,7 @@ export default function HiddenWalletSummary ({ abbreviate, fixedWidth }) {
ref={ref} style={{ width: fixedWidth ? width : undefined }} ref={ref} style={{ width: fixedWidth ? width : undefined }}
className='d-inline-block text-monospace' align='right' onPointerEnter={() => setHover(true)} onPointerLeave={() => setHover(false)} 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 })) : '******'}
</span> </span>
) )
} }

View File

@ -23,7 +23,7 @@ function ImageOriginal ({ src, topLevel, nofollow, tab, children, onClick, ...pr
const [showImage, setShowImage] = useState(false) const [showImage, setShowImage] = useState(false)
useEffect(() => { 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 <img> // make sure it's not a false negative by trying to load URL as <img>
const img = new window.Image() const img = new window.Image()
img.onload = () => setShowImage(true) img.onload = () => setShowImage(true)

View File

@ -67,7 +67,7 @@ export default function ItemAct ({ onClose, itemId, act, down, strike }) {
return ( return (
<Form <Form
initial={{ initial={{
amount: me?.tipDefault || defaultTips[0], amount: me?.privates?.tipDefault || defaultTips[0],
default: false default: false
}} }}
schema={amountSchema} schema={amountSchema}

View File

@ -55,7 +55,7 @@ export function LoggerProvider ({ children }) {
const log = useCallback(level => { const log = useCallback(level => {
return async (message, context) => { return async (message, context) => {
if (!me || !me.diagnostics) return if (!me || !me.privates?.diagnostics) return
const env = { const env = {
userAgent: window.navigator.userAgent, userAgent: window.navigator.userAgent,
// os may not be initialized yet // os may not be initialized yet
@ -78,7 +78,7 @@ export function LoggerProvider ({ children }) {
body: JSON.stringify(body) body: JSON.stringify(body)
}).catch(console.error) }).catch(console.error)
} }
}, [me?.diagnostics, name, os]) }, [me?.privates?.diagnostics, name, os])
const logger = useMemo(() => ({ const logger = useMemo(() => ({
info: log('info'), info: log('info'),

View File

@ -1,4 +1,4 @@
import React, { useContext, useMemo } from 'react' import React, { useContext } from 'react'
import { useQuery } from '@apollo/client' import { useQuery } from '@apollo/client'
import { ME } from '../fragments/users' import { ME } from '../fragments/users'
import { SSR } from '../lib/constants' import { SSR } from '../lib/constants'
@ -9,22 +9,14 @@ export const MeContext = React.createContext({
export function MeProvider ({ me, children }) { export function MeProvider ({ me, children }) {
const { data } = useQuery(ME, SSR ? {} : { pollInterval: 1000, nextFetchPolicy: 'cache-and-network' }) 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 ( return (
<MeContext.Provider value={contextValue}> <MeContext.Provider value={data?.me || me}>
{children} {children}
</MeContext.Provider> </MeContext.Provider>
) )
} }
export function useMe () { export function useMe () {
const { me } = useContext(MeContext) return useContext(MeContext)
return me
} }

View File

@ -18,7 +18,7 @@ export function usePrice () {
export function PriceProvider ({ price, children }) { export function PriceProvider ({ price, children }) {
const me = useMe() const me = useMe()
const fiatCurrency = me?.fiatCurrency const fiatCurrency = me?.privates?.fiatCurrency
const { data } = useQuery(PRICE, { const { data } = useQuery(PRICE, {
variables: { fiatCurrency }, variables: { fiatCurrency },
...(SSR ...(SSR
@ -32,7 +32,7 @@ export function PriceProvider ({ price, children }) {
const contextValue = useMemo(() => ({ const contextValue = useMemo(() => ({
price: data?.price || price, price: data?.price || price,
fiatSymbol: CURRENCY_SYMBOLS[fiatCurrency] || '$' fiatSymbol: CURRENCY_SYMBOLS[fiatCurrency] || '$'
}), [data?.price, price, me?.fiatCurrency]) }), [data?.price, price, me?.privates?.fiatCurrency])
return ( return (
<PriceContext.Provider value={contextValue}> <PriceContext.Provider value={contextValue}>

View File

@ -39,7 +39,7 @@ const UpvotePopover = ({ target, show, handleClose }) => {
<button type='button' className='btn-close' onClick={handleClose}><span className='visually-hidden-focusable'>Close alert</span></button> <button type='button' className='btn-close' onClick={handleClose}><span className='visually-hidden-focusable'>Close alert</span></button>
</Popover.Header> </Popover.Header>
<Popover.Body> <Popover.Body>
<div className='mb-2'>Press the bolt again to zap {me?.tipDefault || 1} more sat{me?.tipDefault > 1 ? 's' : ''}.</div> <div className='mb-2'>Press the bolt again to zap {me?.privates?.tipDefault || 1} more sat{me?.privates?.tipDefault > 1 ? 's' : ''}.</div>
<div>Repeatedly press the bolt to zap more sats.</div> <div>Repeatedly press the bolt to zap more sats.</div>
</Popover.Body> </Popover.Body>
</Popover> </Popover>
@ -83,7 +83,7 @@ export default function UpVote ({ item, className, pendingSats, setPendingSats }
if (!me) return if (!me) return
// if they haven't seen the walkthrough and they have sats // 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) _setVoteShow(true)
} }
@ -97,7 +97,7 @@ export default function UpVote ({ item, className, pendingSats, setPendingSats }
if (!me) return if (!me) return
// if we want to show it, yet we still haven't shown // 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) _setTipShow(true)
} }
@ -124,7 +124,7 @@ export default function UpVote ({ item, className, pendingSats, setPendingSats }
}, },
meSats: me meSats: me
? (existingSats = 0) => { ? (existingSats = 0) => {
if (sats <= me.sats) { if (sats <= me.privates?.sats) {
if (existingSats === 0) { if (existingSats === 0) {
setVoteShow(true) setVoteShow(true)
} else { } else {
@ -186,8 +186,8 @@ export default function UpVote ({ item, className, pendingSats, setPendingSats }
const meSats = (item?.meSats || item?.meAnonSats || 0) + pendingSats const meSats = (item?.meSats || item?.meAnonSats || 0) + pendingSats
// what should our next tip be? // what should our next tip be?
let sats = me?.tipDefault || 1 let sats = me?.privates?.tipDefault || 1
if (me?.turboTipping) { if (me?.privates?.turboTipping) {
let raiseTip = sats let raiseTip = sats
while (meSats >= raiseTip) { while (meSats >= raiseTip) {
raiseTip *= 10 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)] 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 ( return (
<LightningConsumer> <LightningConsumer>

View File

@ -33,6 +33,17 @@ function getClient (uri) {
cache: new InMemoryCache({ cache: new InMemoryCache({
freezeResults: true, freezeResults: true,
typePolicies: { typePolicies: {
User: {
// https://www.apollographql.com/docs/react/caching/cache-field-behavior/#merging-non-normalized-objects
fields: {
privates: {
merge: true
},
optional: {
merge: true
}
}
},
Query: { Query: {
fields: { fields: {
sub: { sub: {

View File

@ -277,7 +277,7 @@ export default function Settings ({ ssrData }) {
name='hideBookmarks' name='hideBookmarks'
groupClassName='mb-0' groupClassName='mb-0'
/> />
{me.isContributor && {me.optional?.isContributor &&
<Checkbox <Checkbox
label={<>hide that I'm a stacker.news contributor</>} label={<>hide that I'm a stacker.news contributor</>}
name='hideIsContributor' name='hideIsContributor'

View File

@ -62,9 +62,9 @@ function YouHaveSats () {
<h2 className={`${me ? 'visible' : 'invisible'} text-success`}> <h2 className={`${me ? 'visible' : 'invisible'} text-success`}>
you have{' '} you have{' '}
<span className='text-monospace'>{me && ( <span className='text-monospace'>{me && (
me.hideWalletBalance me.privates?.hideWalletBalance
? <HiddenWalletSummary /> ? <HiddenWalletSummary />
: numWithUnits(me.sats, { abbreviate: false, format: true }) : numWithUnits(me.privates?.sats, { abbreviate: false, format: true })
)} )}
</span> </span>
</h2> </h2>
@ -201,7 +201,7 @@ export function InvWithdrawal () {
const [createWithdrawl, { called, error }] = useMutation(CREATE_WITHDRAWL) const [createWithdrawl, { called, error }] = useMutation(CREATE_WITHDRAWL)
const maxFeeDefault = me?.withdrawMaxFeeDefault const maxFeeDefault = me?.privates?.withdrawMaxFeeDefault
useEffect(() => { useEffect(() => {
async function effect () { async function effect () {
@ -209,7 +209,7 @@ export function InvWithdrawal () {
const provider = await requestProvider() const provider = await requestProvider()
const { paymentRequest: invoice } = await provider.makeInvoice({ const { paymentRequest: invoice } = await provider.makeInvoice({
defaultMemo: `Withdrawal for @${me.name} on SN`, 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 } }) const { data } = await createWithdrawl({ variables: { invoice, maxFee: maxFeeDefault } })
router.push(`/withdrawals/${data.createWithdrawl.id}`) router.push(`/withdrawals/${data.createWithdrawl.id}`)
@ -340,7 +340,7 @@ export function LnAddrWithdrawal () {
const defaultOptions = { min: 1 } const defaultOptions = { min: 1 }
const [addrOptions, setAddrOptions] = useState(defaultOptions) const [addrOptions, setAddrOptions] = useState(defaultOptions)
const [formSchema, setFormSchema] = useState(lnAddrSchema()) const [formSchema, setFormSchema] = useState(lnAddrSchema())
const maxFeeDefault = me?.withdrawMaxFeeDefault const maxFeeDefault = me?.privates?.withdrawMaxFeeDefault
const onAddrChange = useDebounceCallback(async (formik, e) => { const onAddrChange = useDebounceCallback(async (formik, e) => {
if (!e?.target?.value) { if (!e?.target?.value) {

View File

@ -120,7 +120,7 @@ function PrivacyOption ({ wd }) {
if (!oldEnough) { if (!oldEnough) {
return ( return (
<span className='text-muted fst-italic'> <span className='text-muted fst-italic'>
{`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)}`}
</span> </span>
) )
} }