Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update embed-sdk and usage to listen error events #64

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 37 additions & 37 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion src/components/CrossMintingStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import Link from "next/link";
import Image from "next/image";
import { bundlerActions, ENTRYPOINT_ADDRESS_V07 } from "permissionless";
import { useState } from "react";
import { useEffect, useState } from "react";
import { HiOutlineArrowSmRight } from "react-icons/hi";
import { encodeFunctionData, Hex, createClient, http } from "viem";
import { polygonAmoy } from "viem/chains";
Expand Down Expand Up @@ -39,6 +39,7 @@ const CrossMintingStep = ({
address: web3PayAddress,
selectedEnv,
setLoggedIn,
error: errorFromWallet,
} = useWallet();
const [displayErrorPopup, setDisplayErrorPopup] = useState(false);
const [errorText, setErrorText] = useState("");
Expand Down Expand Up @@ -68,6 +69,7 @@ const CrossMintingStep = ({
value: "0",
},
});

if (resp) {
// setMintSuccess(true);
setMintNftState({
Expand Down Expand Up @@ -149,6 +151,19 @@ const CrossMintingStep = ({
}
}

useEffect(() => {
if (errorFromWallet) {
// show error
setDisplayErrorPopup(true);
setErrorText("Minting failed");
setSubErrorText(errorFromWallet);
} else {
setDisplayErrorPopup(false);
setErrorText("");
setSubErrorText("");
}
}, [errorFromWallet]);

return (
<div className="flex flex-col items-center justify-center w-full">
{!showSummary && (
Expand Down
2 changes: 0 additions & 2 deletions src/components/LogoutPopup.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { useWallet } from "@/context/walletContext";
import useMintStore from "@/lib/store/mint";
import { HiExclamationCircle } from "react-icons/hi";
import { text } from "stream/consumers";

const LogoutPopup = ({ onCancel }: {
onCancel: () => void;
Expand Down
25 changes: 15 additions & 10 deletions src/context/walletContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { SelectedEnv } from "@/utils/interfaces";
import { calculateBaseUrl } from "@/utils/utils";
// WalletContext.js
import { WalletProvider } from "@web3auth/global-accounts-sdk";
import { useRouter } from "next/navigation";
import React, { createContext, useContext, useEffect, useState } from "react";
Expand All @@ -17,7 +16,8 @@ interface IWalletContext {
loggedIn: boolean;
setLoggedIn: (val: boolean) => void;
showNextLoginModal: boolean;
setShowNextLoginModal: (val: boolean) => void;
setShowNextLoginModal: (val: boolean) => void;
error?: string;
}

const WalletContext = createContext<IWalletContext>({
Expand Down Expand Up @@ -47,6 +47,7 @@ export const WalletProviderContext = ({
const [showNextLoginModal, setShowNextLoginModal] = useState<boolean>(false);
const [loggedIn, setLoggedIn] = useState(false);
const [chainId, setChainId] = useState(80002);
const [error, setError] = useState<string | undefined>();

useEffect(() => {
const getWalletURL = () => {
Expand All @@ -67,14 +68,17 @@ export const WalletProviderContext = ({
preference: {
keysUrl: getWalletURL(),
},
});

_walletProvider.addListener("disconnect", () => {
setAddress("");
setWalletProvider(null);
localStorage.clear();
setLoggedIn(false);
setShowNextLoginModal(true);
onError: (_error) => {
console.log("Error occured::error", _error);
setError(_error);
},
onDisconnect: () => {
setAddress("");
setWalletProvider(null);
localStorage.clear();
setLoggedIn(false);
setShowNextLoginModal(true);
},
});

setWalletProvider(_walletProvider);
Expand Down Expand Up @@ -121,6 +125,7 @@ export const WalletProviderContext = ({
setLoggedIn,
showNextLoginModal,
setShowNextLoginModal,
error,
}}
>
{children}
Expand Down
Binary file modified web3auth-global-accounts-sdk-0.1.1-0.tgz
Binary file not shown.