problem: we are not including the right igntion and parent tags

This commit is contained in:
gsovereignty
2024-07-07 15:29:26 +08:00
parent 75206af3fa
commit dce69618d0
7 changed files with 151 additions and 48 deletions

36
package-lock.json generated
View File

@@ -21,11 +21,13 @@
"lucide-svelte": "^0.383.0",
"mode-watcher": "^0.3.0",
"paneforge": "^0.0.4",
"qrious": "^4.0.2",
"svelte-sonner": "^0.3.24",
"sveltekit-superforms": "^2.14.0",
"tailwind-merge": "^2.3.0",
"tailwind-variants": "^0.2.1",
"vaul-svelte": "^0.3.1",
"webln": "^0.3.2",
"zod": "^3.23.8"
},
"devDependencies": {
@@ -1235,6 +1237,14 @@
"tailwindcss": ">=3.0.0 || insiders"
}
},
"node_modules/@types/chrome": {
"version": "0.0.74",
"resolved": "https://registry.npmjs.org/@types/chrome/-/chrome-0.0.74.tgz",
"integrity": "sha512-hzosS5CkQcIKCgxcsV2AzbJ36KNxG/Db2YEN/erEu7Boprg+KpMDLBQqKFmSo+JkQMGqRcicUyqCowJpuT+C6A==",
"dependencies": {
"@types/filesystem": "*"
}
},
"node_modules/@types/cookie": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.6.0.tgz",
@@ -1245,6 +1255,19 @@
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz",
"integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw=="
},
"node_modules/@types/filesystem": {
"version": "0.0.36",
"resolved": "https://registry.npmjs.org/@types/filesystem/-/filesystem-0.0.36.tgz",
"integrity": "sha512-vPDXOZuannb9FZdxgHnqSwAG/jvdGM8Wq+6N4D/d80z+D4HWH+bItqsZaVRQykAn6WEVeEkLm2oQigyHtgb0RA==",
"dependencies": {
"@types/filewriter": "*"
}
},
"node_modules/@types/filewriter": {
"version": "0.0.33",
"resolved": "https://registry.npmjs.org/@types/filewriter/-/filewriter-0.0.33.tgz",
"integrity": "sha512-xFU8ZXTw4gd358lb2jw25nxY9QAgqn2+bKKjKOYfNCzN4DKCFetK7sPtrlpg66Ywe3vWY9FNxprZawAh9wfJ3g=="
},
"node_modules/@types/json-schema": {
"version": "7.0.15",
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz",
@@ -3306,6 +3329,11 @@
"integrity": "sha512-SVtmxhRE/CGkn3eZY1T6pC8Nln6Fr/lu1mKSgRud0eC73whjGfoAogbn78LkD8aFL0zz3bAFerKSnOl7NlErBA==",
"optional": true
},
"node_modules/qrious": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/qrious/-/qrious-4.0.2.tgz",
"integrity": "sha512-xWPJIrK1zu5Ypn898fBp8RHkT/9ibquV2Kv24S/JY9VYEhMBMKur1gHVsOiNUh7PHP9uCgejjpZUHUIXXKoU/g=="
},
"node_modules/queue-microtask": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz",
@@ -4449,6 +4477,14 @@
"node": ">= 8"
}
},
"node_modules/webln": {
"version": "0.3.2",
"resolved": "https://registry.npmjs.org/webln/-/webln-0.3.2.tgz",
"integrity": "sha512-YYT83aOCLup2AmqvJdKtdeBTaZpjC6/JDMe8o6x1kbTYWwiwrtWHyO//PAsPixF3jwFsAkj5DmiceB6w/QSe7Q==",
"dependencies": {
"@types/chrome": "^0.0.74"
}
},
"node_modules/websocket": {
"version": "1.0.35",
"resolved": "https://registry.npmjs.org/websocket/-/websocket-1.0.35.tgz",

View File

@@ -48,11 +48,13 @@
"lucide-svelte": "^0.383.0",
"mode-watcher": "^0.3.0",
"paneforge": "^0.0.4",
"qrious": "^4.0.2",
"svelte-sonner": "^0.3.24",
"sveltekit-superforms": "^2.14.0",
"tailwind-merge": "^2.3.0",
"tailwind-variants": "^0.2.1",
"vaul-svelte": "^0.3.1",
"webln": "^0.3.2",
"zod": "^3.23.8"
}
}

View File

