-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fetch chaindata from Talisman chaindata (#64)
* Fetch chaindata from Talisman chaindata * fix linter errors * add graphql * Native asset transfers * increase performance * add chain logo * revert accidental change * revert * add logo on tranfer page * v-center logo * fix ui bug * fix: don't query all chains * nit fixes * fixes & toast result * Update src/pages/transfer.tsx Co-authored-by: cute0laf <OliverLim818@gmail.com> * fix --------- Co-authored-by: cute0laf <oliverlim818@gmail.com>
- Loading branch information
Showing
13 changed files
with
197 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,107 @@ | ||
import { gql, request } from 'graphql-request'; | ||
import { RELAY_CHAIN } from "@/consts"; | ||
import { gql, request } from "graphql-request" | ||
|
||
const graphqlUrl = 'https://squid.subsquid.io/chaindata/v/v4/graphql'; | ||
const graphqlUrl = "https://squid.subsquid.io/chaindata/v/v4/graphql" | ||
|
||
/// NOTE: this file is copied from the talisman chaindata. | ||
type Chain = { | ||
id: string; | ||
name: string; | ||
paraId: number | null; | ||
relay: { | ||
id: string | ||
} | null; | ||
rpcs: Array<{ url: string }>, | ||
logo: string | ||
} | ||
|
||
const chainsQuery = gql` | ||
query chains { | ||
chains(orderBy: sortIndex_ASC) { | ||
type Token = { | ||
data: { | ||
id: string; | ||
logo: string; | ||
assetId?: any; | ||
onChainId?: any; | ||
type: string; | ||
symbol: string; | ||
decimals: number; | ||
isTestnet: boolean; | ||
evmNetwork?: { | ||
id: string; | ||
}; | ||
themeColor: string; | ||
coingeckoId: string; | ||
} | ||
} | ||
|
||
const chainQuery = gql` | ||
query ChainByRelay($paraId: Int!, $relayId: String!) { | ||
chains( | ||
where: { | ||
paraId_eq: $paraId | ||
relay: { id_eq: $relayId } | ||
} | ||
) { | ||
id | ||
name | ||
paraId | ||
relay { | ||
id | ||
name | ||
paraId | ||
relay { | ||
id | ||
} | ||
rpcs { | ||
url | ||
} | ||
} | ||
rpcs { | ||
url | ||
} | ||
logo | ||
} | ||
} | ||
`; | ||
|
||
const tokensQuery = gql` | ||
query tokens { | ||
tokens(orderBy: id_ASC) { | ||
data | ||
const relayQuery = gql` | ||
query ChainByParaIdAndRelay($relayId: String!) { | ||
chains(where: {paraId_isNull: true, id_eq: $relayId}) { | ||
id | ||
name | ||
relay { | ||
id | ||
} | ||
rpcs { | ||
url | ||
} | ||
logo | ||
} | ||
} | ||
`; | ||
|
||
export const getChains = async (): Promise<Array<any>> => { | ||
const result: any = await request(graphqlUrl, chainsQuery); | ||
return result.chains; | ||
}; | ||
const tokensQuery = gql` | ||
query tokens { | ||
tokens(orderBy: id_ASC) { | ||
data | ||
} | ||
} | ||
`; | ||
|
||
export class Chaindata { | ||
private tokens: Array<Token> = []; | ||
|
||
public async load(): Promise<void> { | ||
const tokensResult: any = await request(graphqlUrl, tokensQuery); | ||
this.tokens = tokensResult.tokens; | ||
} | ||
|
||
export const getTokens = async (): Promise<Array<any>> => { | ||
const result: any = await request(graphqlUrl, tokensQuery); | ||
return result.tokens; | ||
}; | ||
public async getChain(chainId: number): Promise<Chain> { | ||
if (chainId === 0) { | ||
const result: any = await request(graphqlUrl, relayQuery, { | ||
relayId: RELAY_CHAIN | ||
}); | ||
return result.chains[0]; | ||
} else { | ||
const result: any = await request(graphqlUrl, chainQuery, { | ||
paraId: chainId, | ||
relayId: RELAY_CHAIN | ||
}); | ||
return result.chains[0]; | ||
} | ||
} | ||
|
||
public getTokens(): Array<Token> { | ||
return this.tokens; | ||
} | ||
} |
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
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
Oops, something went wrong.