From 29b198816b0c65bad47a35b35dc555c7086f9ef7 Mon Sep 17 00:00:00 2001 From: El-hacen21 Date: Sun, 26 May 2024 11:24:18 +0000 Subject: [PATCH] Add a toast alert in gallery for user connexion --- src/components/Blockchain/contract.ts | 10 +++++----- src/components/Gallery/Gallery.css | 2 -- src/components/Gallery/Gallery.tsx | 10 +++++----- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/components/Blockchain/contract.ts b/src/components/Blockchain/contract.ts index 37019020..9844dbdc 100644 --- a/src/components/Blockchain/contract.ts +++ b/src/components/Blockchain/contract.ts @@ -2,7 +2,7 @@ import { ethers, Signer, Contract, BrowserProvider } from 'ethers'; import contractABI from './ABI.json'; -export const contractAddress = '0x72F2C6EAaAf332999Df158E59Aad670c6d2DA1c8'; +export const contractAddress = '0xDCc49e76b061db2AA11013cB47f5D9ebfC131361'; // Declare global variables for provider, signer, and contract let provider: BrowserProvider | null; @@ -37,21 +37,21 @@ initializeProviderAndSigner(); // Create a contract instance with a signer, which enables sending transactions // const contract = new ethers.Contract(contractAddress, contractABI, signer); -export async function getAccount(): Promise { +export async function getAccount(): Promise { if (provider && signer) try { await provider.send("eth_requestAccounts", []); const account = await signer.getAddress(); if (!account) { console.error("No accessible accounts. Make sure MetaMask is connected."); - return null; + return ''; } return account; } catch (error) { console.error("Could not get access to accounts:", error); - return null; + return ''; } - return null; + return ''; } diff --git a/src/components/Gallery/Gallery.css b/src/components/Gallery/Gallery.css index b3bdb063..74382d7e 100644 --- a/src/components/Gallery/Gallery.css +++ b/src/components/Gallery/Gallery.css @@ -118,8 +118,6 @@ th.actions { } - - /* Specific Button Colors */ .button-outline-primary { color: #030303; diff --git a/src/components/Gallery/Gallery.tsx b/src/components/Gallery/Gallery.tsx index 4a07b6a8..83eff327 100644 --- a/src/components/Gallery/Gallery.tsx +++ b/src/components/Gallery/Gallery.tsx @@ -80,15 +80,17 @@ export const Gallery = () => { const fetchedAccount = await contract.getAccount(); if (fetchedAccount) { setAccount(fetchedAccount); - } else { - toast.info('Merci de vous connecter pour continuer.'); } } catch (error) { - toast.info('Merci de vous connecter pour continuer.'); console.error(error); + toast.info('Merci de vous connecter pour continuer.'); } }; + useEffect(() => { + fetchAccount(); + }, []); + const displayGallery = async (): Promise => { @@ -117,7 +119,6 @@ export const Gallery = () => { } - const displayMyNFTs = async (): Promise => { if (!nfts) { toast.info('You have no NFTs to display!'); @@ -356,7 +357,6 @@ export const Gallery = () => { ) } - );