@@ -1,51 +1,92 @@
<script lang="ts">
import { Rocket } from 'lucide-svelte';
import { goto } from '$app/navigation';
import { base } from '$app/paths';
import { Button, buttonVariants } from '$lib/components/ui/button/index.js';
import * as Dialog from '$lib/components/ui/dialog/index.js';
import { Input } from '$lib/components/ui/input/index.js';
import { Label } from '$lib/components/ui/label/index.js';
import { ndk } from '@/ndk';
import Todo from './Todo.svelte';
import { currentUser } from '@/stores/session';
import { Terminal } from 'lucide-svelte';
import * as Alert from '@/components/ui/alert';
import type NDKSvelte from '@nostr-dev-kit/ndk-svelte';
import { NDKEvent } from '@nostr-dev-kit/ndk';
import { goto } from '$app/navigation';
import { base } from '$app/paths';
import { getRocketURL } from '@/helpers';
import { ndk } from '@/ndk';
import { currentUser } from '@/stores/session';
import { NDKEvent } from '@nostr-dev-kit/ndk';
import { Terminal } from 'lucide-svelte';
import Todo from './Todo.svelte';
export let product:NDKEvent;
export let rocket:NDKEvent;
export let product: NDKEvent;
export let rocket: NDKEvent;
let price:number = 0;
let max:number = 0
let price: number = 0;
let max: number = 0;
function updateIgnitionAndParentTag(rocket: NDKEvent) {
let existingIgnition = rocket.getMatchingTags('ignition');
//let existingParent = rocket.getMatchingTags("parent")
removeIgnitionAndParentTag(rocket);
if (existingIgnition.length > 1) {
throw new Error('too many ignition tags!');
}
if (existingIgnition.length == 0) {
rocket.tags.push(['ignition', rocket.id]);
}
if (existingIgnition.length == 1) {
if (existingIgnition[0][1].length == 64) {
rocket.tags.push(existingIgnition[0]);
}
if (existingIgnition[0][1] == 'this') {
rocket.tags.push(['ignition', rocket.id]);
}
}
rocket.tags.push(['parent', rocket.id]);
}
function removeIgnitionAndParentTag(rocket: NDKEvent) {
let existing = [];
for (let t of rocket.tags) {
existing.push(t);
}
rocket.tags = [];
for (let t of existing) {
if (t[0] !== 'ignition' && t[0] !== 'parent') {
rocket.tags.push(t);
}
}
}
function publish() {
if (!$ndk.signer) {
throw new Error('no ndk signer found');
}
rocket.ndk = $ndk
rocket.ndk = $ndk;
let author = $currentUser;
if (!author) {
throw new Error('no current user');
}
if (rocket.author.pubkey != author.pubkey) {
console.log(rocket.author, author)
throw new Error('you are not the creator of this rocket');
}
rocket.created_at = Math.floor(new Date().getTime() / 1000);
//todo validate d tag
rocket.tags.push(["product", `${product.id}:${price}:${rocket.created_at}:${max}`, "wss://relay.nostrocket.org", JSON.stringify([])])
rocket.publish().then((x)=>{
console.log(x)
goto(`${base}/rockets/${getRocketURL(rocket)}`)
})
if (rocket.author.pubkey != author.pubkey) {
console.log(rocket.author, author);
throw new Error('you are not the creator of this rocket');
}
rocket.created_at = Math.floor(new Date().getTime() / 1000);
//todo validate d tag
rocket.tags.push([
'product',
`${product.id}:${price}:${rocket.created_at}:${max}`,
'wss://relay.nostrocket.org',
JSON.stringify([])
]);
updateIgnitionAndParentTag(rocket)
rocket.publish().then((x) => {
console.log(x);
goto(`${base}/products`);
});
}
</script>
<Dialog.Root>
<Dialog.Trigger class={buttonVariants({ variant: 'default' })}>Make Available for Purchase</Dialog.Trigger>
<Dialog.Trigger class={buttonVariants({ variant: 'default' })}
>Make Available for Purchase</Dialog.Trigger
>
<Dialog.Content class="sm:max-w-[425px]">
<Dialog.Header>
<Dialog.Title>Make this product available to customers</Dialog.Title>
@@ -65,14 +106,24 @@
<Label for="price" class="text-right">Price</Label>
<Input bind:value={price} id="price" placeholder="Price in sats" class="col-span-3" />
</div>
<div class="grid grid-cols-4 items-center gap-4">
<div class="grid grid-cols-4 items-center gap-4">
<Label for="max" class="text-right">Max Available</Label>
<Input bind:value={max} id="max" placeholder="Maximum number that can be sold" class="col-span-3" />
<Input
bind:value={max}
id="max"
placeholder="Maximum number that can be sold"
class="col-span-3"
/>
</div>
</div>
<Todo text={['validate input is a number']} />
<Dialog.Footer>
<Button on:click={()=>{publish()}} type="submit">Publish</Button>
<Button
on:click={() => {
publish();
}}
type="submit">Publish</Button
>
</Dialog.Footer>
</Dialog.Content>
</Dialog.Root>

