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