Skip to content

Commit

Permalink
network switch
Browse files Browse the repository at this point in the history
adds walletconnect support

Signed-off-by: stadolf <[email protected]>
  • Loading branch information
elmariachi111 committed May 20, 2024
1 parent 3544e05 commit 929a321
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID=
16 changes: 13 additions & 3 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"use client"
import { decrypt, encrypt } from "@/utils";
import { Button, Code, Heading, Input, Text, Textarea, VStack } from "@chakra-ui/react";
import { Button, HStack, Heading, Input, Text, Textarea, VStack } from "@chakra-ui/react";
import { LitNodeClient } from "@lit-protocol/lit-node-client";
import { useCallback, useEffect, useState } from "react";
import { Radio, RadioGroup } from '@chakra-ui/react'

export default function Home() {
const [litNetwork, setLitNetwork] = useState<"serrano" | "jalapeno">("jalapeno");
const [client, setClient] = useState<LitNodeClient>();
const [message, setMessage] = useState("Hello World");
const [error, setError] = useState("");
Expand All @@ -19,14 +21,15 @@ export default function Home() {
}>();

useEffect(() => {
setClient(undefined)
const _client = new LitNodeClient({
litNetwork: "jalapeno",
litNetwork,
debug: true,
});
_client.connect().then(() => {
setClient(_client);
});
}, []);
}, [litNetwork]);

const handleEncrypt = useCallback(async () => {
if (!client) throw new Error("No client");
Expand Down Expand Up @@ -58,6 +61,13 @@ export default function Home() {
</Heading>

<Heading size="md">Encrypt Message</Heading>
<RadioGroup onChange={(v) => setLitNetwork(v as typeof litNetwork)} value={litNetwork}>
<HStack >
<Radio value='jalapeno'>Jalapeno</Radio>
<Radio value='serrano'>Serrano</Radio>
</HStack>
</RadioGroup>

<Input onChange={(e) => setMessage(e.target.value)} value={message} />
<Button colorScheme="green" onClick={handleEncrypt} isDisabled={!client}>
Encrypt String
Expand Down
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ const evmContractConditions: AccsEVMParams[] = [{
const unifiedAccessControlConditions: UnifiedAccessControlConditions = evmContractConditions;

export async function encrypt(client: LitNodeClient, message: string) {
const authSig = await checkAndSignAuthMessage({ chain });
const authSig = await checkAndSignAuthMessage({ chain, walletConnectProjectId: process.env.NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID});
const { encryptedString, symmetricKey } = await encryptString(message);

if (!encryptedString) {
throw new Error("Could not encrypt");
}

const encryptedSymmetricKey = await client.saveEncryptionKey({
//accessControlConditions: evmContractConditions,
//accessControlConditions: unifiedAccessControlConditions,
unifiedAccessControlConditions: unifiedAccessControlConditions,
chain,
authSig,
Expand Down

0 comments on commit 929a321

Please sign in to comment.