Compare commits

..

No commits in common. "450c969dfc7535b41406b29d913404bdbc3295be" and "18fbd17025d050b267cc4c65540f17e96120a2c4" have entirely different histories.

12 changed files with 32 additions and 87 deletions

View File

@ -13,13 +13,7 @@ export async function getCost ({ id, boost = 0, uploadIds }, { me, models }) {
// or more boost
const old = await models.item.findUnique({ where: { id: parseInt(id) } })
const { totalFeesMsats } = await uploadFees(uploadIds, { models, me })
const cost = BigInt(totalFeesMsats) + satsToMsats(boost - old.boost)
if (cost > 0 && old.invoiceActionState && old.invoiceActionState !== 'PAID') {
throw new Error('creation invoice not paid')
}
return cost
return BigInt(totalFeesMsats) + satsToMsats(boost - old.boost)
}
export async function perform (args, context) {

View File

@ -1328,6 +1328,10 @@ export const updateItem = async (parent, { sub: subName, forward, hash, hmac, ..
throw new GqlInputError('item is deleted')
}
if (old.invoiceActionState && old.invoiceActionState !== 'PAID') {
throw new GqlInputError('cannot edit unpaid item')
}
// author can edit their own item (except anon)
const meId = Number(me?.id ?? USER_ID.anon)
const authorEdit = !!me && Number(old.userId) === meId

View File

@ -49,10 +49,7 @@ export default {
}
const upload = await models.upload.create({ data: { ...fileParams } })
const extension = type.split('/')[1]
const key = `${upload.id}.${extension}`
return createPresignedPost({ key, type, size })
return createPresignedPost({ key: String(upload.id), type, size })
}
}
}

View File

