Skip to content

Commit

Permalink
feat(tauri/ui): link to vault detail page from order detail page
Browse files Browse the repository at this point in the history
  • Loading branch information
mattyg committed Jan 29, 2024
1 parent 1700e7b commit 6183ae4
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 9 deletions.
10 changes: 10 additions & 0 deletions crates/subgraph/queries/order.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ query OrderQuery($id: ID!) {
tokenVault {
id
vaultId
vault {
owner {
id
}
}
token {
id
name
Expand All @@ -27,6 +32,11 @@ query OrderQuery($id: ID!) {
tokenVault {
id
vaultId
vault {
owner {
id
}
}
token {
id
name
Expand Down
7 changes: 7 additions & 0 deletions crates/subgraph/src/types/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,16 @@ pub struct Io {
pub struct TokenVault {
pub id: cynic::Id,
pub vault_id: BigInt,
pub vault: Vault,
pub token: Erc20,
}

#[typeshare]
#[derive(cynic::QueryFragment, Debug, Clone, Serialize)]
pub struct Vault {
pub owner: Account,
}

#[typeshare]
#[derive(cynic::QueryFragment, Debug, Clone, Serialize)]
#[cynic(graphql_type = "ERC20")]
Expand Down
16 changes: 16 additions & 0 deletions tauri-app/src/lib/components/ButtonVaultLink.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script lang="ts">
import { goto } from "$app/navigation";
import type { TokenVault } from "$lib/typeshare/order";
import { formatAddressShorthand } from "$lib/utils/address";
import { Button } from "flowbite-svelte";
import { toHex } from "viem";
export let tokenVault: TokenVault;
</script>
<Button color="alternative" size="sm" on:click={() => goto(`/vaults/${tokenVault.id}`)} class="max-w-64 px-2">
<div class="text-left w-full">
<div class="text-lg mb-2 font-bold">{tokenVault.token.name}</div>
<div class="mb-1 overflow-hidden text-ellipsis"><span class="font-bold">Vault ID</span> {toHex(tokenVault.vault_id)}</div>
<div><span class="mb-1 font-bold">Owner</span> {formatAddressShorthand(tokenVault.vault.owner.id)}</div>
</div>
</Button>
8 changes: 8 additions & 0 deletions tauri-app/src/lib/utils/address.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { getAddress, isAddress } from "viem";

export function formatAddressShorthand(address: string, size=4) {
if(!isAddress(address)) throw Error("Must be a valid address");
const cased = getAddress(address);

return `${cased.slice(0, size+2)}...${cased.slice(cased.length-size, cased.length)}`;
}
23 changes: 14 additions & 9 deletions tauri-app/src/routes/orders/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ModalOrderRemove from '$lib/components/ModalOrderRemove.svelte';
import BadgeActive from '$lib/components/BadgeActive.svelte';
import { formatTimestampSecondsAsLocal } from '$lib/utils/time';
import ButtonVaultLink from '$lib/components/ButtonVaultLink.svelte';
export let data: { id: string };
let showRemoveModal = false;
Expand Down Expand Up @@ -59,24 +60,28 @@

<div class="mt-8">
<h5 class="mb-2 w-full text-xl font-bold tracking-tight text-gray-900 dark:text-white">
Input Token(s)
Input Vaults
</h5>
<p class="break-all font-normal leading-tight text-gray-700 dark:text-gray-400">
{order.valid_inputs?.map((t) => t.token_vault.token.name)}
</p>
<div class="flex flex-wrap space-x-2 space-y-2">
{#each (order.valid_inputs || []) as t}
<ButtonVaultLink tokenVault={t.token_vault} />
{/each}
</div>
</div>

<div class="mt-8">
<h5 class="mb-2 w-full text-xl font-bold tracking-tight text-gray-900 dark:text-white">
Output Token(s)
Output Vaults
</h5>
<p class="break-all font-normal leading-tight text-gray-700 dark:text-gray-400">
{order.valid_outputs?.map((t) => t.token_vault.token.name)}
</p>
<div class="flex flex-wrap space-x-2 space-y-2">
{#each (order.valid_outputs || []) as t}
<ButtonVaultLink tokenVault={t.token_vault} />
{/each}
</div>
</div>

{#if $walletAddressMatchesOrBlank(order.owner.id) && order.order_active}
<div class="pt-4">
<div class="mt-8">
<div class="flex justify-center space-x-20">
<ButtonLoading color="blue" size="xl" on:click={() => (showRemoveModal = true)}>
Remove
Expand Down

0 comments on commit 6183ae4

Please sign in to comment.