+ )}
- const handleDisConnect = async () => {
- await disconnect();
- localStorage.removeItem("isGoogleLogin");
- localStorage.removeItem("isConnected");
- handleSteps(ESTEPS.ONE);
- setWalletAddress("");
- dispatch({
- type: ACTIONS.LOGOUT,
- payload: "",
- });
- dispatch({
- type: ACTIONS.LOGGED_IN_VIA,
- payload: "",
- });
- dispatch({
- type: ACTIONS.SET_ADDRESS,
- payload: "",
- });
- };
+
+
+
+
+
+ );
};
export default Header;
diff --git a/ui_components/loadchest/LoadChestComponent.tsx b/ui_components/loadchest/LoadChestComponent.tsx
index ecd5ed4..9d7c573 100644
--- a/ui_components/loadchest/LoadChestComponent.tsx
+++ b/ui_components/loadchest/LoadChestComponent.tsx
@@ -4,11 +4,7 @@ import AccountAbstraction from "@safe-global/account-abstraction-kit-poc";
import { EthersAdapter } from "@safe-global/protocol-kit";
import { SafeAccountConfig, SafeFactory } from "@safe-global/protocol-kit";
import { GelatoRelayPack } from "@safe-global/relay-kit";
-import {
- MetaTransactionData,
- MetaTransactionOptions,
- OperationType,
-} from "@safe-global/safe-core-sdk-types";
+import { MetaTransactionData, MetaTransactionOptions, OperationType } from "@safe-global/safe-core-sdk-types";
import { initWasm } from "@trustwallet/wallet-core";
import { serializeError } from "eth-rpc-errors";
import { ethers } from "ethers";
@@ -22,22 +18,11 @@ import { ToastContainer } from "react-toastify";
import ReactTyped from "react-typed";
import { parseEther } from "viem";
-import {
- getBalance,
- getRelayTransactionStatus,
- getSendTransactionStatus,
- getUsdPrice,
-} from "../../apiServices";
+import { getBalance, getRelayTransactionStatus, getSendTransactionStatus, getUsdPrice } from "../../apiServices";
import { GlobalContext } from "../../context/GlobalContext";
import { LOGGED_IN, THandleStep } from "../../pages";
import * as loaderAnimation from "../../public/lottie/loader.json";
-import {
- encodeAddress,
- getCurrencyFormattedNumber,
- getTokenFormattedNumber,
- getTokenValueFormatted,
- hexToNumber,
-} from "../../utils";
+import { encodeAddress, getCurrencyFormattedNumber, getTokenFormattedNumber, getTokenValueFormatted, hexToNumber } from "../../utils";
import { BaseGoerli } from "../../utils/chain/baseGoerli";
import { icons } from "../../utils/images";
import { useWagmi } from "../../utils/wagmi/WagmiContext";
@@ -46,23 +31,11 @@ import PrimaryBtn from "../PrimaryBtn";
import SecondaryBtn from "../SecondaryBtn";
import DepositAmountModal from "./DepositAmountModal";
import { ProfileCard } from "./ProfileCard";
-import {
- GateFiEventTypes,
- GateFiDisplayModeEnum,
- GateFiSDK,
-} from "@gatefi/js-sdk";
+import { GateFiEventTypes, GateFiDisplayModeEnum, GateFiSDK } from "@gatefi/js-sdk";
import { IPaymaster, BiconomyPaymaster } from "@biconomy/paymaster";
import { IBundler, Bundler } from "@biconomy/bundler";
-import {
- BiconomySmartAccount,
- BiconomySmartAccountV2,
- DEFAULT_ENTRYPOINT_ADDRESS,
-} from "@biconomy/account";
-import {
- IHybridPaymaster,
- PaymasterMode,
- SponsorUserOperationDto,
-} from "@biconomy/paymaster";
+import { BiconomySmartAccount, BiconomySmartAccountV2, DEFAULT_ENTRYPOINT_ADDRESS } from "@biconomy/account";
+import { IHybridPaymaster, PaymasterMode, SponsorUserOperationDto } from "@biconomy/paymaster";
export interface ILoadChestComponent {
provider?: any;
@@ -91,12 +64,8 @@ export const LoadChestComponent: FC
= (props) => {
const [balanceInUsd, setBalanceInUsd] = useState("");
const [showActivity, setShowActivity] = useState(false);
const [chestLoadingText, setChestLoadingText] = useState("");
- const ethersProvider = new ethers.providers.JsonRpcProvider(
- BaseGoerli.info.rpc
- );
- const relayPack = new GelatoRelayPack(
- process.env.NEXT_PUBLIC_GELATO_RELAY_API_KEY
- );
+ const ethersProvider = new ethers.providers.JsonRpcProvider(BaseGoerli.info.rpc);
+ const relayPack = new GelatoRelayPack(process.env.NEXT_PUBLIC_GELATO_RELAY_API_KEY);
const isRelayInitiated = useRef(false);
const handleToggle = () => {
setToggle(!toggle);
@@ -128,16 +97,8 @@ export const LoadChestComponent: FC = (props) => {
setTokenPrice(res.data.ethereum.usd);
setFromAddress(address);
const balance = (await getBalance(address)) as any;
- setTokenValue(
- getTokenFormattedNumber(
- hexToNumber(balance.result) as unknown as string,
- 18
- )
- );
- const formatBal = (
- (hexToNumber(balance.result) / Math.pow(10, 18)) *
- res.data.ethereum.usd
- ).toFixed(3);
+ setTokenValue(getTokenFormattedNumber(hexToNumber(balance.result) as unknown as string, 18));
+ const formatBal = ((hexToNumber(balance.result) / Math.pow(10, 18)) * res.data.ethereum.usd).toFixed(3);
setPrice(getCurrencyFormattedNumber(formatBal));
setBalanceInUsd(formatBal);
setLoading(false);
@@ -187,13 +148,11 @@ export const LoadChestComponent: FC = (props) => {
setChestLoadingText("Setting up destination signer and address");
const paymaster = new BiconomyPaymaster({
- paymasterUrl:
- "https://paymaster.biconomy.io/api/v1/84531/76v47JPQ6.7a881a9f-4cec-45e0-95e9-c39c71ca54f4",
+ paymasterUrl: "https://paymaster.biconomy.io/api/v1/84531/76v47JPQ6.7a881a9f-4cec-45e0-95e9-c39c71ca54f4",
});
const bundler: IBundler = new Bundler({
- bundlerUrl:
- "https://bundler.biconomy.io/api/v2/84531/nJPK7B3ru.dd7f7861-190d-41bd-af80-6877f74b8f44",
+ bundlerUrl: "https://bundler.biconomy.io/api/v2/84531/nJPK7B3ru.dd7f7861-190d-41bd-af80-6877f74b8f44",
chainId: 84531,
entryPointAddress: DEFAULT_ENTRYPOINT_ADDRESS,
});
@@ -208,39 +167,9 @@ export const LoadChestComponent: FC = (props) => {
});
const scw = await biWallet.getSmartAccountAddress();
const destinatinoHash = encodeAddress(scw);
- const fullHash = payData.link + "|" + destinatinoHash;
+ const fullHash = payData.link + "~" + destinatinoHash;
setLinkHash(fullHash);
setDestinationAddress(scw);
- console.log(scw, "smart address");
-
- // const destinationSigner = new ethers.Wallet(payData.key, ethersProvider);
- // const destinationEOAAddress = await destinationSigner.getAddress();
- // const ethAdapter = new EthersAdapter({
- // ethers,
- // signerOrProvider: destinationSigner,
- // });
- // setChestLoadingText("Creating safe contract for chest");
- // const safeFactory = await SafeFactory.create({
- // ethAdapter: ethAdapter,
- // });
- // const safeAccountConfig: SafeAccountConfig = {
- // owners: [destinationEOAAddress],
- // threshold: 1,
- // };
- // const destinationAdd = await safeFactory.predictSafeAddress(
- // safeAccountConfig
- // );
- // setDestinationAddress(destinationAdd);
- // const destinatinoHash = encodeAddress(destinationAdd);
- // const fullHash = payData.link + "|" + destinatinoHash;
- // setLinkHash(fullHash);
- // setChestLoadingText("Safe contract created");
- // const fromEthProvider = new ethers.providers.Web3Provider(provider);
- // const fromSigner = await fromEthProvider.getSigner();
- // const safeAccountAbs = new AccountAbstraction(fromSigner);
- // await safeAccountAbs.init({ relayPack });
- // safeAccountAbstraction.current = safeAccountAbs;
- // isRelayInitiated.current = true;
};
const createWallet = async () => {
@@ -255,104 +184,32 @@ export const LoadChestComponent: FC = (props) => {
value: amount,
data,
};
- console.log(tx, "tx");
const smartAccount = biconomyWallet;
let partialUserOp = await smartAccount.buildUserOp([tx]);
- console.log(partialUserOp, "partialUserOp");
setChestLoadingText("Setting up smart account...");
- const biconomyPaymaster =
- smartAccount.paymaster as IHybridPaymaster;
- console.log(biconomyPaymaster, "biconomyPaymaster");
+ const biconomyPaymaster = smartAccount.paymaster as IHybridPaymaster;
let paymasterServiceData: SponsorUserOperationDto = {
mode: PaymasterMode.SPONSORED,
// optional params...
};
- console.log(paymasterServiceData, "paymasterServiceData");
try {
setChestLoadingText("Setting up paymaster...");
- const paymasterAndDataResponse =
- await biconomyPaymaster.getPaymasterAndData(
- partialUserOp,
- paymasterServiceData
- );
- console.log(paymasterAndDataResponse, "paymasterAndDataResponse");
- partialUserOp.paymasterAndData =
- paymasterAndDataResponse.paymasterAndData;
+ const paymasterAndDataResponse = await biconomyPaymaster.getPaymasterAndData(partialUserOp, paymasterServiceData);
+ partialUserOp.paymasterAndData = paymasterAndDataResponse.paymasterAndData;
const userOpResponse = await smartAccount.sendUserOp(partialUserOp);
- console.log(userOpResponse, "userOpResponse");
const transactionDetails = await userOpResponse.wait();
- console.log(transactionDetails, "transactionDetails");
- setExplorerUrl(
- `https://goerli.basescan.org/tx/${transactionDetails.receipt.transactionHash}`
- );
- console.log(transactionDetails.receipt.transactionHash, "tx hash");
+ setExplorerUrl(`https://goerli.basescan.org/tx/${transactionDetails.receipt.transactionHash}`);
setChestLoadingText("Success! Transaction Processed");
setIsSucceed(true);
- handleTransactionStatus(
- transactionDetails.receipt.transactionHash,
- linkHash
- );
+ handleTransactionStatus(transactionDetails.receipt.transactionHash, linkHash);
setChestLoadingText("Transaction Submitted!");
// router.push(linkHash);
} catch (error) {
console.error("Error executing transaction:", error);
}
- // try {
- // if (loggedInVia === LOGGED_IN.GOOGLE) {
- // if (isRelayInitiated.current) {
- // setChestLoadingText("Transaction process has begun...");
-
- // const safeTransactionData: MetaTransactionData = {
- // to: destinationAddress,
- // data: "0x",
- // value: parseEther(inputValue).toString(),
- // operation: OperationType.Call,
- // };
-
- // const options: MetaTransactionOptions = {
- // gasLimit: "100000",
- // isSponsored: true,
- // };
-
- // const gelatoTaskId =
- // await safeAccountAbstraction?.current?.relayTransaction(
- // [safeTransactionData],
- // options
- // );
- // if (gelatoTaskId) {
- // setChestLoadingText(
- // "Transaction on its way! Awaiting confirmation..."
- // );
- // handleTransactionStatus(gelatoTaskId, linkHash);
- // }
- // } else {
- // await handleInitWallet();
- // createWallet();
- // return;
- // }
- // } else {
- // try {
- // const sendAmount = await sendTransaction({
- // to: destinationAddress,
- // value: parseEther(inputValue),
- // });
- // handleTransactionStatus(sendAmount.hash, linkHash);
- // } catch (e: any) {
- // setTransactionLoading(false);
- // const err = serializeError(e);
- // toast.error(err.message);
- // console.log(e, "error");
- // }
- // }
- // } catch (e: any) {
- // setTransactionLoading(false);
- // const err = serializeError(e);
- // toast.error(err.message);
- // console.log(e, "e");
- // }
}
};
@@ -423,74 +280,6 @@ export const LoadChestComponent: FC = (props) => {
}, intervalInMilliseconds);
};
- // const handleTransactionStatus = (hash: string, link: string) => {
- // const intervalInMilliseconds = 1000;
- // const interval = setInterval(() => {
- // if (loggedInVia === LOGGED_IN.GOOGLE) {
- // getRelayTransactionStatus(hash)
- // .then((res: any) => {
- // if (res) {
- // console.log(res, "res");
- // const task = res.data.task;
- // if (task) {
- // setChestLoadingText("Verifying Transaction Status...");
- // if (task.taskState === "ExecSuccess") {
- // setChestLoadingText(
- // "Operation Successful: Transaction Completed!"
- // );
- // router.push(link);
- // if (interval !== null) {
- // clearInterval(interval);
- // }
- // }
- // } else {
- // setTransactionLoading(false);
- // toast.error("Failed to Load Chest. Try Again");
- // if (interval !== null) {
- // clearInterval(interval);
- // }
- // }
- // }
- // })
- // .catch((e) => {
- // setTransactionLoading(false);
- // toast.error(e.message);
- // console.log(e, "e");
- // if (interval !== null) {
- // clearInterval(interval);
- // }
- // });
- // } else {
- // getSendTransactionStatus(hash)
- // .then((res: any) => {
- // if (res.result) {
- // const status = Number(res.result.status);
- // if (status === 1) {
- // router.push(link);
- // if (interval !== null) {
- // clearInterval(interval);
- // }
- // } else {
- // setTransactionLoading(false);
- // toast.error("Failed to Load Chest. Try Again");
- // if (interval !== null) {
- // clearInterval(interval);
- // }
- // }
- // }
- // })
- // .catch((e) => {
- // setTransactionLoading(false);
- // toast.error(e.message);
- // console.log(e, "e");
- // if (interval !== null) {
- // clearInterval(interval);
- // }
- // });
- // }
- // }, intervalInMilliseconds);
- // };
-
const handleShowActivity = () => {
setShowActivity(!showActivity);
};
@@ -499,11 +288,7 @@ export const LoadChestComponent: FC = (props) => {
{!transactionLoading ? (
-
+
{!showActivity ? (
<>
@@ -512,12 +297,7 @@ export const LoadChestComponent: FC
= (props) => {
YOUR BALANCE
-
+
{toggle ? (
loading || loader ? (
@@ -526,12 +306,8 @@ export const LoadChestComponent: FC = (props) => {
) : (
-
- {price}
-
-
- {tokenValue} ETH
-
+
{price}
+
{tokenValue} ETH
)
) : loading ? (
@@ -541,31 +317,15 @@ export const LoadChestComponent: FC
= (props) => {
) : (
-
- ~ {tokenValue} ETH
-
-
- {price}
-
+
~ {tokenValue} ETH
+
{price}
)}
-
- {!loading && !loader ? (
-
- ETH
-
- ) : (
-
- )}
+
+ {!loading && !loader ?
ETH
:
}
= (props) => {
setOpen(true);
}}
>
-
- + Add funds to your account
-
+
+ Add funds to your account