import { Checkbox, Form, Input, SubmitButton, Select, VariableInput } from '../components/form'
import { Alert, Button, InputGroup, Modal } from 'react-bootstrap'
import LayoutCenter from '../components/layout-center'
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/client'
import ModalButton from '../components/modal-button'
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'
export const getServerSideProps = getGetServerSideProps(SETTINGS)
function bech32encode (hexString) {
return bech32.encode('npub', bech32.toWords(Buffer.from(hexString, 'hex')))
}
export default function Settings ({ data: { settings } }) {
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)
if (data) {
({ settings } = data)
}
return (
}
/>}
/>
notify me when ...
privacy
hide invoice descriptions
Use this if you don't want funding sources to be linkable to your SN identity.
It makes your invoice descriptions blank.
This only applies to invoices you create
lnurl-pay and lightning addresses still reference your nym
}
name='hideInvoiceDesc'
groupClassName='mb-0'
/>
hide me from top users >}
name='hideFromTopUsers'
/>
content
wild west mode
don't hide flagged content
don't down rank flagged content
}
name='wildWestMode'
groupClassName='mb-0'
/>
greeter mode
see and screen free posts and comments
help onboard users to SN and Lightning
you might be subject to more spam
}
name='greeterMode'
/>
nostr NIP-05 }
body={
<>
pubkey optional >}
name='nostrPubkey'
clear
/>
relays optional >}
name='nostrRelays'
clear
min={0}
max={NOSTR_MAX_RELAY_NUM}
/>
>
}
/>
save
saturday newsletter
(re)subscribe
{settings?.authMethods &&
}
)
}
function AuthMethods ({ methods }) {
const router = useRouter()
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 } }
}
}
})
}
}
)
const [obstacle, setObstacle] = useState()
const providers = Object.keys(methods).filter(k => k !== '__typename')
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) {
setObstacle(type)
} else {
await unlinkAuth({ variables: { authType: type } })
}
}
return (
<>
setObstacle(null)}
>
setObstacle(null)}>X
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
auth methods
{providers && providers.map(provider => {
switch (provider) {
case 'email':
return methods.email
? (
{
await unlink('email')
}
}
>Unlink Email
)
:
case 'lightning':
return methods.lightning
? {
await unlink('lightning')
}
}
/>
: (
}>
)
case 'slashtags':
return methods.slashtags
? {
await unlink('slashtags')
}
}
/>
: (
}>
)
default:
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 (
)
}