'use client'
import { ethers } from 'ethers'
import { deposit } from 'privacycash-evm'
import { useAccount, useWalletClient } from 'wagmi'
export function DepositButton() {
const { address, connector } = useAccount()
const { data: walletClient } = useWalletClient()
const handleDeposit = async () => {
if (!address) return
// Retrieve the stored signature
const signature = localStorage.getItem(`evm_sign_${address}`)
if (!signature) {
alert('Please sign in first.')
return
}
// Build the txSender callback
const txSender = async (unsignedTx: any) => {
if (walletClient) {
return await walletClient.sendTransaction({
to: unsignedTx.to as `0x${string}`,
data: unsignedTx.data as `0x${string}`,
value: BigInt(unsignedTx.value?.toString() ?? '0'),
})
}
// Fallback via ethers BrowserProvider
const ethereum = await connector?.getProvider()
const provider = new ethers.BrowserProvider(ethereum as any)
const signer = await provider.getSigner(address)
const tx = await signer.sendTransaction(unsignedTx)
return tx.hash
}
const txHash = await deposit({
depositAmountInput: 0.01,
keyBasePath: '/circuit',
signature,
address,
txSender,
})
console.log('Deposit tx:', txHash)
}
return <button onClick={handleDeposit}>Deposit 0.01 ETH</button>
}