-
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.
[Counterfactual] Add first steps widget (#3218)
* feat: Add first steps widget to dashboard * fix: Display the widget in the dashboard * fix: Extract last step as completed step, use enum and memoize items * fix: Revert change to completedName * fix: Remove StatusProgress and add individual first step cards * fix: Add counterfactual check to widget * fix: Remove steps badges
- Loading branch information
1 parent
911d7ea
commit d0f3fb5
Showing
6 changed files
with
203 additions
and
2 deletions.
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,154 @@ | ||
import { TxModalContext } from '@/components/tx-flow' | ||
import { ActivateAccountFlow } from '@/features/counterfactual/ActivateAccount' | ||
import useBalances from '@/hooks/useBalances' | ||
import useSafeInfo from '@/hooks/useSafeInfo' | ||
import { useAppSelector } from '@/store' | ||
import { selectOutgoingTransactions } from '@/store/txHistorySlice' | ||
import React, { useContext, useMemo } from 'react' | ||
import { Card, WidgetBody, WidgetContainer } from '@/components/dashboard/styled' | ||
import { Button, CircularProgress, Grid, Link, Typography } from '@mui/material' | ||
import CircleOutlinedIcon from '@mui/icons-material/CircleOutlined' | ||
import CheckCircleRoundedIcon from '@mui/icons-material/CheckCircleRounded' | ||
import css from './styles.module.css' | ||
|
||
const calculateProgress = (items: StatusProgressItems) => { | ||
const totalNumberOfItems = items.length | ||
const completedItems = items.filter((item) => item.completed) | ||
return Math.round((completedItems.length / totalNumberOfItems) * 100) | ||
} | ||
|
||
const StatusCard = ({ | ||
badge, | ||
title, | ||
content, | ||
completed, | ||
}: { | ||
badge: string | ||
title: string | ||
content: string | ||
completed: boolean | ||
}) => { | ||
return ( | ||
<Card className={css.card}> | ||
<div className={css.topBadge}> | ||
<Typography variant="body2">{badge}</Typography> | ||
</div> | ||
<div className={css.status}> | ||
{completed ? ( | ||
<CheckCircleRoundedIcon color="primary" fontSize="medium" /> | ||
) : ( | ||
<CircleOutlinedIcon color="inherit" fontSize="medium" /> | ||
)} | ||
</div> | ||
<Typography variant="h4" fontWeight="bold" mb={2}> | ||
{title} | ||
</Typography> | ||
<Typography>{content}</Typography> | ||
</Card> | ||
) | ||
} | ||
|
||
type StatusProgressItem = { | ||
title: string | ||
content: string | ||
completed?: boolean | ||
} | ||
|
||
type StatusProgressItems = Array<StatusProgressItem> | ||
|
||
const FirstStepsContent: StatusProgressItems = [ | ||
{ | ||
title: 'Add funds', | ||
content: 'Receive assets to start interacting with your account.', | ||
}, | ||
{ | ||
title: 'Create your first transaction', | ||
content: 'Do a simple transfer or use a safe app to create your first transaction.', | ||
}, | ||
] | ||
|
||
const FirstSteps = () => { | ||
const { balances } = useBalances() | ||
const { safe } = useSafeInfo() | ||
const outgoingTransactions = useAppSelector(selectOutgoingTransactions) | ||
const { setTxFlow } = useContext(TxModalContext) | ||
|
||
const hasNonZeroBalance = balances && (balances.items.length > 1 || BigInt(balances.items[0]?.balance || 0) > 0) | ||
const hasOutgoingTransactions = !!outgoingTransactions && outgoingTransactions.length > 0 | ||
|
||
const items = useMemo( | ||
() => [ | ||
{ ...FirstStepsContent[0], completed: hasNonZeroBalance }, | ||
{ ...FirstStepsContent[1], completed: hasOutgoingTransactions }, | ||
], | ||
[hasNonZeroBalance, hasOutgoingTransactions], | ||
) | ||
|
||
const activateAccount = () => { | ||
setTxFlow(<ActivateAccountFlow />) | ||
} | ||
|
||
const progress = calculateProgress(items) | ||
const stepsCompleted = items.filter((item) => item.completed).length | ||
|
||
if (safe.deployed) return null | ||
|
||
return ( | ||
<WidgetContainer> | ||
<WidgetBody> | ||
<Grid container gap={3} mb={2} flexWrap="nowrap"> | ||
<Grid item position="relative"> | ||
<CircularProgress variant="determinate" value={100} className={css.circleBg} size={60} thickness={5} /> | ||
<CircularProgress | ||
variant="determinate" | ||
value={progress} | ||
className={css.circleProgress} | ||
size={60} | ||
thickness={5} | ||
/> | ||
</Grid> | ||
<Grid item> | ||
<Typography component="div" variant="h2" fontWeight={700} mb={1}> | ||
Activate your Safe Account | ||
</Typography> | ||
<Typography variant="body2"> | ||
<strong> | ||
{stepsCompleted} of {items.length} steps completed. | ||
</strong>{' '} | ||
{progress === 100 ? ( | ||
<> | ||
Congratulations! You finished the first steps. <Link>Hide this section</Link> | ||
</> | ||
) : ( | ||
'Finish the next steps to start using all Safe Account features:' | ||
)} | ||
</Typography> | ||
</Grid> | ||
</Grid> | ||
<Grid container spacing={3}> | ||
{items.map((item) => { | ||
return ( | ||
<Grid item xs={12} md={4} key={item.title}> | ||
<StatusCard badge="First steps" title={item.title} content={item.content} completed={item.completed} /> | ||
</Grid> | ||
) | ||
})} | ||
|
||
<Grid item xs={12} md={4}> | ||
<Card className={css.card}> | ||
<Typography variant="h4" fontWeight="bold" mb={2}> | ||
Skip first steps | ||
</Typography> | ||
<Typography mb={2}>Pay a network fee to immediately access all Safe Account features.</Typography> | ||
<Button variant="contained" onClick={activateAccount}> | ||
Activate Safe Account | ||
</Button> | ||
</Card> | ||
</Grid> | ||
</Grid> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
.circleProgress { | ||
color: var(--color-secondary-main); | ||
} | ||
|
||
.circleBg { | ||
color: var(--color-border-light); | ||
position: absolute; | ||
} | ||
|
||
.card { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: flex-end; | ||
align-items: flex-start; | ||
min-height: 240px; | ||
} | ||
|
||
.topBadge { | ||
position: absolute; | ||
top: 0; | ||
right: 24px; | ||
background-color: var(--color-secondary-light); | ||
border-radius: 0 0 4px 4px; | ||
padding: 4px var(--space-1); | ||
} | ||
|
||
.status { | ||
align-self: flex-start; | ||
margin-bottom: auto; | ||
color: var(--color-border-light); | ||
} |
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
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