Fetch templates and header files according to selection.

This commit is contained in:
muzam
2021-12-16 18:26:58 +05:30
parent fdb1eb01a4
commit f739d4da34
2 changed files with 39 additions and 76 deletions

View File

@@ -82,12 +82,8 @@ const Navigation = () => {
<Spinner /> <Spinner />
) : ( ) : (
<> <>
<Heading css={{ lineHeight: 1 }}> <Heading css={{ lineHeight: 1 }}>{snap.files?.[0]?.name || "XRPL Hooks"}</Heading>
{snap.files?.[0]?.name || "XRPL Hooks"} <Text css={{ fontSize: "$xs", color: "$mauve10", lineHeight: 1 }}>
</Heading>
<Text
css={{ fontSize: "$xs", color: "$mauve10", lineHeight: 1 }}
>
{snap.files.length > 0 ? "Gist: " : "Playground"} {snap.files.length > 0 ? "Gist: " : "Playground"}
<Text css={{ color: "$mauve12" }}> <Text css={{ color: "$mauve12" }}>
{snap.files.length > 0 && {snap.files.length > 0 &&
@@ -99,10 +95,7 @@ const Navigation = () => {
</Flex> </Flex>
{router.isReady && ( {router.isReady && (
<ButtonGroup css={{ marginLeft: "auto" }}> <ButtonGroup css={{ marginLeft: "auto" }}>
<Dialog <Dialog open={snap.mainModalOpen} onOpenChange={open => (state.mainModalOpen = open)}>
open={snap.mainModalOpen}
onOpenChange={(open) => (state.mainModalOpen = open)}
>
<DialogTrigger asChild> <DialogTrigger asChild>
<Button outline> <Button outline>
<FolderOpen size="15px" /> <FolderOpen size="15px" />
@@ -163,12 +156,9 @@ const Navigation = () => {
mb: "$7", mb: "$7",
}} }}
> >
Hooks add smart contract functionality to the XRP Hooks add smart contract functionality to the XRP Ledger.
Ledger.
</Text> </Text>
<Flex <Flex css={{ flexDirection: "column", gap: "$2", mt: "$2" }}>
css={{ flexDirection: "column", gap: "$2", mt: "$2" }}
>
<Text <Text
css={{ css={{
display: "inline-flex", display: "inline-flex",
@@ -253,43 +243,29 @@ const Navigation = () => {
}, },
}} }}
> >
<PanelBox <PanelBox as="a" href="/develop/1d14e51e2e02dc0a508cb0733767a914">
as="a"
href="/develop/be088224fb37c0075e84491da0e602c1"
>
<Heading>Starter</Heading> <Heading>Starter</Heading>
<Text> <Text>Just an empty starter with essential imports</Text>
Just an empty starter with essential imports
</Text>
</PanelBox> </PanelBox>
<PanelBox <PanelBox as="a" href="/develop/bcd6d0c0fcbe52545ddb802481ff9d26">
as="a"
href="/develop/be088224fb37c0075e84491da0e602c1"
>
<Heading>Firewall</Heading> <Heading>Firewall</Heading>
<Text> <Text>This Hook essentially checks a blacklist of accounts</Text>
This Hook essentially checks a blacklist of accounts
</Text>
</PanelBox> </PanelBox>
<PanelBox <PanelBox as="a" href="/develop/1d14e51e2e02dc0a508cb0733767a914">
as="a"
href="/develop/be088224fb37c0075e84491da0e602c1"
>
<Heading>Accept</Heading> <Heading>Accept</Heading>
<Text> <Text>This hook just accepts any transaction coming through it</Text>
This hook just accepts any transaction coming through
it
</Text>
</PanelBox> </PanelBox>
<PanelBox <PanelBox as="a" href="/develop/a789c75f591eeab7932fd702ed8cf9ea">
as="a" <Heading>Notary</Heading>
href="/develop/be088224fb37c0075e84491da0e602c1" <Text>Collecting signatures for multi-sign transactions</Text>
> </PanelBox>
<Heading>Accept</Heading> <PanelBox as="a" href="/develop/43925143fa19735d8c6505c34d3a6a47">
<Text> <Heading>Carbon</Heading>
This hook just accepts any transaction coming through <Text>Send a percentage of sum to an address</Text>
it </PanelBox>
</Text> <PanelBox as="a" href="/develop/ceaf352e2a65741341033ab7ef05c448">
<Heading>Peggy</Heading>
<Text>An oracle based stabe coin hook</Text>
</PanelBox> </PanelBox>
</Flex> </Flex>
</Flex> </Flex>
@@ -336,42 +312,18 @@ const Navigation = () => {
}} }}
> >
<ButtonGroup> <ButtonGroup>
<Link <Link href={gistId ? `/develop/${gistId}` : "/develop"} passHref shallow>
href={gistId ? `/develop/${gistId}` : "/develop"} <Button as="a" outline={!router.pathname.includes("/develop")} uppercase>
passHref
shallow
>
<Button
as="a"
outline={!router.pathname.includes("/develop")}
uppercase
>
Develop Develop
</Button> </Button>
</Link> </Link>
<Link <Link href={gistId ? `/deploy/${gistId}` : "/deploy"} passHref shallow>
href={gistId ? `/deploy/${gistId}` : "/deploy"} <Button as="a" outline={!router.pathname.includes("/deploy")} uppercase>
passHref
shallow
>
<Button
as="a"
outline={!router.pathname.includes("/deploy")}
uppercase
>
Deploy Deploy
</Button> </Button>
</Link> </Link>
<Link <Link href={gistId ? `/test/${gistId}` : "/test"} passHref shallow>
href={gistId ? `/test/${gistId}` : "/test"} <Button as="a" outline={!router.pathname.includes("/test")} uppercase>
passHref
shallow
>
<Button
as="a"
outline={!router.pathname.includes("/test")}
uppercase
>
Test Test
</Button> </Button>
</Link> </Link>

View File

@@ -4,6 +4,8 @@ import state from '../index';
const octokit = new Octokit(); const octokit = new Octokit();
const HEADER_GIST_ID = '9b448e8a55fab11ef5d1274cb59f9cf3'
/* Fetches Gist files from Githug Gists based on /* Fetches Gist files from Githug Gists based on
* gistId and stores the content in global state * gistId and stores the content in global state
*/ */
@@ -17,6 +19,14 @@ export const fetchFiles = (gistId: string) => {
octokit octokit
.request("GET /gists/{gist_id}", { gist_id: gistId }) .request("GET /gists/{gist_id}", { gist_id: gistId })
.then(res => {
// fetch header file(s) and append to res
return octokit.request("GET /gists/{gist_id}", { gist_id: HEADER_GIST_ID }).then(({ data: { files: headerFiles } }) => {
const files = { ...res.data.files, ...headerFiles }
res.data.files = files
return res
})
})
.then((res) => { .then((res) => {
if (res.data.files && Object.keys(res.data.files).length > 0) { if (res.data.files && Object.keys(res.data.files).length > 0) {
const files = Object.keys(res.data.files).map((filename) => ({ const files = Object.keys(res.data.files).map((filename) => ({
@@ -44,6 +54,7 @@ export const fetchFiles = (gistId: string) => {
state.loading = false; state.loading = false;
}) })
.catch((err) => { .catch((err) => {
// console.error(err)
state.loading = false; state.loading = false;
state.logs.push({ state.logs.push({
type: "error", type: "error",