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:
parent
9cb657ab9a
commit
38f2aa309d
|
@ -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)
|
||||
|
|
|
@ -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 (
|
||||
|
|
Loading…
Reference in New Issue