2021-12-05 17:37:55 +00:00
|
|
|
import UpBolt from '../svgs/bolt.svg'
|
2021-04-22 22:14:32 +00:00
|
|
|
import styles from './upvote.module.css'
|
2021-04-26 21:55:15 +00:00
|
|
|
import { gql, useMutation } from '@apollo/client'
|
2021-07-08 18:42:57 +00:00
|
|
|
import ActionTooltip from './action-tooltip'
|
2023-01-10 23:13:37 +00:00
|
|
|
import ItemAct from './item-act'
|
2021-09-12 16:55:38 +00:00
|
|
|
import { useMe } from './me'
|
2021-12-13 19:49:34 +00:00
|
|
|
import Rainbow from '../lib/rainbow'
|
2023-10-06 20:01:51 +00:00
|
|
|
import { useCallback, useMemo, useRef, useState } from 'react'
|
2021-10-30 16:52:24 +00:00
|
|
|
import LongPressable from 'react-longpressable'
|
2023-07-24 18:35:05 +00:00
|
|
|
import Overlay from 'react-bootstrap/Overlay'
|
|
|
|
import Popover from 'react-bootstrap/Popover'
|
2023-01-10 23:13:37 +00:00
|
|
|
import { useShowModal } from './modal'
|
Allow zapping, posting and commenting without funds or an account (#336)
* Add anon zaps
* Add anon comments and posts (link, discussion, poll)
* Use payment hash instead of invoice id as proof of payment
Our invoice IDs can be enumerated.
So there is a - even though very rare - chance that an attacker could find a paid invoice which is not used yet and use it for himself.
Random payment hashes prevent this.
Also, since we delete invoices after use, using database IDs as proof of payments are not suitable.
If a user tells us an invoice ID after we deleted it, we can no longer tell if the invoice was paid or not since the LN node only knows about payment hashes but nothing about the database IDs.
* Allow pay per invoice for stackers
The modal which pops up if the stacker does not have enough sats now has two options: "fund wallet" and "pay invoice"
* Fix onSuccess called twice
For some reason, when calling `showModal`, `useMemo` in modal.js and the code for the modal component (here: <Invoice>) is called twice.
This leads to the `onSuccess` callback being called twice and one failing since the first one deletes the invoice.
* Keep invoice modal open if focus is lost
* Skip anon user during trust calculation
* Add error handling
* Skip 'invoice not found' errors
* Remove duplicate insufficient funds handling
* Fix insufficient funds error detection
* Fix invoice amount for comments
* Allow pay per invoice for bounty and job posts
* Also strike on payment after short press
* Fix unexpected token 'export'
* Fix eslint
* Remove unused id param
* Fix comment copy-paste error
* Rename to useInvoiceable
* Fix unexpected token 'export'
* Fix onConfirmation called at every render
* Add invoice HMAC
This prevents entities which know the invoice hash (like all LN nodes on the payment path) from using the invoice hash on SN.
Only the user which created the invoice knows the HMAC and thus can use the invoice hash.
* make anon posting less hidden, add anon info button explainer
* Fix anon users can't zap other anon users
* Always show repeat and contacts on action error
* Keep track of modal stack
* give anon an icon
* add generic date pivot helper
* make anon user's invoices expire in 5 minutes
* fix forgotten find and replace
* use datePivot more places
* add sat amounts to invoices
* reduce anon invoice expiration to 3 minutes
* don't abbreviate
* Fix [object Object] as error message
Any errors thrown here are already objects of shape { message: string }
* Fix empty invoice creation attempts
I stumbled across this while checking if anons can edit their items.
I monkey patched the code to make it possible (so they can see the 'edit' button) and tried to edit an item but I got this error:
Variable "$amount" of required type "Int!" was not provided.
I fixed this even though this function should never be called without an amount anyway. It will return a sane error in that case now.
* anon func mods, e.g. inv limits
* anon tips should be denormalized
* remove redundant meTotalSats
* correct overlay zap text for anon
* exclude anon from trust graph before algo runs
* remove balance limit on anon
* give anon a bio and remove cowboy hat/top stackers;
* make anon hat appear on profile
* concat hash and hmac and call it a token
* Fix localStorage cleared because error were swallowed
* fix qr layout shift
* restyle fund error modal
* Catch invoice errors in fund error modal
* invoice check backoff
* anon info typo
* make invoice expiration times have saner defaults
* add comma to anon info
* use builtin copy input label
---------
Co-authored-by: ekzyis <ek@stacker.news>
Co-authored-by: keyan <keyan.kousha+huumn@gmail.com>
2023-08-11 23:50:57 +00:00
|
|
|
import { LightningConsumer, useLightning } from './lightning'
|
2023-08-08 22:15:30 +00:00
|
|
|
import { numWithUnits } from '../lib/format'
|
2023-10-06 20:01:51 +00:00
|
|
|
import { payOrLoginError, useInvoiceModal } from './invoice'
|
|
|
|
import useDebounceCallback from './use-debounce-callback'
|
2021-12-09 20:40:40 +00:00
|
|
|
|
|
|
|
const getColor = (meSats) => {
|
|
|
|
if (!meSats || meSats <= 10) {
|
2023-07-24 18:35:05 +00:00
|
|
|
return 'var(--bs-secondary)'
|
2021-12-09 20:40:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const idx = Math.min(
|
2021-12-13 19:49:34 +00:00
|
|
|
Math.floor((Math.log(meSats) / Math.log(10000)) * (Rainbow.length - 1)),
|
2021-12-09 20:40:40 +00:00
|
|
|
Rainbow.length - 1)
|
|
|
|
return Rainbow[idx]
|
|
|
|
}
|
|
|
|
|
2022-04-12 21:09:12 +00:00
|
|
|
const UpvotePopover = ({ target, show, handleClose }) => {
|
|
|
|
const me = useMe()
|
|
|
|
return (
|
|
|
|
<Overlay
|
|
|
|
show={show}
|
|
|
|
target={target}
|
|
|
|
placement='right'
|
|
|
|
>
|
|
|
|
<Popover id='popover-basic'>
|
2023-08-26 00:03:02 +00:00
|
|
|
<Popover.Header className='d-flex justify-content-between alert-dismissible' as='h4'>Zapping
|
|
|
|
<button type='button' className='btn-close' onClick={handleClose}><span className='visually-hidden-focusable'>Close alert</span></button>
|
|
|
|
</Popover.Header>
|
2023-07-24 18:35:05 +00:00
|
|
|
<Popover.Body>
|
2023-06-19 18:21:55 +00:00
|
|
|
<div className='mb-2'>Press the bolt again to zap {me?.tipDefault || 1} more sat{me?.tipDefault > 1 ? 's' : ''}.</div>
|
|
|
|
<div>Repeatedly press the bolt to zap more sats.</div>
|
2023-07-24 18:35:05 +00:00
|
|
|
</Popover.Body>
|
2022-04-12 21:09:12 +00:00
|
|
|
</Popover>
|
|
|
|
</Overlay>
|
|
|
|
)
|
|
|
|
}
|
2021-12-09 20:40:40 +00:00
|
|
|
|
|
|
|
const TipPopover = ({ target, show, handleClose }) => (
|
|
|
|
<Overlay
|
|
|
|
show={show}
|
|
|
|
target={target}
|
|
|
|
placement='right'
|
|
|
|
>
|
|
|
|
<Popover id='popover-basic'>
|
2023-08-26 00:03:02 +00:00
|
|
|
<Popover.Header className='d-flex justify-content-between alert-dismissible' as='h4'>Press and hold
|
|
|
|
<button type='button' className='btn-close' onClick={handleClose}><span className='visually-hidden-focusable'>Close alert</span></button>
|
|
|
|
</Popover.Header>
|
2023-07-24 18:35:05 +00:00
|
|
|
<Popover.Body>
|
2023-06-19 18:21:55 +00:00
|
|
|
<div className='mb-2'>Press and hold bolt to zap a custom amount.</div>
|
|
|
|
<div>As you zap more, the bolt color follows the rainbow.</div>
|
2023-07-24 18:35:05 +00:00
|
|
|
</Popover.Body>
|
2021-12-09 20:40:40 +00:00
|
|
|
</Popover>
|
|
|
|
</Overlay>
|
|
|
|
)
|
2021-04-26 21:55:15 +00:00
|
|
|
|
2023-07-09 16:15:46 +00:00
|
|
|
export default function UpVote ({ item, className, pendingSats, setPendingSats }) {
|
2023-01-10 23:13:37 +00:00
|
|
|
const showModal = useShowModal()
|
2021-12-09 20:40:40 +00:00
|
|
|
const [voteShow, _setVoteShow] = useState(false)
|
|
|
|
const [tipShow, _setTipShow] = useState(false)
|
|
|
|
const ref = useRef()
|
2021-09-12 16:55:38 +00:00
|
|
|
const me = useMe()
|
Allow zapping, posting and commenting without funds or an account (#336)
* Add anon zaps
* Add anon comments and posts (link, discussion, poll)
* Use payment hash instead of invoice id as proof of payment
Our invoice IDs can be enumerated.
So there is a - even though very rare - chance that an attacker could find a paid invoice which is not used yet and use it for himself.
Random payment hashes prevent this.
Also, since we delete invoices after use, using database IDs as proof of payments are not suitable.
If a user tells us an invoice ID after we deleted it, we can no longer tell if the invoice was paid or not since the LN node only knows about payment hashes but nothing about the database IDs.
* Allow pay per invoice for stackers
The modal which pops up if the stacker does not have enough sats now has two options: "fund wallet" and "pay invoice"
* Fix onSuccess called twice
For some reason, when calling `showModal`, `useMemo` in modal.js and the code for the modal component (here: <Invoice>) is called twice.
This leads to the `onSuccess` callback being called twice and one failing since the first one deletes the invoice.
* Keep invoice modal open if focus is lost
* Skip anon user during trust calculation
* Add error handling
* Skip 'invoice not found' errors
* Remove duplicate insufficient funds handling
* Fix insufficient funds error detection
* Fix invoice amount for comments
* Allow pay per invoice for bounty and job posts
* Also strike on payment after short press
* Fix unexpected token 'export'
* Fix eslint
* Remove unused id param
* Fix comment copy-paste error
* Rename to useInvoiceable
* Fix unexpected token 'export'
* Fix onConfirmation called at every render
* Add invoice HMAC
This prevents entities which know the invoice hash (like all LN nodes on the payment path) from using the invoice hash on SN.
Only the user which created the invoice knows the HMAC and thus can use the invoice hash.
* make anon posting less hidden, add anon info button explainer
* Fix anon users can't zap other anon users
* Always show repeat and contacts on action error
* Keep track of modal stack
* give anon an icon
* add generic date pivot helper
* make anon user's invoices expire in 5 minutes
* fix forgotten find and replace
* use datePivot more places
* add sat amounts to invoices
* reduce anon invoice expiration to 3 minutes
* don't abbreviate
* Fix [object Object] as error message
Any errors thrown here are already objects of shape { message: string }
* Fix empty invoice creation attempts
I stumbled across this while checking if anons can edit their items.
I monkey patched the code to make it possible (so they can see the 'edit' button) and tried to edit an item but I got this error:
Variable "$amount" of required type "Int!" was not provided.
I fixed this even though this function should never be called without an amount anyway. It will return a sane error in that case now.
* anon func mods, e.g. inv limits
* anon tips should be denormalized
* remove redundant meTotalSats
* correct overlay zap text for anon
* exclude anon from trust graph before algo runs
* remove balance limit on anon
* give anon a bio and remove cowboy hat/top stackers;
* make anon hat appear on profile
* concat hash and hmac and call it a token
* Fix localStorage cleared because error were swallowed
* fix qr layout shift
* restyle fund error modal
* Catch invoice errors in fund error modal
* invoice check backoff
* anon info typo
* make invoice expiration times have saner defaults
* add comma to anon info
* use builtin copy input label
---------
Co-authored-by: ekzyis <ek@stacker.news>
Co-authored-by: keyan <keyan.kousha+huumn@gmail.com>
2023-08-11 23:50:57 +00:00
|
|
|
const strike = useLightning()
|
2021-12-09 20:40:40 +00:00
|
|
|
const [setWalkthrough] = useMutation(
|
|
|
|
gql`
|
|
|
|
mutation setWalkthrough($upvotePopover: Boolean, $tipPopover: Boolean) {
|
|
|
|
setWalkthrough(upvotePopover: $upvotePopover, tipPopover: $tipPopover)
|
|
|
|
}`
|
|
|
|
)
|
|
|
|
|
2023-07-23 15:08:43 +00:00
|
|
|
const setVoteShow = useCallback((yes) => {
|
2021-12-09 20:40:40 +00:00
|
|
|
if (!me) return
|
|
|
|
|
2022-03-10 20:09:09 +00:00
|
|
|
// if they haven't seen the walkthrough and they have sats
|
|
|
|
if (yes && !me.upvotePopover && me.sats) {
|
|
|
|
_setVoteShow(true)
|
2021-12-09 20:40:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (voteShow && !yes) {
|
2022-03-10 20:09:09 +00:00
|
|
|
_setVoteShow(false)
|
2021-12-09 20:40:40 +00:00
|
|
|
setWalkthrough({ variables: { upvotePopover: true } })
|
|
|
|
}
|
2023-07-23 15:08:43 +00:00
|
|
|
}, [me, voteShow, setWalkthrough])
|
2021-12-09 20:40:40 +00:00
|
|
|
|
2023-07-23 15:08:43 +00:00
|
|
|
const setTipShow = useCallback((yes) => {
|
2021-12-09 20:40:40 +00:00
|
|
|
if (!me) return
|
|
|
|
|
|
|
|
// if we want to show it, yet we still haven't shown
|
2022-03-10 20:09:09 +00:00
|
|
|
if (yes && !me.tipPopover && me.sats) {
|
|
|
|
_setTipShow(true)
|
2021-12-09 20:40:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// if it's currently showing and we want to hide it
|
|
|
|
if (tipShow && !yes) {
|
2022-03-10 20:09:09 +00:00
|
|
|
_setTipShow(false)
|
2021-12-09 20:40:40 +00:00
|
|
|
setWalkthrough({ variables: { tipPopover: true } })
|
|
|
|
}
|
2023-07-23 15:08:43 +00:00
|
|
|
}, [me, tipShow, setWalkthrough])
|
2021-12-09 20:40:40 +00:00
|
|
|
|
2021-09-08 21:51:23 +00:00
|
|
|
const [act] = useMutation(
|
2021-04-26 21:55:15 +00:00
|
|
|
gql`
|
2023-08-31 02:48:49 +00:00
|
|
|
mutation act($id: ID!, $sats: Int!, $hash: String, $hmac: String) {
|
|
|
|
act(id: $id, sats: $sats, hash: $hash, hmac: $hmac) {
|
2021-09-10 21:13:52 +00:00
|
|
|
sats
|
|
|
|
}
|
2021-04-26 21:55:15 +00:00
|
|
|
}`, {
|
2023-07-09 16:15:46 +00:00
|
|
|
update (cache, { data: { act: { sats } } }) {
|
2021-04-26 21:55:15 +00:00
|
|
|
cache.modify({
|
2021-09-10 21:13:52 +00:00
|
|
|
id: `Item:${item.id}`,
|
2021-04-26 21:55:15 +00:00
|
|
|
fields: {
|
|
|
|
sats (existingSats = 0) {
|
2022-01-20 23:04:12 +00:00
|
|
|
return existingSats + sats
|
2021-04-27 21:30:58 +00:00
|
|
|
},
|
Allow zapping, posting and commenting without funds or an account (#336)
* Add anon zaps
* Add anon comments and posts (link, discussion, poll)
* Use payment hash instead of invoice id as proof of payment
Our invoice IDs can be enumerated.
So there is a - even though very rare - chance that an attacker could find a paid invoice which is not used yet and use it for himself.
Random payment hashes prevent this.
Also, since we delete invoices after use, using database IDs as proof of payments are not suitable.
If a user tells us an invoice ID after we deleted it, we can no longer tell if the invoice was paid or not since the LN node only knows about payment hashes but nothing about the database IDs.
* Allow pay per invoice for stackers
The modal which pops up if the stacker does not have enough sats now has two options: "fund wallet" and "pay invoice"
* Fix onSuccess called twice
For some reason, when calling `showModal`, `useMemo` in modal.js and the code for the modal component (here: <Invoice>) is called twice.
This leads to the `onSuccess` callback being called twice and one failing since the first one deletes the invoice.
* Keep invoice modal open if focus is lost
* Skip anon user during trust calculation
* Add error handling
* Skip 'invoice not found' errors
* Remove duplicate insufficient funds handling
* Fix insufficient funds error detection
* Fix invoice amount for comments
* Allow pay per invoice for bounty and job posts
* Also strike on payment after short press
* Fix unexpected token 'export'
* Fix eslint
* Remove unused id param
* Fix comment copy-paste error
* Rename to useInvoiceable
* Fix unexpected token 'export'
* Fix onConfirmation called at every render
* Add invoice HMAC
This prevents entities which know the invoice hash (like all LN nodes on the payment path) from using the invoice hash on SN.
Only the user which created the invoice knows the HMAC and thus can use the invoice hash.
* make anon posting less hidden, add anon info button explainer
* Fix anon users can't zap other anon users
* Always show repeat and contacts on action error
* Keep track of modal stack
* give anon an icon
* add generic date pivot helper
* make anon user's invoices expire in 5 minutes
* fix forgotten find and replace
* use datePivot more places
* add sat amounts to invoices
* reduce anon invoice expiration to 3 minutes
* don't abbreviate
* Fix [object Object] as error message
Any errors thrown here are already objects of shape { message: string }
* Fix empty invoice creation attempts
I stumbled across this while checking if anons can edit their items.
I monkey patched the code to make it possible (so they can see the 'edit' button) and tried to edit an item but I got this error:
Variable "$amount" of required type "Int!" was not provided.
I fixed this even though this function should never be called without an amount anyway. It will return a sane error in that case now.
* anon func mods, e.g. inv limits
* anon tips should be denormalized
* remove redundant meTotalSats
* correct overlay zap text for anon
* exclude anon from trust graph before algo runs
* remove balance limit on anon
* give anon a bio and remove cowboy hat/top stackers;
* make anon hat appear on profile
* concat hash and hmac and call it a token
* Fix localStorage cleared because error were swallowed
* fix qr layout shift
* restyle fund error modal
* Catch invoice errors in fund error modal
* invoice check backoff
* anon info typo
* make invoice expiration times have saner defaults
* add comma to anon info
* use builtin copy input label
---------
Co-authored-by: ekzyis <ek@stacker.news>
Co-authored-by: keyan <keyan.kousha+huumn@gmail.com>
2023-08-11 23:50:57 +00:00
|
|
|
meSats: me
|
|
|
|
? (existingSats = 0) => {
|
|
|
|
if (sats <= me.sats) {
|
|
|
|
if (existingSats === 0) {
|
|
|
|
setVoteShow(true)
|
|
|
|
} else {
|
|
|
|
setTipShow(true)
|
|
|
|
}
|
|
|
|
}
|
2023-01-10 23:13:37 +00:00
|
|
|
|
Allow zapping, posting and commenting without funds or an account (#336)
* Add anon zaps
* Add anon comments and posts (link, discussion, poll)
* Use payment hash instead of invoice id as proof of payment
Our invoice IDs can be enumerated.
So there is a - even though very rare - chance that an attacker could find a paid invoice which is not used yet and use it for himself.
Random payment hashes prevent this.
Also, since we delete invoices after use, using database IDs as proof of payments are not suitable.
If a user tells us an invoice ID after we deleted it, we can no longer tell if the invoice was paid or not since the LN node only knows about payment hashes but nothing about the database IDs.
* Allow pay per invoice for stackers
The modal which pops up if the stacker does not have enough sats now has two options: "fund wallet" and "pay invoice"
* Fix onSuccess called twice
For some reason, when calling `showModal`, `useMemo` in modal.js and the code for the modal component (here: <Invoice>) is called twice.
This leads to the `onSuccess` callback being called twice and one failing since the first one deletes the invoice.
* Keep invoice modal open if focus is lost
* Skip anon user during trust calculation
* Add error handling
* Skip 'invoice not found' errors
* Remove duplicate insufficient funds handling
* Fix insufficient funds error detection
* Fix invoice amount for comments
* Allow pay per invoice for bounty and job posts
* Also strike on payment after short press
* Fix unexpected token 'export'
* Fix eslint
* Remove unused id param
* Fix comment copy-paste error
* Rename to useInvoiceable
* Fix unexpected token 'export'
* Fix onConfirmation called at every render
* Add invoice HMAC
This prevents entities which know the invoice hash (like all LN nodes on the payment path) from using the invoice hash on SN.
Only the user which created the invoice knows the HMAC and thus can use the invoice hash.
* make anon posting less hidden, add anon info button explainer
* Fix anon users can't zap other anon users
* Always show repeat and contacts on action error
* Keep track of modal stack
* give anon an icon
* add generic date pivot helper
* make anon user's invoices expire in 5 minutes
* fix forgotten find and replace
* use datePivot more places
* add sat amounts to invoices
* reduce anon invoice expiration to 3 minutes
* don't abbreviate
* Fix [object Object] as error message
Any errors thrown here are already objects of shape { message: string }
* Fix empty invoice creation attempts
I stumbled across this while checking if anons can edit their items.
I monkey patched the code to make it possible (so they can see the 'edit' button) and tried to edit an item but I got this error:
Variable "$amount" of required type "Int!" was not provided.
I fixed this even though this function should never be called without an amount anyway. It will return a sane error in that case now.
* anon func mods, e.g. inv limits
* anon tips should be denormalized
* remove redundant meTotalSats
* correct overlay zap text for anon
* exclude anon from trust graph before algo runs
* remove balance limit on anon
* give anon a bio and remove cowboy hat/top stackers;
* make anon hat appear on profile
* concat hash and hmac and call it a token
* Fix localStorage cleared because error were swallowed
* fix qr layout shift
* restyle fund error modal
* Catch invoice errors in fund error modal
* invoice check backoff
* anon info typo
* make invoice expiration times have saner defaults
* add comma to anon info
* use builtin copy input label
---------
Co-authored-by: ekzyis <ek@stacker.news>
Co-authored-by: keyan <keyan.kousha+huumn@gmail.com>
2023-08-11 23:50:57 +00:00
|
|
|
return existingSats + sats
|
|
|
|
}
|
|
|
|
: undefined
|
2021-04-26 21:55:15 +00:00
|
|
|
}
|
|
|
|
})
|
2022-09-01 21:53:39 +00:00
|
|
|
|
|
|
|
// update all ancestors
|
|
|
|
item.path.split('.').forEach(id => {
|
|
|
|
if (Number(id) === Number(item.id)) return
|
|
|
|
cache.modify({
|
|
|
|
id: `Item:${id}`,
|
|
|
|
fields: {
|
|
|
|
commentSats (existingCommentSats = 0) {
|
|
|
|
return existingCommentSats + sats
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
2021-04-26 21:55:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2023-10-06 20:01:51 +00:00
|
|
|
const showInvoiceModal = useInvoiceModal(
|
|
|
|
async ({ hash, hmac }, { variables }) => {
|
|
|
|
await act({ variables: { ...variables, hash, hmac } })
|
|
|
|
strike()
|
|
|
|
}, [act, strike])
|
|
|
|
|
|
|
|
const zap = useDebounceCallback(async (sats) => {
|
|
|
|
if (!sats) return
|
|
|
|
const variables = { id: item.id, sats }
|
|
|
|
try {
|
|
|
|
setPendingSats(0)
|
|
|
|
await act({
|
|
|
|
variables,
|
|
|
|
optimisticResponse: {
|
|
|
|
act: {
|
|
|
|
sats
|
2023-07-11 18:33:13 +00:00
|
|
|
}
|
2023-07-09 16:15:46 +00:00
|
|
|
}
|
2023-10-06 20:01:51 +00:00
|
|
|
})
|
|
|
|
} catch (error) {
|
|
|
|
if (payOrLoginError(error)) {
|
|
|
|
showInvoiceModal({ amount: sats }, { variables })
|
|
|
|
return
|
|
|
|
}
|
|
|
|
throw new Error({ message: error.toString() })
|
2023-07-11 18:33:13 +00:00
|
|
|
}
|
2023-10-06 20:01:51 +00:00
|
|
|
}, 500, [act, item?.id, showInvoiceModal, setPendingSats])
|
2023-07-09 16:15:46 +00:00
|
|
|
|
2023-08-28 14:40:29 +00:00
|
|
|
const disabled = useMemo(() => item?.mine || item?.meForward || item?.deletedAt,
|
|
|
|
[item?.mine, item?.meForward, item?.deletedAt])
|
2023-07-09 16:15:46 +00:00
|
|
|
|
2023-07-11 18:33:13 +00:00
|
|
|
const [meSats, sats, overlayText, color] = useMemo(() => {
|
Allow zapping, posting and commenting without funds or an account (#336)
* Add anon zaps
* Add anon comments and posts (link, discussion, poll)
* Use payment hash instead of invoice id as proof of payment
Our invoice IDs can be enumerated.
So there is a - even though very rare - chance that an attacker could find a paid invoice which is not used yet and use it for himself.
Random payment hashes prevent this.
Also, since we delete invoices after use, using database IDs as proof of payments are not suitable.
If a user tells us an invoice ID after we deleted it, we can no longer tell if the invoice was paid or not since the LN node only knows about payment hashes but nothing about the database IDs.
* Allow pay per invoice for stackers
The modal which pops up if the stacker does not have enough sats now has two options: "fund wallet" and "pay invoice"
* Fix onSuccess called twice
For some reason, when calling `showModal`, `useMemo` in modal.js and the code for the modal component (here: <Invoice>) is called twice.
This leads to the `onSuccess` callback being called twice and one failing since the first one deletes the invoice.
* Keep invoice modal open if focus is lost
* Skip anon user during trust calculation
* Add error handling
* Skip 'invoice not found' errors
* Remove duplicate insufficient funds handling
* Fix insufficient funds error detection
* Fix invoice amount for comments
* Allow pay per invoice for bounty and job posts
* Also strike on payment after short press
* Fix unexpected token 'export'
* Fix eslint
* Remove unused id param
* Fix comment copy-paste error
* Rename to useInvoiceable
* Fix unexpected token 'export'
* Fix onConfirmation called at every render
* Add invoice HMAC
This prevents entities which know the invoice hash (like all LN nodes on the payment path) from using the invoice hash on SN.
Only the user which created the invoice knows the HMAC and thus can use the invoice hash.
* make anon posting less hidden, add anon info button explainer
* Fix anon users can't zap other anon users
* Always show repeat and contacts on action error
* Keep track of modal stack
* give anon an icon
* add generic date pivot helper
* make anon user's invoices expire in 5 minutes
* fix forgotten find and replace
* use datePivot more places
* add sat amounts to invoices
* reduce anon invoice expiration to 3 minutes
* don't abbreviate
* Fix [object Object] as error message
Any errors thrown here are already objects of shape { message: string }
* Fix empty invoice creation attempts
I stumbled across this while checking if anons can edit their items.
I monkey patched the code to make it possible (so they can see the 'edit' button) and tried to edit an item but I got this error:
Variable "$amount" of required type "Int!" was not provided.
I fixed this even though this function should never be called without an amount anyway. It will return a sane error in that case now.
* anon func mods, e.g. inv limits
* anon tips should be denormalized
* remove redundant meTotalSats
* correct overlay zap text for anon
* exclude anon from trust graph before algo runs
* remove balance limit on anon
* give anon a bio and remove cowboy hat/top stackers;
* make anon hat appear on profile
* concat hash and hmac and call it a token
* Fix localStorage cleared because error were swallowed
* fix qr layout shift
* restyle fund error modal
* Catch invoice errors in fund error modal
* invoice check backoff
* anon info typo
* make invoice expiration times have saner defaults
* add comma to anon info
* use builtin copy input label
---------
Co-authored-by: ekzyis <ek@stacker.news>
Co-authored-by: keyan <keyan.kousha+huumn@gmail.com>
2023-08-11 23:50:57 +00:00
|
|
|
const meSats = (item?.meSats || item?.meAnonSats || 0) + pendingSats
|
2022-12-09 19:25:38 +00:00
|
|
|
|
2023-07-11 18:33:13 +00:00
|
|
|
// what should our next tip be?
|
|
|
|
let sats = me?.tipDefault || 1
|
Allow zapping, posting and commenting without funds or an account (#336)
* Add anon zaps
* Add anon comments and posts (link, discussion, poll)
* Use payment hash instead of invoice id as proof of payment
Our invoice IDs can be enumerated.
So there is a - even though very rare - chance that an attacker could find a paid invoice which is not used yet and use it for himself.
Random payment hashes prevent this.
Also, since we delete invoices after use, using database IDs as proof of payments are not suitable.
If a user tells us an invoice ID after we deleted it, we can no longer tell if the invoice was paid or not since the LN node only knows about payment hashes but nothing about the database IDs.
* Allow pay per invoice for stackers
The modal which pops up if the stacker does not have enough sats now has two options: "fund wallet" and "pay invoice"
* Fix onSuccess called twice
For some reason, when calling `showModal`, `useMemo` in modal.js and the code for the modal component (here: <Invoice>) is called twice.
This leads to the `onSuccess` callback being called twice and one failing since the first one deletes the invoice.
* Keep invoice modal open if focus is lost
* Skip anon user during trust calculation
* Add error handling
* Skip 'invoice not found' errors
* Remove duplicate insufficient funds handling
* Fix insufficient funds error detection
* Fix invoice amount for comments
* Allow pay per invoice for bounty and job posts
* Also strike on payment after short press
* Fix unexpected token 'export'
* Fix eslint
* Remove unused id param
* Fix comment copy-paste error
* Rename to useInvoiceable
* Fix unexpected token 'export'
* Fix onConfirmation called at every render
* Add invoice HMAC
This prevents entities which know the invoice hash (like all LN nodes on the payment path) from using the invoice hash on SN.
Only the user which created the invoice knows the HMAC and thus can use the invoice hash.
* make anon posting less hidden, add anon info button explainer
* Fix anon users can't zap other anon users
* Always show repeat and contacts on action error
* Keep track of modal stack
* give anon an icon
* add generic date pivot helper
* make anon user's invoices expire in 5 minutes
* fix forgotten find and replace
* use datePivot more places
* add sat amounts to invoices
* reduce anon invoice expiration to 3 minutes
* don't abbreviate
* Fix [object Object] as error message
Any errors thrown here are already objects of shape { message: string }
* Fix empty invoice creation attempts
I stumbled across this while checking if anons can edit their items.
I monkey patched the code to make it possible (so they can see the 'edit' button) and tried to edit an item but I got this error:
Variable "$amount" of required type "Int!" was not provided.
I fixed this even though this function should never be called without an amount anyway. It will return a sane error in that case now.
* anon func mods, e.g. inv limits
* anon tips should be denormalized
* remove redundant meTotalSats
* correct overlay zap text for anon
* exclude anon from trust graph before algo runs
* remove balance limit on anon
* give anon a bio and remove cowboy hat/top stackers;
* make anon hat appear on profile
* concat hash and hmac and call it a token
* Fix localStorage cleared because error were swallowed
* fix qr layout shift
* restyle fund error modal
* Catch invoice errors in fund error modal
* invoice check backoff
* anon info typo
* make invoice expiration times have saner defaults
* add comma to anon info
* use builtin copy input label
---------
Co-authored-by: ekzyis <ek@stacker.news>
Co-authored-by: keyan <keyan.kousha+huumn@gmail.com>
2023-08-11 23:50:57 +00:00
|
|
|
if (me?.turboTipping) {
|
2023-07-11 18:33:13 +00:00
|
|
|
let raiseTip = sats
|
|
|
|
while (meSats >= raiseTip) {
|
|
|
|
raiseTip *= 10
|
|
|
|
}
|
2022-12-09 19:25:38 +00:00
|
|
|
|
2023-07-11 18:33:13 +00:00
|
|
|
sats = raiseTip - meSats
|
|
|
|
}
|
2021-09-12 16:55:38 +00:00
|
|
|
|
Allow zapping, posting and commenting without funds or an account (#336)
* Add anon zaps
* Add anon comments and posts (link, discussion, poll)
* Use payment hash instead of invoice id as proof of payment
Our invoice IDs can be enumerated.
So there is a - even though very rare - chance that an attacker could find a paid invoice which is not used yet and use it for himself.
Random payment hashes prevent this.
Also, since we delete invoices after use, using database IDs as proof of payments are not suitable.
If a user tells us an invoice ID after we deleted it, we can no longer tell if the invoice was paid or not since the LN node only knows about payment hashes but nothing about the database IDs.
* Allow pay per invoice for stackers
The modal which pops up if the stacker does not have enough sats now has two options: "fund wallet" and "pay invoice"
* Fix onSuccess called twice
For some reason, when calling `showModal`, `useMemo` in modal.js and the code for the modal component (here: <Invoice>) is called twice.
This leads to the `onSuccess` callback being called twice and one failing since the first one deletes the invoice.
* Keep invoice modal open if focus is lost
* Skip anon user during trust calculation
* Add error handling
* Skip 'invoice not found' errors
* Remove duplicate insufficient funds handling
* Fix insufficient funds error detection
* Fix invoice amount for comments
* Allow pay per invoice for bounty and job posts
* Also strike on payment after short press
* Fix unexpected token 'export'
* Fix eslint
* Remove unused id param
* Fix comment copy-paste error
* Rename to useInvoiceable
* Fix unexpected token 'export'
* Fix onConfirmation called at every render
* Add invoice HMAC
This prevents entities which know the invoice hash (like all LN nodes on the payment path) from using the invoice hash on SN.
Only the user which created the invoice knows the HMAC and thus can use the invoice hash.
* make anon posting less hidden, add anon info button explainer
* Fix anon users can't zap other anon users
* Always show repeat and contacts on action error
* Keep track of modal stack
* give anon an icon
* add generic date pivot helper
* make anon user's invoices expire in 5 minutes
* fix forgotten find and replace
* use datePivot more places
* add sat amounts to invoices
* reduce anon invoice expiration to 3 minutes
* don't abbreviate
* Fix [object Object] as error message
Any errors thrown here are already objects of shape { message: string }
* Fix empty invoice creation attempts
I stumbled across this while checking if anons can edit their items.
I monkey patched the code to make it possible (so they can see the 'edit' button) and tried to edit an item but I got this error:
Variable "$amount" of required type "Int!" was not provided.
I fixed this even though this function should never be called without an amount anyway. It will return a sane error in that case now.
* anon func mods, e.g. inv limits
* anon tips should be denormalized
* remove redundant meTotalSats
* correct overlay zap text for anon
* exclude anon from trust graph before algo runs
* remove balance limit on anon
* give anon a bio and remove cowboy hat/top stackers;
* make anon hat appear on profile
* concat hash and hmac and call it a token
* Fix localStorage cleared because error were swallowed
* fix qr layout shift
* restyle fund error modal
* Catch invoice errors in fund error modal
* invoice check backoff
* anon info typo
* make invoice expiration times have saner defaults
* add comma to anon info
* use builtin copy input label
---------
Co-authored-by: ekzyis <ek@stacker.news>
Co-authored-by: keyan <keyan.kousha+huumn@gmail.com>
2023-08-11 23:50:57 +00:00
|
|
|
return [meSats, sats, me ? numWithUnits(sats, { abbreviate: false }) : 'zap it', getColor(meSats)]
|
|
|
|
}, [item?.meSats, item?.meAnonSats, pendingSats, me?.tipDefault, me?.turboDefault])
|
2023-01-12 23:53:09 +00:00
|
|
|
|
2021-04-22 22:14:32 +00:00
|
|
|
return (
|
2023-07-05 14:47:44 +00:00
|
|
|
<LightningConsumer>
|
2023-07-23 15:08:43 +00:00
|
|
|
{(strike) =>
|
2022-01-20 19:03:48 +00:00
|
|
|
<div ref={ref} className='upvoteParent'>
|
2021-12-09 20:40:40 +00:00
|
|
|
<LongPressable
|
|
|
|
onLongPress={
|
2021-10-30 16:52:24 +00:00
|
|
|
async (e) => {
|
2022-01-20 23:23:21 +00:00
|
|
|
if (!item) return
|
2021-10-30 16:52:24 +00:00
|
|
|
|
|
|
|
// we can't tip ourselves
|
2023-01-12 23:53:09 +00:00
|
|
|
if (disabled) {
|
2021-10-30 16:52:24 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-12-09 20:40:40 +00:00
|
|
|
setTipShow(false)
|
2023-01-10 23:13:37 +00:00
|
|
|
showModal(onClose =>
|
|
|
|
<ItemAct onClose={onClose} itemId={item.id} act={act} strike={strike} />)
|
2021-10-30 16:52:24 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-09 20:40:40 +00:00
|
|
|
onShortPress={
|
2021-09-24 23:04:59 +00:00
|
|
|
me
|
2021-06-24 23:56:01 +00:00
|
|
|
? async (e) => {
|
2023-07-25 14:14:45 +00:00
|
|
|
if (!item) return
|
2021-09-12 16:55:38 +00:00
|
|
|
|
2023-07-25 14:14:45 +00:00
|
|
|
// we can't tip ourselves
|
|
|
|
if (disabled) {
|
|
|
|
return
|
|
|
|
}
|
2021-09-12 16:55:38 +00:00
|
|
|
|
2023-07-25 14:14:45 +00:00
|
|
|
if (meSats) {
|
|
|
|
setVoteShow(false)
|
|
|
|
}
|
2021-09-10 18:55:36 +00:00
|
|
|
|
2023-07-25 14:14:45 +00:00
|
|
|
strike()
|
2021-09-10 18:55:36 +00:00
|
|
|
|
2023-10-06 20:01:51 +00:00
|
|
|
setPendingSats(pendingSats => {
|
|
|
|
const zapAmount = pendingSats + sats
|
|
|
|
zap(zapAmount)
|
|
|
|
return zapAmount
|
|
|
|
})
|
2023-07-25 14:14:45 +00:00
|
|
|
}
|
Allow zapping, posting and commenting without funds or an account (#336)
* Add anon zaps
* Add anon comments and posts (link, discussion, poll)
* Use payment hash instead of invoice id as proof of payment
Our invoice IDs can be enumerated.
So there is a - even though very rare - chance that an attacker could find a paid invoice which is not used yet and use it for himself.
Random payment hashes prevent this.
Also, since we delete invoices after use, using database IDs as proof of payments are not suitable.
If a user tells us an invoice ID after we deleted it, we can no longer tell if the invoice was paid or not since the LN node only knows about payment hashes but nothing about the database IDs.
* Allow pay per invoice for stackers
The modal which pops up if the stacker does not have enough sats now has two options: "fund wallet" and "pay invoice"
* Fix onSuccess called twice
For some reason, when calling `showModal`, `useMemo` in modal.js and the code for the modal component (here: <Invoice>) is called twice.
This leads to the `onSuccess` callback being called twice and one failing since the first one deletes the invoice.
* Keep invoice modal open if focus is lost
* Skip anon user during trust calculation
* Add error handling
* Skip 'invoice not found' errors
* Remove duplicate insufficient funds handling
* Fix insufficient funds error detection
* Fix invoice amount for comments
* Allow pay per invoice for bounty and job posts
* Also strike on payment after short press
* Fix unexpected token 'export'
* Fix eslint
* Remove unused id param
* Fix comment copy-paste error
* Rename to useInvoiceable
* Fix unexpected token 'export'
* Fix onConfirmation called at every render
* Add invoice HMAC
This prevents entities which know the invoice hash (like all LN nodes on the payment path) from using the invoice hash on SN.
Only the user which created the invoice knows the HMAC and thus can use the invoice hash.
* make anon posting less hidden, add anon info button explainer
* Fix anon users can't zap other anon users
* Always show repeat and contacts on action error
* Keep track of modal stack
* give anon an icon
* add generic date pivot helper
* make anon user's invoices expire in 5 minutes
* fix forgotten find and replace
* use datePivot more places
* add sat amounts to invoices
* reduce anon invoice expiration to 3 minutes
* don't abbreviate
* Fix [object Object] as error message
Any errors thrown here are already objects of shape { message: string }
* Fix empty invoice creation attempts
I stumbled across this while checking if anons can edit their items.
I monkey patched the code to make it possible (so they can see the 'edit' button) and tried to edit an item but I got this error:
Variable "$amount" of required type "Int!" was not provided.
I fixed this even though this function should never be called without an amount anyway. It will return a sane error in that case now.
* anon func mods, e.g. inv limits
* anon tips should be denormalized
* remove redundant meTotalSats
* correct overlay zap text for anon
* exclude anon from trust graph before algo runs
* remove balance limit on anon
* give anon a bio and remove cowboy hat/top stackers;
* make anon hat appear on profile
* concat hash and hmac and call it a token
* Fix localStorage cleared because error were swallowed
* fix qr layout shift
* restyle fund error modal
* Catch invoice errors in fund error modal
* invoice check backoff
* anon info typo
* make invoice expiration times have saner defaults
* add comma to anon info
* use builtin copy input label
---------
Co-authored-by: ekzyis <ek@stacker.news>
Co-authored-by: keyan <keyan.kousha+huumn@gmail.com>
2023-08-11 23:50:57 +00:00
|
|
|
: () => showModal(onClose => <ItemAct onClose={onClose} itemId={item.id} act={act} strike={strike} />)
|
2021-05-20 19:41:21 +00:00
|
|
|
}
|
2021-12-09 20:40:40 +00:00
|
|
|
>
|
2023-07-11 18:33:13 +00:00
|
|
|
<ActionTooltip notForm disable={disabled} overlayText={overlayText}>
|
2021-12-09 20:40:40 +00:00
|
|
|
<div
|
2023-07-11 18:33:13 +00:00
|
|
|
className={`${disabled ? styles.noSelfTips : ''} ${styles.upvoteWrapper}`}
|
2021-12-09 20:40:40 +00:00
|
|
|
>
|
2021-12-06 15:32:33 +00:00
|
|
|
<UpBolt
|
2023-07-25 18:32:48 +00:00
|
|
|
width={26}
|
|
|
|
height={26}
|
2021-12-06 15:32:33 +00:00
|
|
|
className={
|
2021-12-09 20:40:40 +00:00
|
|
|
`${styles.upvote}
|
|
|
|
${className || ''}
|
2023-01-12 23:53:09 +00:00
|
|
|
${disabled ? styles.noSelfTips : ''}
|
2023-07-09 16:15:46 +00:00
|
|
|
${meSats ? styles.voted : ''}`
|
2021-12-09 20:40:40 +00:00
|
|
|
}
|
2023-07-09 16:15:46 +00:00
|
|
|
style={meSats
|
2021-12-06 15:32:33 +00:00
|
|
|
? {
|
|
|
|
fill: color,
|
|
|
|
filter: `drop-shadow(0 0 6px ${color}90)`
|
|
|
|
}
|
|
|
|
: undefined}
|
|
|
|
/>
|
2021-12-09 20:40:40 +00:00
|
|
|
</div>
|
|
|
|
</ActionTooltip>
|
|
|
|
</LongPressable>
|
|
|
|
<TipPopover target={ref.current} show={tipShow} handleClose={() => setTipShow(false)} />
|
|
|
|
<UpvotePopover target={ref.current} show={voteShow} handleClose={() => setVoteShow(false)} />
|
|
|
|
</div>}
|
2023-07-05 14:47:44 +00:00
|
|
|
</LightningConsumer>
|
2021-04-22 22:14:32 +00:00
|
|
|
)
|
|
|
|
}
|