Skip to content

Commit 8551e65

Browse files
committed
feat(frontend): fund during deployment UI and wagmi
1 parent a123080 commit 8551e65

File tree

3 files changed

+50
-9
lines changed

3 files changed

+50
-9
lines changed

frontend/src/app/(routes)/dashboard/deploy/page.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,18 @@ export default function DeployPage() {
9898
</CardHeader>
9999
</Card>
100100

101-
<WalletFunding walletAddress={deployedWalletAddress} />
101+
<Card>
102+
<CardHeader>
103+
<CardTitle>Next Steps</CardTitle>
104+
<CardDescription>
105+
You can add more funds to your wallet or continue to execute
106+
transactions
107+
</CardDescription>
108+
</CardHeader>
109+
<CardContent>
110+
<WalletFunding walletAddress={deployedWalletAddress} />
111+
</CardContent>
112+
</Card>
102113

103114
<div className="flex justify-end">
104115
<Button onClick={() => router.push("/dashboard/execute")}>

frontend/src/components/wallet-deployment.tsx

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { AlertCircle, CheckCircle2, Loader2, Wallet } from "lucide-react";
44
import { useEffect, useState } from "react";
55
import { toast } from "sonner";
6-
import { type Address, isAddress } from "viem";
6+
import { type Address, isAddress, parseEther } from "viem";
77
import { useAccount } from "wagmi";
88
import { Button } from "@/components/ui/button";
99
import {
@@ -36,6 +36,7 @@ export function WalletDeployment({
3636

3737
const [entryPointAddress, setEntryPointAddress] = useState<string>("");
3838
const [verifierAddress, setVerifierAddress] = useState<string>("");
39+
const [initialFunding, setInitialFunding] = useState<string>("");
3940
const [deployedWallet, setDeployedWallet] = useState<Address | null>(null);
4041

4142
// Load default addresses on mount
@@ -86,11 +87,16 @@ export function WalletDeployment({
8687
verifierAddress: verifierAddress as Address,
8788
ownerAddress: userAddress,
8889
initialSecretHash: secretHash,
90+
initialFunding: initialFunding ? parseEther(initialFunding) : undefined,
8991
});
9092

9193
if (walletAddress) {
9294
setDeployedWallet(walletAddress);
93-
toast.success("Wallet deployed successfully!");
95+
toast.success(
96+
initialFunding
97+
? "Wallet deployed and funded successfully!"
98+
: "Wallet deployed successfully!",
99+
);
94100
onDeployed?.(walletAddress);
95101
}
96102
} catch (error) {
@@ -249,6 +255,24 @@ export function WalletDeployment({
249255
/>
250256
</div>
251257
)}
258+
259+
<div className="space-y-2">
260+
<Label htmlFor="funding">Initial Funding (ETH) - Optional</Label>
261+
<Input
262+
id="funding"
263+
type="number"
264+
step="0.001"
265+
min="0"
266+
placeholder="0.1"
267+
value={initialFunding}
268+
onChange={(e) => setInitialFunding(e.target.value)}
269+
disabled={isDeploying || !secretHash}
270+
/>
271+
<p className="text-xs text-muted-foreground">
272+
Fund your wallet during deployment to skip the separate funding
273+
step. Recommended: 0.01 ETH or more for gas fees
274+
</p>
275+
</div>
252276
</CardContent>
253277
<CardFooter>
254278
<Button
@@ -259,12 +283,14 @@ export function WalletDeployment({
259283
{isDeploying ? (
260284
<>
261285
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
262-
Deploying Wallet...
286+
{initialFunding
287+
? "Deploying & Funding..."
288+
: "Deploying Wallet..."}
263289
</>
264290
) : (
265291
<>
266292
<Wallet className="mr-2 h-4 w-4" />
267-
Deploy Wallet
293+
{initialFunding ? "Deploy & Fund Wallet" : "Deploy Wallet"}
268294
</>
269295
)}
270296
</Button>

frontend/src/hooks/use-totp-wallet.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface DeployWalletParams {
1616
verifierAddress: Address;
1717
ownerAddress: Address;
1818
initialSecretHash: bigint;
19+
initialFunding?: bigint; // Optional initial funding amount in wei
1920
}
2021

2122
export interface ExecuteTransactionParams {
@@ -103,17 +104,20 @@ export function useTOTPWallet(): UseTOTPWalletResult {
103104
params.initialSecretHash,
104105
],
105106
gas: BigInt(5000000), // Set a reasonable gas limit for contract deployment
107+
value: params.initialFunding, // Send ETH with deployment transaction
106108
});
107109

108110
// Wait for transaction to be mined
109111
const receipt = await publicClient.waitForTransactionReceipt({ hash });
110112

111-
if (receipt.contractAddress) {
112-
setWalletAddress(receipt.contractAddress);
113-
return receipt.contractAddress;
113+
if (!receipt.contractAddress) {
114+
throw new Error("Failed to get contract address");
114115
}
115116

116-
throw new Error("Failed to get contract address");
117+
const deployedAddress = receipt.contractAddress;
118+
setWalletAddress(deployedAddress);
119+
120+
return deployedAddress;
117121
} catch (err) {
118122
const error = err instanceof Error ? err : new Error(String(err));
119123
setError(error);

0 commit comments

Comments
 (0)