From f22bfcaf53b5134e88a69feb9c575fceac47be5c Mon Sep 17 00:00:00 2001 From: Raul Duarte Pereira Date: Tue, 7 May 2024 19:33:19 -0300 Subject: [PATCH] CU-86dteamh6 - Neon3 - In migration import contacts --- src/renderer/src/hooks/useBackupOrMigrate.ts | 14 +++++--- .../MigrateAccounts/MigrateAccountsStep3.tsx | 18 +++++----- .../MigrateAccounts/MigrateAccountsStep4.tsx | 34 +++++++++++++++++-- 3 files changed, 50 insertions(+), 16 deletions(-) diff --git a/src/renderer/src/hooks/useBackupOrMigrate.ts b/src/renderer/src/hooks/useBackupOrMigrate.ts index 5aae3ee60..8edd9d5b5 100644 --- a/src/renderer/src/hooks/useBackupOrMigrate.ts +++ b/src/renderer/src/hooks/useBackupOrMigrate.ts @@ -7,11 +7,12 @@ import zod from 'zod' import { useModalNavigate } from './useModalRouter' -export type TMigrateAccountSchema = zod.infer +export type TMigrateWalletsSchema = zod.infer +export type TMigrateSchema = zod.infer type TFile = { path: string - content: string | TMigrateAccountSchema[] + content: string | TMigrateSchema } const migrateWalletsSchema = zod.object({ @@ -24,6 +25,11 @@ const migrateWalletsSchema = zod.object({ extra: zod.any(), }) +const migrateSchema = zod.object({ + accounts: zod.array(migrateWalletsSchema), + contacts: zod.array(zod.object({ name: zod.string(), addresses: zod.array(zod.string()) })), +}) + export const useBackupOrMigrate = () => { const { t } = useTranslation('hooks', { keyPrefix: 'useBackupOrMigrate' }) const [file, setFile] = useState() @@ -48,7 +54,7 @@ export const useBackupOrMigrate = () => { try { const parsedContent = JSON.parse(fileContent) - const validatedContent = await migrateWalletsSchema.array().parseAsync(parsedContent) + const validatedContent = await migrateSchema.parseAsync(parsedContent) ToastHelper.success({ message: t('neon2MigrateFileDetected') }) setFile({ path: filePath, content: validatedContent }) setHasError(false) @@ -70,7 +76,7 @@ export const useBackupOrMigrate = () => { } navigate('/app/settings/security/migrate-accounts') - modalNavigate('migrate-accounts-step-3', { state: { content: file.content as TMigrateAccountSchema[] } }) + modalNavigate('migrate-accounts-step-3', { state: { content: file.content } }) } return { diff --git a/src/renderer/src/routes/modals/MigrateAccounts/MigrateAccountsStep3.tsx b/src/renderer/src/routes/modals/MigrateAccounts/MigrateAccountsStep3.tsx index f02702737..4656c5952 100644 --- a/src/renderer/src/routes/modals/MigrateAccounts/MigrateAccountsStep3.tsx +++ b/src/renderer/src/routes/modals/MigrateAccounts/MigrateAccountsStep3.tsx @@ -5,12 +5,12 @@ import { Button } from '@renderer/components/Button' import { Checkbox } from '@renderer/components/Checkbox' import { Separator } from '@renderer/components/Separator' import { useAccountUtils } from '@renderer/hooks/useAccountSelector' -import { TMigrateAccountSchema } from '@renderer/hooks/useBackupOrMigrate' +import { TMigrateSchema, TMigrateWalletsSchema } from '@renderer/hooks/useBackupOrMigrate' import { useModalNavigate, useModalState } from '@renderer/hooks/useModalRouter' import { MigrateAccountsModalLayout } from '@renderer/layouts/MigrateAccountsModalLayout' type TState = { - content: TMigrateAccountSchema[] + content: TMigrateSchema } export const MigrateAccountsStep3Modal = () => { @@ -19,9 +19,9 @@ export const MigrateAccountsStep3Modal = () => { const { modalNavigateWrapper } = useModalNavigate() const { doesAccountExist } = useAccountUtils() - const [selectedAccountsToMigrate, setSelectedAccountsToMigrate] = useState([]) + const [selectedAccountsToMigrate, setSelectedAccountsToMigrate] = useState([]) - const handleSelect = (wallet: TMigrateAccountSchema) => { + const handleSelect = (wallet: TMigrateWalletsSchema) => { setSelectedAccountsToMigrate(prev => { const index = prev.findIndex(prevWallet => prevWallet.address === wallet.address) @@ -34,7 +34,7 @@ export const MigrateAccountsStep3Modal = () => { } const handleSelectAll = () => { - const filteredContent = content.filter(wallet => !doesAccountExist(wallet.address)) + const filteredContent = content.accounts.filter(wallet => !doesAccountExist(wallet.address)) setSelectedAccountsToMigrate(filteredContent) } @@ -49,7 +49,7 @@ export const MigrateAccountsStep3Modal = () => {
- {content.map((wallet, index) => { + {content.accounts.map((wallet, index) => { const isAccountExist = doesAccountExist(wallet.address) return ( @@ -73,14 +73,14 @@ export const MigrateAccountsStep3Modal = () => { />
- {index < content.length - 1 && } + {index < content.accounts.length - 1 && } ) })} - {t('selectedQuantity', { selected: selectedAccountsToMigrate.length, total: content.length })} + {t('selectedQuantity', { selected: selectedAccountsToMigrate.length, total: content.accounts.length })}