diff --git a/app/src/lib/graphql/documents/stats.ts b/app/src/lib/graphql/documents/stats.ts new file mode 100644 index 0000000000..72866baf0b --- /dev/null +++ b/app/src/lib/graphql/documents/stats.ts @@ -0,0 +1,57 @@ +import { graphql } from "gql.tada" + +export const statsQueryDocument = graphql(/* GraphQL */ ` + query StatsQuery @cached(ttl: 5) { + v0_stats { + total_packets + total_transfers + } + } +`) + +export const transferCountQueryDocument = graphql(/* GraphQL */ ` + query TransferCountQuery @cached(ttl: 5) { + v0_transfers_aggregate { + aggregate { + count + } + } + } +`) + +export const transferAddressesCountQueryDocument = graphql(/* GraphQL */ ` + query TransferAddressesCountQuery($addresses: [String!]!) { + v0_transfers_aggregate(where: {normalized_sender: {_in: $addresses}}) { + aggregate { + count + } + } + } +`) + +export const packetCountQueryDocument = graphql(/* GraphQL */ ` + query PacketCountQuery @cached(ttl: 5) { + v0_packets_aggregate { + aggregate { + count + } + } + } +`) + +export const transfersPerDayQueryDocument = graphql(/* GraphQL */ ` + query TransfersPerDay($limit: Int!) @cached(ttl: 60) { + v0_daily_transfers(limit: $limit, order_by: {day: desc}) { + count + day + } + } +`) + +export const packetsPerDayQueryDocument = graphql(/* GraphQL */ ` + query PacketsPerDay($limit: Int!) { + v0_daily_packets(limit: $limit, order_by: {day: desc}) { + count + } + } +`) diff --git a/app/src/lib/graphql/queries/stats.ts b/app/src/lib/graphql/queries/stats.ts index 24ee1c6a13..4be4695089 100644 --- a/app/src/lib/graphql/queries/stats.ts +++ b/app/src/lib/graphql/queries/stats.ts @@ -25,3 +25,13 @@ export const packetsPerDayQueryDocument = graphql(/* GraphQL */ ` } } `) + +export const transferAddressesCountQueryDocument = graphql(/* GraphQL */ ` + query TransferAddressesCountQuery($addresses: [String!]!) { + v1_transfers_aggregate(where: {normalized_sender: {_in: $addresses}}) { + aggregate { + count + } + } + } +`) diff --git a/app/src/lib/queries/stats.ts b/app/src/lib/queries/stats.ts index 5b0d97b230..912a6e670e 100644 --- a/app/src/lib/queries/stats.ts +++ b/app/src/lib/queries/stats.ts @@ -1,6 +1,5 @@ import { createQuery } from "@tanstack/svelte-query" -import { statsQueryDocument, transfersPerDayQueryDocument } from "$lib/graphql/queries/stats.ts" - +import { statsQueryDocument, transfersPerDayQueryDocument, transferAddressesCountQueryDocument } from "$lib/graphql/queries/stats.ts" import { request } from "graphql-request" import { URLS } from "$lib/constants" @@ -22,3 +21,15 @@ export const transfersPerDayQuery = (limit: number) => refetchInterval: 6_000, refetchOnWindowFocus: false }) + +export const transfersAddressQuery = (addresses: Array) => + createQuery({ + queryKey: ["transfer-addresses"], + queryFn: async () => + (await request(URLS.GRAPHQL, transferAddressesCountQueryDocument, { addresses })).v1_transfers_aggregate, + enabled: true, + refetchInterval: 6_000, + refetchOnWindowFocus: false, + }) + + diff --git a/app/src/routes/explorer/(components)/stats-bar.svelte b/app/src/routes/explorer/(components)/stats-bar.svelte index e16295559d..0565c11549 100644 --- a/app/src/routes/explorer/(components)/stats-bar.svelte +++ b/app/src/routes/explorer/(components)/stats-bar.svelte @@ -1,16 +1,18 @@
-
- {#if $deviceWidth > 888 || show === 0} - - - - {/if} - {#if $deviceWidth > 888} - - {/if} - {#if $deviceWidth > 888 || show === 1} - - {#if $transfersPerDayData.data} -
- -
+
+ {#if addresses.length > 0} + + {:else} + {#if $deviceWidth > 888 || show === 0} + + + + {/if} + {#if $deviceWidth > 888} + + {/if} + {#if $deviceWidth > 888 || show === 1} + + {#if $transfersPerDayData.data} +
+ +
+ {/if} +
+ {/if} + {/if} + {#if $deviceWidth > 888 && $supportsWebGL} + + {/if} -
- {/if} - {#if $deviceWidth > 888 && $supportsWebGL} - - - {/if} -
+
+ + diff --git a/app/src/routes/explorer/address/[slug=address]/+layout.svelte b/app/src/routes/explorer/address/[slug=address]/+layout.svelte index 112fd309e5..ae5a5c6968 100644 --- a/app/src/routes/explorer/address/[slug=address]/+layout.svelte +++ b/app/src/routes/explorer/address/[slug=address]/+layout.svelte @@ -33,7 +33,7 @@ let addresses = derived(page, $page => { setContext("addresses", addresses) -
+
{#if $addresses.find( address => chains.find( chain => address.address.startsWith(chain.addr_prefix) ) )} diff --git a/app/src/routes/explorer/address/[slug=address]/+page.svelte b/app/src/routes/explorer/address/[slug=address]/+page.svelte index c3c4db6d08..9953f69607 100644 --- a/app/src/routes/explorer/address/[slug=address]/+page.svelte +++ b/app/src/routes/explorer/address/[slug=address]/+page.svelte @@ -6,6 +6,7 @@ import { derived, writable, type Readable } from "svelte/store" import { decodeTimestampSearchParam } from "$lib/timestamps.ts" import TableTransfers from "$lib/components/transfers-table/transfers-table.svelte" import AddressMultichain from "$lib/components/address-multichain.svelte" +import StatsBar from "../../(components)/stats-bar.svelte" let addresses = getContext>>("addresses") @@ -17,7 +18,10 @@ let normalizedAddresses = derived(addresses, $addresses => -
+
+ +
+
{#each $addresses as address } {/each}