forked from unionlabs/union
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: structure queries and mutations
- Loading branch information
Showing
15 changed files
with
336 additions
and
1,297 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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 |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,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 | ||
}) | ||
} |
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,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 | ||
}) | ||
} |
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,5 @@ | ||
import { readable } from "svelte/store" | ||
|
||
/** | ||
* tanstack/svelte-query polling interval global store | ||
*/ |
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
Oops, something went wrong.