-
Notifications
You must be signed in to change notification settings - Fork 444
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: Subaccounts #4456
Draft
iamacook
wants to merge
26
commits into
dev
Choose a base branch
from
subaccount-demo
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
feat: Subaccounts #4456
Changes from 18 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
9060d1f
Add transaction flow for creating (and funding) Subaccounts
iamacook b60f19f
Fix lint
iamacook c735475
Don't allow multiple selection of assets
iamacook 2f06915
Fix lint
iamacook 1f75787
Simplify code
iamacook c8e8e68
Add popover, settings section and success screen
iamacook 71ff216
Merge branch 'dev' into subaccount-demo
iamacook be43e72
Fix saltNonce collision and remove status screen changes
iamacook d1451c0
Fix merge issues
iamacook 4385779
Add badge
iamacook 9c6e251
Tweak styles and events
iamacook f9e5761
Remove debug
iamacook e5c50ac
Add status screen
iamacook dc5bb92
Convert Subaccount list to correct elements
iamacook 12d7051
Invalidate subaccount cache after deployment
iamacook 4f58bea
Fix CI and add tests
iamacook 97aeed8
Fix types
iamacook f2fc1d4
Fix test
iamacook 93a9283
Update icon in flow
iamacook 55cceba
Address design review
iamacook 5b246ad
Merge branch 'dev' into subaccount-demo
iamacook 2315785
Set pointer on show all
iamacook 00fe4ab
Make Subaccount a link
iamacook 6ef1bca
Close modal when navigating to Subaccount and fix colour in dark mode
iamacook 322f47d
Use `Date.now` for `saltNonce`
iamacook cc3c894
Add fallback name
iamacook 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,124 @@ | ||
import { Paper, Grid, Typography, Button, SvgIcon, Tooltip, IconButton } from '@mui/material' | ||
import { useContext, useMemo, useState } from 'react' | ||
import type { ReactElement } from 'react' | ||
|
||
import AddIcon from '@/public/images/common/add.svg' | ||
import EditIcon from '@/public/images/common/edit.svg' | ||
import CheckWallet from '@/components/common/CheckWallet' | ||
import EthHashInfo from '@/components/common/EthHashInfo' | ||
import ExternalLink from '@/components/common/ExternalLink' | ||
import { CreateSubaccount } from '@/components/tx-flow/flows/CreateSubaccount' | ||
import EntryDialog from '@/components/address-book/EntryDialog' | ||
import { TxModalContext } from '@/components/tx-flow' | ||
import EnhancedTable from '@/components/common/EnhancedTable' | ||
import useSafeInfo from '@/hooks/useSafeInfo' | ||
import { useGetSafesByOwnerQuery } from '@/store/slices' | ||
|
||
import tableCss from '@/components/common/EnhancedTable/styles.module.css' | ||
import Track from '@/components/common/Track' | ||
import { SUBACCOUNT_EVENTS } from '@/services/analytics/events/subaccounts' | ||
import { skipToken } from '@reduxjs/toolkit/query' | ||
|
||
export function SubaccountsList(): ReactElement | null { | ||
const { setTxFlow } = useContext(TxModalContext) | ||
const [addressToRename, setAddressToRename] = useState<string | null>(null) | ||
|
||
const { safe, safeLoaded, safeAddress } = useSafeInfo() | ||
const { data: subaccounts } = useGetSafesByOwnerQuery( | ||
safeLoaded ? { chainId: safe.chainId, ownerAddress: safeAddress } : skipToken, | ||
) | ||
|
||
const rows = useMemo(() => { | ||
return subaccounts?.safes.map((subaccount) => { | ||
return { | ||
cells: { | ||
owner: { | ||
rawValue: subaccount, | ||
content: ( | ||
<EthHashInfo address={subaccount} showCopyButton shortAddress={false} showName={true} hasExplorer /> | ||
), | ||
}, | ||
actions: { | ||
rawValue: '', | ||
sticky: true, | ||
content: ( | ||
<div className={tableCss.actions}> | ||
<CheckWallet> | ||
{(isOk) => ( | ||
<Track {...SUBACCOUNT_EVENTS.RENAME}> | ||
<Tooltip title={isOk ? 'Rename Subaccount' : undefined}> | ||
<span> | ||
<IconButton onClick={() => setAddressToRename(subaccount)} size="small" disabled={!isOk}> | ||
<SvgIcon component={EditIcon} inheritViewBox fontSize="small" color="border" /> | ||
</IconButton> | ||
</span> | ||
</Tooltip> | ||
</Track> | ||
)} | ||
</CheckWallet> | ||
</div> | ||
), | ||
}, | ||
}, | ||
} | ||
}) | ||
}, [subaccounts?.safes]) | ||
|
||
return ( | ||
<> | ||
<Paper sx={{ padding: 4, mt: 2 }}> | ||
<Grid container direction="row" justifyContent="space-between" spacing={3} mb={2}> | ||
<Grid item lg={4} xs={12}> | ||
<Typography variant="h4" fontWeight={700}> | ||
Subaccounts | ||
</Typography> | ||
</Grid> | ||
|
||
<Grid item xs> | ||
<Typography sx={{ mb: 3 }}> | ||
Subaccounts are separate wallets owned by your main Account, perfect for organizing different funds and | ||
projects.{' '} | ||
<ExternalLink | ||
// TODO: Add link | ||
href="#" | ||
> | ||
Learn more | ||
</ExternalLink> | ||
</Typography> | ||
|
||
{subaccounts?.safes.length === 0 && ( | ||
<Typography sx={{ mb: 3 }}> | ||
You don't have any Subaccounts yet. Set one up now to better organize your assets | ||
</Typography> | ||
)} | ||
|
||
<CheckWallet> | ||
{(isOk) => ( | ||
<Button | ||
onClick={() => setTxFlow(<CreateSubaccount />)} | ||
variant="text" | ||
startIcon={<SvgIcon component={AddIcon} inheritViewBox fontSize="small" />} | ||
disabled={!isOk} | ||
sx={{ mb: 3 }} | ||
> | ||
Add Subaccount | ||
</Button> | ||
)} | ||
</CheckWallet> | ||
|
||
{rows && rows.length > 0 && <EnhancedTable rows={rows} headCells={[]} />} | ||
</Grid> | ||
</Grid> | ||
</Paper> | ||
|
||
{addressToRename && ( | ||
<EntryDialog | ||
handleClose={() => setAddressToRename(null)} | ||
defaultValues={{ name: '', address: addressToRename }} | ||
chainIds={[safe.chainId]} | ||
disableAddressInput | ||
/> | ||
)} | ||
</> | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { Tooltip, SvgIcon, Typography, List, ListItem, Box, ListItemAvatar, Avatar, ListItemText } from '@mui/material' | ||
import CheckIcon from '@mui/icons-material/Check' | ||
import type { ReactElement } from 'react' | ||
|
||
import SubaccountsIcon from '@/public/images/sidebar/subaccounts-icon.svg' | ||
import Subaccounts from '@/public/images/sidebar/subaccounts.svg' | ||
import InfoIcon from '@/public/images/notifications/info.svg' | ||
|
||
export function SubaccountInfo(): ReactElement { | ||
return ( | ||
<Box sx={{ display: 'flex', flexDirection: 'column', alignItems: 'center', pt: 1 }}> | ||
<Subaccounts /> | ||
<Box sx={{ display: 'flex', gap: 1, py: 2 }}> | ||
<Typography fontWeight={700}>No Subaccounts yet</Typography> | ||
<Tooltip | ||
title="Subaccounts are separate wallets owned by your main Account, perfect for organizing different funds and projects." | ||
placement="top" | ||
arrow | ||
sx={{ ml: 1 }} | ||
> | ||
<span> | ||
<SvgIcon | ||
component={InfoIcon} | ||
inheritViewBox | ||
fontSize="small" | ||
color="border" | ||
sx={{ verticalAlign: 'middle' }} | ||
/> | ||
</span> | ||
</Tooltip> | ||
</Box> | ||
<Box sx={{ display: 'flex', gap: 2, alignItems: 'center', pt: 1, pb: 4 }}> | ||
<Avatar sx={{ padding: '20px', backgroundColor: 'success.background' }}> | ||
<SvgIcon component={SubaccountsIcon} inheritViewBox color="primary" sx={{ fontSize: 20 }} /> | ||
</Avatar> | ||
<Typography variant="body2" fontWeight={700}> | ||
Subaccounts allow you to: | ||
</Typography> | ||
</Box> | ||
<List sx={{ p: 0, display: 'flex', flexDirection: 'column', gap: 2 }}> | ||
{[ | ||
'Use them for specific cases such as DeFi operations', | ||
'Install modules to execute transactions, bypassing thresholds', | ||
'Make sure that this Safe is not exposed to additional risks', | ||
].map((item) => { | ||
return ( | ||
<ListItem key={item} sx={{ p: 0, pl: 1.5, alignItems: 'unset' }}> | ||
<ListItemAvatar sx={{ minWidth: 'unset', mr: 3 }}> | ||
<Avatar sx={{ width: 25, height: 25, backgroundColor: 'success.background' }}> | ||
<CheckIcon fontSize="small" color="success" /> | ||
</Avatar> | ||
</ListItemAvatar> | ||
<ListItemText sx={{ m: 0 }} primaryTypographyProps={{ variant: 'body2' }}> | ||
{item} | ||
</ListItemText> | ||
</ListItem> | ||
) | ||
})} | ||
</List> | ||
</Box> | ||
) | ||
} |
Oops, something went wrong.
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.
Marking this so we don't forget.