-
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.
* chore: add lint GH * chore: forgot the step * chore: update engine due to node17+ * chore: 17+ * chore: node20 min * chore: add node20 base * feat: add in example code and extra instructions * chore: app dir * chore: refactor and add programs * chore: add pyth env * chore: prettier * chore: publish test * chore: rename build GH * chore: refactor as release yaml * chore: readme and images * chore: upgrade to latest package 0.1.0
- Loading branch information
1 parent
08bf309
commit 3ef89a5
Showing
39 changed files
with
9,390 additions
and
808 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,24 @@ | ||
name: Lint | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [20.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm install | ||
- run: npm run check | ||
- run: npm run format -- --check |
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,27 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [20.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- env: | ||
NODE_AUTH_TOKEN: | ||
${{ secrets.NPM_TOKEN }} | ||
- run: npm install | ||
- run: npm run release |
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,3 @@ | ||
{ | ||
"extends": ["next/core-web-vitals", "next/typescript"] | ||
} |
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,36 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
.yarn/install-state.gz | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# local env files | ||
.env*.local | ||
|
||
# vercel | ||
.vercel | ||
|
||
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts |
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,8 @@ | ||
{ | ||
"trailingComma": "all", | ||
"tabWidth": 2, | ||
"arrowParens": "always", | ||
"semi": true, | ||
"useTabs": false, | ||
"singleQuote": false | ||
} |
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,21 @@ | ||
## Nextjs Example for Create Nillion App (CNA) | ||
|
||
 | ||
|
||
Welcome the Nextjs Example for CNA. | ||
|
||
Once the CLI insturctions have finished, you can run the developent server: | ||
|
||
```bash | ||
npm run dev | ||
# or | ||
yarn dev | ||
# or | ||
pnpm dev | ||
# or | ||
bun dev | ||
``` | ||
|
||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. | ||
|
||
Then follow the rest of the instructions from the Quickstart guide [here.](https://github.com/NillionNetwork/awesome-nillion/issues/2) |
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,11 @@ | ||
"use client"; | ||
|
||
import { ReactNode } from "react"; | ||
|
||
import { NillionProvider } from "@nillion/client-react-hooks"; | ||
|
||
export const ClientWrapper: React.FC<{ children: ReactNode }> = ({ | ||
children, | ||
}) => { | ||
return <NillionProvider network="devnet">{children}</NillionProvider>; | ||
}; |
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,87 @@ | ||
"use client"; | ||
|
||
import { type FC, useState } from "react"; | ||
import { | ||
NadaValue, | ||
NadaValues, | ||
NamedValue, | ||
PartyName, | ||
ProgramBindings, | ||
ProgramId, | ||
} from "@nillion/client-core"; | ||
import { useNilCompute, useNillion } from "@nillion/client-react-hooks"; | ||
|
||
export const Compute: FC = () => { | ||
const { client } = useNillion(); | ||
const nilCompute = useNilCompute(); | ||
const [programId, setProgramId] = useState<ProgramId | string>(""); | ||
const [copiedComputeOutputID, setCopiedComputeOutputID] = useState(false); | ||
|
||
const handleClick = () => { | ||
if (!programId) throw new Error("compute: program id required"); | ||
|
||
const bindings = ProgramBindings.create(programId) | ||
.addInputParty(PartyName.parse("Party1"), client.partyId) | ||
.addOutputParty(PartyName.parse("Party1"), client.partyId); | ||
|
||
// Note: This is hardcoded for demo purposes. | ||
// Feel free to change the NamedValue to your required program values. | ||
const values = NadaValues.create() | ||
.insert(NamedValue.parse("my_int1"), NadaValue.createSecretInteger(2)) | ||
.insert(NamedValue.parse("my_int2"), NadaValue.createSecretInteger(4)); | ||
|
||
nilCompute.execute({ bindings, values }); | ||
}; | ||
|
||
return ( | ||
<div className="border border-gray-400 rounded-lg p-4 w-full max-w-md"> | ||
<h2 className="text-2xl font-bold mb-4">Compute</h2> | ||
<input | ||
className="w-full p-2 mb-4 border border-gray-300 rounded text-black" | ||
placeholder="Program id" | ||
value={programId} | ||
onChange={(e) => setProgramId(e.target.value)} | ||
/> | ||
<button | ||
className={`flex items-center justify-center px-4 py-2 border rounded text-black mb-4 ${ | ||
nilCompute.isLoading || !programId | ||
? "opacity-50 cursor-not-allowed bg-gray-200" | ||
: "bg-white hover:bg-gray-100" | ||
}`} | ||
onClick={handleClick} | ||
disabled={nilCompute.isLoading || !programId} | ||
> | ||
{nilCompute.isLoading ? ( | ||
<div className="w-5 h-5 border-t-2 border-b-2 border-gray-900 rounded-full animate-spin"></div> | ||
) : ( | ||
"Compute" | ||
)} | ||
</button> | ||
<p className="my-2 italic text-sm mt-2"> | ||
Current values are 4 & 2. Refer to ComputeOutput.tsx | ||
</p> | ||
<ul className="list-disc pl-5 mt-4"> | ||
<li className="mt-2">Status: {nilCompute.status}</li> | ||
<li className="mt-2"> | ||
Compute output id: | ||
{nilCompute.isSuccess ? ( | ||
<> | ||
{`${nilCompute.data?.substring(0, 4)}...${nilCompute.data?.substring(nilCompute.data.length - 4)}`} | ||
<button | ||
onClick={() => { | ||
setCopiedComputeOutputID(true); | ||
navigator.clipboard.writeText(nilCompute.data); | ||
setTimeout(() => setCopiedComputeOutputID(false), 2000); | ||
}} | ||
> | ||
{!copiedComputeOutputID ? " 📋" : " ✅"} | ||
</button> | ||
</> | ||
) : ( | ||
"idle" | ||
)} | ||
</li> | ||
</ul> | ||
</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,56 @@ | ||
"use client"; | ||
|
||
import { type FC, useState } from "react"; | ||
import { useNilComputeOutput } from "@nillion/client-react-hooks"; | ||
import { ComputeOutputId } from "@nillion/client-core"; | ||
|
||
export const ComputeOutput: FC = () => { | ||
const nilComputeOutput = useNilComputeOutput(); | ||
const [computeId, setComputeId] = useState<ComputeOutputId | string>(""); | ||
|
||
const handleClick = () => { | ||
if (!computeId) throw new Error("compute-output: Compute id is required"); | ||
nilComputeOutput.execute({ id: computeId }); | ||
}; | ||
|
||
let computeOutput = "idle"; | ||
if (nilComputeOutput.isSuccess) { | ||
computeOutput = JSON.stringify(nilComputeOutput.data, (key, value) => { | ||
if (typeof value === "bigint") { | ||
return value.toString(); | ||
} | ||
return value; | ||
}); | ||
} | ||
|
||
return ( | ||
<div className="border border-gray-400 rounded-lg p-4 w-full max-w-md"> | ||
<h2 className="text-2xl font-bold mb-4">Compute Output</h2> | ||
<input | ||
className="w-full p-2 mb-4 border border-gray-300 rounded text-black" | ||
placeholder="Compute output id" | ||
value={computeId} | ||
onChange={(e) => setComputeId(e.target.value)} | ||
/> | ||
<button | ||
className={`flex items-center justify-center px-4 py-2 border rounded text-black ${ | ||
!computeId || nilComputeOutput.isLoading | ||
? "opacity-50 cursor-not-allowed bg-gray-200" | ||
: "bg-white hover:bg-gray-100" | ||
}`} | ||
onClick={handleClick} | ||
disabled={!computeId || nilComputeOutput.isLoading} | ||
> | ||
{nilComputeOutput.isLoading ? ( | ||
<div className="w-5 h-5 border-t-2 border-b-2 border-gray-900 rounded-full animate-spin"></div> | ||
) : ( | ||
"Fetch" | ||
)} | ||
</button> | ||
<ul className="list-disc pl-5 mt-4"> | ||
<li className="mt-2">Status: {nilComputeOutput.status}</li> | ||
<li className="mt-2">Output: {computeOutput}</li> | ||
</ul> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.