mirror of
https://github.com/aljazceru/hypergolic.git
synced 2026-02-22 05:44:20 +01:00
problem: zap amount is not validated
This commit is contained in:
@@ -21,6 +21,8 @@
|
||||
let desc: string;
|
||||
let image: string;
|
||||
|
||||
let o = false;
|
||||
|
||||
function publish(ndk: NDKSvelte) {
|
||||
if (!ndk.signer) {
|
||||
throw new Error('no ndk signer found');
|
||||
@@ -42,12 +44,13 @@
|
||||
console.log(e.rawEvent());
|
||||
e.publish().then((x) => {
|
||||
console.log(x);
|
||||
goto(`${base}/rockets/${getRocketURL(e)}`);
|
||||
o = false;
|
||||
goto(`${base}/rockets/${getRocketURL(rocketEvent)}`);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<Dialog.Root>
|
||||
<Dialog.Root bind:open={o}>
|
||||
<Dialog.Trigger class={buttonVariants({ variant: 'default' })}
|
||||
>Propose a New Product</Dialog.Trigger
|
||||
>
|
||||
|
||||
@@ -11,19 +11,23 @@
|
||||
import { requestProvider } from 'webln';
|
||||
import QrCodeSvg from './QrCodeSvg.svelte';
|
||||
import CopyButton from './CopyButton.svelte';
|
||||
import type { RocketProduct } from '@/event_helpers/rockets';
|
||||
|
||||
export let product: NDKEvent;
|
||||
export let rocketProduct: RocketProduct | undefined;
|
||||
export let rocket: NDKEvent;
|
||||
|
||||
let invoice: string | null;
|
||||
|
||||
async function zap() {
|
||||
const z = new NDKZap({ ndk: $ndk, zappedEvent: rocket, zappedUser: rocket.author });
|
||||
invoice = await z.createZapRequest(
|
||||
1000,
|
||||
`Purchase of ${product.getMatchingTags('name')[0][1]} from ${rocket.dTag}`,
|
||||
[['product', product.id]]
|
||||
);
|
||||
if (rocketProduct) {
|
||||
const z = new NDKZap({ ndk: $ndk, zappedEvent: rocket, zappedUser: rocket.author });
|
||||
invoice = await z.createZapRequest(
|
||||
rocketProduct.Price * 1000,
|
||||
`Purchase of ${product.getMatchingTags('name')[0][1]} from ${rocket.dTag}`,
|
||||
[['product', product.id]]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function payWithWebLn() {
|
||||
@@ -44,33 +48,37 @@
|
||||
let open: boolean;
|
||||
</script>
|
||||
|
||||
<Dialog.Root bind:open>
|
||||
<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
|
||||
>
|
||||
{#if !currentUser}
|
||||
<Alert.Root>
|
||||
<Terminal class="h-4 w-4" />
|
||||
<Alert.Title>Heads up!</Alert.Title>
|
||||
<Alert.Description
|
||||
>You need a nostr signing extension to use Nostrocket!</Alert.Description
|
||||
>
|
||||
</Alert.Root>
|
||||
{#if rocketProduct}
|
||||
<Dialog.Root bind:open>
|
||||
<Dialog.Trigger class={buttonVariants({ variant: 'default' })}
|
||||
>Buy Now for {rocketProduct.Price} sats</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
|
||||
>
|
||||
{#if !currentUser}
|
||||
<Alert.Root>
|
||||
<Terminal class="h-4 w-4" />
|
||||
<Alert.Title>Heads up!</Alert.Title>
|
||||
<Alert.Description
|
||||
>You need a nostr signing extension to use Nostrocket!</Alert.Description
|
||||
>
|
||||
</Alert.Root>
|
||||
{/if}
|
||||
<Dialog.Description>Pay now with Lightning</Dialog.Description>
|
||||
</Dialog.Header>
|
||||
{#if invoice}
|
||||
<QrCodeSvg content={invoice} />
|
||||
<div class="flex gap-2">
|
||||
<Input bind:value={invoice} readonly />
|
||||
<CopyButton text={invoice} />
|
||||
</div>
|
||||
<Button on:click={payWithWebLn}>Pay with WebLN</Button>
|
||||
{:else}
|
||||
<Button on:click={zap}>Create invoice</Button>
|
||||
{/if}
|
||||
<Dialog.Description>Pay now with Lightning</Dialog.Description>
|
||||
</Dialog.Header>
|
||||
{#if invoice}
|
||||
<QrCodeSvg content={invoice} />
|
||||
<div class="flex gap-2">
|
||||
<Input bind:value={invoice} readonly />
|
||||
<CopyButton text={invoice} />
|
||||
</div>
|
||||
<Button on:click={payWithWebLn}>Pay with WebLN</Button>
|
||||
{:else}
|
||||
<Button on:click={zap}>Create invoice</Button>
|
||||
{/if}
|
||||
</Dialog.Content>
|
||||
</Dialog.Root>
|
||||
</Dialog.Content>
|
||||
</Dialog.Root>
|
||||
{/if}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import type { NDKEvent } from '@nostr-dev-kit/ndk';
|
||||
import AddProductToRocket from './AddProductToRocket.svelte';
|
||||
import PayNow from './PayNow.svelte';
|
||||
import { Rocket } from '@/event_helpers/rockets';
|
||||
|
||||
export let product: NDKEvent;
|
||||
export let rocket: NDKEvent;
|
||||
@@ -34,14 +35,8 @@
|
||||
return test == 3;
|
||||
}
|
||||
|
||||
function includedInRocket(): boolean {
|
||||
let included = false;
|
||||
for (let p of rocket.getMatchingTags('product')) {
|
||||
if (p[1].split(':')[0] == product.id) {
|
||||
included = true;
|
||||
}
|
||||
}
|
||||
return included;
|
||||
function includedInRocket(rocket:Rocket, product:NDKEvent): boolean {
|
||||
return Boolean(rocket.Products().get(product.id))
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -71,10 +66,10 @@
|
||||
/>
|
||||
{/if}
|
||||
<Card.Footer class="flex justify-center pt-2">
|
||||
{#if !includedInRocket()}
|
||||
{#if !includedInRocket(new Rocket(rocket), product)}
|
||||
<AddProductToRocket {product} {rocket} />
|
||||
{:else}
|
||||
<PayNow {product} {rocket} />
|
||||
<PayNow {product} rocketProduct={new Rocket(rocket).Products().get(product.id)} {rocket} />
|
||||
{/if}
|
||||
</Card.Footer>
|
||||
</Card.Root>
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
export let rocket: NDKEvent;
|
||||
export let unratifiedZaps = 0;
|
||||
|
||||
let products = new Rocket(rocket).Products()
|
||||
|
||||
</script>
|
||||
|
||||
<Card.Root class="sm:col-span-3">
|
||||
@@ -18,7 +16,7 @@
|
||||
<Card.Description></Card.Description>
|
||||
</Card.Header>
|
||||
<Card.Content class="grid grid-cols-1 gap-2">
|
||||
{#each products as product (product.ID)}
|
||||
{#each new Rocket(rocket).Products() as [id, product] (id)}
|
||||
<div>
|
||||
<ProductCardFromId {rocket} productID={product.ID}>
|
||||
<ProductPurchases bind:unratifiedZaps={unratifiedZaps} {rocket} {product} />
|
||||
|
||||
@@ -67,10 +67,11 @@ export class Rocket {
|
||||
}
|
||||
return '';
|
||||
}
|
||||
Products(): RocketProduct[] {
|
||||
let _products: RocketProduct[] = [];
|
||||
Products(): Map<string, RocketProduct> {
|
||||
let _products = new Map<string, RocketProduct>()
|
||||
for (let p of this.Event.getMatchingTags('product')) {
|
||||
_products.push(new RocketProduct(p));
|
||||
let rp = new RocketProduct(p)
|
||||
_products.set(rp.ID, rp);
|
||||
}
|
||||
return _products;
|
||||
}
|
||||
@@ -521,7 +522,7 @@ export class ZapPurchase {
|
||||
return true;
|
||||
}
|
||||
let product = this.ProductFromRocket(rocket);
|
||||
if (product && this.Amount >= product.Price) {
|
||||
if (product && this.Amount/1000 >= product.Price) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user