Skip to content

Commit

Permalink
Add a toast alert in gallery for user connexion
Browse files Browse the repository at this point in the history
  • Loading branch information
Segue21 committed May 26, 2024
1 parent c28a190 commit 29b1988
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/components/Blockchain/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<string | null> {
export async function getAccount(): Promise<string> {
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 '';
}


Expand Down
2 changes: 0 additions & 2 deletions src/components/Gallery/Gallery.css
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ th.actions {
}




/* Specific Button Colors */
.button-outline-primary {
color: #030303;
Expand Down
10 changes: 5 additions & 5 deletions src/components/Gallery/Gallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {

Expand Down Expand Up @@ -117,7 +119,6 @@ export const Gallery = () => {

}


const displayMyNFTs = async (): Promise<void> => {
if (!nfts) {
toast.info('You have no NFTs to display!');
Expand Down Expand Up @@ -356,7 +357,6 @@ export const Gallery = () => {
)
}


</Container >

);
Expand Down

0 comments on commit 29b1988

Please sign in to comment.