Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
immortal-tofu committed Dec 16, 2024
1 parent d5d2595 commit 6b2cd4a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
4 changes: 3 additions & 1 deletion app/components/Connect/Connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export const Connect: React.FC<{
};

const hasValidNetwork = async (): Promise<boolean> => {
const currentChainId: string = await window.ethereum.request({ method: 'eth_chainId' });
const currentChainId: string = await window.ethereum.request({
method: 'eth_chainId',
});
return AUTHORIZED_CHAIN_ID.includes(currentChainId.toLowerCase());
};

Expand Down
49 changes: 24 additions & 25 deletions app/components/Devnet/Devnet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,43 @@

import { useEffect, useState } from 'react';
import { getInstance } from '../../fhevmjs';

import './Devnet.css';
import { Eip1193Provider, getAddress } from 'ethers';
import { Eip1193Provider } from 'ethers';

const toHexString = (bytes: Uint8Array) => bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '');

export type DevnetProps = { account: string; provider: Eip1193Provider };
export type DevnetProps = {
account: string;
provider: Eip1193Provider;
};

const CONTRACT_ADDRESS = '0x309cf2aae85ad8a1db70ca88cfd4225bf17a7482';

export const Devnet = ({ account, provider }: DevnetProps) => {
export const Devnet = ({ account }: DevnetProps) => {
const [handles, setHandles] = useState<Uint8Array[]>([]);
const [encryption, setEncryption] = useState<Uint8Array>();
const [eip712, setEip712] = useState<ReturnType<typeof instance.createEIP712>>();
const instance = getInstance();

// Handle EIP712 setup
useEffect(() => {
const { publicKey } = instance.generateKeypair();
const eip = instance.createEIP712(publicKey, '0x309cf2aae85ad8a1db70ca88cfd4225bf17a7482');
const eip = instance.createEIP712(publicKey, CONTRACT_ADDRESS);
setEip712(eip);
}, [instance]);

const encrypt = (val: number) => {
const encrypt = async (val: number) => {
const now = Date.now();
instance
.createEncryptedInput(
getAddress('0x309cf2aae85ad8a1db70ca88cfd4225bf17a7456'),
getAddress('0x309cf2aae85ad8a1db70ca88cfd4225bf17a7482')
)
.add64(val)
.encrypt()
.then(({ handles, inputProof }) => {
console.log(`Took ${(Date.now() - now) / 1000}s`);
setHandles(handles);
setEncryption(inputProof);
})
.catch((e) => {
console.log(e);
console.log(Date.now() - now);
});
try {
const result = await instance.createEncryptedInput(CONTRACT_ADDRESS, account).add64(val).encrypt();

console.log(`Took ${(Date.now() - now) / 1000}s`);
setHandles(result.handles);
setEncryption(result.inputProof);
} catch (e) {
console.error('Encryption error:', e);
console.log(Date.now() - now);
}
};

return (
Expand All @@ -48,12 +47,12 @@ export const Devnet = ({ account, provider }: DevnetProps) => {
<button onClick={() => encrypt(1337)}>Encrypt 1337</button>
<dt className="Devnet__title">This is an encryption of 1337:</dt>
<dd className="Devnet__dd">
<pre className="Devnet__pre">Handle: {handles.length && toHexString(handles[0])}</pre>
<pre className="Devnet__pre">Input Proof: {encryption && toHexString(encryption)}</pre>
<pre className="Devnet__pre">Handle: {handles.length ? toHexString(handles[0]) : ''}</pre>
<pre className="Devnet__pre">Input Proof: {encryption ? toHexString(encryption) : ''}</pre>
</dd>
<dt className="Devnet__title">And this is a EIP-712 token</dt>
<dd className="Devnet__dd">
<pre className="Devnet__pre">{eip712 && JSON.stringify(eip712)}</pre>
<pre className="Devnet__pre">{eip712 ? JSON.stringify(eip712) : ''}</pre>
</dd>
</dl>
</div>
Expand Down

0 comments on commit 6b2cd4a

Please sign in to comment.