diff --git a/src/components/MeritsAndSatflow.svelte b/src/components/MeritsAndSatflow.svelte index 3e6a1ad..3d4af64 100644 --- a/src/components/MeritsAndSatflow.svelte +++ b/src/components/MeritsAndSatflow.svelte @@ -7,11 +7,53 @@ import { writable } from 'svelte/store'; import Pie from './Pie.svelte'; import NumberIncrement from './NumberIncrement.svelte'; + import { toast } from 'svelte-sonner'; + import { onMount } from 'svelte'; + import PurchaseToast from './PurchaseToast.svelte'; + import { devmode } from '@/stores/session'; + import Button from '@/components/ui/button/button.svelte'; export let rocket: Rocket; export let unratifiedZaps: Map; let unratifiedZapsAmount = 0; + let lastCheckTime = Date.now() / 1000; + + function checkNewZaps() { + const currentTime = Date.now() / 1000; + const recentZaps = Array.from(unratifiedZaps.values()).filter( + (zap) => + zap.ZapReceipt.created_at && + zap.ZapReceipt.created_at > lastCheckTime && + zap.ZapReceipt.created_at <= currentTime + ); + + recentZaps.forEach((zapPurchase) => { + toast(PurchaseToast, { + componentProps: { + zapPurchase, + rocket: rocket + } + }); + }); + + lastCheckTime = currentTime; + } + $: { + if (unratifiedZaps.size > 0) { + checkNewZaps(); + } + } + + onMount(() => { + lastCheckTime = Date.now() / 1000 - 30; // 30 seconds ago + }); + + $: lasted = Array.from(unratifiedZaps.values()).sort((a, b) => { + if (a.ZapReceipt.created_at && b.ZapReceipt.created_at) { + return b.ZapReceipt.created_at - a.ZapReceipt.created_at; + } else return 0; + })[0]; $: { unratifiedZapsAmount = 0; @@ -82,6 +124,7 @@ This graph displays the Meritization of equity in {rocket.Name()} + @@ -115,5 +158,27 @@ - + + {#if $devmode} + + + {/if} + diff --git a/src/components/PruchaseToast.svelte b/src/components/PurchaseToast.svelte similarity index 91% rename from src/components/PruchaseToast.svelte rename to src/components/PurchaseToast.svelte index 1b8db28..21d3a7c 100644 --- a/src/components/PruchaseToast.svelte +++ b/src/components/PurchaseToast.svelte @@ -1,11 +1,8 @@
@@ -71,27 +32,6 @@
- {#if $devmode} - - - {/if}