Skip to content

Commit

Permalink
feat: structure queries and mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
o-az committed May 1, 2024
1 parent e9a977f commit 92c4cb2
Show file tree
Hide file tree
Showing 15 changed files with 336 additions and 1,297 deletions.
2 changes: 1 addition & 1 deletion app/app.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{
packages = {
app = unstablePkgs.buildNpmPackage {
npmDepsHash = "sha256-yZ1tygnZX07qovPOGK4sF0uVCxyVS4qdfMUStVvVFrs=";
npmDepsHash = "";
src = ./.;
sourceRoot = "app";
pname = packageJSON.name;
Expand Down
1,222 changes: 230 additions & 992 deletions app/package-lock.json

Large diffs are not rendered by default.

27 changes: 14 additions & 13 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,25 @@
"@formkit/auto-animate": "^0.8.1",
"@formkit/tempo": "^0.0.17",
"@leapwallet/cosmos-snap-provider": "^0.1.26",
"@tanstack/svelte-query": "^5.28.4",
"@tanstack/svelte-query-persist-client": "^5.28.4",
"@tanstack/svelte-query": "^5.28.6",
"@tanstack/svelte-query-persist-client": "^5.28.6",
"@tanstack/svelte-table": "^8.14.0",
"@wagmi/connectors": "^4.1.18",
"@wagmi/core": "^2.6.9",
"bits-ui": "^0.20.0",
"gql.tada": "^1.3.6",
"graphql-request": "^6.1.0",
"svelte-french-toast": "^1.2.0",
"svelte-radix": "^1.1.0",
"tailwind-merge": "^2.2.2",
"tailwind-variants": "^0.2.1",
"unstorage": "^1.10.2",
"vaul-svelte": "^0.3.0",
"viem": "^2.8.12"
"viem": "^2.8.16"
},
"devDependencies": {
"@0no-co/graphqlsp": "^1.6.0",
"@cloudflare/workers-types": "^4.20240314.0",
"@0no-co/graphqlsp": "^1.6.1",
"@cloudflare/workers-types": "^4.20240320.1",
"@cosmjs/amino": "0.32.3",
"@melt-ui/pp": "^0.3.0",
"@melt-ui/svelte": "^0.76.0",
Expand All @@ -47,28 +49,27 @@
"@tailwindcss/aspect-ratio": "^0.4.2",
"@tailwindcss/container-queries": "^0.1.1",
"@tailwindcss/typography": "^0.5.10",
"@tanstack/eslint-plugin-query": "^5.27.7",
"@tanstack/svelte-query-devtools": "^5.28.4",
"@tanstack/svelte-query-devtools": "^5.28.6",
"@total-typescript/ts-reset": "^0.5.1",
"@types/postcss-import": "^14.0.3",
"autoprefixer": "^10.4.18",
"autoprefixer": "^10.4.19",
"buffer": "^6.0.3",
"clsx": "^2.1.0",
"graphql": "^16.8.1",
"patch-package": "^8.0.0",
"postcss": "^8.4.36",
"postcss-import": "^16.0.1",
"postcss": "^8.4.38",
"postcss-import": "^16.1.0",
"process": "^0.11.10",
"svelte": "^4.2.12",
"svelte-check": "^3.6.7",
"svelte-check": "^3.6.8",
"svooltip": "^0.7.8",
"tailwind-scrollbar": "^3.1.0",
"tailwindcss": "^3.4.1",
"tailwindcss-animate": "^1.0.7",
"tslib": "^2.6.2",
"typed-query-selector": "^2.11.2",
"typescript": "^5.4.2",
"vite": "^5.1.6",
"typescript": "^5.4.3",
"vite": "^5.2.2",
"vitest": "^1.4.0"
}
}
4 changes: 3 additions & 1 deletion app/src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
data-sveltekit-preload-data="hover"
class="min-h-screen min-w-full bg-black text-white"
>
%sveltekit.body%
<div>
%sveltekit.body%
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion app/src/lib/components/Faucet.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import clsx from "clsx"
import { snapAddress } from "$/lib/snap.ts"
import { Button } from "$lib/components/ui/button"
import { getUnoFromFaucet } from "$/lib/fetchers/faucet"
import { getUnoFromFaucet } from "$/lib/mutations/faucet"
import { createMutation, useQueryClient } from "@tanstack/svelte-query"
const queryClient = useQueryClient()
Expand Down
10 changes: 10 additions & 0 deletions app/src/lib/constants/assets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const chains = ["SEPOLIA", "UNION"] as const
export type Chain = (typeof chains)[number]

export const assets = {
UNION: ["UNO"],
SEPOLIA: ["ETH", "UNO"]
} as const satisfies Record<Chain, Array<string>>

export type Asset = (typeof assets)[Chain][number] // all assets
export type ChainAsset<T extends Chain> = (typeof assets)[T][number] // assets for a specific chain
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const UNO = {
} as const

export const URLS = {
GRAPHQL: "https://introspect.unionlabs.workers.dev",
UNION: {
/**
* TODO: add array of RPCs and pass to `viem`'s `fallback` array
Expand Down
17 changes: 0 additions & 17 deletions app/src/lib/fetchers/balance.ts

This file was deleted.

60 changes: 0 additions & 60 deletions app/src/lib/fetchers/transfers.ts

This file was deleted.

File renamed without changes.
32 changes: 32 additions & 0 deletions app/src/lib/queries/balance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { graphql } from "gql.tada"
import { URLS } from "$/lib/constants"
import { request } from "graphql-request"
import { createQuery } from "@tanstack/svelte-query"
import type { Chain, ChainAsset } from "$/lib/constants/assets"

/**
* TODO:
* - [ ] Update the GraphQL query to be chain agnostic and receive the chain as a parameter
*/

export function balanceQuery<TChain extends Chain>({
chain,
asset,
address
}: { chain: TChain; address: string; asset: ChainAsset<TChain> }) {
return createQuery({
queryKey: ["balance", chain, asset, address],
queryFn: async () =>
request(
URLS.GRAPHQL,
graphql(/* GraphQL */ `
query userBalances($address: String!) {
cosmosBankV1Beta1AllBalances(address: $address) {
balances { amount denom }
}
}`),
{ address }
),
enabled: !!address
})
}
34 changes: 34 additions & 0 deletions app/src/lib/queries/transfers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { graphql } from "gql.tada"
import { URLS } from "$/lib/constants"
import { request } from "graphql-request"
import { createQuery } from "@tanstack/svelte-query"
import type { Chain, ChainAsset } from "$/lib/constants/assets"

/**
* TODO:
* - [x] Add Union transfers query
* - [ ] Add Sepolia transfers query
*/

export function transfersQuery<TChain extends Chain>({
chain,
address
}: { chain: TChain; address: string }) {
return createQuery({
queryKey: ["transfers", chain, address],
queryFn: async () =>
request(
URLS.GRAPHQL,
graphql(/* GraphQL */ `
query userTransfers($address: String!) {
v0_wasm_ibc_transfers(limit: 10) {
sender
receiver
}
}
`),
{ address }
),
enabled: !!address
})
}
5 changes: 5 additions & 0 deletions app/src/lib/stores/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { readable } from "svelte/store"

/**
* tanstack/svelte-query polling interval global store
*/
2 changes: 1 addition & 1 deletion app/src/lib/union-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { snapAddress } from "$/lib/snap"
import { ucs01relayAbi } from "$/lib/abi"
import { writable, get } from "svelte/store"
import { fromBech32 } from "@cosmjs/encoding"
import { CONTRACT, UNO } from "$/lib/constants.ts"
import { CONTRACT, UNO } from "$/lib/constants"
import { config, unionAddress, wallet } from "$/lib/wallet/config"
import { readContract, simulateContract, writeContract } from "@wagmi/core"

Expand Down
Loading

0 comments on commit 92c4cb2

Please sign in to comment.