Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display wallet's network, address, balance when connected #67

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/frontend/components/buttons/connect-wallet-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import Styled from 'styled-components';

// img
import wallet from './../../assets/images/wallet.png';
import { truncateString } from '../../helpers';
import { useSDK } from '@metamask/sdk-react';

export interface Props {
connected: boolean;
connecting: boolean;
onClick: () => void;
}

Expand All @@ -17,12 +17,19 @@ type BadgeProps = {
};

export default forwardRef<HTMLDivElement>((props: Props, ref) => {
const { connected, connecting, onClick } = props;
const { connected, account } = useSDK();
const { onClick } = props;

return (
return !connected ? (
<ConnectWalletButton.Wrapper onClick={onClick} ref={ref}>
<ConnectWalletButton.Logo src={wallet} />
<ConnectWalletButton.Text>{connected ? 'connected' : 'connect'}</ConnectWalletButton.Text>
<ConnectWalletButton.Text>{'connect'}</ConnectWalletButton.Text>
</ConnectWalletButton.Wrapper>
) : (
<ConnectWalletButton.Wrapper onClick={onClick} ref={ref}>
<ConnectWalletButton.Logo src={wallet} />
<ConnectWalletButton.Text>{truncateString(account ?? '')}</ConnectWalletButton.Text>
{/* <ConnectWalletButton.Text>ETH: {formatEther(balance ?? '0')}</ConnectWalletButton.Text> */}
</ConnectWalletButton.Wrapper>
);
});
Expand Down
22 changes: 15 additions & 7 deletions src/frontend/components/modals/metamask-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import { truncateString } from './../../helpers';

// img
import copyIcon from './../../assets/images/copy-link.png';
import { useSDK } from '@metamask/sdk-react';
import { formatEther } from 'ethers';

export interface Props {
account: string;
}
export interface Props {}

const MetaMaskModal = forwardRef<HTMLDivElement>((props: Props, ref) => {
const { account } = props;
const { account, balance } = useSDK();
if (!account) return null;

const isClipboardAvailable = navigator.clipboard && navigator.clipboard.writeText !== undefined;

Expand All @@ -30,10 +31,17 @@ const MetaMaskModal = forwardRef<HTMLDivElement>((props: Props, ref) => {
/>
</MetaMaskRoot.Row>
) : (
<MetaMaskRoot.Value>{truncateString(account)}</MetaMaskRoot.Value>
<MetaMaskRoot.Row>
<MetaMaskRoot.Value>{truncateString(account)}</MetaMaskRoot.Value>
</MetaMaskRoot.Row>
)}
</MetaMaskRoot.Group>
<MetaMaskRoot.Group></MetaMaskRoot.Group>
<MetaMaskRoot.Group>
<MetaMaskRoot.Label>ETH balance</MetaMaskRoot.Label>
<MetaMaskRoot.Row>
<MetaMaskRoot.Value>{formatEther(balance ?? '0')}</MetaMaskRoot.Value>
</MetaMaskRoot.Row>
</MetaMaskRoot.Group>
</MetaMaskRoot.Layout>
);
});
Expand All @@ -43,7 +51,7 @@ const MetaMaskRoot = {
display: flex;
flex-direction: column;
width: 250px;
height: 70px;
height: 100px;
border-radius: 10px;
background: ${(props) => props.theme.colors.core};
border: 5px solid ${(props) => props.theme.colors.hunter};
Expand Down
10 changes: 8 additions & 2 deletions src/frontend/views/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const ChatView = (): JSX.Element => {
const [isOllamaBeingPolled, setIsOllamaBeingPolled] = useState(false);
const { ready, sdk, connected, connecting, provider, chainId, account, balance } = useSDK();
const ethInWei = '1000000000000000000';
const [selectedNetwork, setSelectedNetwork] = useState('');
const [selectedNetwork, setSelectedNetwork] = useState(chainId);

const chatMainRef = useRef<HTMLDivElement>(null);
const chatInputRef = useRef<HTMLInputElement>(null);
Expand Down Expand Up @@ -72,6 +72,12 @@ const ChatView = (): JSX.Element => {
}
}, [dialogueEntries]);

useEffect(() => {
if (chainId) {
setSelectedNetwork(chainId);
}
}, [chainId]);

//Function to update dialogue entries
const updateDialogueEntries = (question: string, message: string) => {
setCurrentQuestion(undefined);
Expand Down Expand Up @@ -234,7 +240,7 @@ const ChatView = (): JSX.Element => {

return (
<Chat.Layout>
<Chat.Dropdown onChange={handleNetworkChange} value="">
<Chat.Dropdown onChange={handleNetworkChange} value={selectedNetwork}>
<option value="">Select a network</option>
<option value="0x1">Ethereum</option>
<option value="0xaa36a7">Sepolia</option>
Expand Down