Skip to content

Commit

Permalink
Refactor destination address form
Browse files Browse the repository at this point in the history
  • Loading branch information
Jennievon committed Jul 31, 2024
1 parent 2b7928c commit 4f39d03
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ export default function FormComponent({
const receiver = form.getValues("receiver");
const addAddressToMainForm = (e: any) => {
e.preventDefault();
form.setValue("receiver", e.target.elements.address.value);
const address = e.target.form[0].value;
form.setValue("receiver", address);
setOpen(false);
};
return (
<form
className={cn("grid items-start gap-4", className)}
onSubmit={addAddressToMainForm}
>
<form className={cn("grid items-start gap-4", className)}>
<div className="grid gap-2">
<Label htmlFor="address">Address</Label>
<Input
Expand All @@ -41,7 +39,9 @@ export default function FormComponent({
Make sure the address is correct before submitting.
</AlertDescription>
</Alert>
<Button type="submit">Add destination address</Button>
<Button type="button" onClick={addAddressToMainForm}>
Add destination address
</Button>
</form>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
DrawerClose,
} from "../../ui/drawer";
import { useMediaQuery } from "@/src/hooks/useMediaQuery";
import { useFormHook } from "@/src/hooks/useForm";
import FormComponent from "./destination-address-form";

export function DrawerDialog({
Expand Down
22 changes: 0 additions & 22 deletions contracts/src/bridge/frontend/src/lib/utils/walletUtils.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,13 @@
import detectEthereumProvider from "@metamask/detect-provider";
import { ToastType, WalletNetwork } from "../../types";
import { requestMethods } from "../../routes";
import { toast } from "@/src/components/ui/use-toast";

export const getEthereumProvider = async () => {
const provider = await detectEthereumProvider();
console.log("🚀 ~ getEthereumProvider ~ provider:", provider);
if (!provider) {
throw new Error("No Ethereum provider detected");
}
return provider;
};

export const switchNetwork = async (
provider: any,
desiredNetwork: WalletNetwork
) => {
if (!provider) {
toast({
title: "Error",
description: "Please connect to wallet first",
variant: ToastType.DESTRUCTIVE,
});
return;
}
await provider.request({
method: requestMethods.switchNetwork,
params: [{ chainId: desiredNetwork }],
});
};

export const handleStorage = {
save: (key: string, value: string) => localStorage.setItem(key, value),
get: (key: string) => localStorage.getItem(key),
Expand Down
9 changes: 9 additions & 0 deletions contracts/src/bridge/frontend/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ethers } from "ethers";
import React from "react";

export interface SeoProps {
Expand Down Expand Up @@ -182,3 +183,11 @@ export interface ObscuroConfig {
L2CrossChainMessenger: string;
};
}

export interface ContractState {
bridgeContract?: ethers.Contract;
managementContract?: ethers.Contract;
messageBusContract?: ethers.Contract;
wallet?: ethers.Wallet;
messageBusAddress: string;
}

0 comments on commit 4f39d03

Please sign in to comment.