-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: integration React Component / GraphQL API (#14)
- Loading branch information
Showing
22 changed files
with
1,619 additions
and
596 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,4 +1,2 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
npx commitlint --edit $1 |
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,4 +1,2 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
npx lint-staged |
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,5 @@ | ||
@tailwind base; | ||
|
||
@tailwind components; | ||
|
||
@tailwind utilities; |
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,84 @@ | ||
import React, { useState } from "react"; | ||
import LoadingIcon from "./LoadingIcon"; | ||
import PlayIcon from "./PlayIcon"; | ||
|
||
export default function AddressCheckV2() { | ||
const GRAPHQL_ENDPOINT = "https://gql-router.xdefi.services/graphql"; | ||
const [response, setResponse] = useState({}); | ||
const [loading, setLoading] = useState(false); | ||
|
||
const query = ` | ||
query AddressCheckV2($address: AddressRouteInputTypeV2!) { | ||
routingV2 { | ||
addressCheckV2(address: $address) { | ||
isValid | ||
address | ||
chain | ||
} | ||
} | ||
}`; | ||
|
||
const vars = { | ||
address: { | ||
address: "0x7045916CEEFf58547E80E31d2c60ae5F67D63027", | ||
chain: "ETH", | ||
}, | ||
}; | ||
const fetchAddressCheckV2 = async () => { | ||
setLoading(true); | ||
setResponse({}); | ||
|
||
await fetch(GRAPHQL_ENDPOINT, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ | ||
query, | ||
variables: vars, | ||
}), | ||
}) | ||
.then((response) => response.json()) | ||
.then((result) => { | ||
setResponse(result); | ||
}) | ||
.catch((error) => { | ||
setResponse(error); | ||
}) | ||
.finally(() => { | ||
setLoading(false); | ||
}); | ||
}; | ||
|
||
return ( | ||
<> | ||
<div className="flex justify-center"> | ||
<button | ||
onClick={fetchAddressCheckV2} | ||
className="flex justify-center items-center gap-2 bg-[#2770CB] text-white px-2 py-1 rounded" | ||
disabled={loading} | ||
> | ||
{loading ? ( | ||
<> | ||
<LoadingIcon /> | ||
Fetching... | ||
</> | ||
) : ( | ||
<> | ||
<PlayIcon /> | ||
Test the query | ||
</> | ||
)} | ||
</button> | ||
</div> | ||
<div className="my-4 rounded-lg max-h-[600px] overflow-auto bg-[#F6F6F7] text-[#24292E] dark:bg-[#161618] dark:text-[#E1E4E8]"> | ||
<div className="px-5 border-b border-[#e2e2e3] dark:border-black"> | ||
<span className="inline-block border-b-2 border-[#3451b2] dark:border-[#a8b1ff] text-[14px] leading-[48px]">Response</span> | ||
</div> | ||
<pre className="p-5"> | ||
{JSON.stringify(response, null, 2)} | ||
</pre> | ||
</div> | ||
</> | ||
); | ||
} |
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,86 @@ | ||
import React, { useState } from "react"; | ||
import LoadingIcon from "./LoadingIcon"; | ||
import PlayIcon from "./PlayIcon"; | ||
|
||
export default function BridgeableTokens() { | ||
const GRAPHQL_ENDPOINT = "https://gql-router.xdefi.services/graphql"; | ||
const [response, setResponse] = useState({}); | ||
const [loading, setLoading] = useState(false); | ||
|
||
const query = ` | ||
query BridgeableTokens($bridgeToken: BridgeTokenInput) { | ||
routingV2 { | ||
bridgeableTokens(bridgeToken: $bridgeToken) { | ||
asset { | ||
id | ||
chain | ||
name | ||
} | ||
} | ||
} | ||
}`; | ||
|
||
const vars = { | ||
bridgeToken: { | ||
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", | ||
name: "ETH.USDC", | ||
}, | ||
}; | ||
const fetchBridgeableTokens = async () => { | ||
setLoading(true); | ||
setResponse({}); | ||
|
||
await fetch(GRAPHQL_ENDPOINT, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ | ||
query, | ||
variables: vars, | ||
}), | ||
}) | ||
.then((response) => response.json()) | ||
.then((result) => { | ||
setResponse(result); | ||
}) | ||
.catch((error) => { | ||
setResponse(error); | ||
}) | ||
.finally(() => { | ||
setLoading(false); | ||
}); | ||
}; | ||
|
||
return ( | ||
<> | ||
<div className="flex justify-center"> | ||
<button | ||
onClick={fetchBridgeableTokens} | ||
className="flex justify-center items-center gap-2 bg-[#2770CB] text-white px-2 py-1 rounded" | ||
disabled={loading} | ||
> | ||
{loading ? ( | ||
<> | ||
<LoadingIcon /> | ||
Fetching... | ||
</> | ||
) : ( | ||
<> | ||
<PlayIcon /> | ||
Test the query | ||
</> | ||
)} | ||
</button> | ||
</div> | ||
<div className="my-4 rounded-lg max-h-[600px] overflow-auto bg-[#F6F6F7] text-[#24292E] dark:bg-[#161618] dark:text-[#E1E4E8]"> | ||
<div className="px-5 border-b border-[#e2e2e3] dark:border-black"> | ||
<span className="inline-block border-b-2 border-[#3451b2] dark:border-[#a8b1ff] text-[14px] leading-[48px]">Response</span> | ||
</div> | ||
<pre className="p-5"> | ||
{JSON.stringify(response, null, 2)} | ||
</pre> | ||
</div> | ||
</> | ||
); | ||
} |
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,84 @@ | ||
import React, { useState } from "react"; | ||
import LoadingIcon from "./LoadingIcon"; | ||
import PlayIcon from "./PlayIcon"; | ||
|
||
export default function ChainV2GraphQL() { | ||
const GRAPHQL_ENDPOINT = "https://gql-router.xdefi.services/graphql"; | ||
const [response, setResponse] = useState({}); | ||
const [loading, setLoading] = useState(false); | ||
|
||
const query = ` | ||
query ChainV2($name: String!) { | ||
routingV2 { | ||
chainV2(name: $name) { | ||
name | ||
tokens { | ||
asset { | ||
contract | ||
symbol | ||
} | ||
} | ||
} | ||
} | ||
}`; | ||
const vars = { | ||
name: "ETH", | ||
}; | ||
const fetchChainV2 = async () => { | ||
setLoading(true); | ||
setResponse({}); | ||
|
||
await fetch(GRAPHQL_ENDPOINT, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ | ||
query, | ||
variables: vars, | ||
}), | ||
}) | ||
.then((response) => response.json()) | ||
.then((result) => { | ||
setResponse(result); | ||
}) | ||
.catch((error) => { | ||
setResponse(error); | ||
}) | ||
.finally(() => { | ||
setLoading(false); | ||
}); | ||
}; | ||
|
||
return ( | ||
<> | ||
<div className="flex justify-center"> | ||
<button | ||
onClick={fetchChainV2} | ||
className="flex justify-center items-center gap-2 bg-[#2770CB] text-white px-2 py-1 rounded" | ||
disabled={loading} | ||
> | ||
{loading ? ( | ||
<> | ||
<LoadingIcon /> | ||
Fetching... | ||
</> | ||
) : ( | ||
<> | ||
<PlayIcon /> | ||
Test the query | ||
</> | ||
)} | ||
</button> | ||
</div> | ||
<div className="my-4 rounded-lg max-h-[600px] overflow-auto bg-[#F6F6F7] text-[#24292E] dark:bg-[#161618] dark:text-[#E1E4E8]"> | ||
<div className="px-5 border-b border-[#e2e2e3] dark:border-black"> | ||
<span className="inline-block border-b-2 border-[#3451b2] dark:border-[#a8b1ff] text-[14px] leading-[48px]">Response</span> | ||
</div> | ||
<pre className="p-5"> | ||
{JSON.stringify(response, null, 2)} | ||
</pre> | ||
</div> | ||
</> | ||
); | ||
} |
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,57 @@ | ||
import React, { useState } from "react"; | ||
import LoadingIcon from "./LoadingIcon"; | ||
import PlayIcon from "./PlayIcon"; | ||
|
||
export default function ChainsV2() { | ||
const ENDPOINT = "https://routingapi.xdefiservices.com/"; | ||
const [response, setResponse] = useState([]); | ||
const [loading, setLoading] = useState(false); | ||
|
||
const fetchChainsV2 = async () => { | ||
setLoading(true); | ||
setResponse([]); | ||
fetch(ENDPOINT + "chains") | ||
.then((response) => response.json()) | ||
.then((result) => { | ||
setResponse(result); | ||
}) | ||
.catch((error) => { | ||
setResponse(error); | ||
}) | ||
.finally(() => { | ||
setLoading(false); | ||
}); | ||
}; | ||
|
||
return ( | ||
<> | ||
<div className="flex justify-center"> | ||
<button | ||
onClick={fetchChainsV2} | ||
className="flex justify-center items-center gap-2 bg-[#2770CB] text-white px-2 py-1 rounded" | ||
disabled={loading} | ||
> | ||
{loading ? ( | ||
<> | ||
<LoadingIcon /> | ||
Fetching... | ||
</> | ||
) : ( | ||
<> | ||
<PlayIcon /> | ||
Test the query | ||
</> | ||
)} | ||
</button> | ||
</div> | ||
<div className="my-4 rounded-lg max-h-[600px] overflow-auto bg-[#F6F6F7] text-[#24292E] dark:bg-[#161618] dark:text-[#E1E4E8]"> | ||
<div className="px-5 border-b border-[#e2e2e3] dark:border-black"> | ||
<span className="inline-block border-b-2 border-[#3451b2] dark:border-[#a8b1ff] text-[14px] leading-[48px]">Response</span> | ||
</div> | ||
<pre className="p-5"> | ||
{JSON.stringify(response, null, 2)} | ||
</pre> | ||
</div> | ||
</> | ||
); | ||
} |
Oops, something went wrong.