Skip to content

Commit

Permalink
Merge pull request #233 from CityOfZion/CU-86a5cfrb1
Browse files Browse the repository at this point in the history
CU-86a5cfrb1-NEON3 - BUG - Add migration from type ledger to hardware…
  • Loading branch information
thiagocbalducci authored Oct 23, 2024
2 parents c9300dc + 2819ea5 commit 591e4c8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const SettingsMigrateWalletsPage = () => {
const openNeon2Click = () => {
window.open('neon2://open')
}

return (
<SettingsLayout title={t('title')} contentClassName="items-center">
<div className="max-w-[33rem] flex flex-col flex-grow">
Expand Down
12 changes: 8 additions & 4 deletions src/renderer/src/store/reducers/AuthReducer.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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')

Expand Down Expand Up @@ -119,7 +123,7 @@ const saveWallet: CaseReducer<IAuthReducer, PayloadAction<IWalletState>> = (stat

const deleteWallet: CaseReducer<IAuthReducer, PayloadAction<string>> = (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
Expand All @@ -131,7 +135,7 @@ const deleteWallet: CaseReducer<IAuthReducer, PayloadAction<string>> = (state, a

const saveAccount: CaseReducer<IAuthReducer, PayloadAction<IAccountState>> = (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
Expand All @@ -156,7 +160,7 @@ const saveAccount: CaseReducer<IAuthReducer, PayloadAction<IAccountState>> = (st

const deleteAccount: CaseReducer<IAuthReducer, PayloadAction<IAccountState>> = (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
Expand All @@ -167,7 +171,7 @@ const deleteAccount: CaseReducer<IAuthReducer, PayloadAction<IAccountState>> = (

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)
Expand Down

0 comments on commit 591e4c8

Please sign in to comment.