Add a setting for Default Withdrawal max fee (#552)

* add setting for default withdrawal max fee

* Update pages/settings.js

Co-authored-by: ekzyis <27162016+ekzyis@users.noreply.github.com>

* remove extraneous fallback of 21

---------

Co-authored-by: rleed <rleed1@pm.me>
Co-authored-by: ekzyis <27162016+ekzyis@users.noreply.github.com>
This commit is contained in:
rleed 2023-10-20 21:09:41 -03:00 committed by GitHub
parent 01f36184b1
commit c1c1240eab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 110 additions and 94 deletions

View File

@ -20,7 +20,7 @@ export default gql`
extend type Mutation { extend type Mutation {
setName(name: String!): String setName(name: String!): String
setSettings(tipDefault: Int!, turboTipping: Boolean!, fiatCurrency: String!, noteItemSats: Boolean!, setSettings(tipDefault: Int!, turboTipping: Boolean!, fiatCurrency: String!, withdrawMaxFeeDefault: Int!, noteItemSats: Boolean!,
noteEarning: Boolean!, noteAllDescendants: Boolean!, noteMentions: Boolean!, noteDeposits: Boolean!, noteEarning: Boolean!, noteAllDescendants: Boolean!, noteMentions: Boolean!, noteDeposits: Boolean!,
noteInvites: Boolean!, noteJobIndicator: Boolean!, noteCowboyHat: Boolean!, hideInvoiceDesc: Boolean!, noteInvites: Boolean!, noteJobIndicator: Boolean!, noteCowboyHat: Boolean!, hideInvoiceDesc: Boolean!,
hideFromTopUsers: Boolean!, hideCowboyHat: Boolean!, imgproxyOnly: Boolean!, hideFromTopUsers: Boolean!, hideCowboyHat: Boolean!, imgproxyOnly: Boolean!,
@ -62,6 +62,7 @@ export default gql`
tipDefault: Int! tipDefault: Int!
turboTipping: Boolean! turboTipping: Boolean!
fiatCurrency: String! fiatCurrency: String!
withdrawMaxFeeDefault: Int!
nostrPubkey: String nostrPubkey: String
nostrRelays: [String!] nostrRelays: [String!]
bio: Item bio: Item

View File

@ -15,6 +15,7 @@ export const ME = gql`
tipDefault tipDefault
turboTipping turboTipping
fiatCurrency fiatCurrency
withdrawMaxFeeDefault
bioId bioId
upvotePopover upvotePopover
tipPopover tipPopover
@ -48,6 +49,7 @@ export const SETTINGS_FIELDS = gql`
tipDefault tipDefault
turboTipping turboTipping
fiatCurrency fiatCurrency
withdrawMaxFeeDefault
noteItemSats noteItemSats
noteEarning noteEarning
noteAllDescendants noteAllDescendants
@ -90,13 +92,13 @@ ${SETTINGS_FIELDS}
export const SET_SETTINGS = export const SET_SETTINGS =
gql` gql`
${SETTINGS_FIELDS} ${SETTINGS_FIELDS}
mutation setSettings($tipDefault: Int!, $turboTipping: Boolean!, $fiatCurrency: String!, $noteItemSats: Boolean!, mutation setSettings($tipDefault: Int!, $turboTipping: Boolean!, $fiatCurrency: String!, $withdrawMaxFeeDefault: Int!, $noteItemSats: Boolean!,
$noteEarning: Boolean!, $noteAllDescendants: Boolean!, $noteMentions: Boolean!, $noteDeposits: Boolean!, $noteEarning: Boolean!, $noteAllDescendants: Boolean!, $noteMentions: Boolean!, $noteDeposits: Boolean!,
$noteInvites: Boolean!, $noteJobIndicator: Boolean!, $noteCowboyHat: Boolean!, $hideInvoiceDesc: Boolean!, $noteInvites: Boolean!, $noteJobIndicator: Boolean!, $noteCowboyHat: Boolean!, $hideInvoiceDesc: Boolean!,
$hideFromTopUsers: Boolean!, $hideCowboyHat: Boolean!, $imgproxyOnly: Boolean!, $hideFromTopUsers: Boolean!, $hideCowboyHat: Boolean!, $imgproxyOnly: Boolean!,
$wildWestMode: Boolean!, $greeterMode: Boolean!, $nostrPubkey: String, $nostrCrossposting: Boolean!, $nostrRelays: [String!], $hideBookmarks: Boolean!, $wildWestMode: Boolean!, $greeterMode: Boolean!, $nostrPubkey: String, $nostrCrossposting: Boolean!, $nostrRelays: [String!], $hideBookmarks: Boolean!,
$noteForwardedSats: Boolean!, $hideWalletBalance: Boolean!, $hideIsContributor: Boolean!, $diagnostics: Boolean!) { $noteForwardedSats: Boolean!, $hideWalletBalance: Boolean!, $hideIsContributor: Boolean!, $diagnostics: Boolean!) {
setSettings(tipDefault: $tipDefault, turboTipping: $turboTipping, fiatCurrency: $fiatCurrency, setSettings(tipDefault: $tipDefault, turboTipping: $turboTipping, fiatCurrency: $fiatCurrency, withdrawMaxFeeDefault: $withdrawMaxFeeDefault,
noteItemSats: $noteItemSats, noteEarning: $noteEarning, noteAllDescendants: $noteAllDescendants, noteItemSats: $noteItemSats, noteEarning: $noteEarning, noteAllDescendants: $noteAllDescendants,
noteMentions: $noteMentions, noteDeposits: $noteDeposits, noteInvites: $noteInvites, noteMentions: $noteMentions, noteDeposits: $noteDeposits, noteInvites: $noteInvites,
noteJobIndicator: $noteJobIndicator, noteCowboyHat: $noteCowboyHat, hideInvoiceDesc: $hideInvoiceDesc, noteJobIndicator: $noteJobIndicator, noteCowboyHat: $noteCowboyHat, hideInvoiceDesc: $hideInvoiceDesc,

View File

@ -223,6 +223,7 @@ export const amountSchema = object({
export const settingsSchema = object({ export const settingsSchema = object({
tipDefault: intValidator.required('required').positive('must be positive'), tipDefault: intValidator.required('required').positive('must be positive'),
fiatCurrency: string().required('required').oneOf(SUPPORTED_CURRENCIES), fiatCurrency: string().required('required').oneOf(SUPPORTED_CURRENCIES),
withdrawMaxFeeDefault: intValidator.required('required').positive('must be positive'),
nostrPubkey: string().nullable() nostrPubkey: string().nullable()
.or([ .or([
string().nullable().matches(NOSTR_PUBKEY_HEX, 'must be 64 hex chars'), string().nullable().matches(NOSTR_PUBKEY_HEX, 'must be 64 hex chars'),

View File

@ -63,6 +63,7 @@ export default function Settings ({ ssrData }) {
tipDefault: settings?.tipDefault || 21, tipDefault: settings?.tipDefault || 21,
turboTipping: settings?.turboTipping, turboTipping: settings?.turboTipping,
fiatCurrency: settings?.fiatCurrency || 'USD', fiatCurrency: settings?.fiatCurrency || 'USD',
withdrawMaxFeeDefault: settings?.withdrawMaxFeeDefault,
noteItemSats: settings?.noteItemSats, noteItemSats: settings?.noteItemSats,
noteEarning: settings?.noteEarning, noteEarning: settings?.noteEarning,
noteAllDescendants: settings?.noteAllDescendants, noteAllDescendants: settings?.noteAllDescendants,
@ -87,7 +88,7 @@ export default function Settings ({ ssrData }) {
hideIsContributor: settings?.hideIsContributor hideIsContributor: settings?.hideIsContributor
}} }}
schema={settingsSchema} schema={settingsSchema}
onSubmit={async ({ tipDefault, nostrPubkey, nostrRelays, ...values }) => { onSubmit={async ({ tipDefault, withdrawMaxFeeDefault, nostrPubkey, nostrRelays, ...values }) => {
if (nostrPubkey.length === 0) { if (nostrPubkey.length === 0) {
nostrPubkey = null nostrPubkey = null
} else { } else {
@ -103,6 +104,7 @@ export default function Settings ({ ssrData }) {
await setSettings({ await setSettings({
variables: { variables: {
tipDefault: Number(tipDefault), tipDefault: Number(tipDefault),
withdrawMaxFeeDefault: Number(withdrawMaxFeeDefault),
nostrPubkey, nostrPubkey,
nostrRelays: nostrRelaysFiltered, nostrRelays: nostrRelaysFiltered,
...values ...values
@ -163,6 +165,12 @@ export default function Settings ({ ssrData }) {
items={SUPPORTED_CURRENCIES} items={SUPPORTED_CURRENCIES}
required required
/> />
<Input
label='default max fee for withdrawals'
name='withdrawMaxFeeDefault'
required
append={<InputGroup.Text className='text-monospace'>sats</InputGroup.Text>}
/>
<div className='form-label'>notify me when ...</div> <div className='form-label'>notify me when ...</div>
<Checkbox <Checkbox
label='I stack sats from posts and comments' label='I stack sats from posts and comments'

View File

@ -190,23 +190,23 @@ export function SelectedWithdrawalForm () {
} }
} }
const MAX_FEE_DEFAULT = 10
export function InvWithdrawal () { export function InvWithdrawal () {
const router = useRouter() const router = useRouter()
const me = useMe() const me = useMe()
const [createWithdrawl, { called, error }] = useMutation(CREATE_WITHDRAWL) const [createWithdrawl, { called, error }] = useMutation(CREATE_WITHDRAWL)
const maxFeeDefault = me?.withdrawMaxFeeDefault
useEffect(() => { useEffect(() => {
async function effect () { async function effect () {
try { try {
const provider = await requestProvider() const provider = await requestProvider()
const { paymentRequest: invoice } = await provider.makeInvoice({ const { paymentRequest: invoice } = await provider.makeInvoice({
defaultMemo: `Withdrawal for @${me.name} on SN`, defaultMemo: `Withdrawal for @${me.name} on SN`,
maximumAmount: Math.max(me.sats - MAX_FEE_DEFAULT, 0) maximumAmount: Math.max(me.sats - maxFeeDefault, 0)
}) })
const { data } = await createWithdrawl({ variables: { invoice, maxFee: MAX_FEE_DEFAULT } }) const { data } = await createWithdrawl({ variables: { invoice, maxFee: maxFeeDefault } })
router.push(`/withdrawals/${data.createWithdrawl.id}`) router.push(`/withdrawals/${data.createWithdrawl.id}`)
} catch (e) { } catch (e) {
console.log(e.message) console.log(e.message)
@ -224,7 +224,7 @@ export function InvWithdrawal () {
<Form <Form
initial={{ initial={{
invoice: '', invoice: '',
maxFee: MAX_FEE_DEFAULT maxFee: maxFeeDefault
}} }}
initialError={error ? error.toString() : undefined} initialError={error ? error.toString() : undefined}
schema={withdrawlSchema} schema={withdrawlSchema}
@ -300,6 +300,7 @@ export function LnAddrWithdrawal () {
const defaultOptions = { min: 1 } const defaultOptions = { min: 1 }
const [addrOptions, setAddrOptions] = useState(defaultOptions) const [addrOptions, setAddrOptions] = useState(defaultOptions)
const [formSchema, setFormSchema] = useState(lnAddrSchema()) const [formSchema, setFormSchema] = useState(lnAddrSchema())
const maxFeeDefault = me?.withdrawMaxFeeDefault
const onAddrChange = useDebounceCallback(async (formik, e) => { const onAddrChange = useDebounceCallback(async (formik, e) => {
if (!e?.target?.value) { if (!e?.target?.value) {
@ -329,7 +330,7 @@ export function LnAddrWithdrawal () {
initial={{ initial={{
addr: '', addr: '',
amount: 1, amount: 1,
maxFee: 10, maxFee: maxFeeDefault,
comment: '', comment: '',
identifier: false, identifier: false,
name: '', name: '',

View File

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "users" ADD COLUMN "withdrawMaxFeeDefault" INTEGER NOT NULL DEFAULT 10;

View File

@ -48,6 +48,7 @@ model User {
wildWestMode Boolean @default(false) wildWestMode Boolean @default(false)
greeterMode Boolean @default(false) greeterMode Boolean @default(false)
fiatCurrency String @default("USD") fiatCurrency String @default("USD")
withdrawMaxFeeDefault Int @default(10)
hideFromTopUsers Boolean @default(false) hideFromTopUsers Boolean @default(false)
turboTipping Boolean @default(false) turboTipping Boolean @default(false)
imgproxyOnly Boolean @default(false) imgproxyOnly Boolean @default(false)