Skip to content

Commit

Permalink
[Issue-2040] Update list account can migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
S2kael committed Oct 20, 2023
1 parent 6dfbe20 commit d90a44b
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,14 @@ const intersectionArray = (array1: AccountJson[], array2: AccountJson[]): Accoun
return array1.filter((account) => array2.find((acc) => acc.address === account.address));
};

const filterAccountNeedMigrate = (acc: AccountJson) => {
const filterAccountMigrated = (acc: AccountJson) => {
return acc.address !== ALL_ACCOUNT_KEY && !acc.isExternal && acc.isMasterPassword && !acc.isInjected;
};

const filterAccountCanMigrate = (acc: AccountJson) => {
return acc.address !== ALL_ACCOUNT_KEY && !acc.isExternal && !acc.isMasterPassword && !acc.isInjected;
};

const Component: React.FC<Props> = (props: Props) => {
const { isWebUI } = useContext(ScreenContext);
const navigate = useNavigate();
Expand All @@ -109,11 +113,11 @@ const Component: React.FC<Props> = (props: Props) => {

const checkUnlock = useUnlockChecker();

const migratedRef = useRef<AccountJson[]>(accounts.filter(filterAccountNeedMigrate));
const migratedRef = useRef<AccountJson[]>(accounts.filter(filterAccountMigrated));

const migrated = useMemo(() => {
const oldVal = migratedRef.current;
const newVal = accounts.filter(filterAccountNeedMigrate);
const newVal = accounts.filter(filterAccountMigrated);
const result = intersectionArray(oldVal, newVal);

migratedRef.current = result;
Expand All @@ -123,7 +127,7 @@ const Component: React.FC<Props> = (props: Props) => {

const canMigrate = useMemo(
() => accounts
.filter((acc) => acc.address !== ALL_ACCOUNT_KEY && !acc.isExternal)
.filter(filterAccountCanMigrate)
.filter((acc) => !migrated.find((item) => item.address === acc.address))
, [accounts, migrated]
);
Expand Down

0 comments on commit d90a44b

Please sign in to comment.