Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions src/components/Create/useCreateLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,19 @@ export const useCreateLink = () => {
if (!preparedDepositTxs) return
let idx = 0
const signedTxsResponse: string[] = []

if (isActiveWalletPW) {
const params = preparedDepositTxs.unsignedTxs.map((tx) => ({
to: tx.to! as Hex,
value: tx.value?.valueOf(),
data: tx.data as Hex | undefined,
}))
let hash = await handleSendUserOpEncoded(params)
signedTxsResponse.push(hash.toString())
idx++
return signedTxsResponse[signedTxsResponse.length - 1]
}

for (const tx of preparedDepositTxs.unsignedTxs) {
setLoadingState('Sign in wallet')

Expand All @@ -514,18 +527,7 @@ export const useCreateLink = () => {
console.log('error setting fee options, fallback to default')
}
}
if (isActiveWalletPW) {
// TODO: add retry logic in handleSendUserOpEncoded() as below flow
let hash = await handleSendUserOpEncoded({
to: tx.to! as Address,
value: tx.value!,
data: tx.data! as Hex,
})

// TODO: same call as below - group w/ flow below as much as possible
signedTxsResponse.push(hash.toString())
idx++
} else if (isActiveWalletBYOW) {
if (isActiveWalletBYOW) {
// Send the transaction using wagmi
// current stage is encoded but NOT signed
let hash = await sendTransactionAsync({
Expand Down
44 changes: 22 additions & 22 deletions src/context/walletContext/zeroDevContext.context.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use client'
import { ReactNode, createContext, useContext, useState, useCallback, useEffect } from 'react'
import { ReactNode, createContext, useContext, useState, useCallback } from 'react'

// ZeroDev imports
import * as consts from '@/constants/zerodev.consts'
Expand All @@ -18,7 +18,6 @@ import {
} from '@zerodev/passkey-validator'
import { KERNEL_V3_1 } from '@zerodev/sdk/constants'

import { useToast } from '@/components/0_Bruddle/Toast'
import { peanutPublicClient } from '@/constants/viem.consts'
import { infuraRpcUrls } from '@/constants'
import { useAuth } from '../authContext'
Expand All @@ -33,9 +32,9 @@ type UserOpNotEncodedParams = {
args: any[]
}
type UserOpEncodedParams = {
to: Address
value: BigInt | null
data: Hex
to: Hex
value?: bigint | undefined
data?: Hex | undefined
}
interface ZeroDevContextType {
isKernelClientReady: boolean
Expand All @@ -48,7 +47,7 @@ interface ZeroDevContextType {
setIsSendingUserOp: (sendingUserOp: boolean) => void
handleRegister: (handle: string) => Promise<AppSmartAccountClient>
handleLogin: () => Promise<void>
handleSendUserOpEncoded: (args: UserOpEncodedParams) => Promise<string> // TODO: return type may be undefined here (if userop fails for whatever reason)
handleSendUserOpEncoded: (args: UserOpEncodedParams[]) => Promise<string> // TODO: return type may be undefined here (if userop fails for whatever reason)
handleSendUserOpNotEncoded: (args: UserOpNotEncodedParams) => Promise<string> // TODO: return type may be undefined here (if userop fails for whatever reason)
address: string | undefined
}
Expand All @@ -65,7 +64,6 @@ const ZeroDevContext = createContext<ZeroDevContextType | undefined>(undefined)
* adding accounts and logging out. It also provides hooks for child components to access user data and auth-related functions.
*/
export const ZeroDevProvider = ({ children }: { children: ReactNode }) => {
const toast = useToast()
const { fetchUser, user } = useAuth()
const _getPasskeyName = (handle: string) => `${handle}.peanut.wallet`
////// context props
Expand Down Expand Up @@ -111,9 +109,19 @@ export const ZeroDevProvider = ({ children }: { children: ReactNode }) => {
chain: consts.PEANUT_WALLET_CHAIN,
transport: http(consts.PAYMASTER_URL),
})
return zerodevPaymaster.sponsorUserOperation({
userOperation,
})

// Add logging to debug paymaster response
try {
const paymasterResult = await zerodevPaymaster.sponsorUserOperation({
userOperation,
shouldOverrideFee: true,
})

return paymasterResult
} catch (error) {
console.error('Paymaster error:', error)
throw error
}
},
},
})
Expand All @@ -127,10 +135,6 @@ export const ZeroDevProvider = ({ children }: { children: ReactNode }) => {
return kernelClient
}

// TODO: handle logout
// setKernelClient(undefined)
// setIsKernelClientReady(false)

////// Register functions
//
const handleRegister = async (handle: string): Promise<AppSmartAccountClient> => {
Expand Down Expand Up @@ -203,25 +207,21 @@ export const ZeroDevProvider = ({ children }: { children: ReactNode }) => {

////// UserOp functions
//
//

// TODO: better docstrings
// used when data is already encoded from Peanut
// but remains unsigned
const handleSendUserOpEncoded = useCallback(
async ({ to, value, data }: UserOpEncodedParams) => {
async (calls: UserOpEncodedParams[]) => {
if (!kernelClient) {
throw new Error('Trying to send user operation before client initialization')
}
setIsSendingUserOp(true)
console.dir(calls)
const userOpHash = await kernelClient.sendUserOperation({
account: kernelClient.account,
callData: await kernelClient.account!.encodeCalls([
{
to: (to ? to : '') as `0x${string}`,
value: value ? BigInt(value.toString()) : BigInt(0),
data,
},
]),
callData: await kernelClient.account!.encodeCalls(calls),
})

const receipt = await kernelClient.waitForUserOperationReceipt({
Expand Down
Loading