mirror of
https://github.com/coracle-social/coracle.git
synced 2024-09-29 08:21:20 +00:00
Make platform zap a tip
This commit is contained in:
parent
3bf6d97236
commit
65d2da0579
@ -20,7 +20,12 @@
|
||||
{#if zap.invoice}
|
||||
<div class="flex items-center justify-center gap-2">
|
||||
{#if zap.status === "pending"}
|
||||
<i class="fa fa-circle-notch fa-spin" /> Paying
|
||||
<i class="fa fa-circle-notch fa-spin" />
|
||||
{#if zap.isTip}
|
||||
Tipping
|
||||
{:else}
|
||||
Paying
|
||||
{/if}
|
||||
{:else if zap.status === "success"}
|
||||
<i class="fa fa-check text-success" /> Paid
|
||||
{/if}
|
||||
|
@ -5,6 +5,7 @@
|
||||
amount: number
|
||||
status: string
|
||||
invoice?: string
|
||||
isTip?: boolean
|
||||
}
|
||||
</script>
|
||||
|
||||
@ -57,33 +58,29 @@
|
||||
|
||||
return s
|
||||
}),
|
||||
(ss: any[][]) => {
|
||||
const percent = getSetting("platform_zap_split")
|
||||
|
||||
// Avoid divide by zero errors
|
||||
if (totalWeight === 0) {
|
||||
totalWeight = 1
|
||||
}
|
||||
|
||||
// Add our platform split
|
||||
if (percent > 0) {
|
||||
ss.push([
|
||||
$env.PLATFORM_PUBKEY,
|
||||
getPubkeyHint($env.PLATFORM_PUBKEY),
|
||||
String(totalWeight * percent),
|
||||
])
|
||||
}
|
||||
|
||||
return ss
|
||||
},
|
||||
map(([pubkey, relay, weight]: string[]) => ({
|
||||
relay,
|
||||
pubkey,
|
||||
amount: Math.round(totalAmount * (parseFloat(weight) / totalWeight)),
|
||||
status: "pending",
|
||||
invoice: null,
|
||||
})),
|
||||
sortBy((split: Zap) => -split.amount),
|
||||
(zaps: Zap[]) => {
|
||||
const percent = getSetting("platform_zap_split")
|
||||
|
||||
// Add our platform split on top as a "tip"
|
||||
if (percent > 0 && totalWeight > 0) {
|
||||
zaps.push({
|
||||
pubkey: $env.PLATFORM_PUBKEY,
|
||||
relay: getPubkeyHint($env.PLATFORM_PUBKEY),
|
||||
amount: Math.round(zaps.reduce((a, z) => a + z.amount, 0) * percent),
|
||||
status: "pending",
|
||||
isTip: true,
|
||||
})
|
||||
}
|
||||
|
||||
return zaps
|
||||
},
|
||||
])
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user