2023-09-11 21:29:45 +00:00
import Alert from 'react-bootstrap/Alert'
import styles from './banners.module.css'
import { useEffect , useState } from 'react'
2024-03-20 00:37:31 +00:00
import { useMe } from '@/components/me'
2023-09-11 21:29:45 +00:00
import { useMutation } from '@apollo/client'
2024-03-20 00:37:31 +00:00
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'
2023-09-11 21:29:45 +00:00
2024-03-04 22:51:36 +00:00
export function WelcomeBanner ( { Banner } ) {
2024-09-12 18:05:11 +00:00
const { me } = useMe ( )
2023-09-11 21:29:45 +00:00
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 ( ( ) => {
2023-11-20 15:04:38 +00:00
setHidden ( me ? . privates ? . hideWelcomeBanner || ( ! me && window . localStorage . getItem ( 'hideWelcomeBanner' ) ) )
} , [ me ? . privates ? . hideWelcomeBanner ] )
2023-09-11 21:29:45 +00:00
2023-12-15 18:10:29 +00:00
if ( hidden ) return null
2023-09-11 21:29:45 +00:00
2024-03-04 22:51:36 +00:00
return Banner
? < Banner handleClose = { handleClose } / >
: (
< Alert className = { styles . banner } key = 'info' variant = 'info' onClose = { handleClose } dismissible >
< Alert . Heading >
👋 Welcome to Stacker News !
< / A l e r t . H e a d i n g >
< p >
To get started , check out our { ' ' }
< Alert . Link href = '/faq' > FAQs < / A l e r t . L i n k > o r { ' ' }
< Alert . Link href = '/guide' > content guidelines < / A l e r t . L i n k > , o r g o a h e a d a n d { ' ' }
{
2023-09-11 21:29:45 +00:00
me
? (
< Alert . Link href = '/post' > make a post < / A l e r t . L i n k >
)
: (
< >
2023-09-12 19:51:55 +00:00
< Alert . Link href = '/signup' > sign up < / A l e r t . L i n k > o r c r e a t e a n { ' ' }
2023-09-11 21:29:45 +00:00
< Alert . Link href = '/post' > anonymous post < / A l e r t . L i n k >
< / >
)
} .
2024-03-04 22:51:36 +00:00
< / p >
< / A l e r t > )
}
export function MadnessBanner ( { handleClose } ) {
2024-09-12 18:05:11 +00:00
const { me } = useMe ( )
2024-03-04 22:51:36 +00:00
return (
< Alert className = { styles . banner } key = 'info' variant = 'info' onClose = { handleClose } dismissible >
< Alert . Heading >
⚡ ️ Million Sat Madness Is Here !
< / A l e r t . H e a d i n g >
{ me
? (
< div >
< div >
We 're giving away 3 million sats to the top Stacker News contributors in March. <Alert.Link href=' / rewards ' > See the leaderboard ! < / A l e r t . L i n k >
< / d i v >
< div >
How does Million Sat Madness work ? < Alert . Link href = '/items/444168' > Click here < / A l e r t . L i n k > .
< / d i v >
< / d i v >
)
: (
< div >
< div >
We 're giving away 3 million sats to the top Stacker News contributors in March. <Alert.Link href=' / signup ' > Sign up ! < / A l e r t . L i n k >
< / d i v >
< div >
Need help ? Check out our < Alert . Link href = '/faq' > FAQs < / A l e r t . L i n k > .
< / d i v >
< / d i v >
) }
2023-09-11 21:29:45 +00:00
< / A l e r t >
)
}
2023-12-21 23:31:16 +00:00
export function WalletLimitBanner ( ) {
2024-09-12 18:05:11 +00:00
const { me } = useMe ( )
2023-12-21 23:31:16 +00:00
const limitReached = me ? . privates ? . sats >= msatsToSats ( BALANCE _LIMIT _MSATS )
if ( ! me || ! limitReached ) return
return (
< Alert className = { styles . banner } key = 'info' variant = 'warning' >
2023-12-21 23:40:11 +00:00
< Alert . Heading >
Your wallet is over the current limit ( { numWithUnits ( msatsToSats ( BALANCE _LIMIT _MSATS ) ) } )
< / A l e r t . H e a d i n g >
< p className = 'mb-1' >
2024-01-05 01:23:59 +00:00
Deposits to your wallet from < strong > outside < / s t r o n g > o f S N a r e b l o c k e d .
2023-12-21 23:40:11 +00:00
< / p >
2023-12-21 23:31:16 +00:00
< p >
2023-12-21 23:40:11 +00:00
Please spend or withdraw sats to restore full wallet functionality .
2023-12-21 23:31:16 +00:00
< / p >
< / A l e r t >
)
}
2024-02-08 18:33:13 +00:00
2024-10-25 22:46:58 +00:00
export function WalletSecurityBanner ( { isActive } ) {
2024-02-08 18:33:13 +00:00
return (
< Alert className = { styles . banner } key = 'info' variant = 'warning' >
< Alert . Heading >
2024-10-25 22:46:58 +00:00
Gunslingin ' Safety Tips
2024-02-08 18:33:13 +00:00
< / A l e r t . H e a d i n g >
2024-10-25 22:46:58 +00:00
< p className = 'mb-3 line-height-md' >
Listen up , pardner ! Put a limit on yer spendin ' wallet or hook up a wallet that' s only for Stacker News . It 'll keep them varmints from cleanin' out yer whole goldmine if they rustle up yer wallet .
2024-02-08 18:33:13 +00:00
< / p >
2024-10-25 22:46:58 +00:00
< p className = 'line-height-md' >
Your spending wallet ' s credentials are never sent to our servers in plain text . To sync across devices , enable device sync in your settings .
2024-02-08 18:33:13 +00:00
< / p >
< / A l e r t >
)
}
2024-06-12 23:16:54 +00:00
export function AuthBanner ( ) {
return (
< Alert className = { ` ${ styles . banner } mt-0 ` } key = 'info' variant = 'danger' >
Please add a second auth method to avoid losing access to your account .
< / A l e r t >
)
}