import Alert from 'react-bootstrap/Alert'
import styles from './banners.module.css'
import { useEffect, useState } from 'react'
import { useMe } from '@/components/me'
import { useMutation } from '@apollo/client'
import { WELCOME_BANNER_MUTATION } from '@/fragments/users'
import { useToast } from '@/components/toast'
import { BALANCE_LIMIT_MSATS } from '@/lib/constants'
import { msatsToSats, numWithUnits } from '@/lib/format'
export function WelcomeBanner ({ Banner }) {
const me = useMe()
const toaster = useToast()
const [hidden, setHidden] = useState(true)
const handleClose = async () => {
window.localStorage.setItem('hideWelcomeBanner', true)
setHidden(true)
if (me) {
try {
await hideWelcomeBanner()
} catch (err) {
console.log(err)
toaster.danger('mutation failed')
}
}
}
const [hideWelcomeBanner] = useMutation(WELCOME_BANNER_MUTATION, {
update (cache) {
cache.modify({
id: `User:${me.id}`,
fields: {
hideWelcomeBanner () {
return true
}
}
})
}
})
useEffect(() => {
setHidden(me?.privates?.hideWelcomeBanner || (!me && window.localStorage.getItem('hideWelcomeBanner')))
}, [me?.privates?.hideWelcomeBanner])
if (hidden) return null
return Banner
?
: (
👋 Welcome to Stacker News!
To get started, check out our{' '}
FAQs or{' '}
content guidelines, or go ahead and{' '}
{
me
? (
make a post
)
: (
<>
sign up or create an{' '}
anonymous post
>
)
}.
)
}
export function MadnessBanner ({ handleClose }) {
const me = useMe()
return (
⚡️ Million Sat Madness Is Here!
{me
? (
We're giving away 3 million sats to the top Stacker News contributors in March.
See the leaderboard!
How does Million Sat Madness work?
Click here.
)
: (
We're giving away 3 million sats to the top Stacker News contributors in March.
Sign up!
Need help? Check out our
FAQs.
)}
)
}
export function WalletLimitBanner () {
const me = useMe()
const limitReached = me?.privates?.sats >= msatsToSats(BALANCE_LIMIT_MSATS)
if (!me || !limitReached) return
return (
Your wallet is over the current limit ({numWithUnits(msatsToSats(BALANCE_LIMIT_MSATS))})
Deposits to your wallet from outside of SN are blocked.
Please spend or withdraw sats to restore full wallet functionality.
)
}
export function WalletSecurityBanner () {
return (
Wallet Security Disclaimer
Your wallet's credentials are stored in the browser and never go to the server.
However, you should definitely set a budget in your wallet.
Also, for the time being, you will have to reenter your credentials on other devices.
)
}
export function AuthBanner () {
return (
Please add a second auth method to avoid losing access to your account.
)
}