Skip to content

Commit 92c4cb2

Browse files
committed
feat: structure queries and mutations
1 parent e9a977f commit 92c4cb2

File tree

15 files changed

+336
-1297
lines changed

15 files changed

+336
-1297
lines changed

app/app.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{
1010
packages = {
1111
app = unstablePkgs.buildNpmPackage {
12-
npmDepsHash = "sha256-yZ1tygnZX07qovPOGK4sF0uVCxyVS4qdfMUStVvVFrs=";
12+
npmDepsHash = "";
1313
src = ./.;
1414
sourceRoot = "app";
1515
pname = packageJSON.name;

app/package-lock.json

Lines changed: 230 additions & 992 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/package.json

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,25 @@
2121
"@formkit/auto-animate": "^0.8.1",
2222
"@formkit/tempo": "^0.0.17",
2323
"@leapwallet/cosmos-snap-provider": "^0.1.26",
24-
"@tanstack/svelte-query": "^5.28.4",
25-
"@tanstack/svelte-query-persist-client": "^5.28.4",
24+
"@tanstack/svelte-query": "^5.28.6",
25+
"@tanstack/svelte-query-persist-client": "^5.28.6",
26+
"@tanstack/svelte-table": "^8.14.0",
2627
"@wagmi/connectors": "^4.1.18",
2728
"@wagmi/core": "^2.6.9",
2829
"bits-ui": "^0.20.0",
2930
"gql.tada": "^1.3.6",
31+
"graphql-request": "^6.1.0",
3032
"svelte-french-toast": "^1.2.0",
3133
"svelte-radix": "^1.1.0",
3234
"tailwind-merge": "^2.2.2",
3335
"tailwind-variants": "^0.2.1",
3436
"unstorage": "^1.10.2",
3537
"vaul-svelte": "^0.3.0",
36-
"viem": "^2.8.12"
38+
"viem": "^2.8.16"
3739
},
3840
"devDependencies": {
39-
"@0no-co/graphqlsp": "^1.6.0",
40-
"@cloudflare/workers-types": "^4.20240314.0",
41+
"@0no-co/graphqlsp": "^1.6.1",
42+
"@cloudflare/workers-types": "^4.20240320.1",
4143
"@cosmjs/amino": "0.32.3",
4244
"@melt-ui/pp": "^0.3.0",
4345
"@melt-ui/svelte": "^0.76.0",
@@ -47,28 +49,27 @@
4749
"@tailwindcss/aspect-ratio": "^0.4.2",
4850
"@tailwindcss/container-queries": "^0.1.1",
4951
"@tailwindcss/typography": "^0.5.10",
50-
"@tanstack/eslint-plugin-query": "^5.27.7",
51-
"@tanstack/svelte-query-devtools": "^5.28.4",
52+
"@tanstack/svelte-query-devtools": "^5.28.6",
5253
"@total-typescript/ts-reset": "^0.5.1",
5354
"@types/postcss-import": "^14.0.3",
54-
"autoprefixer": "^10.4.18",
55+
"autoprefixer": "^10.4.19",
5556
"buffer": "^6.0.3",
5657
"clsx": "^2.1.0",
5758
"graphql": "^16.8.1",
5859
"patch-package": "^8.0.0",
59-
"postcss": "^8.4.36",
60-
"postcss-import": "^16.0.1",
60+
"postcss": "^8.4.38",
61+
"postcss-import": "^16.1.0",
6162
"process": "^0.11.10",
6263
"svelte": "^4.2.12",
63-
"svelte-check": "^3.6.7",
64+
"svelte-check": "^3.6.8",
6465
"svooltip": "^0.7.8",
6566
"tailwind-scrollbar": "^3.1.0",
6667
"tailwindcss": "^3.4.1",
6768
"tailwindcss-animate": "^1.0.7",
6869
"tslib": "^2.6.2",
6970
"typed-query-selector": "^2.11.2",
70-
"typescript": "^5.4.2",
71-
"vite": "^5.1.6",
71+
"typescript": "^5.4.3",
72+
"vite": "^5.2.2",
7273
"vitest": "^1.4.0"
7374
}
7475
}

app/src/app.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
data-sveltekit-preload-data="hover"
2424
class="min-h-screen min-w-full bg-black text-white"
2525
>
26-
%sveltekit.body%
26+
<div>
27+
%sveltekit.body%
28+
</div>
2729
</body>
2830
</html>

app/src/lib/components/Faucet.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import clsx from "clsx"
33
44
import { snapAddress } from "$/lib/snap.ts"
55
import { Button } from "$lib/components/ui/button"
6-
import { getUnoFromFaucet } from "$/lib/fetchers/faucet"
6+
import { getUnoFromFaucet } from "$/lib/mutations/faucet"
77
import { createMutation, useQueryClient } from "@tanstack/svelte-query"
88
99
const queryClient = useQueryClient()

app/src/lib/constants/assets.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export const chains = ["SEPOLIA", "UNION"] as const
2+
export type Chain = (typeof chains)[number]
3+
4+
export const assets = {
5+
UNION: ["UNO"],
6+
SEPOLIA: ["ETH", "UNO"]
7+
} as const satisfies Record<Chain, Array<string>>
8+
9+
export type Asset = (typeof assets)[Chain][number] // all assets
10+
export type ChainAsset<T extends Chain> = (typeof assets)[T][number] // assets for a specific chain

app/src/lib/constants.ts renamed to app/src/lib/constants/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const UNO = {
66
} as const
77

88
export const URLS = {
9+
GRAPHQL: "https://introspect.unionlabs.workers.dev",
910
UNION: {
1011
/**
1112
* TODO: add array of RPCs and pass to `viem`'s `fallback` array

app/src/lib/fetchers/balance.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

app/src/lib/fetchers/transfers.ts

Lines changed: 0 additions & 60 deletions
This file was deleted.
File renamed without changes.

app/src/lib/queries/balance.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { graphql } from "gql.tada"
2+
import { URLS } from "$/lib/constants"
3+
import { request } from "graphql-request"
4+
import { createQuery } from "@tanstack/svelte-query"
5+
import type { Chain, ChainAsset } from "$/lib/constants/assets"
6+
7+
/**
8+
* TODO:
9+
* - [ ] Update the GraphQL query to be chain agnostic and receive the chain as a parameter
10+
*/
11+
12+
export function balanceQuery<TChain extends Chain>({
13+
chain,
14+
asset,
15+
address
16+
}: { chain: TChain; address: string; asset: ChainAsset<TChain> }) {
17+
return createQuery({
18+
queryKey: ["balance", chain, asset, address],
19+
queryFn: async () =>
20+
request(
21+
URLS.GRAPHQL,
22+
graphql(/* GraphQL */ `
23+
query userBalances($address: String!) {
24+
cosmosBankV1Beta1AllBalances(address: $address) {
25+
balances { amount denom }
26+
}
27+
}`),
28+
{ address }
29+
),
30+
enabled: !!address
31+
})
32+
}

app/src/lib/queries/transfers.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { graphql } from "gql.tada"
2+
import { URLS } from "$/lib/constants"
3+
import { request } from "graphql-request"
4+
import { createQuery } from "@tanstack/svelte-query"
5+
import type { Chain, ChainAsset } from "$/lib/constants/assets"
6+
7+
/**
8+
* TODO:
9+
* - [x] Add Union transfers query
10+
* - [ ] Add Sepolia transfers query
11+
*/
12+
13+
export function transfersQuery<TChain extends Chain>({
14+
chain,
15+
address
16+
}: { chain: TChain; address: string }) {
17+
return createQuery({
18+
queryKey: ["transfers", chain, address],
19+
queryFn: async () =>
20+
request(
21+
URLS.GRAPHQL,
22+
graphql(/* GraphQL */ `
23+
query userTransfers($address: String!) {
24+
v0_wasm_ibc_transfers(limit: 10) {
25+
sender
26+
receiver
27+
}
28+
}
29+
`),
30+
{ address }
31+
),
32+
enabled: !!address
33+
})
34+
}

app/src/lib/stores/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { readable } from "svelte/store"
2+
3+
/**
4+
* tanstack/svelte-query polling interval global store
5+
*/

app/src/lib/union-actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { snapAddress } from "$/lib/snap"
1313
import { ucs01relayAbi } from "$/lib/abi"
1414
import { writable, get } from "svelte/store"
1515
import { fromBech32 } from "@cosmjs/encoding"
16-
import { CONTRACT, UNO } from "$/lib/constants.ts"
16+
import { CONTRACT, UNO } from "$/lib/constants"
1717
import { config, unionAddress, wallet } from "$/lib/wallet/config"
1818
import { readContract, simulateContract, writeContract } from "@wagmi/core"
1919

0 commit comments

Comments
 (0)