From eca591aaeac1136037e51e47e90ade1068b31a47 Mon Sep 17 00:00:00 2001 From: Salief Date: Tue, 19 Dec 2023 10:41:02 -0500 Subject: [PATCH] test ci after formatting --- .../app/providers/PrivyProviderWrapper.tsx | 2 +- apps/site/components/client/User.tsx | 2 +- .../site/components/client/UsernameDialog.tsx | 46 +++++++------ apps/site/config/customChainConfig.ts | 53 +++++++------- apps/site/config/ethersClient.ts | 2 +- apps/site/config/publicClient.ts | 2 - apps/site/context/UserContext.tsx | 6 +- apps/site/lib/actions/relayPost.ts | 2 +- apps/site/lib/actions/relayRegisterFor.ts | 69 +++++++++---------- apps/site/lib/register/index.ts | 2 +- apps/site/lib/register/processRegisterFor.ts | 33 +++++---- 11 files changed, 113 insertions(+), 106 deletions(-) diff --git a/apps/site/app/providers/PrivyProviderWrapper.tsx b/apps/site/app/providers/PrivyProviderWrapper.tsx index 81843e92e..3da8fed5a 100644 --- a/apps/site/app/providers/PrivyProviderWrapper.tsx +++ b/apps/site/app/providers/PrivyProviderWrapper.tsx @@ -22,7 +22,7 @@ export function PrivyProviderWrapper({ noPromptOnSignature: true, }, defaultChain: river_j5bpjduqfv, - supportedChains: [river_j5bpjduqfv] + supportedChains: [river_j5bpjduqfv], }} > {children} diff --git a/apps/site/components/client/User.tsx b/apps/site/components/client/User.tsx index 6fd6a4f73..803353fb6 100644 --- a/apps/site/components/client/User.tsx +++ b/apps/site/components/client/User.tsx @@ -21,7 +21,7 @@ export function User({ setOpen }: UserProps) { return ( - + diff --git a/apps/site/components/client/UsernameDialog.tsx b/apps/site/components/client/UsernameDialog.tsx index a10657f4f..a4a71a318 100644 --- a/apps/site/components/client/UsernameDialog.tsx +++ b/apps/site/components/client/UsernameDialog.tsx @@ -16,10 +16,7 @@ import { Separator, Toast, } from '@/design-system' -import { - checkUsernameAvailability, - processRegisterFor -} from '@/lib' +import { checkUsernameAvailability, processRegisterFor } from '@/lib' import { zodResolver } from '@hookform/resolvers/zod' import { useForm } from 'react-hook-form' import { publicClient } from '@/config/publicClient' @@ -28,8 +25,15 @@ import { useDebounce } from 'usehooks-ts' import { addresses } from 'scrypt' import { AlchemyProvider } from '@alchemy/aa-alchemy' import { useUserContext } from '@/context' -import { type Hex, createWalletClient, custom, getAddress, encodeFunctionData, Address } from 'viem' -import { usePrivy, useWallets } from '@privy-io/react-auth'; +import { + type Hex, + createWalletClient, + custom, + getAddress, + encodeFunctionData, + Address, +} from 'viem' +import { usePrivy, useWallets } from '@privy-io/react-auth' import { river_j5bpjduqfv } from '@/config/customChainConfig' import { postGatewayABI, idRegistryABI } from 'scrypt' import { SubmitButton } from '@/client' @@ -42,7 +46,6 @@ interface UsernameDialogProps { } export function UsernameDialog({ open, setOpen }: UsernameDialogProps) { - // import user embedded wallet // const { user, sendTransaction } = usePrivy(); // const { wallets } = useWallets(); @@ -50,15 +53,15 @@ export function UsernameDialog({ open, setOpen }: UsernameDialogProps) { // const { eth } = usePrivyWagmi() // const active = await yo.setActiveWallet -// Retrieve Account from an EIP-1193 Provider. -// const [account] = await window.ethereum.request({ -// method: 'eth_requestAccounts' -// }) + // Retrieve Account from an EIP-1193 Provider. + // const [account] = await window.ethereum.request({ + // method: 'eth_requestAccounts' + // }) -// export const walletClient = createWalletClient({ -// account, -// transport: custom(window.ethereum) -// }) + // export const walletClient = createWalletClient({ + // account, + // transport: custom(window.ethereum) + // }) // embeddedWallet?.getEthersProvider() @@ -113,25 +116,24 @@ export function UsernameDialog({ open, setOpen }: UsernameDialogProps) { const { signMessage, embeddedWallet } = useUserContext() async function onSubmit(data: z.infer) { - if (signMessage && embeddedWallet?.address) { - console.log("running processRegisterFor") + console.log('running processRegisterFor') await processRegisterFor({ privySignerAddress: embeddedWallet.address, privySignMessage: signMessage, - username: `${data.username}.sbvrsv.eth` + username: `${data.username}.sbvrsv.eth`, }) - console.log("finished processRegisterFor") + console.log('finished processRegisterFor') } - setOpen(false) - + setOpen(false) + toast.custom((t) => ( {'Welcome to River'} {form.getValues().username} - )) + )) } return ( diff --git a/apps/site/config/customChainConfig.ts b/apps/site/config/customChainConfig.ts index c5b9e4891..17b9d8423 100644 --- a/apps/site/config/customChainConfig.ts +++ b/apps/site/config/customChainConfig.ts @@ -1,31 +1,34 @@ -import { defineChain } from "viem" +import { defineChain } from 'viem' export const river_j5bpjduqfv = defineChain({ - id: 36912, - name: 'river_j5bpjduqfv', - network: 'river_j5bpjduqfv', - nativeCurrency: { - decimals: 18, - name: 'Ether', - symbol: 'ETH', + id: 36912, + name: 'river_j5bpjduqfv', + network: 'river_j5bpjduqfv', + nativeCurrency: { + decimals: 18, + name: 'Ether', + symbol: 'ETH', + }, + rpcUrls: { + default: { + http: ['https://l2-river-j5bpjduqfv.t.conduit.xyz'], + webSocket: ['wss://l2-river-j5bpjduqfv.t.conduit.xyz'], }, - rpcUrls: { - default: { - http: ['https://l2-river-j5bpjduqfv.t.conduit.xyz'], - webSocket: ['wss://l2-river-j5bpjduqfv.t.conduit.xyz'], - }, - public: { - http: ['https://l2-river-j5bpjduqfv.t.conduit.xyz'], - webSocket: ['wss://l2-river-j5bpjduqfv.t.conduit.xyz'], - }, + public: { + http: ['https://l2-river-j5bpjduqfv.t.conduit.xyz'], + webSocket: ['wss://l2-river-j5bpjduqfv.t.conduit.xyz'], }, - blockExplorers: { - default: { name: 'Explorer', url: 'https://explorerl2new-river-j5bpjduqfv.t.conduit.xyz/' }, + }, + blockExplorers: { + default: { + name: 'Explorer', + url: 'https://explorerl2new-river-j5bpjduqfv.t.conduit.xyz/', }, - contracts: { - multicall3: { - address: '0xcA11bde05977b3631167028862bE2a173976CA11', - blockCreated: 5882, - }, + }, + contracts: { + multicall3: { + address: '0xcA11bde05977b3631167028862bE2a173976CA11', + blockCreated: 5882, }, - }) \ No newline at end of file + }, +}) diff --git a/apps/site/config/ethersClient.ts b/apps/site/config/ethersClient.ts index d220dd253..6767b4d80 100644 --- a/apps/site/config/ethersClient.ts +++ b/apps/site/config/ethersClient.ts @@ -6,4 +6,4 @@ const provider = new ethers.JsonRpcProvider(process.env.RPC_URL) const signer = new ethers.Wallet(process.env.PRIVATE_KEY as string, provider) -export const nonceManager = new NonceManager(signer) \ No newline at end of file +export const nonceManager = new NonceManager(signer) diff --git a/apps/site/config/publicClient.ts b/apps/site/config/publicClient.ts index 894e9b051..6f3c1e7b0 100644 --- a/apps/site/config/publicClient.ts +++ b/apps/site/config/publicClient.ts @@ -8,7 +8,6 @@ export const publicClient = createPublicClient({ transport: transport, }) - // const transport = http( // `https://opt-goerli.g.alchemy.com/v2/${process.env.NEXT_PUBLIC_ALCHEMY_KEY}`, // ) @@ -17,4 +16,3 @@ export const publicClient = createPublicClient({ // chain: opGoerliViem, // transport: transport, // }) - diff --git a/apps/site/context/UserContext.tsx b/apps/site/context/UserContext.tsx index 795bda800..4a1ea3ea6 100644 --- a/apps/site/context/UserContext.tsx +++ b/apps/site/context/UserContext.tsx @@ -11,9 +11,7 @@ import { useWallets, type ConnectedWallet, User } from '@privy-io/react-auth' import { usePrivy } from '@privy-io/react-auth' import { getUserId } from '@/gql' import { getUsername } from '@/lib' -import { - type Address, -} from 'viem' +import { type Address } from 'viem' import { SignMessageModalUIOptions } from '@privy-io/react-auth' const UserContext = createContext<{ @@ -43,7 +41,7 @@ export function UserContextComponent({ children }: { children: ReactNode }) { const { userId } = await getUserId({ custodyAddress: embeddedWallet.address as Address, }) - + if (!userId) return setUserId(userId) diff --git a/apps/site/lib/actions/relayPost.ts b/apps/site/lib/actions/relayPost.ts index 49e41ae35..3c259d332 100644 --- a/apps/site/lib/actions/relayPost.ts +++ b/apps/site/lib/actions/relayPost.ts @@ -24,7 +24,7 @@ export async function relayPost({ try { const postTxn = await nonceManager.sendTransaction({ // to: addresses.postGateway.opGoerli, - to: "0x1B692589017d4b2276227b52cD3A2a1796cb2b86", + to: '0x1B692589017d4b2276227b52cD3A2a1796cb2b86', data: encodePostCall, }) diff --git a/apps/site/lib/actions/relayRegisterFor.ts b/apps/site/lib/actions/relayRegisterFor.ts index 8904ad12c..e14f6b696 100644 --- a/apps/site/lib/actions/relayRegisterFor.ts +++ b/apps/site/lib/actions/relayRegisterFor.ts @@ -1,19 +1,19 @@ -"use server"; +'use server' -import { addresses, idRegistryABI } from "scrypt"; -import { nonceManager } from "@/config/ethersClient"; -import { Hash, Hex, encodeFunctionData } from "viem"; -import { revalidatePath } from "next/cache"; -import { getTxnWithHash } from "@/gql"; -import { setUsername } from "../username"; -import { publicClient } from "@/config/publicClient"; +import { addresses, idRegistryABI } from 'scrypt' +import { nonceManager } from '@/config/ethersClient' +import { Hash, Hex, encodeFunctionData } from 'viem' +import { revalidatePath } from 'next/cache' +import { getTxnWithHash } from '@/gql' +import { setUsername } from '../username' +import { publicClient } from '@/config/publicClient' interface RelayRegisterForProps { - registerForRecipient: Hex; - expiration: bigint; - signature: Hash; - username: string; - pathToRevalidate: string; + registerForRecipient: Hex + expiration: bigint + signature: Hash + username: string + pathToRevalidate: string } export async function relayRegisterFor({ @@ -23,23 +23,22 @@ export async function relayRegisterFor({ username, pathToRevalidate, }: RelayRegisterForProps) { - const encodedRegisterCall = encodeFunctionData({ abi: idRegistryABI, - functionName: "registerFor", + functionName: 'registerFor', args: [ registerForRecipient, // to - "0x33F59bfD58c16dEfB93612De65A5123F982F58bA", // backup + '0x33F59bfD58c16dEfB93612De65A5123F982F58bA', // backup expiration, // expiration signature, // sig ], - }); + }) try { const registerTxn = await nonceManager.sendTransaction({ to: addresses.idRegistry.river_j5bpjduqfv, data: encodedRegisterCall, - }); + }) const transaction = await publicClient.waitForTransactionReceipt({ hash: registerTxn.hash as Hash, @@ -48,7 +47,7 @@ export async function relayRegisterFor({ const userIdRegistered = parseInt( transaction.logs[0].topics[2] as string, 16, - ) + ) await setUsername({ registrationParameters: { @@ -56,45 +55,45 @@ export async function relayRegisterFor({ name: username, owner: registerForRecipient, }, - }); + }) - const resp = await getTxnInclusion(registerTxn.hash as Hash); + const resp = await getTxnInclusion(registerTxn.hash as Hash) if (resp) { - console.log(`txn ${registerTxn.hash} was processed by ponder`); - revalidatePath(pathToRevalidate); + console.log(`txn ${registerTxn.hash} was processed by ponder`) + revalidatePath(pathToRevalidate) } else { - console.log(`txn ${registerTxn.hash} NOT found by ponder`); + console.log(`txn ${registerTxn.hash} NOT found by ponder`) } } catch (error) { - console.error("Register transaction failed: ", error); + console.error('Register transaction failed: ', error) } } async function getTxnInclusion(txnHash: Hash) { - let txn; - let attemptCount = 0; // Initialize counter + let txn + let attemptCount = 0 // Initialize counter while (!txn && attemptCount < 10) { // Check counter in loop condition try { - const response = await getTxnWithHash({ hash: txnHash }); + const response = await getTxnWithHash({ hash: txnHash }) if (response && response.txn) { - txn = response.txn; - break; // Exit the loop once a valid txn is found + txn = response.txn + break // Exit the loop once a valid txn is found } } catch (error) { - console.error(`Error fetching txn hash: ${txnHash}`, error); + console.error(`Error fetching txn hash: ${txnHash}`, error) } - attemptCount++; // Increment the counter after each attempt - console.log(`Attempt count for txn hash :${txnHash}`, attemptCount); // Log the attempt count + attemptCount++ // Increment the counter after each attempt + console.log(`Attempt count for txn hash :${txnHash}`, attemptCount) // Log the attempt count // Add a delay only if another attempt will follow if (!txn && attemptCount < 10) { - await new Promise((resolve) => setTimeout(resolve, 1000)); // Waits for 1 second + await new Promise((resolve) => setTimeout(resolve, 1000)) // Waits for 1 second } } - return txn; // Will return null if the txn isn't found within 10 attempts + return txn // Will return null if the txn isn't found within 10 attempts } diff --git a/apps/site/lib/register/index.ts b/apps/site/lib/register/index.ts index 13f8997fe..7b3bb4ad8 100644 --- a/apps/site/lib/register/index.ts +++ b/apps/site/lib/register/index.ts @@ -1 +1 @@ -export * from "./processRegisterFor" \ No newline at end of file +export * from './processRegisterFor' diff --git a/apps/site/lib/register/processRegisterFor.ts b/apps/site/lib/register/processRegisterFor.ts index 337148488..78e2904e8 100644 --- a/apps/site/lib/register/processRegisterFor.ts +++ b/apps/site/lib/register/processRegisterFor.ts @@ -1,35 +1,42 @@ -import { relayRegisterFor } from "lib/actions"; -import { getExpiration, remove0xPrefix, registerForHash } from "scrypt"; -import { Hash, Hex, recoverMessageAddress, recoverAddress, hashMessage, keccak256 } from "viem"; -import { SignMessageModalUIOptions } from "@privy-io/react-auth"; +import { relayRegisterFor } from 'lib/actions' +import { getExpiration, remove0xPrefix, registerForHash } from 'scrypt' +import { + Hash, + Hex, + recoverMessageAddress, + recoverAddress, + hashMessage, + keccak256, +} from 'viem' +import { SignMessageModalUIOptions } from '@privy-io/react-auth' export async function processRegisterFor({ privySignerAddress, privySignMessage, username, }: { - privySignerAddress: string; + privySignerAddress: string privySignMessage: ( message: string, - uiOptions?: SignMessageModalUIOptions | undefined - ) => Promise; - username: string; + uiOptions?: SignMessageModalUIOptions | undefined, + ) => Promise + username: string }) { // Declare constants/params const sigExpiration: bigint = getExpiration() // const sigExpriration: bigint = BigInt(1734558342000); // Get the hash to be signed - const hash = registerForHash({ expiration: sigExpiration }); + const hash = registerForHash({ expiration: sigExpiration }) // Sign hash with privy. hash is first wrapped in eip191 wrapper. - const sig = await privySignMessage(hash); + const sig = await privySignMessage(hash) // Check if sig generated - if (!sig) return; + if (!sig) return // pass inputs to relayRegisterFor await relayRegisterFor({ registerForRecipient: privySignerAddress as Hex, expiration: sigExpiration, signature: sig as Hash, username: username, - pathToRevalidate: "/", - }); + pathToRevalidate: '/', + }) }