-
Notifications
You must be signed in to change notification settings - Fork 465
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add first steps widget to dashboard
- Loading branch information
1 parent
074146d
commit 28f84b5
Showing
3 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
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,77 @@ | ||
import useBalances from '@/hooks/useBalances' | ||
import { useAppSelector } from '@/store' | ||
import { selectOutgoingTransactions } from '@/store/txHistorySlice' | ||
import { type ReactNode } from 'react' | ||
import { Card, WidgetBody, WidgetContainer } from '@/components/dashboard/styled' | ||
import { LinearProgress, List, ListItem, ListItemIcon, Typography } from '@mui/material' | ||
import CircleOutlinedIcon from '@mui/icons-material/CircleOutlined' | ||
import CheckCircleRoundedIcon from '@mui/icons-material/CheckCircleRounded' | ||
|
||
const StatusItem = ({ children, completed = false }: { children: ReactNode; completed?: boolean }) => { | ||
return ( | ||
<ListItem disableGutters> | ||
<ListItemIcon sx={{ minWidth: 24, mr: 1, color: (theme) => theme.palette.primary.main }}> | ||
{completed ? <CheckCircleRoundedIcon /> : <CircleOutlinedIcon />} | ||
</ListItemIcon> | ||
{children} | ||
</ListItem> | ||
) | ||
} | ||
|
||
type StatusProgressItems = Array<{ | ||
name: string | ||
completed: boolean | ||
}> | ||
|
||
const StatusProgress = ({ items }: { items: StatusProgressItems }) => { | ||
const totalNumberOfItems = items.length | ||
const completedItems = items.filter((item) => item.completed) | ||
const progress = Math.ceil(completedItems.length / totalNumberOfItems) * 100 | ||
|
||
return ( | ||
<> | ||
<List disablePadding sx={{ py: 3 }}> | ||
{items.map(({ name, completed }) => { | ||
return ( | ||
<StatusItem key={name} completed={completed}> | ||
{name} | ||
</StatusItem> | ||
) | ||
})} | ||
</List> | ||
<LinearProgress color="secondary" variant="determinate" value={progress} sx={{ borderRadius: 1 }} /> | ||
<Typography variant="body2" mt={0.5}> | ||
{progress}% completed | ||
</Typography> | ||
</> | ||
) | ||
} | ||
|
||
const FirstSteps = () => { | ||
const { balances } = useBalances() | ||
const outgoingTransactions = useAppSelector(selectOutgoingTransactions) | ||
|
||
const hasNonZeroBalance = balances && (balances.items.length > 1 || BigInt(balances.items[0]?.balance || 0) > 0) | ||
const hasOutgoingTransactions = !!outgoingTransactions && outgoingTransactions.length > 0 | ||
|
||
const items = [ | ||
{ name: 'Add funds', completed: hasNonZeroBalance }, | ||
{ name: 'Create your first transaction', completed: hasOutgoingTransactions }, | ||
{ name: 'Safe is ready', completed: hasNonZeroBalance && hasOutgoingTransactions }, | ||
] | ||
|
||
return ( | ||
<WidgetContainer> | ||
<WidgetBody> | ||
<Card> | ||
<Typography variant="h4" fontWeight="bold"> | ||
First steps | ||
</Typography> | ||
<StatusProgress items={items} /> | ||
</Card> | ||
</WidgetBody> | ||
</WidgetContainer> | ||
) | ||
} | ||
|
||
export default FirstSteps |
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