Compare commits
6 Commits
3710840167
...
6cf16d3da7
Author | SHA1 | Date | |
---|---|---|---|
|
6cf16d3da7 | ||
|
94d9d9513c | ||
|
f05b6fab84 | ||
|
e0f91ace41 | ||
|
0312012089 | ||
|
02472bb81f |
@ -104,7 +104,7 @@ COMMANDS
|
||||
|
||||
#### Running specific services
|
||||
|
||||
By default all services will be run. If you want to exclude specific services from running, set `COMPOSE_PROFILES` to use one or more of `minimal|images|search|payments|email|capture`. To only run mininal services without images, search, or payments:
|
||||
By default all services will be run. If you want to exclude specific services from running, set `COMPOSE_PROFILES` to use one or more of `minimal|images|search|payments|wallets|email|capture`. To only run mininal services without images, search, email, wallets, or payments:
|
||||
|
||||
```sh
|
||||
$ COMPOSE_PROFILES=minimal ./sndev start
|
||||
|
@ -11,7 +11,7 @@ export async function getCost ({ sats }) {
|
||||
}
|
||||
|
||||
export async function perform ({ invoiceId, sats, id: itemId, ...args }, { me, cost, tx }) {
|
||||
const feeMsats = cost / BigInt(100)
|
||||
const feeMsats = cost / BigInt(10) // 10% fee
|
||||
const zapMsats = cost - feeMsats
|
||||
itemId = parseInt(itemId)
|
||||
|
||||
@ -79,12 +79,16 @@ export async function onPaid ({ invoice, actIds }, { models, tx }) {
|
||||
FROM forwardees
|
||||
), forward AS (
|
||||
UPDATE users
|
||||
SET msats = users.msats + forwardees.msats
|
||||
SET
|
||||
msats = users.msats + forwardees.msats,
|
||||
"stackedMsats" = users."stackedMsats" + forwardees.msats
|
||||
FROM forwardees
|
||||
WHERE users.id = forwardees."userId"
|
||||
)
|
||||
UPDATE users
|
||||
SET msats = msats + ${itemAct.msats}::BIGINT - (SELECT msats FROM total_forwarded)::BIGINT
|
||||
SET
|
||||
msats = msats + ${itemAct.msats}::BIGINT - (SELECT msats FROM total_forwarded)::BIGINT,
|
||||
"stackedMsats" = "stackedMsats" + ${itemAct.msats}::BIGINT - (SELECT msats FROM total_forwarded)::BIGINT
|
||||
WHERE id = ${itemAct.item.userId}::INTEGER`
|
||||
|
||||
// perform denomormalized aggregates: weighted votes, upvotes, msats, lastZapAt
|
||||
|
@ -8,7 +8,6 @@ import { amountSchema } from '@/lib/validate'
|
||||
import { useToast } from './toast'
|
||||
import { useLightning } from './lightning'
|
||||
import { nextTip } from './upvote'
|
||||
import { InvoiceCanceledError } from './payment'
|
||||
import { ZAP_UNDO_DELAY_MS } from '@/lib/constants'
|
||||
import { usePaidMutation } from './use-paid-mutation'
|
||||
import { ACT_MUTATION } from '@/fragments/paidAction'
|
||||
@ -72,7 +71,7 @@ export default function ItemAct ({ onClose, item, down, children, abortSignal })
|
||||
}
|
||||
}
|
||||
}
|
||||
await act({
|
||||
const { error } = await act({
|
||||
variables: {
|
||||
id: item.id,
|
||||
sats: Number(amount),
|
||||
@ -95,6 +94,7 @@ export default function ItemAct ({ onClose, item, down, children, abortSignal })
|
||||
if (!me) setItemMeAnonSats({ id: item.id, amount })
|
||||
}
|
||||
})
|
||||
if (error) throw error
|
||||
addCustomTip(Number(amount))
|
||||
}, [me, act, down, item.id, onClose, abortSignal, strike])
|
||||
|
||||
@ -219,15 +219,15 @@ export function useZap () {
|
||||
try {
|
||||
await abortSignal.pause({ me, amount: sats })
|
||||
strike()
|
||||
await act({ variables, optimisticResponse })
|
||||
const { error } = await act({ variables, optimisticResponse })
|
||||
if (error) throw error
|
||||
} catch (error) {
|
||||
if (error instanceof InvoiceCanceledError || error instanceof ActCanceledError) {
|
||||
if (error instanceof ActCanceledError) {
|
||||
return
|
||||
}
|
||||
|
||||
const reason = error?.message || error?.toString?.()
|
||||
|
||||
toaster.danger('zap failed: ' + reason)
|
||||
toaster.danger(reason)
|
||||
}
|
||||
}, [me?.id, strike])
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import { MuteSubDropdownItem, PinSubDropdownItem } from './territory-header'
|
||||
import UserPopover from './user-popover'
|
||||
import { useQrPayment } from './payment'
|
||||
import { useRetryCreateItem } from './use-item-submit'
|
||||
import { useToast } from './toast'
|
||||
|
||||
export default function ItemInfo ({
|
||||
item, full, commentsText = 'comments',
|
||||
@ -32,6 +33,7 @@ export default function ItemInfo ({
|
||||
}) {
|
||||
const editThreshold = new Date(item.invoice?.confirmedAt ?? item.createdAt).getTime() + 10 * 60000
|
||||
const me = useMe()
|
||||
const toaster = useToast()
|
||||
const router = useRouter()
|
||||
const [canEdit, setCanEdit] =
|
||||
useState(item.mine && (Date.now() < editThreshold))
|
||||
@ -72,7 +74,14 @@ export default function ItemInfo ({
|
||||
if (me && item.invoice?.actionState && item.invoice?.actionState !== 'PAID') {
|
||||
if (item.invoice?.actionState === 'FAILED') {
|
||||
Component = () => <span className='text-warning'>retry payment</span>
|
||||
onClick = async () => await retryCreateItem({ variables: { invoiceId: parseInt(item.invoice?.id) } }).catch(console.error)
|
||||
onClick = async () => {
|
||||
try {
|
||||
const { error } = await retryCreateItem({ variables: { invoiceId: parseInt(item.invoice?.id) } })
|
||||
if (error) throw error
|
||||
} catch (error) {
|
||||
toaster.danger(error.message)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Component = () => (
|
||||
<span
|
||||
|
@ -36,6 +36,7 @@ import { usePollVote } from './poll'
|
||||
import { paidActionCacheMods } from './use-paid-mutation'
|
||||
import { useRetryCreateItem } from './use-item-submit'
|
||||
import { payBountyCacheMods } from './pay-bounty'
|
||||
import { useToast } from './toast'
|
||||
|
||||
function Notification ({ n, fresh }) {
|
||||
const type = n.__typename
|
||||
@ -334,6 +335,7 @@ function useActRetry ({ invoice }) {
|
||||
}
|
||||
|
||||
function Invoicification ({ n: { invoice, sortTime } }) {
|
||||
const toaster = useToast()
|
||||
const actRetry = useActRetry({ invoice })
|
||||
const retryCreateItem = useRetryCreateItem({ id: invoice.item?.id })
|
||||
const retryPollVote = usePollVote({ query: RETRY_PAID_ACTION, itemId: invoice.item?.id })
|
||||
@ -390,8 +392,13 @@ function Invoicification ({ n: { invoice, sortTime } }) {
|
||||
<Button
|
||||
size='sm' variant='outline-warning ms-2 border-1 rounded py-0'
|
||||
style={{ '--bs-btn-hover-color': '#fff', '--bs-btn-active-color': '#fff' }}
|
||||
onClick={() => {
|
||||
retry({ variables: { invoiceId: parseInt(invoiceId) } }).catch(console.error)
|
||||
onClick={async () => {
|
||||
try {
|
||||
const { error } = await retry({ variables: { invoiceId: parseInt(invoiceId) } })
|
||||
if (error) throw error
|
||||
} catch (error) {
|
||||
toaster.danger(error?.message || error?.toString?.())
|
||||
}
|
||||
}}
|
||||
>
|
||||
retry
|
||||
|
@ -7,7 +7,6 @@ import { numWithUnits } from '@/lib/format'
|
||||
import { useShowModal } from './modal'
|
||||
import { useRoot } from './root'
|
||||
import { ActCanceledError, useAct } from './item-act'
|
||||
import { InvoiceCanceledError } from './payment'
|
||||
import { useLightning } from './lightning'
|
||||
import { useToast } from './toast'
|
||||
|
||||
@ -58,15 +57,15 @@ export default function PayBounty ({ children, item }) {
|
||||
const handlePayBounty = async onCompleted => {
|
||||
try {
|
||||
strike()
|
||||
await act({ onCompleted })
|
||||
const { error } = await act({ onCompleted })
|
||||
if (error) throw error
|
||||
} catch (error) {
|
||||
if (error instanceof InvoiceCanceledError || error instanceof ActCanceledError) {
|
||||
if (error instanceof ActCanceledError) {
|
||||
return
|
||||
}
|
||||
|
||||
const reason = error?.message || error?.toString?.()
|
||||
|
||||
toaster.danger('pay bounty failed: ' + reason)
|
||||
toaster.danger(reason)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ export class InvoiceCanceledError extends Error {
|
||||
super(actionError ?? `invoice canceled: ${hash}`)
|
||||
this.name = 'InvoiceCanceledError'
|
||||
this.hash = hash
|
||||
this.actionError = actionError
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ import { useMe } from './me'
|
||||
import styles from './poll.module.css'
|
||||
import { signIn } from 'next-auth/react'
|
||||
import ActionTooltip from './action-tooltip'
|
||||
import { InvoiceCanceledError, useQrPayment } from './payment'
|
||||
import { useQrPayment } from './payment'
|
||||
import { useToast } from './toast'
|
||||
import { usePaidMutation } from './use-paid-mutation'
|
||||
import { POLL_VOTE, RETRY_PAID_ACTION } from '@/fragments/paidAction'
|
||||
@ -25,18 +25,14 @@ export default function Poll ({ item }) {
|
||||
const variables = { id: v.id }
|
||||
const optimisticResponse = { pollVote: { __typename: 'PollVotePaidAction', result: { id: v.id } } }
|
||||
try {
|
||||
await pollVote({
|
||||
const { error } = await pollVote({
|
||||
variables,
|
||||
optimisticResponse
|
||||
})
|
||||
if (error) throw error
|
||||
} catch (error) {
|
||||
if (error instanceof InvoiceCanceledError) {
|
||||
return
|
||||
}
|
||||
|
||||
const reason = error?.message || error?.toString?.()
|
||||
|
||||
toaster.danger('poll vote failed: ' + reason)
|
||||
toaster.danger(reason)
|
||||
}
|
||||
}
|
||||
: signIn}
|
||||
|
@ -41,7 +41,7 @@ export default function TerritoryForm ({ sub }) {
|
||||
: await upsertSub({ variables: { oldName: sub?.name, ...variables } })
|
||||
|
||||
if (error) throw error
|
||||
if (payError) throw new Error('payment required')
|
||||
if (payError) return
|
||||
|
||||
// modify graphql cache to include new sub
|
||||
client.cache.modify({
|
||||
|
@ -16,15 +16,13 @@ export default function TerritoryPaymentDue ({ sub }) {
|
||||
const client = useApolloClient()
|
||||
const [paySub] = usePaidMutation(SUB_PAY)
|
||||
|
||||
const onSubmit = useCallback(
|
||||
async ({ ...variables }) => {
|
||||
const { error, payError } = await paySub({
|
||||
variables
|
||||
})
|
||||
const onSubmit = useCallback(async ({ ...variables }) => {
|
||||
const { error } = await paySub({
|
||||
variables
|
||||
})
|
||||
|
||||
if (error) throw error
|
||||
if (payError) throw new Error('payment required')
|
||||
}, [client, paySub])
|
||||
if (error) throw error
|
||||
}, [client, paySub])
|
||||
|
||||
if (!sub || sub.userId !== Number(me?.id) || sub.status === 'ACTIVE') return null
|
||||
|
||||
|
@ -139,7 +139,7 @@ export const ToastProvider = ({ children }) => {
|
||||
>
|
||||
<ToastBody>
|
||||
<div className='d-flex align-items-center'>
|
||||
<div className='flex-grow-1'>{toast.body}</div>
|
||||
<div className='flex-grow-1 overflow-hidden'>{toast.body}</div>
|
||||
<Button
|
||||
variant={null}
|
||||
className='p-0 ps-2'
|
||||
|
@ -59,7 +59,7 @@ export default function useItemSubmit (mutation,
|
||||
})
|
||||
|
||||
if (error) throw error
|
||||
if (payError) throw new Error('payment required')
|
||||
if (payError) return
|
||||
|
||||
// we don't know the mutation name, so we have to extract the result
|
||||
const response = Object.values(data)[0]
|
||||
|
@ -63,6 +63,14 @@ export function usePaidMutation (mutation,
|
||||
|
||||
// if the mutation returns an invoice, pay it
|
||||
if (invoice) {
|
||||
// adds payError, escalating to a normal error if the invoice is not canceled or
|
||||
// has an actionError
|
||||
const addPayError = (e, rest) => ({
|
||||
...rest,
|
||||
payError: e,
|
||||
error: e instanceof InvoiceCanceledError && e.actionError ? e : undefined
|
||||
})
|
||||
|
||||
// should we wait for the invoice to be paid?
|
||||
if (response?.paymentMethod === 'OPTIMISTIC' && !forceWaitForPayment) {
|
||||
// onCompleted is called before the invoice is paid for optimistic updates
|
||||
@ -75,7 +83,7 @@ export function usePaidMutation (mutation,
|
||||
// onPayError is called after the invoice fails to pay
|
||||
// useful for updating invoiceActionState to FAILED
|
||||
onPayError?.(e, client.cache, { data })
|
||||
setInnerResult(r => ({ payError: e, ...r }))
|
||||
setInnerResult(r => addPayError(e, r))
|
||||
})
|
||||
} else {
|
||||
// the action is pessimistic
|
||||
@ -95,7 +103,7 @@ export function usePaidMutation (mutation,
|
||||
} catch (e) {
|
||||
console.error('usePaidMutation: failed to pay invoice', e)
|
||||
onPayError?.(e, client.cache, { data })
|
||||
rest = { ...rest, payError: e, error: e }
|
||||
rest = addPayError(e, rest)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react'
|
||||
import { useWalletLogger } from '../logger'
|
||||
import LNC from '@lightninglabs/lnc-web'
|
||||
import { Status, migrateLocalStorage } from '.'
|
||||
import { bolt11Tags } from '@/lib/bolt11'
|
||||
import useModal from '../modal'
|
||||
@ -16,6 +15,7 @@ const mutex = new Mutex()
|
||||
|
||||
async function getLNC ({ me }) {
|
||||
if (window.lnc) return window.lnc
|
||||
const { default: LNC } = await import('@lightninglabs/lnc-web')
|
||||
// backwards compatibility: migrate to new storage key
|
||||
if (me) migrateLocalStorage('lnc-web:default', `lnc-web:stacker:${me.id}`)
|
||||
window.lnc = new LNC({ namespace: me?.id ? `stacker:${me.id}` : undefined })
|
||||
|
@ -373,7 +373,7 @@ services:
|
||||
build:
|
||||
context: ./docker/litd
|
||||
profiles:
|
||||
- payments
|
||||
- wallets
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
<<: *healthcheck
|
||||
@ -479,7 +479,7 @@ services:
|
||||
context: ./docker/nwc
|
||||
container_name: nwc
|
||||
profiles:
|
||||
- payments
|
||||
- wallets
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
stacker_lnd:
|
||||
@ -509,7 +509,7 @@ services:
|
||||
image: lnbits/lnbits:0.12.5
|
||||
container_name: lnbits
|
||||
profiles:
|
||||
- payments
|
||||
- wallets
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "${LNBITS_WEB_PORT}:5000"
|
||||
|
Loading…
x
Reference in New Issue
Block a user