From 4f39d03cdc249155da13d9c8c631265315f7db13 Mon Sep 17 00:00:00 2001 From: Jennifer Echenim Date: Wed, 31 Jul 2024 19:38:58 +0400 Subject: [PATCH] Refactor destination address form --- .../common/destination-address-form.tsx | 12 +++++----- .../modules/common/drawer-dialog.tsx | 1 - .../frontend/src/lib/utils/walletUtils.ts | 22 ------------------- .../src/bridge/frontend/src/types/index.ts | 9 ++++++++ 4 files changed, 15 insertions(+), 29 deletions(-) diff --git a/contracts/src/bridge/frontend/src/components/modules/common/destination-address-form.tsx b/contracts/src/bridge/frontend/src/components/modules/common/destination-address-form.tsx index 36ad296fdb..5946c40dc9 100644 --- a/contracts/src/bridge/frontend/src/components/modules/common/destination-address-form.tsx +++ b/contracts/src/bridge/frontend/src/components/modules/common/destination-address-form.tsx @@ -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 ( -
+
- + ); } diff --git a/contracts/src/bridge/frontend/src/components/modules/common/drawer-dialog.tsx b/contracts/src/bridge/frontend/src/components/modules/common/drawer-dialog.tsx index f6f72757f3..5a6782ca5a 100644 --- a/contracts/src/bridge/frontend/src/components/modules/common/drawer-dialog.tsx +++ b/contracts/src/bridge/frontend/src/components/modules/common/drawer-dialog.tsx @@ -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({ diff --git a/contracts/src/bridge/frontend/src/lib/utils/walletUtils.ts b/contracts/src/bridge/frontend/src/lib/utils/walletUtils.ts index 45c63c8b60..49aad2d57e 100644 --- a/contracts/src/bridge/frontend/src/lib/utils/walletUtils.ts +++ b/contracts/src/bridge/frontend/src/lib/utils/walletUtils.ts @@ -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), diff --git a/contracts/src/bridge/frontend/src/types/index.ts b/contracts/src/bridge/frontend/src/types/index.ts index f9ba4f8927..d491031528 100644 --- a/contracts/src/bridge/frontend/src/types/index.ts +++ b/contracts/src/bridge/frontend/src/types/index.ts @@ -1,3 +1,4 @@ +import { ethers } from "ethers"; import React from "react"; export interface SeoProps { @@ -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; +}