-
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.
update nextjs template for cartesi core implementation
- Loading branch information
Showing
37 changed files
with
5,283 additions
and
14,433 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
NEXT_PUBLIC_WALLECT_CONNECT_PROJECT_ID = YOUR_PROJECT_ID |
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,30 @@ | ||
"use client" | ||
import { useMemo } from 'react'; | ||
import { | ||
UrqlProvider, | ||
ssrExchange, | ||
cacheExchange, | ||
fetchExchange, | ||
createClient, | ||
} from '@urql/next'; | ||
|
||
// YOUR API URL | ||
const API_BASE_URL = 'http://localhost:8080/graphql' | ||
|
||
export default function GraphQLClient({ children }: React.PropsWithChildren) { | ||
const [client, ssr] = useMemo(() => { | ||
const ssr = ssrExchange({ | ||
isClient: typeof window !== 'undefined', | ||
}); | ||
const client = createClient({ | ||
url: API_BASE_URL, | ||
exchanges: [cacheExchange, ssr, fetchExchange], | ||
suspense: true, | ||
}); | ||
|
||
return [client, ssr]; | ||
}, []); | ||
|
||
return {client, ssr} | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
"use client" | ||
// Copyright 2022 Cartesi Pte. Ltd. | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
// use this file except in compliance with the License. You may obtain a copy | ||
// of the license at http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
// License for the specific language governing permissions and limitations | ||
// under the License. | ||
|
||
import { ethers } from "ethers"; | ||
import React, {useEffect} from "react"; | ||
|
||
import { useNoticesQuery } from "../cartesi/generated/graphql"; | ||
|
||
type Notice = { | ||
id: string; | ||
index: number; | ||
input: any, //{index: number; epoch: {index: number; } | ||
payload: string; | ||
}; | ||
|
||
export const Notices: React.FC = () => { | ||
const [result,reexecuteQuery] = useNoticesQuery(); | ||
const { data, fetching, error } = result; | ||
|
||
useEffect(() => { | ||
reexecuteQuery({ requestPolicy: 'network-only' }); | ||
}, [reexecuteQuery]); | ||
|
||
if (fetching) return <p>Loading...</p>; | ||
if (error) return <p>Oh no... {error.message}</p>; | ||
|
||
if (!data || !data.notices) return <p>No notices</p>; | ||
|
||
const notices: Notice[] = data.notices.edges.map((node: any) => { | ||
const n = node.node; | ||
let inputPayload = n?.input.payload; | ||
if (inputPayload) { | ||
try { | ||
inputPayload = ethers.toUtf8String(inputPayload); | ||
} catch (e) { | ||
inputPayload = inputPayload + " (hex)"; | ||
} | ||
} else { | ||
inputPayload = "(empty)"; | ||
} | ||
let payload = n?.payload; | ||
if (payload) { | ||
try { | ||
payload = ethers.toUtf8String(payload); | ||
} catch (e) { | ||
payload = payload + " (hex)"; | ||
} | ||
} else { | ||
payload = "(empty)"; | ||
} | ||
return { | ||
id: `${n?.id}`, | ||
index: parseInt(n?.index), | ||
payload: `${payload}`, | ||
input: n ? {index:n.input.index,payload: inputPayload} : {}, | ||
}; | ||
}).sort((b: any, a: any) => { | ||
if (a.input.index === b.input.index) { | ||
return b.index - a.index; | ||
} else { | ||
return b.input.index - a.input.index; | ||
} | ||
}); | ||
|
||
// const forceUpdate = useForceUpdate(); | ||
return ( | ||
<div> | ||
<button className="text-slate-400" onClick={() => reexecuteQuery({ requestPolicy: 'network-only' })}> | ||
Reload | ||
</button> | ||
<table className="text-slate-400 border"> | ||
<thead> | ||
<tr className="border"> | ||
<th className="border p-2">Input Index</th> | ||
<th className="border p-2">Notice Index</th> | ||
{/* <th>Input Payload</th> */} | ||
<th className="border p-2">Payload</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{notices.length === 0 && ( | ||
<tr> | ||
<td className="p-4" colSpan={4}>no notices</td> | ||
</tr> | ||
)} | ||
{notices.map((n: any) => ( | ||
<tr key={`${n.input.index}-${n.index}`}> | ||
<td>{n.input.index}</td> | ||
<td>{n.index}</td> | ||
{/* <td>{n.input.payload}</td> */} | ||
<td>{n.payload}</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
|
||
</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
Oops, something went wrong.