mirror of
https://github.com/aljazceru/hypergolic.git
synced 2025-12-24 16:54:24 +01:00
problem: can't see existing bitcoin address registrations
This commit is contained in:
@@ -1,18 +1,32 @@
|
||||
<script lang="ts">
|
||||
import * as Card from "@/components/ui/card";
|
||||
import * as Card from '@/components/ui/card';
|
||||
|
||||
import Heading from './Heading.svelte';
|
||||
import InputBitcoinAddress from './InputBitcoinAddress.svelte';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { ndk } from '@/ndk';
|
||||
import { currentUser } from '@/stores/session';
|
||||
import { NDKEvent } from '@nostr-dev-kit/ndk';
|
||||
import validate from 'bitcoin-address-validation';
|
||||
import type { Rocket } from '@/event_helpers/rockets';
|
||||
import { derived } from 'svelte/store';
|
||||
|
||||
import Heading from "./Heading.svelte";
|
||||
import InputBitcoinAddress from "./InputBitcoinAddress.svelte";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ndk } from "@/ndk";
|
||||
import { currentUser } from "@/stores/session";
|
||||
import { NDKEvent } from "@nostr-dev-kit/ndk";
|
||||
import validate from "bitcoin-address-validation";
|
||||
let bitcoinAddress: string;
|
||||
export let rocket: Rocket;
|
||||
|
||||
let bitcoinAddress:string;
|
||||
let associatedAddresses = derived(currentUser, ($currentUser) => {
|
||||
let addresses: Set<string> = new Set();
|
||||
if ($currentUser) {
|
||||
for (let [_, a] of rocket.BitcoinAssociations()) {
|
||||
if (a.Pubkey == $currentUser.pubkey && a.Address && validate(a.Address)) {
|
||||
addresses.add(a.Address);
|
||||
}
|
||||
}
|
||||
}
|
||||
return addresses;
|
||||
});
|
||||
|
||||
function publish(address:string) {
|
||||
function publish(address: string) {
|
||||
if (!$ndk.signer) {
|
||||
throw new Error('no ndk signer found');
|
||||
}
|
||||
@@ -20,27 +34,45 @@
|
||||
if (!author) {
|
||||
throw new Error('no current user');
|
||||
}
|
||||
if (!validate(address)) {
|
||||
throw new Error("invalid bitcoin address")
|
||||
}
|
||||
let event = new NDKEvent($ndk)
|
||||
event.kind = 1413
|
||||
event.tags.push(["onchain", address])
|
||||
if (!validate(address)) {
|
||||
throw new Error('invalid bitcoin address');
|
||||
}
|
||||
let event = new NDKEvent($ndk);
|
||||
event.kind = 1413;
|
||||
event.tags.push(['onchain', address]);
|
||||
//todo: let user specify a rocket
|
||||
console.log("todo: let user specify a rocket")
|
||||
event.publish().then((x) => {
|
||||
console.log(x);
|
||||
}).catch(()=>{ console.log("failed to publish", event.rawEvent())});
|
||||
console.log('todo: let user specify a rocket');
|
||||
event
|
||||
.publish()
|
||||
.then((x) => {
|
||||
console.log(x);
|
||||
})
|
||||
.catch(() => {
|
||||
console.log('failed to publish', event.rawEvent());
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<Heading title="Sponsor a Contributor" />
|
||||
<Card.Root>
|
||||
<Card.Header><Card.Title>Associate Bitcoin Address</Card.Title></Card.Header>
|
||||
<Card.Header><Card.Title>Your Bitcoin Addresses</Card.Title></Card.Header>
|
||||
<Card.Content>
|
||||
<div class="m-2 flex">
|
||||
You must associate at least one Bitcoin address with your npub before you can pay a Contributor. Merit purchases from this address will be associated with your pubkey.
|
||||
</div>
|
||||
<div class="flex"><InputBitcoinAddress bind:bitcoinAddress /><Button on:click={()=>publish(bitcoinAddress)} class="mt-3 max-w-xs">Publish</Button></div>
|
||||
</Card.Content>
|
||||
</Card.Root>
|
||||
<div class="m-2 flex">
|
||||
Merit purchases must be conducted with a Bitcoin address that is associated with your pubkey,
|
||||
otherwise you will not recieve the Merits upon payment.
|
||||
</div>
|
||||
{#if $associatedAddresses.size == 0}You do not have any registered addresses{:else}
|
||||
Your registered addresses:
|
||||
<ul class="m-2 flex">
|
||||
{#each $associatedAddresses as address}<li>{address}</li>{/each}
|
||||
</ul>
|
||||
{/if}
|
||||
Add a new address now
|
||||
<div class="flex">
|
||||
<InputBitcoinAddress bind:bitcoinAddress /><Button
|
||||
on:click={() => publish(bitcoinAddress)}
|
||||
class="mt-3 max-w-xs">Publish</Button
|
||||
>
|
||||
</div>
|
||||
</Card.Content>
|
||||
</Card.Root>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { NDKEvent, type NDKTag } from '@nostr-dev-kit/ndk';
|
||||
import { MapOfVotes, MeritRequest, Votes } from './merits';
|
||||
import { getAuthorizedZapper } from '@/helpers';
|
||||
import { BitcoinTipTag, txs } from '@/stores/bitcoin';
|
||||
import { NDKEvent, type NDKTag } from '@nostr-dev-kit/ndk';
|
||||
import validate from 'bitcoin-address-validation';
|
||||
import { BitcoinTipTag, bitcoinTip, txs } from '@/stores/bitcoin';
|
||||
import { MapOfVotes, MeritRequest, Votes } from './merits';
|
||||
|
||||
export class Rocket {
|
||||
Event: NDKEvent;
|
||||
@@ -41,6 +41,13 @@ export class Rocket {
|
||||
}
|
||||
UpsertMeritTransfer(): NDKEvent | undefined {
|
||||
let event: NDKEvent | undefined = undefined;
|
||||
this.PrepareForUpdate();
|
||||
event = new NDKEvent(this.Event.ndk, this.Event.rawEvent());
|
||||
event.created_at = Math.floor(new Date().getTime() / 1000);
|
||||
event.tags.push(['address', `${association.Pubkey}:${association.Address}`]);
|
||||
event.tags.push(['proof_full', JSON.stringify(association.Event.rawEvent())]);
|
||||
updateIgnitionAndParentTag(event);
|
||||
updateBitcoinTip(event);
|
||||
return event;
|
||||
}
|
||||
|
||||
|
||||
@@ -111,26 +111,45 @@
|
||||
if (t) console.log(t);
|
||||
});
|
||||
|
||||
let nostrocket = derived(rockets, ($rockets) => {
|
||||
let rocket: Rocket | undefined = undefined;
|
||||
for (let r of $rockets) {
|
||||
if (
|
||||
r.Name() == 'NOSTROCKET' &&
|
||||
r.Event.pubkey == 'd91191e30e00444b942c0e82cad470b32af171764c2275bee0bd99377efd4075'
|
||||
) {
|
||||
//we consume the current list of bitcoin addresses from Nostrocket as a service so that users don't need to add a new address for every rocket
|
||||
//todo: make this dependent on votepower not my pubkey
|
||||
//todo: also allow rockets to have their own list of addresses so they can be used without nostrocket
|
||||
rocket = r;
|
||||
}
|
||||
}
|
||||
return rocket;
|
||||
});
|
||||
|
||||
transactions.subscribe((t) => {});
|
||||
|
||||
let noAssociatedBitcoinAddress = derived(
|
||||
[currentUser, pendingSales],
|
||||
([$currentUser, $pendingSales]) => {
|
||||
let show = false;
|
||||
if ($currentUser) {
|
||||
for (let [r, a] of $pendingSales) {
|
||||
if (a.length > 0 && !r.BitcoinAssociations().get($currentUser.pubkey)) {
|
||||
console.log($currentUser.pubkey, r.Name());
|
||||
show = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return show;
|
||||
}
|
||||
);
|
||||
// let noAssociatedBitcoinAddress = derived(
|
||||
// [currentUser, pendingSales],
|
||||
// ([$currentUser, $pendingSales]) => {
|
||||
// let show = false;
|
||||
// if ($currentUser) {
|
||||
// for (let [r, a] of $pendingSales) {
|
||||
// if (a.length > 0) {
|
||||
// let show = true
|
||||
// for (let [_, ba] of r.BitcoinAssociations()) {
|
||||
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return show;
|
||||
// }
|
||||
// );
|
||||
</script>
|
||||
|
||||
{#if $noAssociatedBitcoinAddress}<AssociateBitcoinAddress />{/if}
|
||||
{#if $nostrocket}<AssociateBitcoinAddress rocket={$nostrocket} />
|
||||
{/if}
|
||||
|
||||
{#if $currentUser}
|
||||
{#each $pendingSales as [rocket, amr] (rocket.Event.id)}
|
||||
|
||||
Reference in New Issue
Block a user