-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Same wallet import optimization (#3001)
* fix: issue 291 * fix * fix * fix: remove unused files * fix: test * fix: Same wallet import optimization * fix * fix: comments * fix: comments * fix: comments * fix: comments * fix: Merge * fix --------- Co-authored-by: Chen Yu <[email protected]>
- Loading branch information
1 parent
2809428
commit 21a2f35
Showing
31 changed files
with
693 additions
and
150 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
...ron-ui/src/components/DetectDuplicateWalletDialog/detectDuplicateWalletDialog.module.scss
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,32 @@ | ||
.content { | ||
width: 648px; | ||
.detail { | ||
margin: 0; | ||
color: var(--secondary-text-color); | ||
} | ||
.groupWrap { | ||
margin-top: 16px; | ||
height: 177px; | ||
overflow-y: scroll; | ||
border: 1px solid var(--divide-line-color); | ||
border-radius: 8px; | ||
padding-left: 16px; | ||
> div { | ||
border-bottom: 1px solid var(--divide-line-color); | ||
padding-top: 16px; | ||
&:last-child { | ||
border: none; | ||
} | ||
} | ||
.radioItem { | ||
padding: 0 0 16px; | ||
&:hover, | ||
&:focus { | ||
background: transparent; | ||
button { | ||
visibility: visible; | ||
} | ||
} | ||
} | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
packages/neuron-ui/src/components/DetectDuplicateWalletDialog/index.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,114 @@ | ||
import React, { useMemo, useState, useCallback } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import Dialog from 'widgets/Dialog' | ||
import RadioGroup from 'widgets/RadioGroup' | ||
import { useState as useGlobalState, useDispatch, AppActions } from 'states' | ||
import { requestPassword } from 'services/remote' | ||
import styles from './detectDuplicateWalletDialog.module.scss' | ||
|
||
const DetectDuplicateWalletDialog = ({ onClose }: { onClose: () => void }) => { | ||
const { | ||
wallet: { id: currentID = '' }, | ||
settings: { wallets = [] }, | ||
} = useGlobalState() | ||
const dispatch = useDispatch() | ||
const [duplicatedWallets, setDuplicatedWallets] = useState<string[]>([]) | ||
const [t] = useTranslation() | ||
|
||
const groups = useMemo(() => { | ||
const obj: { | ||
[key: string]: State.WalletIdentity[] | ||
} = {} | ||
wallets.forEach(item => { | ||
if (item.extendedKey in obj) { | ||
obj[item.extendedKey].push(item) | ||
} else { | ||
obj[item.extendedKey] = [item] | ||
} | ||
}) | ||
|
||
return Object.values(obj).filter(list => list.length > 1) | ||
}, [wallets]) | ||
|
||
const handleGroupChange = useCallback( | ||
(checked: string) => { | ||
const [extendedKey, id] = checked.split('_') | ||
|
||
const list = wallets | ||
.filter(item => { | ||
if (item.extendedKey === extendedKey) { | ||
return item.id !== id | ||
} | ||
return duplicatedWallets.includes(item.id) | ||
}) | ||
.map(item => item.id) | ||
|
||
setDuplicatedWallets(list) | ||
}, | ||
[wallets, duplicatedWallets, setDuplicatedWallets] | ||
) | ||
|
||
const onConfirm = useCallback(async () => { | ||
const getRequest = (id: string) => { | ||
if (wallets.find(item => (item.id === id && item.device) || item.isWatchOnly)) { | ||
return requestPassword({ walletID: id, action: 'delete-wallet' }) | ||
} | ||
return new Promise(resolve => { | ||
dispatch({ | ||
type: AppActions.RequestPassword, | ||
payload: { | ||
walletID: id, | ||
actionType: 'delete', | ||
onSuccess: async () => { | ||
await resolve(id) | ||
}, | ||
}, | ||
}) | ||
}) | ||
} | ||
|
||
const requestToDeleteIds = duplicatedWallets | ||
.filter(item => item !== currentID) | ||
.concat(duplicatedWallets.includes(currentID) ? [currentID] : []) | ||
|
||
// eslint-disable-next-line no-restricted-syntax | ||
for (const id of requestToDeleteIds) { | ||
// eslint-disable-next-line no-await-in-loop | ||
await getRequest(id) | ||
} | ||
onClose() | ||
}, [wallets, duplicatedWallets, requestPassword, onClose, dispatch]) | ||
|
||
return ( | ||
<Dialog | ||
show | ||
title={t('settings.wallet-manager.detected-duplicate.title')} | ||
onCancel={onClose} | ||
onConfirm={onConfirm} | ||
disabled={duplicatedWallets.length === 0} | ||
> | ||
<div className={styles.content}> | ||
<p className={styles.detail}>{t('settings.wallet-manager.detected-duplicate.detail')}</p> | ||
<div className={styles.groupWrap}> | ||
{groups.map(group => ( | ||
<RadioGroup | ||
inputIdPrefix="detect-duplicate-wallet" | ||
key={group[0].extendedKey} | ||
defaultValue="" | ||
onChange={handleGroupChange} | ||
itemClassName={styles.radioItem} | ||
options={group.map(wallet => ({ | ||
value: `${wallet.extendedKey}_${wallet.id}`, | ||
label: <span className={styles.walletName}>{wallet.name}</span>, | ||
}))} | ||
/> | ||
))} | ||
</div> | ||
</div> | ||
</Dialog> | ||
) | ||
} | ||
|
||
DetectDuplicateWalletDialog.displayName = 'DetectDuplicateWalletDialog' | ||
|
||
export default DetectDuplicateWalletDialog |
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
Oops, something went wrong.
21a2f35
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.
Packaging for test is done in 7695895920
21a2f35
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.
Packaging for test is done in 7695894495