mirror of
https://github.com/aljazceru/hypergolic.git
synced 2025-12-20 15:04:18 +01:00
Merge pull request #69 from bob2402/price-display
problem: product price not displayed nicely
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
import QrCodeSvg from './QrCodeSvg.svelte';
|
import QrCodeSvg from './QrCodeSvg.svelte';
|
||||||
import CopyButton from './CopyButton.svelte';
|
import CopyButton from './CopyButton.svelte';
|
||||||
import type { Product, Rocket, RocketProduct } from '@/event_helpers/rockets';
|
import type { Product, Rocket, RocketProduct } from '@/event_helpers/rockets';
|
||||||
|
import { formatSats } from '@/helpers';
|
||||||
|
|
||||||
export let product: Product;
|
export let product: Product;
|
||||||
export let rocketProduct: RocketProduct | undefined;
|
export let rocketProduct: RocketProduct | undefined;
|
||||||
@@ -21,7 +22,11 @@
|
|||||||
|
|
||||||
async function zap() {
|
async function zap() {
|
||||||
if (rocketProduct) {
|
if (rocketProduct) {
|
||||||
const z = new NDKZap({ ndk: $ndk, zappedEvent: rocket.Event, zappedUser: rocket.Event.author });
|
const z = new NDKZap({
|
||||||
|
ndk: $ndk,
|
||||||
|
zappedEvent: rocket.Event,
|
||||||
|
zappedUser: rocket.Event.author
|
||||||
|
});
|
||||||
invoice = await z.createZapRequest(
|
invoice = await z.createZapRequest(
|
||||||
rocketProduct.Price * 1000,
|
rocketProduct.Price * 1000,
|
||||||
`Purchase of ${product.Name()} from ${rocket.Event.dTag}`,
|
`Purchase of ${product.Name()} from ${rocket.Event.dTag}`,
|
||||||
@@ -51,13 +56,11 @@
|
|||||||
{#if rocketProduct}
|
{#if rocketProduct}
|
||||||
<Dialog.Root bind:open>
|
<Dialog.Root bind:open>
|
||||||
<Dialog.Trigger class={buttonVariants({ variant: 'default' })}
|
<Dialog.Trigger class={buttonVariants({ variant: 'default' })}
|
||||||
>Buy Now for {rocketProduct.Price} sats</Dialog.Trigger
|
>Buy Now for {formatSats(rocketProduct.Price)}</Dialog.Trigger
|
||||||
>
|
>
|
||||||
<Dialog.Content class="sm:max-w-[425px]">
|
<Dialog.Content class="sm:max-w-[425px]">
|
||||||
<Dialog.Header>
|
<Dialog.Header>
|
||||||
<Dialog.Title
|
<Dialog.Title>Buy {product.Name()} from {rocket.Name()} now!</Dialog.Title>
|
||||||
>Buy {product.Name()} from {rocket.Name()} now!</Dialog.Title
|
|
||||||
>
|
|
||||||
{#if !currentUser}
|
{#if !currentUser}
|
||||||
<Alert.Root>
|
<Alert.Root>
|
||||||
<Terminal class="h-4 w-4" />
|
<Terminal class="h-4 w-4" />
|
||||||
@@ -67,7 +70,11 @@
|
|||||||
>
|
>
|
||||||
</Alert.Root>
|
</Alert.Root>
|
||||||
{/if}
|
{/if}
|
||||||
<Dialog.Description>Pay {rocketProduct.Price} sats now with Lightning</Dialog.Description>
|
<Dialog.Description
|
||||||
|
>Pay {rocketProduct.Price === 1
|
||||||
|
? `${rocketProduct.Price} sat`
|
||||||
|
: `${rocketProduct.Price} sats`} now with Lightning</Dialog.Description
|
||||||
|
>
|
||||||
</Dialog.Header>
|
</Dialog.Header>
|
||||||
{#if invoice}
|
{#if invoice}
|
||||||
<QrCodeSvg content={invoice} />
|
<QrCodeSvg content={invoice} />
|
||||||
|
|||||||
@@ -71,6 +71,17 @@ export function formatReferenceTime(hours: number) {
|
|||||||
return result || '0 minutes';
|
return result || '0 minutes';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function formatSats(sats: number): string {
|
||||||
|
if (sats === 1) {
|
||||||
|
return '1 sat';
|
||||||
|
} else if (sats >= 1000) {
|
||||||
|
const kSats = (sats / 1000).toFixed(0);
|
||||||
|
return `${kSats}k sats`;
|
||||||
|
} else {
|
||||||
|
return `${sats} sats`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function getCuckPrice(): Promise<number | Error> {
|
export async function getCuckPrice(): Promise<number | Error> {
|
||||||
try {
|
try {
|
||||||
var url = 'https://api.coindesk.com/v1/bpi/currentprice.json';
|
var url = 'https://api.coindesk.com/v1/bpi/currentprice.json';
|
||||||
|
|||||||
Reference in New Issue
Block a user