@ -13,7 +13,6 @@ import { usePaidMutation } from './use-paid-mutation'
import { ACT_MUTATION } from '@/fragments/paidAction'
import { meAnonSats } from '@/lib/apollo'
import { BoostItemInput } from './adv-post-form'
import { useWallet } from '../wallets'
const defaultTips = [100, 1000, 10_000, 100_000]
@ -251,12 +250,12 @@ export function useAct ({ query = ACT_MUTATION, ...options } = {}) {
}
export function useZap () {
const wallet = useWallet()
const act = useAct()
const { me } = useMe()
const strike = useLightning()
const toaster = useToast()
return useCallback(async ({ item, me, abortSignal }) => {
return useCallback(async ({ item, abortSignal }) => {
const meSats = (item?.meSats || 0)
// add current sats to next tip since idempotent zaps use desired total zap not difference
@ -268,8 +267,7 @@ export function useZap () {
try {
await abortSignal.pause({ me, amount: sats })
strike()
// batch zaps if wallet is enabled or using fee credits so they can be executed serially in a single request
const { error } = await act({ variables, optimisticResponse, context: { batch: !!wallet || me?.privates?.sats > sats } })
const { error } = await act({ variables, optimisticResponse })
if (error) throw error
} catch (error) {
if (error instanceof ActCanceledError) {
@ -279,7 +277,7 @@ export function useZap () {
const reason = error?.message || error?.toString?.()
toaster.danger(reason)
}
}, [act, toaster, strike, !!wallet])
}, [act, me?.id, strike])
}
export class ActCanceledError extends Error {

View File

@ -65,29 +65,6 @@ export default function ItemInfo ({
const meSats = (me ? item.meSats : item.meAnonSats) || 0
const EditInfo = () => {
if (canEdit) {
return (
<>
<span> \ </span>
<span
className='text-reset pointer fw-bold'
onClick={() => onEdit ? onEdit() : router.push(`/items/${item.id}/edit`)}
>
<span>{editText || 'edit'} </span>
{(!item.invoice?.actionState || item.invoice?.actionState === 'PAID') &&
<Countdown
date={editThreshold}
onComplete={() => { setCanEdit(false) }}
/>}
</span>
</>
)
}
return null
}
const PaymentInfo = () => {
const waitForQrPayment = useQrPayment()
if (item.deletedAt) return null
@ -113,6 +90,18 @@ export default function ItemInfo ({
)
onClick = () => waitForQrPayment({ id: item.invoice?.id }, null, { cancelOnClose: false }).catch(console.error)
}
} else if (canEdit) {
Component = () => (
<>
<span>{editText || 'edit'} </span>
<Countdown
date={editThreshold}
onComplete={() => {
setCanEdit(false)
}}
/>
</>)
onClick = () => onEdit ? onEdit() : router.push(`/items/${item.id}/edit`)
} else {
return null
}
@ -218,7 +207,6 @@ export default function ItemInfo ({
showActionDropdown &&
<>
<EditInfo />
<PaymentInfo />
<ActionDropdown>
<CopyLinkDropdownItem item={item} />
<InfoDropdownItem item={item} />

View File

@ -5,7 +5,6 @@ import Link from 'next/link'
import { LoginButtons, LogoutDropdownItem, NavWalletSummary } from '../common'
import AnonIcon from '@/svgs/spy-fill.svg'
import styles from './footer.module.css'
import canvasStyles from './offcanvas.module.css'
import classNames from 'classnames'
export default function OffCanvas ({ me, dropNavKey }) {
@ -29,7 +28,7 @@ export default function OffCanvas ({ me, dropNavKey }) {
<>
<MeImage onClick={handleShow} />
<Offcanvas className={canvasStyles.offcanvas} show={show} onHide={handleClose} placement='end'>
<Offcanvas style={{ maxWidth: '250px', zIndex: '10000' }} show={show} onHide={handleClose} placement='end'>
<Offcanvas.Header closeButton>
<Offcanvas.Title><NavWalletSummary /></Offcanvas.Title>
</Offcanvas.Header>

View File

@ -1,15 +0,0 @@
.offcanvas {
max-width: 250px;
z-index: 10000;
right: -100%;
animation: slide ease-out 0.2s;
}
@keyframes slide {
0% {
transform: translateX(100%);
}
100% {
transform: translateX(0%)
}
}

View File

@ -1,27 +1,13 @@
.toastContainer {
transform: translate3d(0, 0, 0);
display: grid;
}
.toast {
font-size: small;
width: fit-content;
justify-self: right;
width: auto;
color: #fff;
bottom: -100%;
border-width: 1px;
border-style: solid;
text-overflow: ellipsis;
animation: slide ease-out 0.2s;
}
@keyframes slide {
0% {
transform: translateY(100%);
}
100% {
transform: translateY(0%)
}
}
.success {
@ -84,3 +70,9 @@
.toastClose:hover {
opacity: 0.7;
}
@media screen and (min-width: 400px) {
.toast {
width: var(--bs-toast-max-width);
}
}

View File

@ -1,5 +1,4 @@
import { ApolloClient, InMemoryCache, HttpLink, makeVar, split } from '@apollo/client'
import { BatchHttpLink } from '@apollo/client/link/batch-http'
import { ApolloClient, InMemoryCache, HttpLink, makeVar } from '@apollo/client'
import { decodeCursor, LIMIT } from './cursor'
import { SSR } from './constants'
@ -29,15 +28,8 @@ export default function getApolloClient () {
export const meAnonSats = {}
function getClient (uri) {
const link = split(
// batch zaps if wallet is enabled so they can be executed serially in a single request
operation => operation.operationName === 'act' && operation.variables.act === 'TIP' && operation.getContext().batch,
new BatchHttpLink({ uri, batchInterval: 1000, batchDebounce: true, batchMax: 0, batchKey: op => op.variables.id }),
new HttpLink({ uri })
)
return new ApolloClient({
link,
link: new HttpLink({ uri }),
ssrMode: SSR,
connectToDevTools: process.env.NODE_ENV !== 'production',
cache: new InMemoryCache({

View File

@ -16,7 +16,6 @@ const apolloServer = new ApolloServer({
typeDefs,
resolvers,
introspection: true,
allowBatchedHttpRequests: true,
plugins: [{
requestDidStart (initialRequestContext) {
return {

View File

@ -1,2 +0,0 @@
-- CreateIndex
CREATE INDEX "Item_boost_idx" ON "Item"("boost");

View File

@ -532,7 +532,6 @@ model Item {
@@index([invoiceActionState])
@@index([cost])
@@index([url])
@@index([boost])
}
// we use this to denormalize a user's aggregated interactions (zaps) with an item