Fix bolt hover ignores turbozaps (#881)

* Fix bolt hover color ignores turbo zaps

* Refactor next tip code into own function
This commit is contained in:
ekzyis 2024-02-27 01:09:09 +01:00 committed by GitHub
parent 9cb657ab9a
commit 38f2aa309d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 21 deletions

View File

@ -9,6 +9,7 @@ import { gql, useApolloClient, useMutation } from '@apollo/client'
import { payOrLoginError, useInvoiceModal } from './invoice'
import { TOAST_DEFAULT_DELAY_MS, useToast, withToastFlow } from './toast'
import { useLightning } from './lightning'
import { nextTip } from './upvote'
const defaultTips = [100, 1000, 10000, 100000]
@ -370,15 +371,8 @@ export function useZap () {
return useCallback(async ({ item, me }) => {
const meSats = (item?.meSats || 0)
// what should our next tip be?
let sats = me?.privates?.tipDefault || 1
if (me?.privates?.turboTipping) {
while (meSats >= sats) {
sats *= 10
}
} else {
sats = meSats + sats
}
// add current sats to next tip since idempotent zaps use desired total zap not difference
const sats = meSats + nextTip(meSats, { ...me?.privates })
const variables = { id: item.id, sats, act: 'TIP', amount: sats - meSats }
const insufficientFunds = me?.privates.sats < (sats - meSats)

View File

@ -67,6 +67,22 @@ export function DropdownItemUpVote ({ item }) {
)
}
export const nextTip = (meSats, { tipDefault, turboTipping }) => {
// what should our next tip be?
if (!turboTipping) return (tipDefault || 1)
let sats = tipDefault || 1
if (turboTipping) {
while (meSats >= sats) {
sats *= 10
}
// deduct current sats since turbo tipping is about total zap not making the next zap 10x
sats -= meSats
}
return sats
}
export default function UpVote ({ item, className }) {
const showModal = useShowModal()
const [voteShow, _setVoteShow] = useState(false)
@ -119,21 +135,11 @@ export default function UpVote ({ item, className }) {
const meSats = (item?.meSats || item?.meAnonSats || 0)
// what should our next tip be?
let sats = me?.privates?.tipDefault || 1
let raiseSats = sats
if (me?.privates?.turboTipping) {
while (meSats >= raiseSats) {
raiseSats *= 10
}
sats = raiseSats - meSats
} else {
raiseSats = meSats + sats
}
const sats = nextTip(meSats, { ...me?.privates })
return [
meSats, me ? numWithUnits(sats, { abbreviate: false }) : 'zap it',
getColor(meSats), getColor(meSats + (me?.privates?.tipDefault || 0))]
getColor(meSats), getColor(meSats + sats)]
}, [item?.meSats, item?.meAnonSats, me?.privates?.tipDefault, me?.privates?.turboDefault])
return (