Add env var for disabling zaps

This commit is contained in:
Jonathan Staab 2023-04-26 10:24:21 -05:00
parent f7231a757b
commit 30a5ab3e94
5 changed files with 23 additions and 14 deletions

1
.env
View File

@ -2,5 +2,6 @@ VITE_THEME_DARK=transparent:transparent,black:#0f0f0e,white:#FFFFFF,accent:#EB5E
VITE_THEME_LIGHT=transparent:transparent,black:#0f0f0e,white:#FFFFFF,accent:#EB5E28,accent-light:#FB652C,gray-8:#FFFFFF,gray-7:#FAF6F1,gray-6:#F2EBE1,gray-5:#B3AA98,gray-4:#B3AA98,gray-3:#565249,gray-2:#393530,gray-1:#252422,danger:#ff0000,warning:#ebd112,success:#37ab51,input:#FAF6F1,input-hover:#F2EBE1
VITE_DUFFLEPUD_URL=https://dufflepud.onrender.com
VITE_DEFAULT_FOLLOWS=97c70a44366a6535c145b333f973ea86dfdc2d7a99da618c40c64705ad98e322,3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d,82341f882b6eabcd2ba7f1ef90aad961cf074af15b9ef44a09f9d2a8fbfbe6a2,6e468422dfb74a5738702a8823b9b28168abab8655faacb6853cd0ee15deee93
VITE_ENABLE_ZAPS=true
VITE_FORCE_RELAYS=
VITE_LOGO_URL=

View File

@ -15,6 +15,7 @@ import {
import {personKinds, appDataKeys, findReplyId} from "src/util/nostr"
import {chunk, ensurePlural} from "hurdak/lib/hurdak"
import {batch, now, timedelta} from "src/util/misc"
import {enableZaps} from "src/agent/settings"
import {
getRelaysForEventParent,
getAllPubkeyWriteRelays,
@ -252,6 +253,7 @@ const loadParents = (notes, opts = {}) => {
const streamContext = ({notes, onChunk, maxDepth = 2}) => {
const subs = []
const seen = new Set()
const kinds = enableZaps ? [1, 7, 9735] : [1, 7]
const relays = sampleRelays(aggregateScores(notes.map(getRelaysForEventChildren)))
const loadChunk = (events, depth) => {
@ -274,7 +276,7 @@ const streamContext = ({notes, onChunk, maxDepth = 2}) => {
subs.push(
listen({
relays,
filter: [{kinds: [1, 7, 9735], "#e": ids, since: now()}],
filter: [{kinds, "#e": ids, since: now()}],
onChunk: newEvents => {
onChunk(newEvents)
@ -296,7 +298,7 @@ const streamContext = ({notes, onChunk, maxDepth = 2}) => {
chunk(256, newIds).forEach(ids => {
load({
relays,
filter: [{kinds: [1, 7, 9735], "#e": ids}],
filter: [{kinds, "#e": ids}],
onChunk: newEvents => {
onChunk(newEvents)

1
src/agent/settings.ts Normal file
View File

@ -0,0 +1 @@
export const enableZaps = JSON.parse(import.meta.env.VITE_ENABLE_ZAPS)

View File

@ -15,6 +15,7 @@
import CopyValue from "src/partials/CopyValue.svelte"
import PersonBadge from "src/app/shared/PersonBadge.svelte"
import RelayCard from "src/app/shared/RelayCard.svelte"
import {enableZaps} from "src/agent/settings"
import {getEventPublishRelays} from "src/agent/relays"
import {getPersonWithFallback} from "src/agent/db"
import pool from "src/agent/pool"
@ -126,16 +127,18 @@
})} />
{$likesCount}
</button>
<button
class={cx("w-20 text-left", {
"pointer-events-none opacity-50":
disableActions || $author.pubkey === user.getPubkey() || !$author.zapper,
"text-accent": zap,
})}
on:click={startZap}>
<i class="fa fa-bolt cursor-pointer" />
{formatSats($zapsTotal)}
</button>
{#if enableZaps}
<button
class={cx("w-20 text-left", {
"pointer-events-none opacity-50":
disableActions || $author.pubkey === user.getPubkey() || !$author.zapper,
"text-accent": zap,
})}
on:click={startZap}>
<i class="fa fa-bolt cursor-pointer" />
{formatSats($zapsTotal)}
</button>
{/if}
</div>
<div class="flex items-center">
{#if pool.forceUrls.length === 0}

View File

@ -13,6 +13,7 @@ import {Tags, isNotification, userKinds} from "src/util/nostr"
import {findReplyId} from "src/util/nostr"
import {modal, toast} from "src/partials/state"
import {notifications, watch, userEvents, contacts, rooms} from "src/agent/db"
import {enableZaps} from "src/agent/settings"
import keys from "src/agent/keys"
import network from "src/agent/network"
import pool from "src/agent/pool"
@ -168,6 +169,7 @@ export const listen = async () => {
const pubkey = user.getPubkey()
const {roomsJoined} = user.getProfile()
const since = now() - timedelta(30, "days")
const kinds = enableZaps ? [1, 4, 7, 9735] : [1, 4, 7]
const eventIds = doPipe(userEvents.all({kind: 1, created_at: {$gt: since}}), [
sortBy(e => -e.created_at),
slice(0, 256),
@ -180,8 +182,8 @@ export const listen = async () => {
relays: getUserReadRelays(),
filter: [
{kinds: [1, 4], authors: [pubkey], since},
{kinds: [1, 7, 4, 9735], "#p": [pubkey], since},
{kinds: [1, 7, 4, 9735], "#e": eventIds, since},
{kinds, "#p": [pubkey], since},
{kinds, "#e": eventIds, since},
{kinds: [42], "#e": roomsJoined, since},
],
onChunk: async events => {