Skip to content

Commit

Permalink
Merge pull request #21 from NillionNetwork/timhm/tweaks-for-release
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-hm authored Sep 4, 2024
2 parents 53cb3f4 + f287ab1 commit 9567da4
Show file tree
Hide file tree
Showing 22 changed files with 109 additions and 104 deletions.
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

echo "Checking commit message..."
npx commitlint -g commitlint.config.mjs --verbose --edit $1
3 changes: 0 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#!/usr/bin/env bash

just check

echo "Checking commit message..."
npx commitlint -g commitlint.config.mjs --verbose --edit
2 changes: 1 addition & 1 deletion examples/nextjs/app/components/compute-output.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const ComputeOutput: FC = () => {

const handleClick = () => {
if (!computeId) throw new Error("compute-output: Compute id is required");
nilComputeOutput.execute(computeId);
nilComputeOutput.execute({ id: computeId });
};

let computeOutput = "idle";
Expand Down
4 changes: 1 addition & 3 deletions examples/nextjs/app/components/compute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ export const Compute: FC = () => {
.insert(NamedValue.parse("A"), NadaValue.createSecretInteger(2))
.insert(NamedValue.parse("B"), NadaValue.createSecretInteger(4));

const storeIds = [] as string[];

nilCompute.execute({ bindings, values, storeIds });
nilCompute.execute({ bindings, values });
};

return (
Expand Down
6 changes: 2 additions & 4 deletions examples/nextjs/app/components/delete-value.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const DeleteValue: FC = () => {

const handleClick = () => {
if (!id) throw new Error("delete-value: Id is required");
nilDelete.execute(id);
nilDelete.execute({ id });
};

return (
Expand All @@ -40,9 +40,7 @@ export const DeleteValue: FC = () => {
sx={{ width: "150px", mt: 4 }}
startIcon={<DeleteIcon />}
loading={nilDelete.isLoading}
onClick={() => {
nilDelete.execute(id);
}}
onClick={handleClick}
disabled={!id || nilDelete.isLoading}
>
Delete
Expand Down
2 changes: 1 addition & 1 deletion examples/nextjs/app/components/fetch-value.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const FetchValue: FC = () => {

const handleClick = () => {
if (!id) throw new Error("fetch-value: Id is required");
nilFetch.execute(id);
nilFetch.execute({ id });
};

return (
Expand Down
4 changes: 2 additions & 2 deletions examples/nextjs/app/components/store-value.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { Box, TextField, Typography } from "@mui/material";
import { useNilStoreValue } from "@nillion/client-react-hooks";

export const StoreValue: FC = () => {
const nilStore = useNilStoreValue({ ttl: 1 });
const nilStore = useNilStoreValue();
const [secret, setSecret] = useState<number | null>(null);

const handleClick = () => {
if (!secret) throw new Error("store-value: Value required");
nilStore.execute(secret!);
nilStore.execute({ data: secret, ttl: 1 }!);
};

return (
Expand Down
24 changes: 1 addition & 23 deletions examples/nextjs/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,40 +1,18 @@
/* eslint-disable */
/** @type {import("next").NextConfig} */
const nextConfig = {
webpack: (config) => {
// config.resolve.fallback = {
// crypto: false,
// stream: false,
// buffer: false,
// vm: false,
// };
//
// config.module.rules.push({
// test: /\.wasm$/,
// type: "asset/resource",
// });

return config;
},
async headers() {
return [
{
source: "/:path*",
// headers required for @nillion/client-wasm's wasm artefact
headers: [
{ key: "Cross-Origin-Embedder-Policy", value: "require-corp" },
{ key: "Cross-Origin-Opener-Policy", value: "same-origin" },
],
},
];
},
async rewrites() {
return [
{
source: "/nilchain",
destination: "http://127.0.0.1:48102/",
},
];
},
};

export default nextConfig;
6 changes: 3 additions & 3 deletions examples/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
"next": "14.2.7",
"react": "^18",
"react-dom": "^18",
"@nillion/client-core": "0.1.0-rc.14",
"@nillion/client-react-hooks": "0.1.0-rc.14",
"@nillion/client-vms": "0.1.0-rc.14"
"@nillion/client-core": "0.1.0-rc.15",
"@nillion/client-react-hooks": "0.1.0-rc.15",
"@nillion/client-vms": "0.1.0-rc.15"
},
"devDependencies": {
"@types/node": "^22",
Expand Down
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/client-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@nillion/client-core",
"license": "MIT",
"author": "[email protected]",
"version": "0.1.0-rc.14",
"version": "0.1.0-rc.15",
"homepage": "https://nillion.pub/client-ts",
"repository": {
"type": "git",
Expand All @@ -25,7 +25,7 @@
"test:serve": "npx jasmine-browser-runner serve --config=jasmine.config.mjs"
},
"dependencies": {
"@nillion/client-wasm": "0.1.0-rc.14",
"@nillion/client-wasm": "0.1.0-rc.15",
"debug": "^4.3.6",
"effect": "3.6.5",
"zod": "^3.23.8"
Expand Down
4 changes: 2 additions & 2 deletions packages/client-core/src/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const NamedNetworkConfig = {
),
],
nilChainId: ChainId.parse("nillion-chain-devnet"),
nilChainEndpoint: Url.parse("http://localhost:3000/nilchain"),
nilChainEndpoint: Url.parse("http://127.0.0.1:48102"),
},
photon: {
clusterId: ClusterId.parse("b13880d3-dde8-4a75-a171-8a1a9d985e6c"),
Expand All @@ -25,7 +25,7 @@ export const NamedNetworkConfig = {
],
nilChainId: ChainId.parse("nillion-chain-testnet-1"),
nilChainEndpoint: Url.parse(
"https://rpc.testnet.nilchain-rpc-proxy.nilogy.xyz",
"http://rpc.testnet-numia.nilchain-rpc-proxy.nilogy.xyz",
),
},
};
5 changes: 3 additions & 2 deletions packages/client-payments/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@nillion/client-payments",
"license": "MIT",
"author": "[email protected]",
"version": "0.1.0-rc.14",
"version": "0.1.0-rc.15",
"homepage": "https://nillion.pub/client-ts",
"repository": {
"type": "git",
Expand All @@ -26,9 +26,10 @@
"test:serve": "npx jasmine-browser-runner serve --config=jasmine.config.mjs"
},
"dependencies": {
"@bufbuild/protobuf": "^2.0.0",
"@cosmjs/proto-signing": "^0.32.4",
"@cosmjs/stargate": "^0.32.4",
"@nillion/client-core": "0.1.0-rc.14",
"@nillion/client-core": "0.1.0-rc.15",
"debug": "^4.3.6",
"effect": "3.6.5",
"zod": "^3.23.8"
Expand Down
4 changes: 2 additions & 2 deletions packages/client-react-hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@nillion/client-react-hooks",
"license": "MIT",
"author": "[email protected]",
"version": "0.1.0-rc.14",
"version": "0.1.0-rc.15",
"homepage": "https://nillion.pub/client-ts",
"repository": {
"type": "git",
Expand All @@ -21,7 +21,7 @@
"build:watch": "node esbuild.config.mjs --watch"
},
"dependencies": {
"@nillion/client-vms": "0.1.0-rc.14",
"@nillion/client-vms": "0.1.0-rc.15",
"@tanstack/react-query": "^5.52.0",
"debug": "^4.3.6",
"react": "^18.3.1"
Expand Down
22 changes: 18 additions & 4 deletions packages/client-react-hooks/src/nillion-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,31 @@ import {
QueryClientProvider,
} from "@tanstack/react-query";

import { NamedNetwork, NamedNetworkConfig } from "@nillion/client-core";
import { type NetworkConfig, NillionClient } from "@nillion/client-vms";
import {
ChainId,
ClusterId,
Multiaddr,
NamedNetwork,
NamedNetworkConfig,
Url,
} from "@nillion/client-core";
import { NetworkConfig, NillionClient } from "@nillion/client-vms";

import { Log } from "./logging";

interface WithConfigProps {
config?: NetworkConfig;
config?: ProviderNetworkConfig;
network?: NamedNetwork;
client?: never;
}

interface ProviderNetworkConfig {
bootnodes?: (Multiaddr | string)[];
clusterId?: ClusterId | string;
nilChainId?: ChainId | string;
nilChainEndpoint?: Url | string;
}

interface WithClientProps {
client: NillionClient;
config?: never;
Expand Down Expand Up @@ -57,7 +71,7 @@ export const NillionProvider: React.FC<
else Log("No react query context detected; creating one.");

// default to photon
let combined = NamedNetworkConfig.photon;
let combined: ProviderNetworkConfig = NamedNetworkConfig.photon;

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- parse and on failure throw if invalid "network" value
if (network && NamedNetwork.parse(network)) {
Expand Down
13 changes: 8 additions & 5 deletions packages/client-react-hooks/src/use-nil-compute-output.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import { useMutation } from "@tanstack/react-query";

import { ComputeOutputId } from "@nillion/client-core";
import { ComputeOutputId, NadaPrimitiveValue } from "@nillion/client-core";

import { nilHookBaseResult, UseNilHook } from "./nil-hook-base";
import { useNillion } from "./use-nillion";

type ExecuteArgs = ComputeOutputId | string;
type ExecuteResult = object;
interface ExecuteArgs {
id: ComputeOutputId | string;
}

type ExecuteResult = Record<string, NadaPrimitiveValue>;

type UseNilComputeOutput = UseNilHook<ExecuteArgs, ExecuteResult>;

export const useNilComputeOutput = (): UseNilComputeOutput => {
const { client: nilClient } = useNillion();

const mutationFn = async (id: ExecuteArgs): Promise<ExecuteResult> => {
const response = await nilClient.fetchComputeOutput({ id });
const mutationFn = async (args: ExecuteArgs): Promise<ExecuteResult> => {
const response = await nilClient.fetchComputeOutput(args);
if (response.err) throw response.err as Error;
return response.ok;
};
Expand Down
11 changes: 8 additions & 3 deletions packages/client-react-hooks/src/use-nil-compute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { useNillion } from "./use-nillion";

interface ExecuteArgs {
bindings: ProgramBindings;
values: NadaValues;
storeIds: (StoreId | string)[];
values?: NadaValues;
storeIds?: (StoreId | string)[];
}
type ExecuteResult = ComputeOutputId;

Expand All @@ -23,7 +23,12 @@ export const useNilCompute = (): UseNilCompute => {
const { client: nilClient } = useNillion();

const mutationFn = async (args: ExecuteArgs): Promise<ExecuteResult> => {
const response = await nilClient.compute(args);
const computeArgs = {
bindings: args.bindings,
values: args.values ?? NadaValues.create(),
storeIds: args.storeIds ?? [],
};
const response = await nilClient.compute(computeArgs);
if (response.err) throw response.err as Error;
return response.ok;
};
Expand Down
Loading

0 comments on commit 9567da4

Please sign in to comment.