better random zaps
This commit is contained in:
parent
0c3337fb97
commit
5d0e071939
@ -67,29 +67,39 @@ export function DropdownItemUpVote ({ item }) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const defaultTipIncludingRandom = ({ tipDefault, tipRandom, tipRandomMin, tipRandomMax } = {}) =>
|
export const defaultTipIncludingRandom = ({ tipDefault, tipRandom, tipRandomMin, tipRandomMax } = {}) => {
|
||||||
tipRandom
|
return tipRandom
|
||||||
? Math.floor((Math.random() * (tipRandomMax - tipRandomMin)) + tipRandomMin)
|
? Math.floor((Math.random() * (tipRandomMax - tipRandomMin + 1)) + tipRandomMin)
|
||||||
: (tipDefault || 100)
|
: (tipDefault || 100)
|
||||||
|
}
|
||||||
|
|
||||||
export const nextTip = (meSats, { tipDefault, turboTipping, tipRandom, tipRandomMin, tipRandomMax }) => {
|
export const nextTip = (meSats, { tipDefault, turboTipping, tipRandom, tipRandomMin, tipRandomMax }) => {
|
||||||
// what should our next tip be?
|
if (turboTipping) {
|
||||||
const calculatedDefault = defaultTipIncludingRandom({ tipDefault, tipRandom, tipRandomMin, tipRandomMax })
|
if (tipRandom) {
|
||||||
|
let pow = 0
|
||||||
if (!turboTipping) {
|
// find the first power of 10 that is greater than meSats
|
||||||
return calculatedDefault
|
while (!(meSats <= tipRandomMax * 10 ** pow)) {
|
||||||
|
pow++
|
||||||
|
}
|
||||||
|
// if meSats is in that power of 10's range already, move into the next range
|
||||||
|
if (meSats >= tipRandomMin * 10 ** pow) {
|
||||||
|
pow++
|
||||||
|
}
|
||||||
|
// make sure the our range minimum doesn't overlap with the previous range maximum
|
||||||
|
tipRandomMin = tipRandomMax * 10 ** (pow - 1) >= tipRandomMin * 10 ** pow ? tipRandomMax * 10 ** (pow - 1) + 1 : tipRandomMin * 10 ** pow
|
||||||
|
tipRandomMax = tipRandomMax * 10 ** pow
|
||||||
|
return Math.floor((Math.random() * (tipRandomMax - tipRandomMin + 1)) + tipRandomMin) - meSats
|
||||||
}
|
}
|
||||||
|
|
||||||
let sats = calculatedDefault
|
let sats = defaultTipIncludingRandom({ tipDefault, tipRandom, tipRandomMin, tipRandomMax })
|
||||||
if (turboTipping) {
|
|
||||||
while (meSats >= sats) {
|
while (meSats >= sats) {
|
||||||
sats *= 10
|
sats *= 10
|
||||||
}
|
}
|
||||||
// deduct current sats since turbo tipping is about total zap not making the next zap 10x
|
// deduct current sats since turbo tipping is about total zap not making the next zap 10x
|
||||||
sats -= meSats
|
return sats - meSats
|
||||||
}
|
}
|
||||||
|
|
||||||
return sats
|
return defaultTipIncludingRandom({ tipDefault, tipRandom, tipRandomMin, tipRandomMax })
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function UpVote ({ item, className }) {
|
export default function UpVote ({ item, className }) {
|
||||||
|
@ -114,7 +114,7 @@ export default function Settings ({ ssrData }) {
|
|||||||
tipDefault: settings?.tipDefault || 21,
|
tipDefault: settings?.tipDefault || 21,
|
||||||
tipRandom: settings?.tipRandom,
|
tipRandom: settings?.tipRandom,
|
||||||
tipRandomMin: settings?.tipRandomMin || 1,
|
tipRandomMin: settings?.tipRandomMin || 1,
|
||||||
tipRandomMax: settings?.tipRandomMax || settings?.tipDefault || 21,
|
tipRandomMax: settings?.tipRandomMax || 10,
|
||||||
turboTipping: settings?.turboTipping,
|
turboTipping: settings?.turboTipping,
|
||||||
zapUndos: settings?.zapUndos || (settings?.tipDefault ? 100 * settings.tipDefault : 2100),
|
zapUndos: settings?.zapUndos || (settings?.tipDefault ? 100 * settings.tipDefault : 2100),
|
||||||
zapUndosEnabled: settings?.zapUndos !== null,
|
zapUndosEnabled: settings?.zapUndos !== null,
|
||||||
@ -1040,7 +1040,7 @@ const TipRandomField = () => {
|
|||||||
groupClassName='mb-0'
|
groupClassName='mb-0'
|
||||||
label={
|
label={
|
||||||
<div className='d-flex align-items-center'>
|
<div className='d-flex align-items-center'>
|
||||||
Enable random zap values
|
random zap values
|
||||||
<Info>
|
<Info>
|
||||||
<ul className='fw-bold'>
|
<ul className='fw-bold'>
|
||||||
<li>Set a minimum and maximum zap amount</li>
|
<li>Set a minimum and maximum zap amount</li>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user