Skip to content

Commit df07ec2

Browse files
authored
feat(app): show recommended channels in explorer (#3739)
2 parents f747b0b + 29bd3b3 commit df07ec2

File tree

18 files changed

+82
-42
lines changed

18 files changed

+82
-42
lines changed

app/app.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ _: {
1919
{
2020
packages = {
2121
app = jsPkgs.buildNpmPackage {
22-
npmDepsHash = "sha256-tNMs7TF64XK3agDQY9mcZ1mAz1y0gKPokYB6XnGjHAA=";
22+
npmDepsHash = "sha256-udhyqmAnsVAlVlyoML6Gc5RTgLb6H9ahNaAKHEFUkNA=";
2323
src = ./.;
2424
sourceRoot = "app";
2525
npmFlags = [

app/package-lock.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"@tanstack/svelte-query": "5.61.5",
2929
"@tanstack/svelte-table": "^8.20.5",
3030
"@tanstack/svelte-virtual": "3.10.9",
31-
"@unionlabs/client": "^0.0.59",
31+
"@unionlabs/client": "^0.0.60",
3232
"@wagmi/connectors": "5.7.5",
3333
"@wagmi/core": "2.16.3",
3434
"bits-ui": "^0.21.13",

app/src/lib/components/address.svelte

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const explorer = chain?.explorers?.at(0)?.address_url ?? null
4040
{#if !explorer}
4141
{#if truncate}<Truncate value={parsedAddress} type="address"/>{:else}{parsedAddress}{/if}
4242
{:else}
43-
<a class="underline" on:click={(e) => e.stopPropagation()} href={`${explorer}${parsedAddress}`}>{#if truncate}<Truncate class="underline" value={parsedAddress} type="address"/>{:else}{parsedAddress}{/if}</a>
43+
<a class="underline" target="_blank" on:click={(e) => e.stopPropagation()} href={`${explorer}${parsedAddress}`}>{#if truncate}<Truncate class="underline text-muted-foreground" value={parsedAddress} type="address"/>{:else}{parsedAddress}{/if}</a>
4444
{/if}{#if showChain}<span class="text-muted-foreground flex gap-1"><ArrowLeftIcon />{toDisplayName(
4545
chainId,
4646
chains,
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
<script lang="ts">
2+
import ChainDetails from "$lib/chain-details.svelte"
3+
import type { Chain } from "$lib/types"
24
import { cn } from "$lib/utilities/shadcn.ts"
5+
import { fromHex, isHex } from "viem"
6+
import Address from "../address.svelte"
37
import CellCopy from "./cell-copy.svelte"
8+
import { bech32AddressToHex } from "@unionlabs/client"
9+
10+
export let chains: Array<Chain>
411
512
export let value: {
613
chain_display_name: string | undefined
@@ -9,12 +16,23 @@ export let value: {
916
channel_id: string | undefined
1017
port_id: string | undefined
1118
}
19+
20+
export const chain = chains.find(c => c.chain_id === value.chain_id)
21+
export const port =
22+
chain?.rpc_type === "cosmos" && isHex(value.port_id)
23+
? bech32AddressToHex({ address: fromHex(value.port_id, "string") })
24+
: value.port_id
1225
</script>
1326

14-
<div {...$$restProps} class={cn("flex flex-col ")}>
15-
{#if value.chain_display_name}<CellCopy value={value.chain_display_name}/>{/if}
16-
{#if value.chain_id}<CellCopy label="Chain ID: " value={value.chain_id}/>{/if}
17-
{#if value.connection_id}<CellCopy label="Connection ID: " value={value.connection_id}/>{/if}
18-
{#if value.channel_id}<CellCopy label="Channel ID: " value={value.channel_id}/>{/if}
19-
{#if value.port_id}<CellCopy label="Port: " trunc={10} value={value.port_id}/>{/if}
27+
<div {...$$restProps} class={cn("flex flex-col items-start")}>
28+
29+
{#if chain}
30+
<div class="font-bold">
31+
<ChainDetails {chain}/>
32+
</div>
33+
{#if value.chain_id && value.channel_id && value.connection_id}<div class="text-muted-foreground">{value.chain_id} | {value.connection_id} | {value.channel_id}</div>{/if}
34+
{#if port && value.chain_id}<Address {chains} chainId={value.chain_id} address={port}/>{/if}
35+
{:else}
36+
<div>chain {value.chain_id} not found</div>
37+
{/if}
2038
</div>

app/src/lib/components/tables/packets.svelte

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ import {
1616
import { timestamp } from "$lib/stores/page.ts"
1717
import CellCopy from "../table-cells/cell-copy.svelte"
1818
import { page } from "$app/stores"
19-
import type { ChainFeature } from "$lib/types.ts"
19+
import type { Chain, ChainFeature } from "$lib/types.ts"
2020
21+
export let chains: Array<Chain>
2122
// export let chains: Array<Chain>
2223
export let chain_id: string | undefined = undefined
2324
export let connection_id: number | undefined = undefined
@@ -56,12 +57,12 @@ const columns: Array<ColumnDef<PacketRow>> = [
5657
{
5758
accessorKey: "source",
5859
size: 200,
59-
cell: info => flexRender(CellOriginChannel, { value: info.getValue() })
60+
cell: info => flexRender(CellOriginChannel, { chains, value: info.getValue() })
6061
},
6162
{
6263
accessorKey: "destination",
6364
size: 200,
64-
cell: info => flexRender(CellOriginChannel, { value: info.getValue() })
65+
cell: info => flexRender(CellOriginChannel, { chains, value: info.getValue() })
6566
},
6667
{
6768
accessorKey: "send",

app/src/lib/components/trace.svelte

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ $: pTraces = ((): Array<Trace> => {
126126
</div>
127127
<div class="font-bold py-4 flex flex-col min-h-[80px] max-w-[calc(100%-80px)] break-words justify-center">
128128
{#if trace.timestamp}
129-
<p class="text-xs -mb-1 text-muted-foreground">{toIsoString(new Date(trace.timestamp)).split('T')[1]} on {toDisplayName(trace.chain.chain_id, chains)} at {#if trace.block_url}<a class="underline" href={trace.block_url}>{trace.height}</a>{:else}{trace.height}{/if}</p>
129+
<p class="text-xs -mb-1 text-muted-foreground">{toIsoString(new Date(trace.timestamp)).split('T')[1]} on {toDisplayName(trace.chain.chain_id, chains)} at {#if trace.block_url}<a class="underline" target="_blank" href={trace.block_url}>{trace.height}</a>{:else}{trace.height}{/if}</p>
130130
{/if}
131131
<div>{trace.type}</div>
132132
{#if trace.transaction_hash}
133133
{#if trace.transaction_url}
134-
<a href={trace.transaction_url} class="-mt-1 block underline text-xs text-muted-foreground"><Truncate class="underline" value={trace.transaction_hash} type="hash"/></a>
134+
<a href={trace.transaction_url} target="_blank" class="-mt-1 block underline text-xs text-muted-foreground"><Truncate class="underline" value={trace.transaction_hash} type="hash"/></a>
135135
{:else}
136136
<p class="text-xs text-muted-foreground"><Truncate value={trace.transaction_hash} type="hash"/></p>
137137
{/if}

app/src/lib/graphql/queries/channels.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { graphql } from "gql.tada"
22

33
export const channelsQuery =
44
graphql(/* GraphQL */ `query ChannelsQuery($limit: Int = 500) @cached(ttl: 30) {
5-
v1_ibc_union_channels(
6-
# where: {source_chain: {enabled: {_eq: true}}, destination_chain: {enabled: {_eq: true}}},
5+
v1_ibc_union_channel_recommendations(
6+
where: {source_chain: {enabled: {_eq: true}}, destination_chain: {enabled: {_eq: true}}},
77
order_by: [
88
{status: asc},
99
{source_chain_id: asc},
@@ -30,8 +30,9 @@ export const channelsQuery =
3030
destination_chain {
3131
enabled
3232
display_name
33-
}
33+
}
3434
status
35+
version
3536
}
3637
}`)
3738

app/src/routes/explorer/(components)/table-channels.svelte

+15-9
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,31 @@ import { derived } from "svelte/store"
99
import CellOriginChannel from "$lib/components/table-cells/cell-origin-channel.svelte"
1010
import LoadingLogo from "$lib/components/loading-logo.svelte"
1111
import type { UnwrapReadable } from "$lib/utilities/types"
12-
import type { ChainFeature } from "$lib/types.ts"
12+
import type { Chain, ChainFeature } from "$lib/types.ts"
1313
import { page } from "$app/stores"
1414
15+
export let chains: Array<Chain>
1516
let channels = createQuery({
1617
queryKey: ["channels"],
1718
refetchInterval: 5_000,
1819
retryDelay: attempt => Math.min(attempt > 1 ? 2 ** attempt * 1000 : 1000, 30 * 1000),
1920
queryFn: async () => request(URLS().GRAPHQL, channelsQuery, {}),
2021
select: data =>
21-
data.v1_ibc_union_channels.map(channel => ({
22+
data.v1_ibc_union_channel_recommendations.map(channel => ({
2223
source_chain: {
23-
chain_display_name: channel.destination_chain?.display_name ?? "unknown",
2424
chain_id: channel.source_chain_id ?? "unknown",
2525
connection_id: channel.destination_connection_id ?? "unknown",
2626
channel_id: channel.source_channel_id ?? "unknown",
2727
port_id: channel.source_port_id ?? "unknown"
2828
},
2929
destination_chain: {
30-
chain_display_name: channel.source_chain?.display_name ?? "unknown",
3130
chain_id: channel.destination_chain_id ?? "unknown",
3231
connection_id: channel.destination_connection_id ?? "unknown",
3332
channel_id: channel.destination_channel_id ?? "unknown",
3433
port_id: channel.destination_port_id ?? "unknown"
3534
},
36-
status: channel.status
35+
status: channel.status,
36+
version: channel.version
3737
}))
3838
})
3939
@@ -54,15 +54,21 @@ type DataRow = UnwrapReadable<typeof channelsDataStore>[number]
5454
const columns: Array<ColumnDef<DataRow>> = [
5555
{
5656
accessorKey: "source_chain",
57-
header: () => "Source chain",
57+
header: () => "Source",
5858
size: 200,
59-
cell: info => flexRender(CellOriginChannel, { value: info.getValue() })
59+
cell: info => flexRender(CellOriginChannel, { chains, value: info.getValue() })
6060
},
6161
{
6262
accessorKey: "destination_chain",
63-
header: () => "Destination chain",
63+
header: () => "Destination",
6464
size: 200,
65-
cell: info => flexRender(CellOriginChannel, { value: info.getValue() })
65+
cell: info => flexRender(CellOriginChannel, { chains, value: info.getValue() })
66+
},
67+
{
68+
accessorKey: "status"
69+
},
70+
{
71+
accessorKey: "version"
6672
}
6773
]
6874
</script>

app/src/routes/explorer/(components)/table.svelte

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ onDestroy(unsubscribe)
9494
{#each $virtualizer.getVirtualItems() as row, index (row.index)}
9595
{@const url = $rows[row.index].original.url ?? undefined}
9696
<Table.Row
97-
class={cn("cursor-pointer",
97+
class={cn(url ? "cursor-pointer" : "",
9898
index % 2 === 0 ? 'bg-secondary/10' : 'bg-transparent',
9999
)}
100100
on:click={(e) => {if (url) { goto(url)}}}

app/src/routes/explorer/+layout.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const load = (loadEvent => ({
3434
{
3535
route: "channels",
3636
icon: ChannelsIcon,
37-
description: "Open IBC Channels"
37+
description: "Recommended open IBC channels"
3838
},
3939
{
4040
route: "index-status",
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<script lang="ts">
2+
import ChainsGate from "$lib/components/chains-gate.svelte"
23
import TableChannels from "../(components)/table-channels.svelte"
34
</script>
45

5-
<TableChannels />
6+
<ChainsGate let:chains>
7+
<TableChannels {chains} />
8+
</ChainsGate>
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<script lang="ts">
2+
import ChainsGate from "$lib/components/chains-gate.svelte"
23
import TablePackets from "$lib/components/tables/packets.svelte"
34
</script>
45

5-
<TablePackets />
6+
<ChainsGate let:chains>
7+
<TablePackets {chains} />
8+
</ChainsGate>
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<script lang="ts">
22
import { page } from "$app/stores"
3+
import ChainsGate from "$lib/components/chains-gate.svelte"
34
import TablePackets from "$lib/components/tables/packets.svelte"
4-
55
const chain_id = $page.params.chain_id
66
</script>
7-
<TablePackets {chain_id}/>
7+
8+
<ChainsGate let:chains>
9+
<TablePackets {chains} {chain_id}/>
10+
</ChainsGate>
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<script lang="ts">
22
import { page } from "$app/stores"
33
import TablePackets from "$lib/components/tables/packets.svelte"
4+
import ChainsGate from "$lib/components/chains-gate.svelte"
45
56
const chain_id = $page.params.chain_id
67
const connection_id = $page.params.connection_id
78
</script>
89

9-
10-
<TablePackets {chain_id} {connection_id}/>
10+
<ChainsGate let:chains>
11+
<TablePackets {chains} {chain_id} {connection_id}/>
12+
</ChainsGate>
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<script lang="ts">
22
import { page } from "$app/stores"
33
import TablePackets from "$lib/components/tables/packets.svelte"
4+
import ChainsGate from "$lib/components/chains-gate.svelte"
45
56
const chain_id = $page.params.chain_id
67
const connection_id = $page.params.connection_id
78
const channel_id = $page.params.channel_id
89
</script>
910

10-
<TablePackets {chain_id} {connection_id} {channel_id}/>
11+
<ChainsGate let:chains>
12+
<TablePackets {chains} {chain_id} {connection_id} {channel_id}/>
13+
</ChainsGate>

typescript-sdk/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@unionlabs/client",
3-
"version": "0.0.59",
3+
"version": "0.0.60",
44
"homepage": "https://union.build",
55
"description": "Union Labs cross-chain transfers client",
66
"type": "module",

typescript-sdk/src/convert.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { raise } from "./utilities/index.ts"
22
import { bech32, hex, bytes } from "@scure/base"
33
import type { Bech32Address, HexAddress } from "./types.ts"
4-
import { isValidBech32Address } from "./utilities/address.ts"
4+
import { isValidBech32Address, isValidBech32ContractAddress } from "./utilities/address.ts"
55

66
/**
77
* convert a bech32 address (cosmos, osmosis, union addresses) to hex address (evm)
@@ -11,7 +11,7 @@ import { isValidBech32Address } from "./utilities/address.ts"
1111
* ```
1212
*/
1313
export function bech32AddressToHex({ address }: { address: string }): HexAddress {
14-
if (!isValidBech32Address(address)) raise(`Invalid bech32 address: ${address}`)
14+
if (!isValidBech32ContractAddress(address)) raise(`Invalid bech32 address: ${address}`)
1515
const { bytes } = bech32.decodeToBytes(address)
1616
return `0x${bytesToHex(bytes)}`
1717
}

0 commit comments

Comments
 (0)