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 {
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!,
noteInvites: Boolean!, noteJobIndicator: Boolean!, noteCowboyHat: Boolean!, hideInvoiceDesc: Boolean!,
hideFromTopUsers: Boolean!, hideCowboyHat: Boolean!, imgproxyOnly: Boolean!,
@ -62,6 +62,7 @@ export default gql`
tipDefault: Int!
turboTipping: Boolean!
fiatCurrency: String!
withdrawMaxFeeDefault: Int!
nostrPubkey: String
nostrRelays: [String!]
bio: Item

View File

@ -15,6 +15,7 @@ export const ME = gql`
tipDefault
turboTipping
fiatCurrency
withdrawMaxFeeDefault
bioId
upvotePopover
tipPopover
@ -48,6 +49,7 @@ export const SETTINGS_FIELDS = gql`
tipDefault
turboTipping
fiatCurrency
withdrawMaxFeeDefault
noteItemSats
noteEarning
noteAllDescendants
@ -90,13 +92,13 @@ ${SETTINGS_FIELDS}
export const SET_SETTINGS =
gql`
${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!,
$noteInvites: Boolean!, $noteJobIndicator: Boolean!, $noteCowboyHat: Boolean!, $hideInvoiceDesc: Boolean!,
$hideFromTopUsers: Boolean!, $hideCowboyHat: Boolean!, $imgproxyOnly: Boolean!,
$wildWestMode: Boolean!, $greeterMode: Boolean!, $nostrPubkey: String, $nostrCrossposting: Boolean!, $nostrRelays: [String!], $hideBookmarks: 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,
noteMentions: $noteMentions, noteDeposits: $noteDeposits, noteInvites: $noteInvites,
noteJobIndicator: $noteJobIndicator, noteCowboyHat: $noteCowboyHat, hideInvoiceDesc: $hideInvoiceDesc,

View File

@ -223,6 +223,7 @@ export const amountSchema = object({
export const settingsSchema = object({
tipDefault: intValidator.required('required').positive('must be positive'),
fiatCurrency: string().required('required').oneOf(SUPPORTED_CURRENCIES),
withdrawMaxFeeDefault: intValidator.required('required').positive('must be positive'),
nostrPubkey: string().nullable()
.or([
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,
turboTipping: settings?.turboTipping,
fiatCurrency: settings?.fiatCurrency || 'USD',
withdrawMaxFeeDefault: settings?.withdrawMaxFeeDefault,
noteItemSats: settings?.noteItemSats,
noteEarning: settings?.noteEarning,
noteAllDescendants: settings?.noteAllDescendants,
@ -87,7 +88,7 @@ export default function Settings ({ ssrData }) {
hideIsContributor: settings?.hideIsContributor
}}
schema={settingsSchema}
onSubmit={async ({ tipDefault, nostrPubkey, nostrRelays, ...values }) => {
onSubmit={async ({ tipDefault, withdrawMaxFeeDefault, nostrPubkey, nostrRelays, ...values }) => {
if (nostrPubkey.length === 0) {
nostrPubkey = null
} else {
@ -103,6 +104,7 @@ export default function Settings ({ ssrData }) {
await setSettings({
variables: {
tipDefault: Number(tipDefault),
withdrawMaxFeeDefault: Number(withdrawMaxFeeDefault),
nostrPubkey,
nostrRelays: nostrRelaysFiltered,
...values
@ -163,6 +165,12 @@ export default function Settings ({ ssrData }) {
items={SUPPORTED_CURRENCIES}
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>
<Checkbox
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 () {
const router = useRouter()
const me = useMe()
const [createWithdrawl, { called, error }] = useMutation(CREATE_WITHDRAWL)
const maxFeeDefault = me?.withdrawMaxFeeDefault
useEffect(() => {
async function effect () {
try {
const provider = await requestProvider()
const { paymentRequest: invoice } = await provider.makeInvoice({
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}`)
} catch (e) {
console.log(e.message)
@ -224,7 +224,7 @@ export function InvWithdrawal () {
<Form
initial={{
invoice: '',
maxFee: MAX_FEE_DEFAULT
maxFee: maxFeeDefault
}}
initialError={error ? error.toString() : undefined}
schema={withdrawlSchema}
@ -300,6 +300,7 @@ export function LnAddrWithdrawal () {
const defaultOptions = { min: 1 }
const [addrOptions, setAddrOptions] = useState(defaultOptions)
const [formSchema, setFormSchema] = useState(lnAddrSchema())
const maxFeeDefault = me?.withdrawMaxFeeDefault
const onAddrChange = useDebounceCallback(async (formik, e) => {
if (!e?.target?.value) {
@ -329,7 +330,7 @@ export function LnAddrWithdrawal () {
initial={{
addr: '',
amount: 1,
maxFee: 10,
maxFee: maxFeeDefault,
comment: '',
identifier: false,
name: '',

View File

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

View File

@ -13,90 +13,91 @@ model Snl {
}
model User {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
name String? @unique(map: "users.name_unique") @db.Citext
email String? @unique(map: "users.email_unique")
emailVerified DateTime? @map("email_verified")
image String?
msats BigInt @default(0)
freeComments Int @default(5)
freePosts Int @default(2)
checkedNotesAt DateTime?
pubkey String? @unique(map: "users.pubkey_unique")
tipDefault Int @default(100)
bioId Int?
inviteId String?
tipPopover Boolean @default(false)
upvotePopover Boolean @default(false)
trust Float @default(0)
lastSeenAt DateTime?
stackedMsats BigInt @default(0)
noteAllDescendants Boolean @default(true)
noteDeposits Boolean @default(true)
noteEarning Boolean @default(true)
noteInvites Boolean @default(true)
noteItemSats Boolean @default(true)
noteMentions Boolean @default(true)
noteForwardedSats Boolean @default(true)
lastCheckedJobs DateTime?
noteJobIndicator Boolean @default(true)
photoId Int?
upvoteTrust Float @default(0)
hideInvoiceDesc Boolean @default(false)
wildWestMode Boolean @default(false)
greeterMode Boolean @default(false)
fiatCurrency String @default("USD")
hideFromTopUsers Boolean @default(false)
turboTipping Boolean @default(false)
imgproxyOnly Boolean @default(false)
hideWalletBalance Boolean @default(false)
referrerId Int?
nostrPubkey String?
nostrAuthPubkey String? @unique(map: "users.nostrAuthPubkey_unique")
nostrCrossposting Boolean @default(false)
slashtagId String? @unique(map: "users.slashtagId_unique")
noteCowboyHat Boolean @default(true)
streak Int?
subs String[]
hideCowboyHat Boolean @default(false)
Bookmarks Bookmark[]
Donation Donation[]
Earn Earn[]
invites Invite[] @relation("Invites")
invoices Invoice[]
items Item[] @relation("UserItems")
actions ItemAct[]
mentions Mention[]
messages Message[]
PollVote PollVote[]
PushSubscriptions PushSubscription[]
ReferralAct ReferralAct[]
Streak Streak[]
Subscriptions Subscription[]
ThreadSubscriptions ThreadSubscription[]
Upload Upload[] @relation("Uploads")
nostrRelays UserNostrRelay[]
withdrawls Withdrawl[]
bio Item? @relation(fields: [bioId], references: [id])
invite Invite? @relation(fields: [inviteId], references: [id])
photo Upload? @relation(fields: [photoId], references: [id])
referrer User? @relation("referrals", fields: [referrerId], references: [id])
referrees User[] @relation("referrals")
Account Account[]
Session Session[]
itemForwards ItemForward[]
hideBookmarks Boolean @default(false)
followers UserSubscription[] @relation("follower")
followees UserSubscription[] @relation("followee")
hideWelcomeBanner Boolean @default(false)
diagnostics Boolean @default(false)
hideIsContributor Boolean @default(false)
muters Mute[] @relation("muter")
muteds Mute[] @relation("muted")
ArcOut Arc[] @relation("fromUser")
ArcIn Arc[] @relation("toUser")
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
name String? @unique(map: "users.name_unique") @db.Citext
email String? @unique(map: "users.email_unique")
emailVerified DateTime? @map("email_verified")
image String?
msats BigInt @default(0)
freeComments Int @default(5)
freePosts Int @default(2)
checkedNotesAt DateTime?
pubkey String? @unique(map: "users.pubkey_unique")
tipDefault Int @default(100)
bioId Int?
inviteId String?
tipPopover Boolean @default(false)
upvotePopover Boolean @default(false)
trust Float @default(0)
lastSeenAt DateTime?
stackedMsats BigInt @default(0)
noteAllDescendants Boolean @default(true)
noteDeposits Boolean @default(true)
noteEarning Boolean @default(true)
noteInvites Boolean @default(true)
noteItemSats Boolean @default(true)
noteMentions Boolean @default(true)
noteForwardedSats Boolean @default(true)
lastCheckedJobs DateTime?
noteJobIndicator Boolean @default(true)
photoId Int?
upvoteTrust Float @default(0)
hideInvoiceDesc Boolean @default(false)
wildWestMode Boolean @default(false)
greeterMode Boolean @default(false)
fiatCurrency String @default("USD")
withdrawMaxFeeDefault Int @default(10)
hideFromTopUsers Boolean @default(false)
turboTipping Boolean @default(false)
imgproxyOnly Boolean @default(false)
hideWalletBalance Boolean @default(false)
referrerId Int?
nostrPubkey String?
nostrAuthPubkey String? @unique(map: "users.nostrAuthPubkey_unique")
nostrCrossposting Boolean @default(false)
slashtagId String? @unique(map: "users.slashtagId_unique")
noteCowboyHat Boolean @default(true)
streak Int?
subs String[]
hideCowboyHat Boolean @default(false)
Bookmarks Bookmark[]
Donation Donation[]
Earn Earn[]
invites Invite[] @relation("Invites")
invoices Invoice[]
items Item[] @relation("UserItems")
actions ItemAct[]
mentions Mention[]
messages Message[]
PollVote PollVote[]
PushSubscriptions PushSubscription[]
ReferralAct ReferralAct[]
Streak Streak[]
Subscriptions Subscription[]
ThreadSubscriptions ThreadSubscription[]
Upload Upload[] @relation("Uploads")
nostrRelays UserNostrRelay[]
withdrawls Withdrawl[]
bio Item? @relation(fields: [bioId], references: [id])
invite Invite? @relation(fields: [inviteId], references: [id])
photo Upload? @relation(fields: [photoId], references: [id])
referrer User? @relation("referrals", fields: [referrerId], references: [id])
referrees User[] @relation("referrals")
Account Account[]
Session Session[]
itemForwards ItemForward[]
hideBookmarks Boolean @default(false)
followers UserSubscription[] @relation("follower")
followees UserSubscription[] @relation("followee")
hideWelcomeBanner Boolean @default(false)
diagnostics Boolean @default(false)
hideIsContributor Boolean @default(false)
muters Mute[] @relation("muter")
muteds Mute[] @relation("muted")
ArcOut Arc[] @relation("fromUser")
ArcIn Arc[] @relation("toUser")
@@index([createdAt], map: "users.created_at_index")
@@index([inviteId], map: "users.inviteId_index")