Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: integration React Component / GraphQL API #14

Merged
merged 3 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx commitlint --edit $1
2 changes: 0 additions & 2 deletions .husky/pre-commit
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
1 change: 1 addition & 0 deletions .vitepress/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { h } from "vue";
import Theme from "vitepress/theme";
import "./style.css";
import "./tailwind.postcss";

export default {
extends: Theme,
Expand Down
5 changes: 5 additions & 0 deletions .vitepress/theme/tailwind.postcss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@tailwind base;

@tailwind components;

@tailwind utilities;
83 changes: 83 additions & 0 deletions components/AddressCheckV2.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import React, { useState, useEffect } 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);
});
};

useEffect(() => {
fetchAddressCheckV2();
}, []);

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 />
Fetch
</>
)}
</button>
</div>
<pre className="my-4 p-5 rounded-lg max-h-[600px] overflow-auto bg-[#F6F6F7] text-[#24292E] dark:bg-[#161618] dark:text-[#E1E4E8]">
{JSON.stringify(response, null, 2)}
</pre>
</>
);
}
85 changes: 85 additions & 0 deletions components/BridgeableTokens.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import React, { useState, useEffect } 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);
});
};

useEffect(() => {
fetchBridgeableTokens();
}, []);

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 />
Fetch
</>
)}
</button>
</div>
<pre className="my-4 p-5 rounded-lg max-h-[600px] overflow-auto bg-[#F6F6F7] text-[#24292E] dark:bg-[#161618] dark:text-[#E1E4E8]">
{JSON.stringify(response, null, 2)}
</pre>
</>
);
}
83 changes: 83 additions & 0 deletions components/ChainV2GraphQL.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import React, { useState, useEffect } 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);
});
};

useEffect(() => {
fetchChainV2();
}, []);

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 />
Fetch
</>
)}
</button>
</div>
<pre className="my-4 p-5 rounded-lg max-h-[600px] overflow-auto bg-[#F6F6F7] text-[#24292E] dark:bg-[#161618] dark:text-[#E1E4E8]">
{JSON.stringify(response, null, 2)}
</pre>
</>
);
}
56 changes: 56 additions & 0 deletions components/ChainsV2.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React, { useState, useEffect } 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/")
HoangVD2 marked this conversation as resolved.
Show resolved Hide resolved
.then((response) => response.json())
.then((result) => {
setResponse(result);
})
.catch((error) => {
setResponse(error);
})
.finally(() => {
setLoading(false);
});
};

useEffect(() => {
fetchChainsV2();
}, []);

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 />
Fetch
</>
)}
</button>
</div>
<pre className="my-4 p-5 rounded-lg max-h-[600px] overflow-auto bg-[#F6F6F7] text-[#24292E] dark:bg-[#161618] dark:text-[#E1E4E8]">
{JSON.stringify(response, null, 2)}
</pre>
</>
);
}
Loading
Loading