Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
chore: add address bar
Browse files Browse the repository at this point in the history
  • Loading branch information
zintarh committed Nov 28, 2024
1 parent 0376d15 commit f57838a
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 34 deletions.
17 changes: 17 additions & 0 deletions frontend/src/assets/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,23 @@ export const BarcodeIcon = (props: any) => (
</svg>
);

export const UserIcon = (props: any) => (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
width="24"
height="24"
>
<circle cx="12" cy="8" r="4"></circle>
<path d="M16 16c0-2-4-3-4-3s-4 1-4 3v4h8v-4z"></path>
</svg>
);

export const NoticeIcon = (props: any) => (
<svg
xmlns="http://www.w3.org/2000/svg"
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/components/ConnectModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const ConnectModal = ({ isOpen, onClose }: Props) => {
<div className="flex p-4 w-full lg:p-0 ">
<div className="basis-5/6 lg:col-span-2 l lg:py-4 lg:pl-8">
<h2 className="text-center my-4 lg:text-start font-bold text-white text-[1.125em]">
Connect Wallet
Connect Wallet
</h2>
</div>
<div className="ml-auto lg:col-span-3 lg:py-4 lg:pr-8">
Expand Down Expand Up @@ -122,7 +122,6 @@ const ConnectModal = ({ isOpen, onClose }: Props) => {
))}
</div>
</div>

</div>
</GenericModal>
);
Expand Down
17 changes: 10 additions & 7 deletions frontend/src/components/ConnectWallet.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
import { roboto } from '@/app/fonts';
import { useState } from 'react';
import ConnectModal from './ConnectModal';
import { WalletIcon } from '@heroicons/react/24/outline';

const ConnectWallet = (props: any) => {
const [isOpen, setisOpen] = useState<boolean>(false)
const [isOpen, setisOpen] = useState<boolean>(false);
return (
<div>
<button
onClick={() => setisOpen(!isOpen)}
className={`w-[12.5rem] h-14 grid py-2 px-[1.25rem]
place-items-center rounded-2xl gap-2 text-textPrimary
className={` flex items-center py-3 px-[1.25rem]
place-items-center rounded-full gap-2 text-textPrimary
font-medium text-base bg-primary ${roboto.variable} font-roboto`}
{...props}
>
<div>
<WalletIcon className="text-white w-6 h-6" />
</div>
CONNECT WALLET
</button>

{
isOpen && <ConnectModal isOpen={isOpen} onClose={() => setisOpen(false)} />
}

{isOpen && (
<ConnectModal isOpen={isOpen} onClose={() => setisOpen(false)} />
)}
</div>
);
};
Expand Down
18 changes: 7 additions & 11 deletions frontend/src/components/GenericModal.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';

import { useEffect } from "react";
import ReactPortal from "./react-portal";
import { useEffect } from 'react';
import ReactPortal from './react-portal';

const GenericModal = ({
isOpen,
Expand All @@ -18,31 +18,27 @@ const GenericModal = ({
className?: string;
position?: string;
}) => {

useEffect(() => {
const closeOnEscapeKey = (e: KeyboardEvent) =>
e.key === "Escape" ? onClose() : null;
document.body.addEventListener("keydown", closeOnEscapeKey);
e.key === 'Escape' ? onClose() : null;
document.body.addEventListener('keydown', closeOnEscapeKey);
return (): void => {
document.body.removeEventListener("keydown", closeOnEscapeKey);
document.body.removeEventListener('keydown', closeOnEscapeKey);
};
}, [onClose]);

useEffect(() => {
document.body.style.overflow = "hidden";
document.body.style.overflow = 'hidden';
return (): void => {
document.body.style.overflow = "unset";
document.body.style.overflow = 'unset';
};
}, [isOpen]);

if (!isOpen) {
return null;
}
return (


<>

<ReactPortal containerId="react-portal-modal-container">
<div className="w-full">
<div
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import Link from 'next/link';
import ConnectWallet from './ConnectWallet';
import { roboto } from '@/app/fonts';
import { useAlert } from '@/hooks/useAlert';
import { useAccount } from '@starknet-react/core';
import WalletBar from './WalletBar';

const NavBar = (props: any) => {
const { showAlert } = useAlert();
const { account, address } = useAccount();

return (
<nav
className={`flex items-center justify-between px-4 lg:px-20
Expand All @@ -24,9 +28,7 @@ const NavBar = (props: any) => {
</Link>
<NavLinks />
</div>
<div>
<ConnectWallet />
</div>
<div>{address ? <WalletBar /> : <ConnectWallet />}</div>
</nav>
);
};
Expand Down
16 changes: 10 additions & 6 deletions frontend/src/components/WalletBar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use client';
import { useAccount, useConnect, useDisconnect } from '@starknet-react/core';
import { UserCircleIcon } from '@heroicons/react/24/outline';
import { useAccount, useDisconnect } from '@starknet-react/core';
import { useMemo } from 'react';

function WalletConnected() {
Expand All @@ -12,16 +13,19 @@ function WalletConnected() {
}, [address]);

return (
<div>
<span>Connected: {shortenedAddress}</span>
<button onClick={() => disconnect()}>Disconnect</button>
<div
onClick={() => disconnect()}
className="bg-primary cursor-pointer flex items-center gap-x-2 rounded-full px-5 py-3"
>
<div>
<UserCircleIcon className="text-white w-6 h-6" />
</div>
<span className="text-white">{shortenedAddress}</span>
</div>
);
}

function ConnectWallet() {
const { connectors, connect } = useConnect();

return (
<div>
<span>Choose a wallet: </span>
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/components/react-portal.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";
'use client';

import { useLayoutEffect, useState } from "react";
import { createPortal } from "react-dom";
import { useLayoutEffect, useState } from 'react';
import { createPortal } from 'react-dom';

interface ReactPortalProps {
children: React.ReactElement;
Expand All @@ -10,8 +10,8 @@ interface ReactPortalProps {

const createContainerAndAppendToBody = (containerId: string) => {
if (!document) return null;
const wrapperElement = document.createElement("div");
wrapperElement.setAttribute("id", containerId);
const wrapperElement = document.createElement('div');
wrapperElement.setAttribute('id', containerId);
document.body.appendChild(wrapperElement);
return wrapperElement;
};
Expand Down

0 comments on commit f57838a

Please sign in to comment.