Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new hook for storing multiple NadaValues #24

Merged
merged 1 commit into from
Oct 7, 2024

Conversation

Envoy-VC
Copy link
Contributor

This PR introduces new Hook called useNilStoreValues which helps in storing multiple NadaValues using the nilClient.storeValues() function.

It takes in the following args:

interface ExecuteArgs {
  values: NadaValues;
  ttl: Days;
  acl?: StoreAcl;
}

Usage:

import React from "react";

import { Days, NadaValue, NadaValues, NamedValue } from "@nillion/client-core";
import { useNilStoreValues } from "@nillion/client-react-hooks";

const Page = () => {
  const storeValues = useNilStoreValues();

  const onStoreValues = async () => {
    const secrets = NadaValues.create();
    secrets.insert(
      NamedValue.parse("value1"),
      NadaValue.createSecretInteger(1),
    );
    secrets.insert(
      NamedValue.parse("value2"),
      NadaValue.createSecretInteger(2),
    );

    const storeId = await storeValues.executeAsync({
      values: secrets,
      ttl: Days.parse(1),
    });

    console.log(storeId);
  };

  return (
    <div>
      <button onClick={onStoreValues}>Store Values</button>
    </div>
  );
};

export default Page;

@wwwehr wwwehr requested a review from tim-hm September 19, 2024 22:56
@tim-hm
Copy link
Collaborator

tim-hm commented Oct 2, 2024

Apologies was focused on another project the past few weeks. Will try and review this tomorrow. Thank you for your patience.

Copy link
Collaborator

@tim-hm tim-hm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this @Envoy-VC 🙏 I'm going to merge as is, but just wanted to call out that internally we're discussing some changes to the API which may make unnecessary in future releases. Until then this is a nice way to access multiple values.

@tim-hm tim-hm merged commit fb716df into NillionNetwork:main Oct 7, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants