diff --git a/src/renderer/src/routes/modals/ConfirmPasswordBackup/index.tsx b/src/renderer/src/routes/modals/ConfirmPasswordBackup/index.tsx index c3ba29e8..fc78716b 100644 --- a/src/renderer/src/routes/modals/ConfirmPasswordBackup/index.tsx +++ b/src/renderer/src/routes/modals/ConfirmPasswordBackup/index.tsx @@ -12,7 +12,7 @@ import { DateHelper } from '@renderer/helpers/DateHelper' import { ToastHelper } from '@renderer/helpers/ToastHelper' import { useAccountsSelector } from '@renderer/hooks/useAccountSelector' import { useActions } from '@renderer/hooks/useActions' -import { useCurrentLoginSessionSelector } from '@renderer/hooks/useAuthSelector' +import { useCurrentLoginSessionSelector, useSwapRecordsSelector } from '@renderer/hooks/useAuthSelector' import { useContactsSelector } from '@renderer/hooks/useContactSelector' import { useModalNavigate, useModalState } from '@renderer/hooks/useModalRouter' import { useWalletsSelector } from '@renderer/hooks/useWalletSelector' @@ -46,6 +46,7 @@ export const ConfirmPasswordBackupModal = () => { const { contacts } = useContactsSelector() const { wallets } = useWalletsSelector() const { accounts } = useAccountsSelector() + const { swapRecords } = useSwapRecordsSelector() const { selectedFilePath } = useModalState() const { modalNavigate } = useModalNavigate() @@ -69,7 +70,7 @@ export const ConfirmPasswordBackupModal = () => { } try { - const backupFile: TBackupFormat = { wallets: [], contacts } + const backupFile: TBackupFormat = { wallets: [], contacts, swapRecords } backupFile.wallets = wallets.map(({ encryptedMnemonic, ...wallet }) => { let mnemonic: string | undefined diff --git a/src/renderer/src/routes/modals/ConfirmPasswordRecover/index.tsx b/src/renderer/src/routes/modals/ConfirmPasswordRecover/index.tsx index b7fc72e1..f4ced304 100644 --- a/src/renderer/src/routes/modals/ConfirmPasswordRecover/index.tsx +++ b/src/renderer/src/routes/modals/ConfirmPasswordRecover/index.tsx @@ -10,7 +10,9 @@ import { useAccountUtils } from '@renderer/hooks/useAccountSelector' import { useActions } from '@renderer/hooks/useActions' import { useBlockchainActions } from '@renderer/hooks/useBlockchainActions' import { useModalNavigate, useModalState } from '@renderer/hooks/useModalRouter' +import { useAppDispatch } from '@renderer/hooks/useRedux' import { SideModalLayout } from '@renderer/layouts/SideModal' +import { authReducerActions } from '@renderer/store/reducers/AuthReducer' import { TAccountsToImport, TBackupFormat } from '@shared/@types/blockchain' type TFormData = { @@ -40,6 +42,7 @@ export const ConfirmPasswordRecoverModal = () => { const { doesAccountExist } = useAccountUtils() const { modalNavigate } = useModalNavigate() const { createContacts, createWallet, importAccounts } = useBlockchainActions() + const dispatch = useAppDispatch() const { actionData, actionState, handleAct, setDataFromEventWrapper, setError, reset } = useActions({ password: '', @@ -53,15 +56,18 @@ export const ConfirmPasswordRecoverModal = () => { try { const contentDecrypted = await window.api.sendAsync('decryptBasedSecret', { value: content, secret: password }) - const backupFile = JSON.parse(contentDecrypted) as TBackupFormat + const backupFile = JSON.parse(contentDecrypted as string) as TBackupFormat ApplicationDataHelper.convertTypes(backupFile.wallets) + if (!backupFile.swapRecords) backupFile.swapRecords = [] + if (onDecrypt) { onDecrypt(backupFile) return } + backupFile.swapRecords.forEach(swapRecord => dispatch(authReducerActions.persistSwapRecord(swapRecord))) createContacts(backupFile.contacts) const importPromises = backupFile.wallets.map(async wallet => { diff --git a/src/renderer/src/routes/modals/SwapDetails/index.tsx b/src/renderer/src/routes/modals/SwapDetails/index.tsx index 11ad2cfc..cc96a017 100644 --- a/src/renderer/src/routes/modals/SwapDetails/index.tsx +++ b/src/renderer/src/routes/modals/SwapDetails/index.tsx @@ -53,6 +53,7 @@ export const SwapDetailsModal = () => { const response = await swapServiceHelper.getStatus(swapRecord.swapId) const updatedSwapRecord: TSwapRecord = { ...swapRecord, swapStatus: response.status, txTo: response.txTo } + setSwapRecord(updatedSwapRecord) dispatch(authReducerActions.persistSwapRecord(updatedSwapRecord)) diff --git a/src/renderer/src/routes/pages/Welcome/ImportWallet/Step4.tsx b/src/renderer/src/routes/pages/Welcome/ImportWallet/Step4.tsx index a079167f..92876f8e 100644 --- a/src/renderer/src/routes/pages/Welcome/ImportWallet/Step4.tsx +++ b/src/renderer/src/routes/pages/Welcome/ImportWallet/Step4.tsx @@ -6,14 +6,17 @@ import { Progress } from '@renderer/components/Progress' import { ToastHelper } from '@renderer/helpers/ToastHelper' import { UtilsHelper } from '@renderer/helpers/UtilsHelper' import { useBlockchainActions } from '@renderer/hooks/useBlockchainActions' +import { useAppDispatch } from '@renderer/hooks/useRedux' import { useSettingsActions } from '@renderer/hooks/useSettingsSelector' +import { authReducerActions } from '@renderer/store/reducers/AuthReducer' import { TAccountsToImport, TWalletToCreate } from '@shared/@types/blockchain' -import { IContactState } from '@shared/@types/store' +import { IContactState, TSwapRecord } from '@shared/@types/store' type TLocationState = { wallets: (TWalletToCreate & { accounts: TAccountsToImport })[] + swapRecords?: TSwapRecord[] contacts?: IContactState[] password: string } @@ -24,6 +27,7 @@ export const WelcomeImportWalletStep4Page = () => { const navigate = useNavigate() const { createWallet, importAccounts, createContacts } = useBlockchainActions() const { setHasPassword } = useSettingsActions() + const dispatch = useAppDispatch() const isImporting = useRef(false) @@ -31,13 +35,14 @@ export const WelcomeImportWalletStep4Page = () => { const handleImport = async () => { try { - const { wallets, contacts, password } = state + const { wallets, contacts, password, swapRecords } = state const progressByStep = 100 / wallets.length + 3 await setHasPassword(password) setProgress(progress => progress + progressByStep) + if (swapRecords) swapRecords.forEach(swapRecord => dispatch(authReducerActions.persistSwapRecord(swapRecord))) if (contacts) createContacts(contacts) await UtilsHelper.sleep(1000) diff --git a/src/shared/@types/blockchain.ts b/src/shared/@types/blockchain.ts index 3a134a0b..1d0ea14e 100644 --- a/src/shared/@types/blockchain.ts +++ b/src/shared/@types/blockchain.ts @@ -3,7 +3,7 @@ import { BSEthereumNetworkId } from '@cityofzion/bs-ethereum' import { BSNeoLegacyNetworkId } from '@cityofzion/bs-neo-legacy' import { BSNeo3NetworkId } from '@cityofzion/bs-neo3' -import { IAccountState, IContactState, IWalletState, TAccountType, TSkin, TWalletType } from './store' +import { IAccountState, IContactState, IWalletState, TAccountType, TSkin, TSwapRecord, TWalletType } from './store' export type TBlockchainServiceKey = 'neo3' | 'neoLegacy' | 'ethereum' | 'neox' export type TBlockchainImageColor = 'white' | 'gray' | 'blue' | 'green' @@ -66,6 +66,7 @@ export type TWalletBackupFormat = Omit & { export type TBackupFormat = { wallets: TWalletBackupFormat[] contacts: IContactState[] + swapRecords: TSwapRecord[] } export type TAccountToEdit = {