From 2819ea5833d93d0bcbf8a679c981e99f860fbdce Mon Sep 17 00:00:00 2001 From: hotequil Date: Wed, 23 Oct 2024 18:02:13 -0300 Subject: [PATCH] CU-86a5cfrb1-NEON3 - BUG - Add migration from type ledger to hardware on update app --- ...{BackupFileHelper.ts => ApplicationDataHelper.ts} | 6 +++--- .../routes/modals/ConfirmPasswordBackup/index.tsx | 4 ++-- .../routes/modals/ConfirmPasswordRecover/index.tsx | 4 ++-- .../pages/Settings/SettingsMigrateWallets/index.tsx | 1 + src/renderer/src/store/reducers/AuthReducer.ts | 12 ++++++++---- 5 files changed, 16 insertions(+), 11 deletions(-) rename src/renderer/src/helpers/{BackupFileHelper.ts => ApplicationDataHelper.ts} (64%) diff --git a/src/renderer/src/helpers/BackupFileHelper.ts b/src/renderer/src/helpers/ApplicationDataHelper.ts similarity index 64% rename from src/renderer/src/helpers/BackupFileHelper.ts rename to src/renderer/src/helpers/ApplicationDataHelper.ts index d56355f0..7f71832f 100644 --- a/src/renderer/src/helpers/BackupFileHelper.ts +++ b/src/renderer/src/helpers/ApplicationDataHelper.ts @@ -1,7 +1,7 @@ -import { TBackupFormat } from '@shared/@types/blockchain' +import { IWalletState } from '@shared/@types/store' -export class BackupFileHelper { - static convertTypes({ wallets }: TBackupFormat) { +export class ApplicationDataHelper { + static convertTypes(wallets: IWalletState[]) { wallets.forEach(wallet => { if (wallet.type === 'ledger') wallet.type = 'hardware' diff --git a/src/renderer/src/routes/modals/ConfirmPasswordBackup/index.tsx b/src/renderer/src/routes/modals/ConfirmPasswordBackup/index.tsx index cbd3e47b..c3ba29e8 100644 --- a/src/renderer/src/routes/modals/ConfirmPasswordBackup/index.tsx +++ b/src/renderer/src/routes/modals/ConfirmPasswordBackup/index.tsx @@ -7,7 +7,7 @@ import { ButtonDownloadPasswordQRCode } from '@renderer/components/ButtonDownloa import { Input } from '@renderer/components/Input' import { Separator } from '@renderer/components/Separator' import { BACKUP_FILE_EXTENSION } from '@renderer/constants/backup' -import { BackupFileHelper } from '@renderer/helpers/BackupFileHelper' +import { ApplicationDataHelper } from '@renderer/helpers/ApplicationDataHelper' import { DateHelper } from '@renderer/helpers/DateHelper' import { ToastHelper } from '@renderer/helpers/ToastHelper' import { useAccountsSelector } from '@renderer/hooks/useAccountSelector' @@ -99,7 +99,7 @@ export const ConfirmPasswordBackupModal = () => { return { ...wallet, mnemonic, accounts: walletAccounts } }) - BackupFileHelper.convertTypes(backupFile) + ApplicationDataHelper.convertTypes(backupFile.wallets) const content = await window.api.sendAsync('encryptBasedSecret', { value: JSON.stringify(backupFile), diff --git a/src/renderer/src/routes/modals/ConfirmPasswordRecover/index.tsx b/src/renderer/src/routes/modals/ConfirmPasswordRecover/index.tsx index 88d3439e..b7fc72e1 100644 --- a/src/renderer/src/routes/modals/ConfirmPasswordRecover/index.tsx +++ b/src/renderer/src/routes/modals/ConfirmPasswordRecover/index.tsx @@ -4,7 +4,7 @@ import { AlertErrorBanner } from '@renderer/components/AlertErrorBanner' import { Button } from '@renderer/components/Button' import { Input } from '@renderer/components/Input' import { Separator } from '@renderer/components/Separator' -import { BackupFileHelper } from '@renderer/helpers/BackupFileHelper' +import { ApplicationDataHelper } from '@renderer/helpers/ApplicationDataHelper' import { UtilsHelper } from '@renderer/helpers/UtilsHelper' import { useAccountUtils } from '@renderer/hooks/useAccountSelector' import { useActions } from '@renderer/hooks/useActions' @@ -55,7 +55,7 @@ export const ConfirmPasswordRecoverModal = () => { const contentDecrypted = await window.api.sendAsync('decryptBasedSecret', { value: content, secret: password }) const backupFile = JSON.parse(contentDecrypted) as TBackupFormat - BackupFileHelper.convertTypes(backupFile) + ApplicationDataHelper.convertTypes(backupFile.wallets) if (onDecrypt) { onDecrypt(backupFile) diff --git a/src/renderer/src/routes/pages/Settings/SettingsMigrateWallets/index.tsx b/src/renderer/src/routes/pages/Settings/SettingsMigrateWallets/index.tsx index 75d326a5..f2c41970 100644 --- a/src/renderer/src/routes/pages/Settings/SettingsMigrateWallets/index.tsx +++ b/src/renderer/src/routes/pages/Settings/SettingsMigrateWallets/index.tsx @@ -12,6 +12,7 @@ export const SettingsMigrateWalletsPage = () => { const openNeon2Click = () => { window.open('neon2://open') } + return (
diff --git a/src/renderer/src/store/reducers/AuthReducer.ts b/src/renderer/src/store/reducers/AuthReducer.ts index bd104a79..c05a29f7 100644 --- a/src/renderer/src/store/reducers/AuthReducer.ts +++ b/src/renderer/src/store/reducers/AuthReducer.ts @@ -1,5 +1,6 @@ import { BlockchainService, waitForTransaction } from '@cityofzion/blockchain-service' import { CaseReducer, createAsyncThunk, createSlice, PayloadAction } from '@reduxjs/toolkit' +import { ApplicationDataHelper } from '@renderer/helpers/ApplicationDataHelper' import { ToastHelper } from '@renderer/helpers/ToastHelper' import { UtilsHelper } from '@renderer/helpers/UtilsHelper' import { buildQueryKeyBalance } from '@renderer/hooks/useBalances' @@ -35,12 +36,15 @@ const authReducerMigrations = { walletsJSON.forEach(wallet => { const accounts = accountsJSON.filter(account => account.idWallet === wallet.id) + passwordWallets.push({ ...wallet, accounts, }) }) + ApplicationDataHelper.convertTypes(passwordWallets) + window.localStorage.removeItem('persist:walletReducer') window.localStorage.removeItem('persist:accountReducer') @@ -119,7 +123,7 @@ const saveWallet: CaseReducer> = (stat const deleteWallet: CaseReducer> = (state, action) => { if (!state.currentLoginSession) { - throw new Error('Error to save wallet: Current login session is not defined') + throw new Error('Error to delete wallet: Current login session is not defined') } const loginSessionType = state.currentLoginSession.type @@ -131,7 +135,7 @@ const deleteWallet: CaseReducer> = (state, a const saveAccount: CaseReducer> = (state, action) => { if (!state.currentLoginSession) { - throw new Error('Error to save wallet: Current login session is not defined') + throw new Error('Error to save account: Current login session is not defined') } const loginSessionType = state.currentLoginSession.type @@ -156,7 +160,7 @@ const saveAccount: CaseReducer> = (st const deleteAccount: CaseReducer> = (state, action) => { if (!state.currentLoginSession) { - throw new Error('Error to save wallet: Current login session is not defined') + throw new Error('Error to delete account: Current login session is not defined') } const loginSessionType = state.currentLoginSession.type @@ -167,7 +171,7 @@ const deleteAccount: CaseReducer> = ( const wallet = applicationData.wallets.find(it => it.id === walletId) if (!wallet) { - throw new Error('Error to save account: Wallet not found') + throw new Error('Error to delete account: Wallet not found') } wallet.accounts = wallet.accounts.filter(account => account.id !== accountToRemove.id)