import { getGetServerSideProps } from '@/api/ssrApollo' import { Checkbox, Form, Input, SubmitButton } from '@/components/form' import Info from '@/components/info' import { isNumber } from '@/lib/format' import { WalletLayout, WalletLayoutHeader, WalletLayoutSubHeader } from '@/wallets/client/components' import { useMutation, useQuery } from '@apollo/client' import Link from 'next/link' import { useCallback, useMemo } from 'react' import { InputGroup } from 'react-bootstrap' import styles from '@/styles/wallet.module.css' import classNames from 'classnames' import { useField } from 'formik' import { SET_WALLET_SETTINGS, WALLET_SETTINGS } from '@/wallets/client/fragments' import { walletSettingsSchema } from '@/lib/validate' import { useToast } from '@/components/toast' import CancelButton from '@/components/cancel-button' export const getServerSideProps = getGetServerSideProps({ query: WALLET_SETTINGS, authRequired: true }) export default function WalletSettings ({ ssrData }) { const { data } = useQuery(WALLET_SETTINGS) const [setSettings] = useMutation(SET_WALLET_SETTINGS) const { walletSettings: settings } = useMemo(() => data ?? ssrData, [data, ssrData]) const toaster = useToast() const initial = { receiveCreditsBelowSats: settings?.receiveCreditsBelowSats, sendCreditsBelowSats: settings?.sendCreditsBelowSats, autoWithdrawThreshold: settings?.autoWithdrawThreshold ?? 10000, autoWithdrawMaxFeePercent: settings?.autoWithdrawMaxFeePercent ?? 1, autoWithdrawMaxFeeTotal: settings?.autoWithdrawMaxFeeTotal ?? 1, proxyReceive: settings?.proxyReceive } const onSubmit = useCallback(async (values) => { try { await setSettings({ variables: { settings: values } }) toaster.success('saved settings') } catch (err) { console.error(err) toaster.danger('failed to save settings') } }, [toaster]) return (
wallet settings apply globally to all wallets
save
) } function CowboyCreditsSettings () { return ( <> cowboy credits sats} type='number' min={0} /> sats} type='number' min={0} /> ) } function LightningAddressSettings () { return ( <> @stacker.news lightning address enhance privacy of my lightning address } name='proxyReceive' groupClassName='mb-0' /> ) } function AutowithdrawSettings () { const [{ value: threshold }] = useField('autoWithdrawThreshold') const sendThreshold = Math.max(Math.floor(threshold / 10), 1) return ( <> autowithdrawal sats} required type='number' min={0} /> ) } function LightningNetworkFeesSettings () { return ( <> lightning network fees
we'll use whichever setting is higher during{' '} pathfinding
%} required type='number' min={0} /> sats} required type='number' min={0} /> ) } function Separator ({ children, className }) { return (
{children}
) }