optimistic response on tip
This commit is contained in:
parent
5d49ecc536
commit
faaa30ac50
|
@ -62,7 +62,6 @@ const TipPopover = ({ target, show, handleClose }) => (
|
||||||
export default function UpVote ({ item, className }) {
|
export default function UpVote ({ item, className }) {
|
||||||
const { setError } = useFundError()
|
const { setError } = useFundError()
|
||||||
const { setItem } = useItemAct()
|
const { setItem } = useItemAct()
|
||||||
const [voteLock, setVoteLock] = useState()
|
|
||||||
const [voteShow, _setVoteShow] = useState(false)
|
const [voteShow, _setVoteShow] = useState(false)
|
||||||
const [tipShow, _setTipShow] = useState(false)
|
const [tipShow, _setTipShow] = useState(false)
|
||||||
const ref = useRef()
|
const ref = useRef()
|
||||||
|
@ -149,7 +148,7 @@ export default function UpVote ({ item, className }) {
|
||||||
<LongPressable
|
<LongPressable
|
||||||
onLongPress={
|
onLongPress={
|
||||||
async (e) => {
|
async (e) => {
|
||||||
if (!item || voteLock) return
|
if (!item) return
|
||||||
|
|
||||||
// we can't tip ourselves
|
// we can't tip ourselves
|
||||||
if (item?.mine) {
|
if (item?.mine) {
|
||||||
|
@ -163,7 +162,7 @@ export default function UpVote ({ item, className }) {
|
||||||
onShortPress={
|
onShortPress={
|
||||||
me
|
me
|
||||||
? async (e) => {
|
? async (e) => {
|
||||||
if (!item || voteLock) return
|
if (!item) return
|
||||||
|
|
||||||
// we can't tip ourselves
|
// we can't tip ourselves
|
||||||
if (item?.mine) {
|
if (item?.mine) {
|
||||||
|
@ -177,16 +176,22 @@ export default function UpVote ({ item, className }) {
|
||||||
strike()
|
strike()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setVoteLock(true)
|
await act({
|
||||||
await act({ variables: { id: item.id, sats: me.tipDefault || 1 } })
|
variables: { id: item.id, sats: me.tipDefault || 1 },
|
||||||
|
optimisticResponse: {
|
||||||
|
act: {
|
||||||
|
id: `Item:${item.id}`,
|
||||||
|
sats: me.tipDefault || 1,
|
||||||
|
vote: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.toString().includes('insufficient funds')) {
|
if (error.toString().includes('insufficient funds')) {
|
||||||
setError(true)
|
setError(true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
throw new Error({ message: error.toString() })
|
throw new Error({ message: error.toString() })
|
||||||
} finally {
|
|
||||||
setVoteLock(false)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
: signIn
|
: signIn
|
||||||
|
|
Loading…
Reference in New Issue