Skip to content

Commit

Permalink
fix: wallet not showing up
Browse files Browse the repository at this point in the history
  • Loading branch information
irisdv committed Aug 23, 2023
1 parent 7f3b1bf commit 220d693
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions components/UI/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const Navbar: FunctionComponent = () => {
const [isConnected, setIsConnected] = useState<boolean>(false);
const [isWrongNetwork, setIsWrongNetwork] = useState(false);
const [txLoading, setTxLoading] = useState<number>(0);
const { available, connect, disconnect } = useConnectors();
const { available, connect, disconnect, refresh } = useConnectors();
const { provider } = useProvider();
const domainOrAddressMinified = useDisplayName(address ?? "");
const domain = useDomainFromAddress(address ?? "").domain;
Expand All @@ -40,10 +40,14 @@ const Navbar: FunctionComponent = () => {
const [showWallet, setShowWallet] = useState<boolean>(false);
const router = useRouter();

useEffect(() => {
useEffect(() => {
// to handle autoconnect starknet-react adds connector id in local storage
// if there is no value stored, we show the wallet modal
if (!localStorage.getItem("lastUsedConnector") && router?.pathname !== "/partnership") setHasWallet(true);
if (
!localStorage.getItem("lastUsedConnector") &&
router?.pathname !== "/partnership"
)
setHasWallet(true);
}, []);

useEffect(() => {
Expand Down Expand Up @@ -75,6 +79,7 @@ const Navbar: FunctionComponent = () => {
}

function onTopButtonClick(): void {
refresh();
if (available.length > 0) {
if (available.length === 1) {
connect(available[0]);
Expand Down Expand Up @@ -107,6 +112,12 @@ const Navbar: FunctionComponent = () => {
};
}, []);

// Refresh available connectors before showing wallet modal
function refreshAndShowWallet(): void {
refresh();
setHasWallet(true);
}

return (
<>
<div className={`fixed w-full z-[1]`}>
Expand Down Expand Up @@ -144,9 +155,7 @@ const Navbar: FunctionComponent = () => {
onClick={
isConnected
? () => setShowWallet(true)
: available.length === 1
? () => connect(available[0])
: () => setHasWallet(true)
: () => refreshAndShowWallet()
}
>
{isConnected ? (
Expand Down

0 comments on commit 220d693

Please sign in to comment.