From 14ce79a4321290f5c03e9bdb8fdd48c73ffffc17 Mon Sep 17 00:00:00 2001 From: Rushikesh Nimkar Date: Thu, 22 Aug 2024 13:22:02 +0530 Subject: [PATCH 1/2] dvpnnft page error handling --- pages/dvpnnft.tsx | 49 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/pages/dvpnnft.tsx b/pages/dvpnnft.tsx index 8f97945..8c20753 100644 --- a/pages/dvpnnft.tsx +++ b/pages/dvpnnft.tsx @@ -23,16 +23,23 @@ const BaliDVPNNFTPage = () => { setResponse(result.data); setError(null); - // Check if the response contains a transaction hash + // Check if the response contains a transaction hash or if status is 302 if (result.data && result.data.transaction_hash) { setShowPopup(true); + } else if (result.status === 302) { + setShowPopup(true); + setResponse({ alreadyMinted: true }); } } catch (err) { - setError('An error occurred while processing your request.'); - setResponse(null); + if (err.response && err.response.status === 302) { + setShowPopup(true); + setResponse({ alreadyMinted: true }); + } else { + setError('An error occurred while processing your request.'); + setResponse(null); + } } }; - const renderResponse = () => { if (error) { return

{error}

; @@ -53,21 +60,37 @@ const BaliDVPNNFTPage = () => { const renderPopup = () => { if (!showPopup) return null; + const isAlreadyMinted = response && response.alreadyMinted; + return (
- - - -
-

Success!

-

Your transaction was successful.

-
-

Transaction Hash:

-

{response.transaction_hash}

+ {isAlreadyMinted ? ( + + + + ) : ( + + + + )}
+

+ {isAlreadyMinted ? "Already Minted" : "Success!"} +

+

+ {isAlreadyMinted + ? "You have already minted an NFT with this wallet address." + : "Your transaction was successful."} +

+ {!isAlreadyMinted && ( +
+

Transaction Hash:

+

{response.transaction_hash}

+
+ )} + onClick={handleGoClick} + className="bg-blue-800 hover:bg-blue-900 text-white font-bold py-3 px-6 rounded-full text-xl mb-6" + disabled={isLoading} + > + {isLoading ? 'Processing...' : 'GO'} +
Erebrus DVPN @@ -166,12 +186,14 @@ const BaliDVPNNFTPage = () => { />
- +
{renderPopup()} @@ -180,6 +202,8 @@ const BaliDVPNNFTPage = () => {
+ {renderLoadingAnimation()} +