View File

@@ -42,7 +42,7 @@
console.log(e.rawEvent())
e.publish().then((x) => {
console.log(x);
//goto(`${base}/rockets/${getRocketURL(e)}`);
goto(`${base}/rockets/${getRocketURL(e)}`);
});
}
</script>

View File

@@ -31,6 +31,8 @@
//todo validate d tag
e.tags.push(["d", name])
e.tags.push(["ruleset", "334000"])
e.tags.push(["ignition", "this"])
e.tags.push(["parent", "this"])
e.publish().then((x)=>{
console.log(x)
goto(`${base}/rockets/${getRocketURL(e)}`)

View File

@@ -1,31 +1,42 @@
<script lang="ts">
import { Rocket } from 'lucide-svelte';
import { Button, buttonVariants } from '$lib/components/ui/button/index.js';
import { buttonVariants } from '$lib/components/ui/button/index.js';
import * as Dialog from '$lib/components/ui/dialog/index.js';
import { Input } from '$lib/components/ui/input/index.js';
import { Label } from '$lib/components/ui/label/index.js';
import { ndk } from '@/ndk';
import Todo from './Todo.svelte';
import { currentUser } from '@/stores/session';
import { Terminal } from 'lucide-svelte';
import * as Alert from '@/components/ui/alert';
import type NDKSvelte from '@nostr-dev-kit/ndk-svelte';
import { NDKEvent } from '@nostr-dev-kit/ndk';
import { goto } from '$app/navigation';
import { base } from '$app/paths';
import { getRocketURL } from '@/helpers';
import { ndk } from '@/ndk';
import { currentUser } from '@/stores/session';
import { NDKEvent, NDKZap } from '@nostr-dev-kit/ndk';
import { Terminal } from 'lucide-svelte';
import Todo from './Todo.svelte';
import { requestProvider } from 'webln';
export let product:NDKEvent;
export let rocket:NDKEvent;
function zap() {
let z = new NDKZap({ndk:$ndk, zappedEvent:rocket, zappedUser: rocket.author})
z.createZapRequest(1000, `Purchase of ${product.getMatchingTags("name")[0][1]} from ${rocket.dTag}`, [["e", product.id]]).then(invoice=>{
if (invoice) {
requestProvider().then((webln)=>{
webln.sendPayment(invoice).then((response)=>{
if (response && response.preimage) {
console.log(response.preimage)
}
})
});
}
})
}
</script>
<Dialog.Root>
<Dialog.Trigger class={buttonVariants({ variant: 'default' })}>Buy Now</Dialog.Trigger>
<Dialog.Content class="sm:max-w-[425px]">
<Dialog.Header>
<Dialog.Title>Buy {product.getMatchingTags("name")[0][1]} from {rocket.dTag} now!</Dialog.Title>
<Dialog.Title
>Buy {product.getMatchingTags('name')[0][1]} from {rocket.dTag} now!</Dialog.Title
>
{#if !currentUser}
<Alert.Root>
<Terminal class="h-4 w-4" />
@@ -37,9 +48,10 @@
{/if}
<Dialog.Description>Pay now with Lightning</Dialog.Description>
</Dialog.Header>
<Todo text={["generate zap request and get invoice"]} />
<Dialog.Footer>
<Todo text={['generate zap request and get invoice']} />
<Dialog.Footer>
<a href="#" on:click={zap}>test</a>
</Dialog.Footer>
</Dialog.Content>
</Dialog.Root>

View File

@@ -32,7 +32,7 @@
//warn user that this information is probably out of date and let them reroute to get the latest
}
if (rIgnitionOrActual.length == 64 && rName && rPubkey) {
if (rName && rPubkey) {
//the user wants the latest valid state of this rocket
rocketEvents = $ndk.storeSubscribe(
[{ '#d': [rName], authors: [rPubkey], kinds: [31108 as number] },