Skip to content

Commit

Permalink
test ci after formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
salieflewis committed Dec 19, 2023
1 parent 215f6e2 commit eca591a
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 106 deletions.
2 changes: 1 addition & 1 deletion apps/site/app/providers/PrivyProviderWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function PrivyProviderWrapper({
noPromptOnSignature: true,
},
defaultChain: river_j5bpjduqfv,
supportedChains: [river_j5bpjduqfv]
supportedChains: [river_j5bpjduqfv],
}}
>
{children}
Expand Down
2 changes: 1 addition & 1 deletion apps/site/components/client/User.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function User({ setOpen }: UserProps) {
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="link">{username ? username : "Logout"}</Button>
<Button variant="link">{username ? username : 'Logout'}</Button>
</DropdownMenuTrigger>
<DropdownMenuContent className="w-32" align="end">
<DropdownMenuGroup className="flex flex-col gap-2">
Expand Down
46 changes: 24 additions & 22 deletions apps/site/components/client/UsernameDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -42,23 +46,22 @@ interface UsernameDialogProps {
}

export function UsernameDialog({ open, setOpen }: UsernameDialogProps) {

// import user embedded wallet
// const { user, sendTransaction } = usePrivy();
// const { wallets } = useWallets();
// const embeddedWallet = wallets.find((wallet) => wallet.walletClientType === 'privy');
// 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()

Expand Down Expand Up @@ -113,25 +116,24 @@ export function UsernameDialog({ open, setOpen }: UsernameDialogProps) {
const { signMessage, embeddedWallet } = useUserContext()

async function onSubmit(data: z.infer<typeof UsernameSchema>) {

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) => (
<Toast>
{'Welcome to River'}
<span className="font-bold">{form.getValues().username}</span>
</Toast>
))
))
}

return (
Expand Down
53 changes: 28 additions & 25 deletions apps/site/config/customChainConfig.ts
Original file line number Diff line number Diff line change
@@ -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,
},
})
},
})
2 changes: 1 addition & 1 deletion apps/site/config/ethersClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
export const nonceManager = new NonceManager(signer)
2 changes: 0 additions & 2 deletions apps/site/config/publicClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
// )
Expand All @@ -17,4 +16,3 @@ export const publicClient = createPublicClient({
// chain: opGoerliViem,
// transport: transport,
// })

6 changes: 2 additions & 4 deletions apps/site/context/UserContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<{
Expand Down Expand Up @@ -43,7 +41,7 @@ export function UserContextComponent({ children }: { children: ReactNode }) {
const { userId } = await getUserId({
custodyAddress: embeddedWallet.address as Address,
})

if (!userId) return

setUserId(userId)
Expand Down
2 changes: 1 addition & 1 deletion apps/site/lib/actions/relayPost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function relayPost({
try {
const postTxn = await nonceManager.sendTransaction({
// to: addresses.postGateway.opGoerli,
to: "0x1B692589017d4b2276227b52cD3A2a1796cb2b86",
to: '0x1B692589017d4b2276227b52cD3A2a1796cb2b86',
data: encodePostCall,
})

Expand Down
69 changes: 34 additions & 35 deletions apps/site/lib/actions/relayRegisterFor.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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,
Expand All @@ -48,53 +47,53 @@ export async function relayRegisterFor({
const userIdRegistered = parseInt(
transaction.logs[0].topics[2] as string,
16,
)
)

await setUsername({
registrationParameters: {
id: String(userIdRegistered),
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
}
2 changes: 1 addition & 1 deletion apps/site/lib/register/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./processRegisterFor"
export * from './processRegisterFor'
Loading

0 comments on commit eca591a

Please sign in to comment.