Skip to content

Commit

Permalink
feat: add limit about create wallet and persona (DimensionDev#5701)
Browse files Browse the repository at this point in the history
* feat: add limit about create wallet and persona

* chore: reply review

* fix: bugfix

* fix: bugfix
  • Loading branch information
albert-0229 authored Feb 25, 2022
1 parent c5d841b commit 3b94686
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { PersonaCard } from '../PersonaCard'
import { useDashboardI18N } from '../../../../locales'
import { PersonaIdentifier, PersonaInformation, DashboardRoutes } from '@masknet/shared-base'
import { useNavigate } from 'react-router-dom'
import { MAX_PERSONA_LIMIT } from '@masknet/shared'

const useStyles = makeStyles()((theme) => ({
paper: {
Expand Down Expand Up @@ -97,7 +98,11 @@ export const PersonaDrawerUI = memo<PersonaDrawerUIProps>(
)
})}
<Box className={classes.buttons}>
<Button onClick={() => navigate(DashboardRoutes.SignUp)}>{t.personas_add_persona()}</Button>
<Button
onClick={() => navigate(DashboardRoutes.SignUp)}
disabled={personas.length >= MAX_PERSONA_LIMIT}>
{t.personas_add_persona()}
</Button>
<Button
color="warning"
onClick={() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ export async function restoreBackup(json: object, whoAmI?: ProfileIdentifier) {
}

for (const [_, x] of data.wallets.entries()) {
const record = WalletRecordFromJSONFormat(x)
const name = record.name
try {
const record = WalletRecordFromJSONFormat(x)
const name = record.name

if (record.storedKeyInfo && record.derivationPath)
await addWallet(record.address, name, record.derivationPath, record.storedKeyInfo)
else if (record.privateKey) await recoverWalletFromPrivateKey(name, record.privateKey)
Expand All @@ -73,6 +74,7 @@ export async function restoreBackup(json: object, whoAmI?: ProfileIdentifier) {
}
} catch (error) {
console.error(error)
continue
}
}
{
Expand Down
16 changes: 11 additions & 5 deletions packages/mask/src/extension/popups/pages/Personas/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import { PersonaContext } from '../hooks/usePersonaContext'
import { useHistory } from 'react-router-dom'
import { DeleteIcon, MasksIcon, EditIcon } from '@masknet/icons'
import { Button, Typography } from '@mui/material'
import { formatFingerprint } from '@masknet/shared'
import { formatFingerprint, MAX_PERSONA_LIMIT } from '@masknet/shared'
import { PopupRoutes } from '@masknet/shared-base'
import { ChevronDown, ChevronUp } from 'react-feather'
import { ProfileList } from '../components/ProfileList'
import { EnterDashboard } from '../../../components/EnterDashboard'
import { PersonaList } from '../components/PersonaList'
import { useI18N } from '../../../../../utils'
import urlcat from 'urlcat'
import classNames from 'classnames'

const useStyles = makeStyles()({
content: {
Expand Down Expand Up @@ -83,15 +84,20 @@ const useStyles = makeStyles()({
marginLeft: 10,
cursor: 'pointer',
},
secondaryButton: {
backgroundColor: '#F7F9FA',
color: '#1C68F3',
},
})

const PersonaHome = memo(() => {
const { t } = useI18N()
const { classes } = useStyles()
const [isExpand, setExpand] = useState(true)
const { currentPersona, setDeletingPersona } = PersonaContext.useContainer()
const { currentPersona, setDeletingPersona, personas } = PersonaContext.useContainer()
const history = useHistory()

console.log(personas)
return (
<>
<div className={classes.content}>
Expand Down Expand Up @@ -136,14 +142,14 @@ const PersonaHome = memo(() => {
<div className={classes.controller}>
<Button
variant="contained"
className={classes.button}
className={classNames(classes.button, classes.secondaryButton)}
disabled={personas && personas.length >= MAX_PERSONA_LIMIT - 1}
onClick={() => {
browser.tabs.create({
active: true,
url: browser.runtime.getURL('/dashboard.html#/sign-up'),
})
}}
style={{ backgroundColor: '#F7F9FA', color: '#1C68F3' }}>
}}>
{t('create')}
</Button>
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { useCopyToClipboard } from 'react-use'
import { NetworkSelector } from '../../../components/NetworkSelector'
import { currentProviderSettings } from '../../../../../plugins/Wallet/settings'
import { WalletItem } from './WalletItem'
import { MAX_WALLET_LIMIT } from '@masknet/shared'
import classNames from 'classnames'

const useStyles = makeStyles()({
header: {
Expand Down Expand Up @@ -72,6 +74,10 @@ const useStyles = makeStyles()({
fontSize: 14,
lineHeight: '20px',
},
secondaryButton: {
backgroundColor: '#F7F9FA',
color: '#1C68F3',
},
})

const SwitchWallet = memo(() => {
Expand Down Expand Up @@ -137,13 +143,14 @@ const SwitchWallet = memo(() => {
<div className={classes.controller}>
<Button
variant="contained"
className={classes.button}
onClick={handleClickCreate}
style={{ backgroundColor: '#F7F9FA', color: '#1C68F3' }}>
className={classNames(classes.button, classes.secondaryButton)}
disabled={wallets.length >= MAX_WALLET_LIMIT}
onClick={handleClickCreate}>
{t('create')}
</Button>
<Button
variant="contained"
disabled={wallets.length >= MAX_WALLET_LIMIT}
className={classes.button}
onClick={() => history.push(PopupRoutes.ImportWallet)}>
{t('import')}
Expand Down
3 changes: 3 additions & 0 deletions packages/shared/src/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ export const SOCIAL_MEDIA_ICON_MAPPING: Record<string, ReactNode> = {
}

export const mediaViewerUrl = 'https://media-viewer.r2d2.to/index.html'

export const MAX_WALLET_LIMIT = 100
export const MAX_PERSONA_LIMIT = 10

0 comments on commit 3b94686

Please sign in to comment.