From faaa30ac50dd90585d0b1cd017d11d7b9537b24e Mon Sep 17 00:00:00 2001 From: keyan Date: Thu, 20 Jan 2022 17:23:21 -0600 Subject: [PATCH] optimistic response on tip --- components/upvote.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/components/upvote.js b/components/upvote.js index b32fd4a0..0d7ed10d 100644 --- a/components/upvote.js +++ b/components/upvote.js @@ -62,7 +62,6 @@ const TipPopover = ({ target, show, handleClose }) => ( export default function UpVote ({ item, className }) { const { setError } = useFundError() const { setItem } = useItemAct() - const [voteLock, setVoteLock] = useState() const [voteShow, _setVoteShow] = useState(false) const [tipShow, _setTipShow] = useState(false) const ref = useRef() @@ -149,7 +148,7 @@ export default function UpVote ({ item, className }) { { - if (!item || voteLock) return + if (!item) return // we can't tip ourselves if (item?.mine) { @@ -163,7 +162,7 @@ export default function UpVote ({ item, className }) { onShortPress={ me ? async (e) => { - if (!item || voteLock) return + if (!item) return // we can't tip ourselves if (item?.mine) { @@ -177,16 +176,22 @@ export default function UpVote ({ item, className }) { strike() try { - setVoteLock(true) - await act({ variables: { id: item.id, sats: me.tipDefault || 1 } }) + await act({ + variables: { id: item.id, sats: me.tipDefault || 1 }, + optimisticResponse: { + act: { + id: `Item:${item.id}`, + sats: me.tipDefault || 1, + vote: 0 + } + } + }) } catch (error) { if (error.toString().includes('insufficient funds')) { setError(true) return } throw new Error({ message: error.toString() }) - } finally { - setVoteLock(false) } } : signIn