From 8d8d7da8053639e7a4ae5c1262306a33a1999ae8 Mon Sep 17 00:00:00 2001 From: Max Petretta Date: Mon, 22 Aug 2022 23:18:04 -0400 Subject: [PATCH] Only show network alert once --- react/components/AppProvider.jsx | 2 +- react/components/Editor.jsx | 2 +- react/components/Layout.jsx | 25 ++++++++++++++----------- react/components/Nav.jsx | 2 +- react/components/Tweet.jsx | 2 +- react/pages/404.js | 2 +- 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/react/components/AppProvider.jsx b/react/components/AppProvider.jsx index 29a8f0b..37587ce 100644 --- a/react/components/AppProvider.jsx +++ b/react/components/AppProvider.jsx @@ -13,7 +13,7 @@ export const AppProvider = ({ children }) => { const [confetti, setConfetti] = useState(false) useAccount({ onSuccess(data) { - if (data) { + if (data && !address) { setAddress(data.address) } }, diff --git a/react/components/Editor.jsx b/react/components/Editor.jsx index 0ef42b4..25a510f 100644 --- a/react/components/Editor.jsx +++ b/react/components/Editor.jsx @@ -18,7 +18,7 @@ export default function Editor() { const [price, setPrice] = useState(0) useAccount({ onSuccess(data) { - if (data) { + if (data && !address) { setAddress(data.address) } }, diff --git a/react/components/Layout.jsx b/react/components/Layout.jsx index 80b3545..66f759d 100644 --- a/react/components/Layout.jsx +++ b/react/components/Layout.jsx @@ -1,7 +1,7 @@ import Head from "next/head" import { useRouter } from "next/router" import { useState } from "react" -import toast, { Toaster } from "react-hot-toast" +import { toast, Toaster } from "react-hot-toast" import { useAccount, useContractRead } from "wagmi" import { contractABI, contractAddress } from "../lib/contract.js" import Nav from "./Nav" @@ -30,16 +30,19 @@ export default function Layout(props) { console.debug("Found authorized account: ", data.address) // Alert user to which networks are available - toast("Twitt3r only supports Goerli & Ropsten testnets!", { - duration: 8000, - position: "top-center", - style: { - color: "#FFFFFF", - backgroundColor: "#DC2626", - minWidth: "440px", - }, - icon: "⚠️", - }) + if (!sessionStorage.getItem("seenNetworkAlert")) { + toast("Twitt3r only supports Goerli & Ropsten testnets!", { + duration: 8000, + position: "top-center", + style: { + color: "#FFFFFF", + backgroundColor: "#DC2626", + minWidth: "440px", + }, + icon: "⚠️", + }) + sessionStorage.setItem("seenNetworkAlert", true) + } // Check if this is the owner's wallet if ( diff --git a/react/components/Nav.jsx b/react/components/Nav.jsx index a0a3fdc..424a70e 100644 --- a/react/components/Nav.jsx +++ b/react/components/Nav.jsx @@ -8,7 +8,7 @@ export default function Nav() { const [address, setAddress] = useState("") useAccount({ onSuccess(data) { - if (data) { + if (data && !address) { setAddress(data.address) } }, diff --git a/react/components/Tweet.jsx b/react/components/Tweet.jsx index 678d4fc..ab1e4ca 100644 --- a/react/components/Tweet.jsx +++ b/react/components/Tweet.jsx @@ -30,7 +30,7 @@ export default function Tweet(props) { const { tweets } = useTweets() useAccount({ onSuccess(data) { - if (data) { + if (data && !address) { setAddress(data.address) } }, diff --git a/react/pages/404.js b/react/pages/404.js index 599cfbb..a313b58 100644 --- a/react/pages/404.js +++ b/react/pages/404.js @@ -8,7 +8,7 @@ export default function Error404() { const [address, setAddress] = useState() useAccount({ onSuccess(data) { - if (data) { + if (data && !address) { setAddress(data.address) } },