This repository has been archived by the owner on Sep 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
34 additions
and
39 deletions.
There are no files selected for viewing
Binary file not shown.
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 |
---|---|---|
@@ -1,25 +1,19 @@ | ||
"use client" | ||
import { Defined } from "@definedfi/sdk/dist/sdk"; | ||
import { Network } from "@definedfi/sdk/src/resources/graphql"; | ||
|
||
import { Defined } from '@definedfi/sdk/dist/sdk' | ||
import { useEffect, useState } from 'react' | ||
import { Network } from '@definedfi/sdk/src/resources/graphql' | ||
async function getData() { | ||
const sdk = new Defined(process.env.NEXT_PUBLIC_DEFINED_API_KEY || ""); | ||
const res = await sdk.send<{ getNetworks: Network[] }>( | ||
`query { getNetworks { id, name } }`, | ||
); | ||
if (!res.getNetworks) { | ||
// This will activate the closest `error.js` Error Boundary | ||
throw new Error("Failed to fetch data"); | ||
} | ||
return res.getNetworks; | ||
} | ||
|
||
// Don't do this -- instead use a .env file and next server routes | ||
const sdk = new Defined(process.env.NEXT_PUBLIC_DEFINED_API_KEY || '') | ||
|
||
export default function GetNetworks() { | ||
const [networks, setNetworks] = useState<Network[]>([]) | ||
useEffect(() => { | ||
const getNetworks = async () => { | ||
const res = await sdk.send<{getNetworks: Network[]}>(`query { getNetworks { id, name } }`) | ||
setNetworks(res.getNetworks) | ||
} | ||
getNetworks() | ||
}, []) | ||
|
||
return ( | ||
<pre> | ||
{JSON.stringify(networks, null, 2)} | ||
</pre> | ||
) | ||
} | ||
export default async function GetNetworks() { | ||
const data = await getData(); | ||
return <pre>{JSON.stringify(data, null, 2)}</pre>; | ||
} |
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,22 +1,23 @@ | ||
import './globals.css' | ||
import type { Metadata } from 'next' | ||
import { Inter } from 'next/font/google' | ||
import "./globals.css"; | ||
|
||
const inter = Inter({ subsets: ['latin'] }) | ||
import type { Metadata } from "next"; | ||
import { Inter } from "next/font/google"; | ||
|
||
const inter = Inter({ subsets: ["latin"] }); | ||
|
||
export const metadata: Metadata = { | ||
title: 'Create Next App', | ||
description: 'Generated by create next app', | ||
} | ||
title: "Create Next App", | ||
description: "Generated by create next app", | ||
}; | ||
|
||
export default function RootLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode | ||
children: React.ReactNode; | ||
}) { | ||
return ( | ||
<html lang="en"> | ||
<body className={inter.className}>{children}</body> | ||
</html> | ||
) | ||
); | ||
} |
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