import { Checkbox, Form, Input, SubmitButton, Select, VariableInput } from '../components/form' import Alert from 'react-bootstrap/Alert' import Button from 'react-bootstrap/Button' import InputGroup from 'react-bootstrap/InputGroup' import { CenterLayout } from '../components/layout' import { useState } from 'react' import { gql, useMutation, useQuery } from '@apollo/client' import { getGetServerSideProps } from '../api/ssrApollo' import LoginButton from '../components/login-button' import { signIn } from 'next-auth/react' import { LightningAuth, SlashtagsAuth } from '../components/lightning-auth' import { SETTINGS, SET_SETTINGS } from '../fragments/users' import { useRouter } from 'next/router' import Info from '../components/info' import Link from 'next/link' import AccordianItem from '../components/accordian-item' import { bech32 } from 'bech32' import { NOSTR_MAX_RELAY_NUM, NOSTR_PUBKEY_BECH32 } from '../lib/nostr' import { emailSchema, lastAuthRemovalSchema, settingsSchema } from '../lib/validate' import { SUPPORTED_CURRENCIES } from '../lib/currency' import PageLoading from '../components/page-loading' import { useShowModal } from '../components/modal' import { authErrorMessage } from '../components/login' export const getServerSideProps = getGetServerSideProps(SETTINGS) function bech32encode (hexString) { return bech32.encode('npub', bech32.toWords(Buffer.from(hexString, 'hex'))) } export default function Settings ({ ssrData }) { const [success, setSuccess] = useState() const [setSettings] = useMutation(SET_SETTINGS, { update (cache, { data: { setSettings } }) { cache.modify({ id: 'ROOT_QUERY', fields: { settings () { return setSettings } } }) } } ) const { data } = useQuery(SETTINGS) const { settings } = data || ssrData if (!data && !ssrData) return return (

settings

{ if (nostrPubkey.length === 0) { nostrPubkey = null } else { if (NOSTR_PUBKEY_BECH32.test(nostrPubkey)) { const { words } = bech32.decode(nostrPubkey) nostrPubkey = Buffer.from(bech32.fromWords(words)).toString('hex') } } const nostrRelaysFiltered = nostrRelays?.filter(word => word.trim().length > 0) await setSettings({ variables: { tipDefault: Number(tipDefault), nostrPubkey, nostrRelays: nostrRelaysFiltered, ...values } }) setSuccess('settings saved') }} > {success && setSuccess(undefined)} dismissible>{success}} sats} hint={note: you can also press and hold the lightning bolt to zap custom amounts} />
advanced
} body={turbo zapping
  • Makes every additional bolt click raise your total zap to another 10x multiple of your default zap
  • e.g. if your zap default is 10 sats
    • 1st click: 10 sats total zapped
    • 2nd click: 100 sats total zapped
    • 3rd click: 1000 sats total zapped
    • 4th click: 10000 sats total zapped
    • and so on ...
  • You can still custom zap via long press
    • the next bolt click rounds up to the next greatest 10x multiple of your default
} />} /> pubkey optional} name='nostrPubkey' clear /> relays optional} name='nostrRelays' clear min={0} max={NOSTR_MAX_RELAY_NUM} /> } />
save
saturday newsletter
{settings?.authMethods && }
) } function QRLinkButton ({ provider, unlink, status }) { const showModal = useShowModal() const text = status ? 'Unlink' : 'Link' const onClick = status ? unlink : () => showModal(onClose =>
{provider === 'slashtags' ? : }
) return ( ) } function UnlinkObstacle ({ onClose, type, unlinkAuth }) { const router = useRouter() return (
You are removing your last auth method. It is recommended you link another auth method before removing your last auth method. If you'd like to proceed anyway, type the following below
If I logout, even accidentally, I will never be able to access my account again
{ await unlinkAuth({ variables: { authType: type } }) router.push('/settings') onClose() }} > do it
) } function AuthMethods ({ methods }) { const showModal = useShowModal() const router = useRouter() const [err, setErr] = useState(authErrorMessage(router.query.error)) const [unlinkAuth] = useMutation( gql` mutation unlinkAuth($authType: String!) { unlinkAuth(authType: $authType) { lightning email twitter github } }`, { update (cache, { data: { unlinkAuth } }) { cache.modify({ id: 'ROOT_QUERY', fields: { settings (existing) { return { ...existing, authMethods: { ...unlinkAuth } } } } }) } } ) // sort to prevent hydration mismatch const providers = Object.keys(methods).filter(k => k !== '__typename').sort() const unlink = async type => { // if there's only one auth method left const links = providers.reduce((t, p) => t + (methods[p] ? 1 : 0), 0) if (links === 1) { showModal(onClose => ()) } else { await unlinkAuth({ variables: { authType: type } }) } } return ( <>
auth methods
{err && ( { const { pathname, query: { error, nodata, ...rest } } = router router.replace({ pathname, query: { nodata, ...rest } }, { pathname, query: { ...rest } }, { shallow: true }) setErr(undefined) }} dismissible >{err} )} {providers?.map(provider => { if (provider === 'email') { return methods.email ? (
) :
} else if (provider === 'lightning' || provider === 'slashtags') { return ( await unlink(provider)} /> ) } else { return ( { if (methods[provider]) { await unlink(provider) } else { signIn(provider) } }} text={methods[provider] ? 'Unlink' : 'Link'} /> ) } })} ) } export function EmailLinkForm ({ callbackUrl }) { const [linkUnverifiedEmail] = useMutation( gql` mutation linkUnverifiedEmail($email: String!) { linkUnverifiedEmail(email: $email) }` ) return (
{ // add email to user's account // then call signIn const { data } = await linkUnverifiedEmail({ variables: { email } }) if (data.linkUnverifiedEmail) { signIn('email', { email, callbackUrl }) } }} >
Link Email
) }