-
Notifications
You must be signed in to change notification settings - Fork 13
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
feat(wallet-dashboard): add settings menu and network switcher #4509
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d67bdde
feat: add settings menu and network switcher
brancoder 5b7528f
fix: reset react queries
brancoder d5c1c60
fix: change notifications for toast
brancoder 1fec5c7
fix: resolve conflicts
brancoder 0f1ba84
fix: view enums and icon ordering in top nav
brancoder 07c42ec
fix: resolve conflicts
brancoder d62d9a7
Merge branch 'develop' into tooling-dashboard/add-network-switcher
brancoder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
31 changes: 28 additions & 3 deletions
31
apps/wallet-dashboard/app/(protected)/components/top-nav/TopNav.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 |
---|---|---|
@@ -1,18 +1,43 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { SettingsDialog, useSettingsDialog } from '@/components'; | ||
import { Badge, BadgeType, Button, ButtonType } from '@iota/apps-ui-kit'; | ||
import { ConnectButton, useIotaClientContext } from '@iota/dapp-kit'; | ||
import { getNetwork, Network } from '@iota/iota-sdk/client'; | ||
import { ThemeSwitcher } from '@iota/core'; | ||
import { ConnectButton } from '@iota/dapp-kit'; | ||
import { Settings } from '@iota/ui-icons'; | ||
|
||
export function TopNav() { | ||
const { network } = useIotaClientContext(); | ||
const { name: networkName } = getNetwork(network); | ||
const { | ||
isSettingsDialogOpen, | ||
settingsDialogView, | ||
setSettingsDialogView, | ||
onCloseSettingsDialogClick, | ||
onOpenSettingsDialogClick, | ||
} = useSettingsDialog(); | ||
|
||
return ( | ||
<div className="flex w-full flex-row items-center justify-end gap-md py-xs--rs"> | ||
<Badge label="Mainnet" type={BadgeType.PrimarySoft} /> | ||
<Badge | ||
label={networkName} | ||
type={network === Network.Mainnet ? BadgeType.PrimarySoft : BadgeType.Neutral} | ||
/> | ||
<ConnectButton size="md" /> | ||
<Button | ||
icon={<Settings />} | ||
type={ButtonType.Ghost} | ||
onClick={onOpenSettingsDialogClick} | ||
/> | ||
<SettingsDialog | ||
isOpen={isSettingsDialogOpen} | ||
handleClose={onCloseSettingsDialogClick} | ||
view={settingsDialogView} | ||
setView={setSettingsDialogView} | ||
/> | ||
<ThemeSwitcher /> | ||
<Button icon={<Settings />} type={ButtonType.Ghost} /> | ||
</div> | ||
); | ||
} |
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
38 changes: 38 additions & 0 deletions
38
apps/wallet-dashboard/components/Dialogs/settings/SettingsDialog.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,38 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import React from 'react'; | ||
import { Dialog } from '@iota/apps-ui-kit'; | ||
import { SettingsDialogView } from './enums'; | ||
import { SettingsListView, NetworkSelectorView } from './views'; | ||
|
||
interface SettingsDialogProps { | ||
isOpen: boolean; | ||
handleClose: () => void; | ||
view: SettingsDialogView | undefined; | ||
setView: (view: SettingsDialogView) => void; | ||
} | ||
|
||
export function SettingsDialog({ | ||
isOpen, | ||
handleClose, | ||
view, | ||
setView, | ||
}: SettingsDialogProps): JSX.Element { | ||
function onBack(): void { | ||
setView(SettingsDialogView.SelectSetting); | ||
} | ||
|
||
return ( | ||
<Dialog open={isOpen} onOpenChange={() => handleClose()}> | ||
<> | ||
{view === SettingsDialogView.SelectSetting && ( | ||
<SettingsListView handleClose={handleClose} setView={setView} /> | ||
)} | ||
{view === SettingsDialogView.NetworkSettings && ( | ||
<NetworkSelectorView handleClose={handleClose} onBack={onBack} /> | ||
)} | ||
</> | ||
</Dialog> | ||
); | ||
} |
4 changes: 4 additions & 0 deletions
4
apps/wallet-dashboard/components/Dialogs/settings/enums/index.ts
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,4 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export * from './view.enums'; |
11 changes: 11 additions & 0 deletions
11
apps/wallet-dashboard/components/Dialogs/settings/enums/view.enums.ts
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,11 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export enum SettingsDialogView { | ||
SelectSetting = 'SelectSetting', | ||
NetworkSettings = 'NetworkSettings', | ||
AutoLockProfile = 'AutoLockProfile', | ||
FAQ = 'FAQ', | ||
Themes = 'Themes', | ||
Logout = 'Logout', | ||
cpl121 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
4 changes: 4 additions & 0 deletions
4
apps/wallet-dashboard/components/Dialogs/settings/hooks/index.ts
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,4 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export * from './useSettingsDialog'; |
27 changes: 27 additions & 0 deletions
27
apps/wallet-dashboard/components/Dialogs/settings/hooks/useSettingsDialog.ts
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,27 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { useState } from 'react'; | ||
import { SettingsDialogView } from '../enums'; | ||
|
||
export function useSettingsDialog() { | ||
const [settingsDialogView, setSettingsDialogView] = useState<SettingsDialogView | undefined>(); | ||
|
||
const isSettingsDialogOpen = settingsDialogView !== undefined; | ||
|
||
function onCloseSettingsDialogClick() { | ||
setSettingsDialogView(undefined); | ||
} | ||
|
||
function onOpenSettingsDialogClick() { | ||
setSettingsDialogView(SettingsDialogView.SelectSetting); | ||
} | ||
|
||
return { | ||
isSettingsDialogOpen, | ||
settingsDialogView, | ||
setSettingsDialogView, | ||
onCloseSettingsDialogClick, | ||
onOpenSettingsDialogClick, | ||
}; | ||
} |
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,7 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export * from './enums'; | ||
export * from './SettingsDialog'; | ||
export * from './hooks'; | ||
export * from './views'; |
53 changes: 53 additions & 0 deletions
53
apps/wallet-dashboard/components/Dialogs/settings/views/NetworkSelectorView.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,53 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import React from 'react'; | ||
import { Header, RadioButton } from '@iota/apps-ui-kit'; | ||
import { DialogLayout, DialogLayoutBody } from '../../layout'; | ||
import { NetworkConfiguration } from '@iota/iota-sdk/client'; | ||
import { useIotaClientContext } from '@iota/dapp-kit'; | ||
import toast from 'react-hot-toast'; | ||
|
||
interface NetworkSelectorViewProps { | ||
handleClose: () => void; | ||
onBack: () => void; | ||
} | ||
|
||
export function NetworkSelectorView({ | ||
handleClose, | ||
onBack, | ||
}: NetworkSelectorViewProps): JSX.Element { | ||
const clientContext = useIotaClientContext(); | ||
const activeNetwork = clientContext.network; | ||
|
||
async function handleNetworkChange(network: NetworkConfiguration) { | ||
if (activeNetwork === network.id) { | ||
return; | ||
} | ||
clientContext.selectNetwork(network.id); | ||
toast.success(`Switched to ${network.name}`); | ||
} | ||
return ( | ||
<DialogLayout> | ||
<Header title="Network" onClose={handleClose} onBack={onBack} titleCentered /> | ||
<DialogLayoutBody> | ||
<div className="flex w-full flex-col gap-md"> | ||
{Object.keys(clientContext.networks).map((network) => { | ||
const networkConfig = clientContext.networks[ | ||
network | ||
] as NetworkConfiguration; | ||
return ( | ||
<div className="px-md" key={networkConfig.id}> | ||
<RadioButton | ||
label={networkConfig.name} | ||
isChecked={activeNetwork === networkConfig.id} | ||
onChange={() => handleNetworkChange(networkConfig)} | ||
/> | ||
</div> | ||
); | ||
})} | ||
</div> | ||
</DialogLayoutBody> | ||
</DialogLayout> | ||
); | ||
} |
60 changes: 60 additions & 0 deletions
60
apps/wallet-dashboard/components/Dialogs/settings/views/SettingsListView.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,60 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import React from 'react'; | ||
import { | ||
Card, | ||
CardAction, | ||
CardActionType, | ||
CardBody, | ||
CardImage, | ||
CardType, | ||
Header, | ||
ImageType, | ||
} from '@iota/apps-ui-kit'; | ||
import { DialogLayout, DialogLayoutBody } from '../../layout'; | ||
import { SettingsDialogView } from '../enums'; | ||
import { getNetwork } from '@iota/iota-sdk/client'; | ||
import { useIotaClientContext } from '@iota/dapp-kit'; | ||
import { Globe } from '@iota/ui-icons'; | ||
|
||
interface SettingsListViewProps { | ||
handleClose: () => void; | ||
setView: (view: SettingsDialogView) => void; | ||
} | ||
|
||
export function SettingsListView({ handleClose, setView }: SettingsListViewProps): JSX.Element { | ||
const { network } = useIotaClientContext(); | ||
const { name: networkName } = getNetwork(network); | ||
function onSelectSettingClick(view: SettingsDialogView): void { | ||
setView(view); | ||
} | ||
const MENU_ITEMS = [ | ||
{ | ||
title: 'Network', | ||
subtitle: networkName, | ||
icon: <Globe />, | ||
onClick: () => onSelectSettingClick(SettingsDialogView.NetworkSettings), | ||
}, | ||
]; | ||
return ( | ||
<DialogLayout> | ||
<Header title="Settings" onClose={handleClose} onBack={handleClose} titleCentered /> | ||
<DialogLayoutBody> | ||
<div className="flex w-full flex-col gap-md"> | ||
{MENU_ITEMS.map((item, index) => ( | ||
<Card key={index} type={CardType.Default} onClick={item.onClick}> | ||
<CardImage type={ImageType.BgSolid}> | ||
<div className="flex h-10 w-10 items-center justify-center rounded-full text-neutral-10 dark:text-neutral-92 [&_svg]:h-5 [&_svg]:w-5"> | ||
<span className="text-2xl">{item.icon}</span> | ||
</div> | ||
</CardImage> | ||
<CardBody title={item.title} subtitle={item.subtitle} /> | ||
<CardAction type={CardActionType.Link} /> | ||
</Card> | ||
))} | ||
</div> | ||
</DialogLayoutBody> | ||
</DialogLayout> | ||
); | ||
} |
5 changes: 5 additions & 0 deletions
5
apps/wallet-dashboard/components/Dialogs/settings/views/index.ts
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,5 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export * from './SettingsListView'; | ||
export * from './NetworkSelectorView'; |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would put the settings icon the last element