-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
403 additions
and
86 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/frontend/components/buttons/sidebar-menu-navigation-button.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import Styled from 'styled-components'; | ||
import { Link, useLocation } from 'react-router-dom'; | ||
|
||
interface ButtonProps { | ||
active: 'active' | ''; | ||
} | ||
|
||
interface MainNavButtonProps { | ||
text: string; | ||
href: string; | ||
exact: boolean; | ||
} | ||
|
||
const SidebarMenuNavigationButton = ({ text, href, exact }: MainNavButtonProps) => { | ||
const path = useLocation(); | ||
const active = exact ? path.pathname === href : path.pathname.includes(href); | ||
|
||
return ( | ||
<MenuNavItem.Wrapper to={href} active={active ? 'active' : ''}> | ||
<MenuNavItem.ButtonText>{text}</MenuNavItem.ButtonText> | ||
</MenuNavItem.Wrapper> | ||
); | ||
}; | ||
|
||
const MenuNavItem = { | ||
Wrapper: Styled(Link)<ButtonProps>` | ||
display: flex; | ||
flex-direction: column; | ||
padding: 24px 0 24px 12px; | ||
color: ${(props) => (props.active === 'active' ? props.theme.colors.black : props.theme.colors.balance)}; | ||
text-decoration: none; | ||
background-color: ${(props) => props.active && props.theme.colors.balance}; | ||
&:hover span { | ||
color: ${(props) => !props.active && props.theme.colors.gray}; | ||
} | ||
`, | ||
Icon: Styled.img` | ||
display: flex; | ||
width: 30px; | ||
height: 30px; | ||
`, | ||
ButtonText: Styled.span` | ||
font-family: ${(props) => props.theme.fonts.family.primary.regular}; | ||
font-size: ${(props) => props.theme.fonts.size.medium}; | ||
`, | ||
}; | ||
|
||
export default SidebarMenuNavigationButton; |
84 changes: 84 additions & 0 deletions
84
src/frontend/components/dropdowns/network-selection-dropdown.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import React from 'react'; | ||
import Styled from 'styled-components'; | ||
|
||
import { getChainInfoByChainId } from '../../utils/chain'; | ||
import { useSDK } from '@metamask/sdk-react'; | ||
import { useAIMessagesContext } from '../../contexts'; | ||
|
||
const NetworkSelectionDropdown = () => { | ||
const { provider, account } = useSDK(); | ||
const [dialogueEntries, setDialogueEntries] = useAIMessagesContext(); | ||
|
||
const handleNetworkChange = async (e: React.ChangeEvent<HTMLSelectElement>) => { | ||
const selectedChain = e.target.value; | ||
|
||
// Check if the default option is selected | ||
if (!selectedChain) { | ||
console.log('No network selected.'); | ||
return; // Early return to avoid further execution | ||
} | ||
|
||
// Sanity Checks: | ||
if (!account || !provider) { | ||
const errorMessage = `Error: Please connect to MetaMask`; | ||
setDialogueEntries([ | ||
...dialogueEntries, | ||
{ question: '', answer: errorMessage, answered: true }, | ||
]); | ||
return; | ||
} | ||
|
||
try { | ||
const response = await provider.request({ | ||
method: 'wallet_switchEthereumChain', | ||
params: [{ chainId: selectedChain }], | ||
}); | ||
console.log(response); | ||
} catch (error) { | ||
//if switch chain fails then add the chain | ||
try { | ||
const chainInfo = getChainInfoByChainId(selectedChain); | ||
const response = await provider.request({ | ||
method: 'wallet_addEthereumChain', | ||
params: [chainInfo], | ||
}); | ||
} catch (error) { | ||
console.error('Failed to switch networks:', error); | ||
} | ||
} | ||
}; | ||
|
||
return ( | ||
<Dropdown onChange={handleNetworkChange} value=""> | ||
<option value="">Select a network</option> | ||
<option value="0x1">Ethereum</option> | ||
<option value="0xaa36a7">Sepolia</option> | ||
<option value="0xa4b1">Arbitrum</option> | ||
<option value="0x64">Gnosis</option> | ||
</Dropdown> | ||
); | ||
}; | ||
|
||
const Dropdown = Styled.select` | ||
padding: 8px 10px; | ||
margin: 12px 0 12px 12px; | ||
border-radius: 10px; | ||
background-color: ${(props) => props.theme.colors.core}; | ||
color: ${(props) => props.theme.colors.notice}; | ||
border: 2px solid ${(props) => props.theme.colors.hunter}; | ||
font-family: ${(props) => props.theme.fonts.family.primary.regular}; | ||
font-size: ${(props) => props.theme.fonts.size.small}; | ||
cursor: pointer; | ||
&:hover { | ||
border: 2px solid ${(props) => props.theme.colors.emerald}; | ||
} | ||
option { | ||
background-color: ${(props) => props.theme.colors.core}; | ||
color: ${(props) => props.theme.colors.emerald}; | ||
} | ||
`; | ||
|
||
export default NetworkSelectionDropdown; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// libs | ||
import React from 'react'; | ||
import Styled from 'styled-components'; | ||
import { useSidebarContext } from '../../contexts'; | ||
|
||
export default () => { | ||
const { isOpen, setIsOpen } = useSidebarContext(); | ||
return ( | ||
<SidebarToggle.Layout> | ||
<SidebarToggle.Carat | ||
onClick={() => { | ||
setIsOpen((isOpen) => !isOpen); | ||
}} | ||
isOpen={isOpen} | ||
/> | ||
</SidebarToggle.Layout> | ||
); | ||
}; | ||
|
||
type SidebarToggleCarat = { | ||
isOpen: boolean; | ||
}; | ||
|
||
const SidebarToggle = { | ||
Layout: Styled.div` | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
width: 40px; | ||
height: 100%; | ||
background: ${(props) => props.theme.colors.core}; | ||
padding-left: 8px; | ||
`, | ||
Carat: Styled.div<SidebarToggleCarat>` | ||
display: inline-block; | ||
width: 20px; | ||
height: 20px; | ||
border-top: 2px solid ${(props) => props.theme.colors.emerald}; | ||
border-left: 2px solid ${(props) => props.theme.colors.emerald}; | ||
transform: rotate(${(props) => (props.isOpen ? '-45deg' : '135deg')}); | ||
&:hover { | ||
cursor: pointer; | ||
opacity: 0.8; | ||
} | ||
`, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import Styled from 'styled-components'; | ||
|
||
import Logo from './../../assets/images/logo_white.png'; | ||
import SidebarMenuNavigationButton from '../buttons/sidebar-menu-navigation-button'; | ||
import NetworkSelectionDropdown from '../dropdowns/network-selection-dropdown'; | ||
import { useSidebarContext } from '../../contexts'; | ||
|
||
export default (): JSX.Element => { | ||
const { isOpen } = useSidebarContext(); | ||
return ( | ||
<Sidebar.Layout isOpen={isOpen}> | ||
<Sidebar.Top> | ||
<Sidebar.Logo src={Logo} /> | ||
</Sidebar.Top> | ||
<Sidebar.Menu> | ||
<NetworkSelectionDropdown /> | ||
<SidebarMenuNavigationButton text="Wallet" href="/wallet" exact={true} /> | ||
<SidebarMenuNavigationButton text="Chat" href="/chat" exact={true} /> | ||
<SidebarMenuNavigationButton text="Models" href="/models" exact={true} /> | ||
<SidebarMenuNavigationButton text="Agents" href="/agents" exact={true} /> | ||
<Sidebar.SeparatorLine /> | ||
<SidebarMenuNavigationButton text="Provider Hub" href="/provider" exact={true} /> | ||
<SidebarMenuNavigationButton text="Sessions" href="/session" exact={true} /> | ||
<Sidebar.SeparatorLine /> | ||
</Sidebar.Menu> | ||
<Sidebar.Bottom>MorpheusAI.org</Sidebar.Bottom> | ||
</Sidebar.Layout> | ||
); | ||
}; | ||
|
||
type SidebarLayoutProps = { | ||
isOpen: boolean; | ||
}; | ||
|
||
const Sidebar = { | ||
Layout: Styled.div<SidebarLayoutProps>` | ||
width: ${(props) => (props.isOpen ? '250px' : '0px')}; | ||
height: 100%; | ||
background: black; | ||
display: flex; | ||
flex-direction: column; | ||
flex-shrink: 0; | ||
transition: 0.2s; | ||
`, | ||
Top: Styled.div` | ||
height: 50px; | ||
display: flex; | ||
justify-content: center; | ||
flex-shrink: 0; | ||
`, | ||
Logo: Styled.img` | ||
height: 50px; | ||
width: 50px; | ||
`, | ||
Menu: Styled.div` | ||
flex-grow: 1; | ||
overflow-y: auto; | ||
`, | ||
MenuItem: Styled.div` | ||
display: flex; | ||
align-items: center; | ||
`, | ||
|
||
Bottom: Styled.div` | ||
height: 50px; | ||
flex-shrink: 0; | ||
color: ${(props) => props.theme.colors.balance}; | ||
font-family: ${(props) => props.theme.fonts.family.primary.regular}; | ||
font-size: ${(props) => props.theme.fonts.size.small}; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
`, | ||
SeparatorLine: Styled.div` | ||
height: 1px; | ||
background: ${(props) => props.theme.colors.gray}; | ||
`, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.