import { useCallback } from 'react' import Button from 'react-bootstrap/Button' import InputGroup from 'react-bootstrap/InputGroup' import { useField } from 'formik' import classNames from 'classnames' import { useRouter } from 'next/router' import { useMutation, useQuery } from '@apollo/client' import { Checkbox, Form, Input, SubmitButton } from '@/components/form' import Info from '@/components/info' import { useToast } from '@/components/toast' import AccordianItem from '@/components/accordian-item' import { isNumber } from '@/lib/format' import { walletSettingsSchema } from '@/lib/validate' import styles from '@/styles/wallet.module.css' import { useShowModal } from '@/components/modal' import { SET_WALLET_SETTINGS, WALLET_SETTINGS } from '@/wallets/client/fragments' import { useWalletDelete } from '@/wallets/client/hooks' import { useSaveWallet, useWallet } from './hooks' import { BackButton } from './button' import { isWallet } from '@/wallets/lib/util' export function Settings () { const wallet = useWallet() const { data } = useQuery(WALLET_SETTINGS) const [setSettings] = useMutation(SET_WALLET_SETTINGS) const toaster = useToast() const saveWallet = useSaveWallet() const router = useRouter() const onSubmit = useCallback(async (settings) => { try { await saveWallet() await setSettings({ variables: { settings }, update: (cache, { data }) => { cache.writeQuery({ query: WALLET_SETTINGS, data: { walletSettings: { __typename: 'WalletSettings', ...data?.setWalletSettings } } }) } }) router.push('/wallets') } catch (err) { console.error(err) toaster.danger('failed to save wallet') } }, [saveWallet, setSettings, toaster, router]) const initial = { receiveCreditsBelowSats: data?.walletSettings?.receiveCreditsBelowSats ?? 10, sendCreditsBelowSats: data?.walletSettings?.sendCreditsBelowSats ?? 10, autoWithdrawThreshold: data?.walletSettings?.autoWithdrawThreshold ?? 10000, autoWithdrawMaxFeePercent: data?.walletSettings?.autoWithdrawMaxFeePercent ?? 1, autoWithdrawMaxFeeTotal: data?.walletSettings?.autoWithdrawMaxFeeTotal ?? 1, proxyReceive: data?.walletSettings?.proxyReceive ?? true } return ( <>
{isWallet(wallet) && } save
) } function Separator ({ children, className }) { return (
{children}
) } function WalletDeleteButton ({ className }) { const showModal = useShowModal() const wallet = useWallet() return ( ) } function WalletDeleteObstacle ({ wallet, onClose }) { const deleteWallet = useWalletDelete(wallet) const toaster = useToast() const router = useRouter() const onClick = useCallback(async () => { try { await deleteWallet() onClose() router.push('/wallets') } catch (err) { console.error('failed to delete wallet:', err) toaster.danger('failed to delete wallet') } }, [deleteWallet, onClose, toaster, router]) return (

Delete wallet

Are you sure you want to delete this wallet?

) } function GlobalSettings () { return ( <> global settings } /> ) } function AutowithdrawSettings () { const [{ value: threshold }] = useField('autoWithdrawThreshold') const sendThreshold = Math.max(Math.floor(threshold / 10), 1) return ( <> sats} required type='number' min={0} groupClassName='mb-2' /> max fee rate
  • configure fee budget for autowithdrawals
  • if max fee total is higher for a withdrawal, we will use it instead to find a route
  • higher fee settings increase the likelihood of successful withdrawals
} name='autoWithdrawMaxFeePercent' append={%} required type='number' min={0} /> max fee total
  • configure fee budget for autowithdrawals
  • if max fee rate is higher for a withdrawal, we will use it instead to find a route to your wallet
  • higher fee settings increase the likelihood of successful withdrawals
} name='autoWithdrawMaxFeeTotal' append={sats} required type='number' min={0} /> ) } function LightningAddressSettings () { return ( <> enhance privacy of my lightning address
  • Enabling this setting hides details (ie node pubkey) of your attached wallets when anyone pays your SN lightning address or lnurl-pay
  • The lightning invoice will appear to have SN's node as the destination to preserve your wallet's privacy
  • This will incur in a 10% fee
  • Disable this setting to receive payments directly to your attached wallets (which will reveal their details to the payer)
  • Note: this privacy behavior is standard for internal zaps/payments on SN, and this setting only applies to external payments
} name='proxyReceive' groupClassName='mb-3' /> ) } function CowboyCreditsSettings () { return ( <> receive credits for zaps below
  • we will not attempt to forward zaps below this amount to you, you will receive credits instead
  • this setting is useful if small amounts are expensive to receive for you
} name='receiveCreditsBelowSats' required append={sats} type='number' min={0} /> send credits for zaps below
  • we will not attempt to send zaps below this amount from your wallet if you have enough credits
  • this setting is useful if small amounts are expensive to send for you
} name='sendCreditsBelowSats' required append={sats} type='number' min={0} /> ) }