-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #738 from rainlanguage/2024-07-24-vault-detail
splitting out vault detail
- Loading branch information
Showing
15 changed files
with
799 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
27 changes: 27 additions & 0 deletions
27
tauri-app/src/lib/components/charts/TanstackLightweightChartLine.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<script lang="ts" generics="T"> | ||
import LightweightChartLine from './LightweightChartLine.svelte'; | ||
import type { CreateQueryResult } from '@tanstack/svelte-query'; | ||
import type { UTCTimestamp } from 'lightweight-charts'; | ||
import { sortBy } from 'lodash'; | ||
// eslint-disable-next-line no-undef | ||
export let query: CreateQueryResult<T[]>; | ||
// eslint-disable-next-line no-undef | ||
export let timeTransform: (data: T) => UTCTimestamp; | ||
// eslint-disable-next-line no-undef | ||
export let valueTransform: (data: T) => number; | ||
// eslint-disable-next-line no-undef | ||
const transformAndSortData = (data: T[]) => { | ||
const transformedData = data.map((d) => ({ | ||
value: valueTransform(d), | ||
time: timeTransform(d), | ||
})); | ||
return sortBy(transformedData, (d) => d.time); | ||
}; | ||
$: data = transformAndSortData($query.data ?? []); | ||
</script> | ||
|
||
<LightweightChartLine {data} loading={$query.isLoading} {...$$props} /> |
31 changes: 31 additions & 0 deletions
31
tauri-app/src/lib/components/charts/VaultBalanceChart.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<script lang="ts"> | ||
import { timestampSecondsToUTCTimestamp } from '$lib/utils/time'; | ||
import { bigintToFloat } from '$lib/utils/number'; | ||
import type { Vault } from '$lib/typeshare/vaultDetail'; | ||
import { createQuery } from '@tanstack/svelte-query'; | ||
import { vaultBalanceChangesList } from '$lib/queries/vaultBalanceChangesList'; | ||
import { subgraphUrl } from '$lib/stores/settings'; | ||
import TanstackLightweightChartLine from './TanstackLightweightChartLine.svelte'; | ||
export let vault: Vault; | ||
$: query = createQuery({ | ||
queryKey: ['vaultBalanceChanges', vault.id], | ||
queryFn: () => { | ||
return vaultBalanceChangesList(vault.id, '', 0, 1000); | ||
}, | ||
enabled: !!$subgraphUrl, | ||
}); | ||
</script> | ||
|
||
{#if vault} | ||
<TanstackLightweightChartLine | ||
title="Balance history" | ||
priceSymbol={vault.token.symbol} | ||
{query} | ||
timeTransform={(d) => timestampSecondsToUTCTimestamp(BigInt(d.timestamp))} | ||
valueTransform={(d) => | ||
bigintToFloat(BigInt(d.new_vault_balance), Number(vault.token.decimals ?? 0))} | ||
emptyMessage="No deposits or withdrawals found" | ||
/> | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<script lang="ts"> | ||
import VaultBalanceChangesTable from '../tables/VaultBalanceChangesTable.svelte'; | ||
import { Button } from 'flowbite-svelte'; | ||
import { walletAddressMatchesOrBlank } from '$lib/stores/wallets'; | ||
import { bigintStringToHex } from '$lib/utils/hex'; | ||
import Hash from '$lib/components/Hash.svelte'; | ||
import { HashType } from '$lib/types/hash'; | ||
import { goto } from '$app/navigation'; | ||
import { ArrowDownOutline, ArrowUpOutline } from 'flowbite-svelte-icons'; | ||
import CardProperty from '$lib/components/CardProperty.svelte'; | ||
import { formatUnits } from 'viem'; | ||
import { createQuery } from '@tanstack/svelte-query'; | ||
import { vaultDetail } from '$lib/queries/vaultDetail'; | ||
import { QKEY_VAULT } from '$lib/queries/keys'; | ||
import { subgraphUrl } from '$lib/stores/settings'; | ||
import { handleDepositModal, handleWithdrawModal } from '$lib/services/modal'; | ||
import TanstackContentDetail from '$lib/components/detail/TanstackPageContentDetail.svelte'; | ||
import VaultBalanceChart from '$lib/components/charts/VaultBalanceChart.svelte'; | ||
export let id: string; | ||
$: vaultDetailQuery = createQuery({ | ||
queryKey: [QKEY_VAULT + id], | ||
queryFn: () => { | ||
return vaultDetail(id, $subgraphUrl || ''); | ||
}, | ||
enabled: !!$subgraphUrl, | ||
}); | ||
</script> | ||
|
||
<TanstackContentDetail query={vaultDetailQuery} emptyMessage="Vault not found"> | ||
<svelte:fragment slot="top" let:data> | ||
<div | ||
data-testid="vaultDetailTokenName" | ||
class="flex gap-x-4 text-3xl font-medium dark:text-white" | ||
> | ||
{data.token.name} | ||
</div> | ||
<div> | ||
{#if $walletAddressMatchesOrBlank(data.owner)} | ||
<Button | ||
data-testid="vaultDetailDepositButton" | ||
color="dark" | ||
on:click={() => handleDepositModal(data)} | ||
><ArrowDownOutline size="xs" class="mr-2" />Deposit</Button | ||
> | ||
<Button | ||
data-testid="vaultDetailWithdrawButton" | ||
color="dark" | ||
on:click={() => handleWithdrawModal(data)} | ||
><ArrowUpOutline size="xs" class="mr-2" />Withdraw</Button | ||
> | ||
{/if} | ||
</div> | ||
</svelte:fragment> | ||
<svelte:fragment slot="card" let:data> | ||
<CardProperty data-testid="vaultDetailVaultId"> | ||
<svelte:fragment slot="key">Vault ID</svelte:fragment> | ||
<svelte:fragment slot="value">{bigintStringToHex(data.vault_id)}</svelte:fragment> | ||
</CardProperty> | ||
|
||
<CardProperty data-testid="vaultDetailOwnerAddress"> | ||
<svelte:fragment slot="key">Owner Address</svelte:fragment> | ||
<svelte:fragment slot="value"> | ||
<Hash type={HashType.Wallet} value={data.owner} /> | ||
</svelte:fragment> | ||
</CardProperty> | ||
|
||
<CardProperty data-testid="vaultDetailTokenAddress"> | ||
<svelte:fragment slot="key">Token address</svelte:fragment> | ||
<svelte:fragment slot="value"> | ||
<Hash value={data.token.id} /> | ||
</svelte:fragment> | ||
</CardProperty> | ||
|
||
<CardProperty data-testid="vaultDetailBalance"> | ||
<svelte:fragment slot="key">Balance</svelte:fragment> | ||
<svelte:fragment slot="value" | ||
>{formatUnits(BigInt(data.balance), Number(data.token.decimals ?? 0))} | ||
{data.token.symbol}</svelte:fragment | ||
> | ||
</CardProperty> | ||
|
||
<CardProperty> | ||
<svelte:fragment slot="key">Orders as input</svelte:fragment> | ||
<svelte:fragment slot="value"> | ||
<p data-testid="vaultDetailOrdersAsInput" class="flex flex-wrap justify-start"> | ||
{#if data.orders_as_input && data.orders_as_input.length > 0} | ||
{#each data.orders_as_input as order} | ||
<Button | ||
class={'mr-1 mt-1 px-1 py-0' + (!order.active ? ' opacity-50' : '')} | ||
color="light" | ||
data-order={order.id} | ||
data-testid={'vaultDetailOrderAsInputOrder' + order.id} | ||
on:click={() => goto(`/orders/${order.id}`)} | ||
> | ||
<Hash type={HashType.Identifier} value={order.order_hash} copyOnClick={false} /> | ||
</Button> | ||
{/each} | ||
{:else} | ||
None | ||
{/if} | ||
</p> | ||
</svelte:fragment> | ||
</CardProperty> | ||
|
||
<CardProperty> | ||
<svelte:fragment slot="key">Orders as output</svelte:fragment> | ||
<svelte:fragment slot="value"> | ||
<p data-testid="vaulDetailOrdersAsOutput" class="flex flex-wrap justify-start"> | ||
{#if data.orders_as_output && data.orders_as_output.length > 0} | ||
{#each data.orders_as_output as order} | ||
<Button | ||
class={'mr-1 mt-1 px-1 py-0' + (!order.active ? ' opacity-50' : '')} | ||
color="alternative" | ||
data-order={order.id} | ||
data-testid={'vaultDetailOrderAsOutputOrder' + order.id} | ||
on:click={() => goto(`/orders/${order.id}`)} | ||
> | ||
<Hash type={HashType.Identifier} value={order.order_hash} copyOnClick={false} /> | ||
</Button> | ||
{/each} | ||
{:else} | ||
None | ||
{/if} | ||
</p> | ||
</svelte:fragment> | ||
</CardProperty> | ||
</svelte:fragment> | ||
|
||
<svelte:fragment slot="chart" let:data> | ||
<VaultBalanceChart vault={data} /> | ||
</svelte:fragment> | ||
|
||
<svelte:fragment slot="below"><VaultBalanceChangesTable {id} /></svelte:fragment> | ||
</TanstackContentDetail> |
Oops, something went wrong.