From 326c7332961b4a973badb54e89c71cbfa332064e Mon Sep 17 00:00:00 2001 From: Veado Date: Thu, 11 Aug 2022 11:10:21 +0200 Subject: [PATCH 1/2] Quick fix styles --- src/renderer/components/settings/WalletSettings.tsx | 2 +- src/renderer/views/wallet/NoWalletView/NoWalletView.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/renderer/components/settings/WalletSettings.tsx b/src/renderer/components/settings/WalletSettings.tsx index dc9814917..5474c0712 100644 --- a/src/renderer/components/settings/WalletSettings.tsx +++ b/src/renderer/components/settings/WalletSettings.tsx @@ -495,7 +495,7 @@ export const WalletSettings: React.FC = (props): JSX.Element => {
{/* TODO(@veado) Make wallet name editable */}

{walletName}

-
+
{ const intl = useIntl() return ( -
+
accounts: {JSON.stringify(keystoreAccounts)}
+
accounts: {JSON.stringify(keystoreWallets)}
diff --git a/src/renderer/components/wallet/unlock/UnlockForm.tsx b/src/renderer/components/wallet/unlock/UnlockForm.tsx index 17bac687d..adfb3943a 100644 --- a/src/renderer/components/wallet/unlock/UnlockForm.tsx +++ b/src/renderer/components/wallet/unlock/UnlockForm.tsx @@ -11,7 +11,7 @@ import { getUrlSearchParam } from '../../../helpers/url.helper' import * as appRoutes from '../../../routes/app' import { ReferrerState } from '../../../routes/types' import * as walletRoutes from '../../../routes/wallet' -import { KeystoreState, RemoveAccountHandler } from '../../../services/wallet/types' +import { KeystoreState, RemoveKeystoreWalletHandler } from '../../../services/wallet/types' import { isLocked, getWalletName } from '../../../services/wallet/util' import { RemoveWalletConfirmationModal } from '../../modal/confirmation/RemoveWalletConfirmationModal' import { BackLink } from '../../uielements/backLink' @@ -25,7 +25,7 @@ type FormData = { export type Props = { keystore: KeystoreState unlock: (password: string) => Promise - removeKeystore: RemoveAccountHandler + removeKeystore: RemoveKeystoreWalletHandler } export const UnlockForm: React.FC = (props): JSX.Element => { diff --git a/src/renderer/hooks/useKeystoreAccounts.ts b/src/renderer/hooks/useKeystoreAccounts.ts deleted file mode 100644 index c8a9a5468..000000000 --- a/src/renderer/hooks/useKeystoreAccounts.ts +++ /dev/null @@ -1,21 +0,0 @@ -import * as RD from '@devexperts/remote-data-ts' -import * as FP from 'fp-ts/lib/function' -import { useObservableState } from 'observable-hooks' - -import { useWalletContext } from '../contexts/WalletContext' -import { KeystoreAccountsRD, KeystoreAccountsUI } from '../services/wallet/types' - -export const useKeystoreAccounts = (): { - accounts: KeystoreAccountsRD - reload: FP.Lazy - accountsUI: KeystoreAccountsUI -} => { - const { - keystoreService: { reloadKeystoreAccounts: reload, keystoreAccounts$, keystoreAccountsUI$ } - } = useWalletContext() - - const accounts = useObservableState(keystoreAccounts$, RD.initial) - const accountsUI = useObservableState(keystoreAccountsUI$, []) - - return { accounts, accountsUI, reload } -} diff --git a/src/renderer/hooks/useKeystoreState.ts b/src/renderer/hooks/useKeystoreState.ts index fae4c52b5..5db46eb11 100644 --- a/src/renderer/hooks/useKeystoreState.ts +++ b/src/renderer/hooks/useKeystoreState.ts @@ -5,19 +5,19 @@ import * as RxOp from 'rxjs/operators' import { useWalletContext } from '../contexts/WalletContext' import { INITIAL_KEYSTORE_STATE } from '../services/wallet/const' -import { KeystoreState, Phrase, RemoveAccountHandler } from '../services/wallet/types' +import { KeystoreState, Phrase, RemoveKeystoreWalletHandler } from '../services/wallet/types' import { getPhrase, getWalletName } from '../services/wallet/util' export const useKeystoreState = (): { state: KeystoreState phrase: O.Option walletName: O.Option - remove: RemoveAccountHandler + remove: RemoveKeystoreWalletHandler unlock: (password: string) => Promise lock: FP.Lazy } => { const { - keystoreService: { keystore$, unlock, lock, removeKeystoreAccount: remove } + keystoreService: { keystore$, unlock, lock, removeKeystoreWallet: remove } } = useWalletContext() const state = useObservableState(keystore$, INITIAL_KEYSTORE_STATE) diff --git a/src/renderer/hooks/useKeystoreWallets.ts b/src/renderer/hooks/useKeystoreWallets.ts new file mode 100644 index 000000000..d72747288 --- /dev/null +++ b/src/renderer/hooks/useKeystoreWallets.ts @@ -0,0 +1,21 @@ +import * as RD from '@devexperts/remote-data-ts' +import * as FP from 'fp-ts/lib/function' +import { useObservableState } from 'observable-hooks' + +import { useWalletContext } from '../contexts/WalletContext' +import { KeystoreWalletsRD, KeystoreWalletsUI } from '../services/wallet/types' + +export const useKeystoreWallets = (): { + wallets: KeystoreWalletsRD + reload: FP.Lazy + walletsUI: KeystoreWalletsUI +} => { + const { + keystoreService: { reloadKeystoreWallets: reload, keystoreWallets$, keystoreWalletsUI$ } + } = useWalletContext() + + const wallets = useObservableState(keystoreWallets$, RD.initial) + const walletsUI = useObservableState(keystoreWalletsUI$, []) + + return { wallets: wallets, walletsUI, reload } +} diff --git a/src/renderer/services/wallet/index.ts b/src/renderer/services/wallet/index.ts index fb05545ee..41c981598 100644 --- a/src/renderer/services/wallet/index.ts +++ b/src/renderer/services/wallet/index.ts @@ -1,7 +1,7 @@ import { network$ } from '../app/service' import { createBalancesService } from './balances' import { setSelectedAsset, selectedAsset$, client$ } from './common' -import { keystoreService, removeKeystoreAccount } from './keystore' +import { keystoreService, removeKeystoreWallet } from './keystore' import { createLedgerService } from './ledger' import { getTxs$, loadTxs, explorerUrl$, resetTxsPage } from './transaction' @@ -22,7 +22,7 @@ const { reloadBalances, reloadBalancesByChain, balancesState$, chainBalances$ } export { client$, keystoreService, - removeKeystoreAccount as removeKeystore, + removeKeystoreWallet, setSelectedAsset, selectedAsset$, loadTxs, diff --git a/src/renderer/services/wallet/keystore.ts b/src/renderer/services/wallet/keystore.ts index 6a7fe2db6..0165ba7dc 100644 --- a/src/renderer/services/wallet/keystore.ts +++ b/src/renderer/services/wallet/keystore.ts @@ -8,7 +8,7 @@ import * as O from 'fp-ts/lib/Option' import * as Rx from 'rxjs' import * as RxOp from 'rxjs/operators' -import { ipcKeystoreAccountsIO, KeystoreAccounts } from '../../../shared/api/io' +import { ipcKeystoreWalletsIO, KeystoreWallets } from '../../../shared/api/io' import { isError } from '../../../shared/utils/guard' import { liveData } from '../../helpers/rx/liveData' import { observableState, triggerStream } from '../../helpers/stateHelper' @@ -20,8 +20,8 @@ import { LoadKeystoreLD, ImportKeystoreParams, AddKeystoreParams, - KeystoreAccountsLD, - KeystoreAccountsUI$ + KeystoreWalletsLD, + KeystoreWalletsUI$ } from './types' import { getKeystore, @@ -33,14 +33,14 @@ import { } from './util' /** - * State of importing keystore account + * State of importing a keystore wallet */ const { get$: importingKeystoreState$, set: setImportingKeystoreState } = observableState< RD.RemoteData >(RD.initial) /** - * State of selected keystore account + * State of selected keystore wallet */ const { get$: getKeystoreState$, @@ -49,30 +49,30 @@ const { } = observableState(INITIAL_KEYSTORE_STATE) /** - * Internal state of keystore accounts - not shared to outside world + * Internal state of keystore wallets - not shared to outside world */ const { - get$: getKeystoreAccounts$, - get: getKeystoreAccounts, - set: setKeystoreAccounts -} = observableState([]) + get$: getKeystoreWallets$, + get: getKeystoreWallets, + set: setKeystoreWallets +} = observableState([]) /** * Adds a keystore and saves it to disk */ -const addKeystoreAccount = async ({ phrase, name, id, password }: AddKeystoreParams): Promise => { +const addKeystoreWallet = async ({ phrase, name, id, password }: AddKeystoreParams): Promise => { try { setImportingKeystoreState(RD.pending) const keystore: Keystore = await encryptToKeyStore(phrase, password) - // remove selected state from current accounts - const accounts = FP.pipe( - getKeystoreAccounts(), - A.map((account) => ({ ...account, selected: false })) + // remove selected state from current wallets + const wallets = FP.pipe( + getKeystoreWallets(), + A.map((wallet) => ({ ...wallet, selected: false })) ) - // Add account to accounts + mark it `selected` - const newAccounts: KeystoreAccounts = [ - ...accounts, + // Add new wallet to wallet list + mark it `selected` + const updatedWallets: KeystoreWallets = [ + ...wallets, { id, name, @@ -81,11 +81,11 @@ const addKeystoreAccount = async ({ phrase, name, id, password }: AddKeystorePar } ] - const encodedAccounts = ipcKeystoreAccountsIO.encode(newAccounts) - // Save accounts to disk - await window.apiKeystore.saveKeystoreAccounts(encodedAccounts) + const encodedWallets = ipcKeystoreWalletsIO.encode(updatedWallets) + // Save wallets to disk + await window.apiKeystore.saveKeystoreWallets(encodedWallets) // Update states - setKeystoreAccounts(newAccounts) + setKeystoreWallets(updatedWallets) setKeystoreState(O.some({ id, phrase, name })) setImportingKeystoreState(RD.success(true)) return Promise.resolve() @@ -95,29 +95,29 @@ const addKeystoreAccount = async ({ phrase, name, id, password }: AddKeystorePar } } -export const removeKeystoreAccount = async () => { +export const removeKeystoreWallet = async () => { const state = getKeystoreState() - const id = FP.pipe(state, getKeystoreId, O.toNullable) - if (!id) { + const keystoreId = FP.pipe(state, getKeystoreId, O.toNullable) + if (!keystoreId) { throw Error(`Can't remove wallet - keystore id is missing`) } - // Remove it from `accounts` - const accounts = FP.pipe( - getKeystoreAccounts(), - A.filter(({ id: accountId }) => accountId !== id) + // Remove it from `wallets` + const wallets = FP.pipe( + getKeystoreWallets(), + A.filter(({ id }) => id !== keystoreId) ) - const encodedAccounts = ipcKeystoreAccountsIO.encode(accounts) - // Save updated `accounts` to disk - await window.apiKeystore.saveKeystoreAccounts(encodedAccounts) + const encodedWallets = ipcKeystoreWalletsIO.encode(wallets) + // Save updated `wallets` to disk + await window.apiKeystore.saveKeystoreWallets(encodedWallets) // Update states - setKeystoreAccounts(accounts) - // Set previous to current account (if available) - const prevAccount = FP.pipe(accounts, A.last) - setKeystoreState(prevAccount) + setKeystoreWallets(wallets) + // Set previous to current wallets (if available) + const prevWallet = FP.pipe(wallets, A.last) + setKeystoreState(prevWallet) - // return no. of accounts - return accounts.length + // return no. of wallets + return wallets.length } const importKeystore = async ({ keystore, password, name, id }: ImportKeystoreParams): Promise => { @@ -125,7 +125,7 @@ const importKeystore = async ({ keystore, password, name, id }: ImportKeystorePa setImportingKeystoreState(RD.pending) const phrase = await decryptFromKeystore(keystore, password) await delay(200) - return await addKeystoreAccount({ phrase, name, id, password }) + return await addKeystoreWallet({ phrase, name, id, password }) } catch (error) { setImportingKeystoreState(RD.failure(isError(error) ? error : Error('Could not add keystore'))) return Promise.reject(error) @@ -142,12 +142,12 @@ const exportKeystore = async () => { throw Error(`Can't export keystore - keystore id is missing in KeystoreState`) } - const accounts = getKeystoreAccounts() - const keystore = FP.pipe(accounts, getKeystore(id), O.toNullable) + const wallets = getKeystoreWallets() + const keystore = FP.pipe(wallets, getKeystore(id), O.toNullable) if (!keystore) { - throw Error(`Can't export keystore - keystore is missing in accounts`) + throw Error(`Can't export keystore - keystore is missing in wallet list`) } - const fileName = `asgardex-${FP.pipe(accounts, getKeystoreWalletName(id), O.toNullable) || 'keystore'}.json` + const fileName = `asgardex-${FP.pipe(wallets, getKeystoreWalletName(id), O.toNullable) || 'keystore'}.json` return await window.apiKeystore.exportKeystore({ fileName, keystore }) } catch (error) { return Promise.reject(error) @@ -193,10 +193,10 @@ const unlock = async (password: string) => { const { id, name } = lockedData - // get keystore from account list (not stored in `KeystoreState`) - const keystore = FP.pipe(getKeystoreAccounts(), getKeystore(id), O.toNullable) + // get keystore from wallet list (not stored in `KeystoreState`) + const keystore = FP.pipe(getKeystoreWallets(), getKeystore(id), O.toNullable) if (!keystore) { - throw Error(`Can't unlock - keystore is missing in accounts`) + throw Error(`Can't unlock - keystore is missing in wallet list`) } try { // decrypt phrase from keystore @@ -208,36 +208,36 @@ const unlock = async (password: string) => { } // `TriggerStream` to reload data of `ThorchainLastblock` -const { stream$: reloadKeystoreAccounts$, trigger: reloadKeystoreAccounts } = triggerStream() +const { stream$: reloadKeystoreWallets$, trigger: reloadKeystoreWallets } = triggerStream() -const keystoreAccounts$: KeystoreAccountsLD = FP.pipe( - reloadKeystoreAccounts$, - RxOp.switchMap(() => Rx.from(window.apiKeystore.initKeystoreAccounts())), +const keystoreWallets$: KeystoreWalletsLD = FP.pipe( + reloadKeystoreWallets$, + RxOp.switchMap(() => Rx.from(window.apiKeystore.initKeystoreWallets())), RxOp.catchError((e) => Rx.of(E.left(e))), RxOp.switchMap( FP.flow( - E.fold( + E.fold( (e) => Rx.of(RD.failure(e)), - (accounts) => Rx.of(RD.success(accounts)) + (wallets) => Rx.of(RD.success(wallets)) ) ) ), - liveData.map((accounts) => { - const state = getInitialKeystoreData(accounts) + liveData.map((wallets) => { + const state = getInitialKeystoreData(wallets) setKeystoreState(state) - setKeystoreAccounts(accounts) + setKeystoreWallets(wallets) - return accounts + return wallets }), RxOp.startWith(RD.pending), RxOp.shareReplay(1) ) -// Simplified `KeystoreAccounts` (w/o loading state, w/o `keystore`) to display data at UIs -const keystoreAccountsUI$: KeystoreAccountsUI$ = FP.pipe( - getKeystoreAccounts$, - // Transform `KeystoreAccounts` -> `KeystoreAccountsUI` +// Simplified `KeystoreWallets` (w/o loading state, w/o `keystore`) to display data at UIs +const keystoreWalletsUI$: KeystoreWalletsUI$ = FP.pipe( + getKeystoreWallets$, + // Transform `KeystoreWallets` -> `KeystoreWalletsUI` RxOp.map(FP.flow(A.map(({ id, name, selected }) => ({ id, name, selected })))), RxOp.shareReplay(1) ) @@ -252,7 +252,7 @@ const validatePassword$ = (password: string): ValidatePasswordLD => ? FP.pipe( getKeystoreState(), getKeystoreId, - O.chain((id) => FP.pipe(getKeystoreAccounts(), getKeystore(id))), + O.chain((id) => FP.pipe(getKeystoreWallets(), getKeystore(id))), O.fold( () => Rx.of(RD.failure(Error('Could not get current keystore to validate password'))), (keystore) => @@ -269,21 +269,21 @@ const validatePassword$ = (password: string): ValidatePasswordLD => export const keystoreService: KeystoreService = { keystore$: getKeystoreState$, - addKeystoreAccount, - removeKeystoreAccount, + addKeystoreWallet, + removeKeystoreWallet, importKeystore, exportKeystore, loadKeystore$, lock, unlock, validatePassword$, - reloadKeystoreAccounts, - keystoreAccountsUI$, - keystoreAccounts$, + reloadKeystoreWallets, + keystoreWalletsUI$, + keystoreWallets$, importingKeystoreState$, resetImportingKeystoreState: () => setImportingKeystoreState(RD.initial) } // TODO(@Veado) Remove it - for debugging only getKeystoreState$.subscribe((v) => console.log('keystoreState subscription', v)) -getKeystoreAccounts$.subscribe((v) => console.log('keystoreAccounts subscription', v)) +getKeystoreWallets$.subscribe((v) => console.log('keystoreWallets subscription', v)) diff --git a/src/renderer/services/wallet/types.ts b/src/renderer/services/wallet/types.ts index 34d2b75f3..26fc2b3d2 100644 --- a/src/renderer/services/wallet/types.ts +++ b/src/renderer/services/wallet/types.ts @@ -8,7 +8,7 @@ import { NonEmptyArray } from 'fp-ts/lib/NonEmptyArray' import * as O from 'fp-ts/lib/Option' import * as Rx from 'rxjs' -import { KeystoreAccount, KeystoreAccounts } from '../../../shared/api/io' +import { KeystoreWallet, KeystoreWallets } from '../../../shared/api/io' import { KeystoreId, LedgerError, Network } from '../../../shared/api/types' import { WalletAddress, WalletBalanceType, WalletType } from '../../../shared/wallet/types' import { LiveData } from '../../helpers/rx/liveData' @@ -56,12 +56,12 @@ export type LoadKeystoreLD = LiveData export type ImportingKeystoreStateRD = RD.RemoteData export type ImportingKeystoreStateLD = Rx.Observable -export type RemoveAccountHandler = () => Promise +export type RemoveKeystoreWalletHandler = () => Promise export type KeystoreService = { keystore$: KeystoreState$ - addKeystoreAccount: (params: AddKeystoreParams) => Promise - removeKeystoreAccount: RemoveAccountHandler + addKeystoreWallet: (params: AddKeystoreParams) => Promise + removeKeystoreWallet: RemoveKeystoreWalletHandler loadKeystore$: () => LoadKeystoreLD importKeystore: (params: ImportKeystoreParams) => Promise exportKeystore: () => Promise @@ -72,9 +72,9 @@ export type KeystoreService = { * No need to store any success data. Only status */ validatePassword$: ValidatePasswordHandler - reloadKeystoreAccounts: FP.Lazy - keystoreAccounts$: KeystoreAccountsLD - keystoreAccountsUI$: KeystoreAccountsUI$ + reloadKeystoreWallets: FP.Lazy + keystoreWallets$: KeystoreWalletsLD + keystoreWalletsUI$: KeystoreWalletsUI$ importingKeystoreState$: ImportingKeystoreStateLD resetImportingKeystoreState: FP.Lazy } @@ -212,9 +212,9 @@ export type LedgerAddressMap$ = Rx.Observable export type LedgerAddressesMap = Record export type LedgerAddressesMap$ = Rx.Observable -export type KeystoreAccountsRD = RD.RemoteData -export type KeystoreAccountsLD = LiveData +export type KeystoreWalletsRD = RD.RemoteData +export type KeystoreWalletsLD = LiveData -export type KeystoreAccountUI = Omit -export type KeystoreAccountsUI = KeystoreAccountUI[] -export type KeystoreAccountsUI$ = Rx.Observable +export type KeystoreWalletUI = Omit +export type KeystoreWalletsUI = KeystoreWalletUI[] +export type KeystoreWalletsUI$ = Rx.Observable diff --git a/src/renderer/services/wallet/util.test.ts b/src/renderer/services/wallet/util.test.ts index b5c3ec767..107cebae9 100644 --- a/src/renderer/services/wallet/util.test.ts +++ b/src/renderer/services/wallet/util.test.ts @@ -101,7 +101,7 @@ describe('services/wallet/util/', () => { }) describe('getInitialKeystoreData', () => { - it('finds selected account', () => { + it('finds selected wallet', () => { const result = getInitialKeystoreData([ { id: 0, name: 'name0', selected: false }, { id: 1, name: 'name1', selected: false }, @@ -111,7 +111,7 @@ describe('services/wallet/util/', () => { expect(result).toEqual(O.some({ id: 2, name: 'name2' })) }) - it('uses first account', () => { + it('uses first wallet', () => { const result = getInitialKeystoreData([ { id: 0, name: 'name0', selected: false }, { id: 1, name: 'name1', selected: false }, @@ -121,7 +121,7 @@ describe('services/wallet/util/', () => { expect(result).toEqual(O.some({ id: 0, name: 'name0' })) }) - it('empty list of account', () => { + it('empty list of wallet', () => { const result = getInitialKeystoreData([]) expect(result).toBeNone() }) diff --git a/src/renderer/services/wallet/util.ts b/src/renderer/services/wallet/util.ts index 649cd7569..d760caa57 100644 --- a/src/renderer/services/wallet/util.ts +++ b/src/renderer/services/wallet/util.ts @@ -8,7 +8,7 @@ import * as Ord from 'fp-ts/Ord' import * as S from 'fp-ts/string' import { IntlShape } from 'react-intl' -import { KeystoreAccounts, KeystoreAccount } from '../../../shared/api/io' +import { KeystoreWallets, KeystoreWallet } from '../../../shared/api/io' import { KeystoreId, LedgerErrorId } from '../../../shared/api/types' import { WalletType } from '../../../shared/wallet/types' import { eqAsset } from '../../helpers/fp/eq' @@ -50,44 +50,44 @@ export const getWalletName = (state: KeystoreState): O.Option => export const getLockedData = (state: KeystoreState): O.Option => FP.pipe(sequenceSOption({ id: getKeystoreId(state), name: getWalletName(state) })) -export const getSelectedKeystoreId = (accounts: KeystoreAccounts): O.Option => +export const getSelectedKeystoreId = (wallets: KeystoreWallets): O.Option => FP.pipe( - accounts, + wallets, A.filterMap(({ selected, id }) => (selected ? O.some(id) : O.none)), A.head ) /** - * Returns initial keystore state by given accouns + * Returns initial keystore state by given wallets * * Initial `Keystore` is always set to `KeystoreLocked` */ export const getInitialKeystoreData = ( - accounts: Array> + wallets: Array> ): O.Option => FP.pipe( - accounts, - // get selected account (if available) + wallets, + // get selected wallet (if available) A.filterMap(O.fromPredicate(({ selected }) => selected)), A.head, - // if no selected account, use first account in list (if available) - O.alt(() => (accounts.length ? O.some(accounts[0]) : O.none)), - // get needed data from account + // if no selected wallet, use first wallet in list (if available) + O.alt(() => (wallets.length ? O.some(wallets[0]) : O.none)), + // get needed data from wallet O.map(({ id, name }) => ({ id, name })) ) -export const getKeystore: (id: KeystoreId) => (accounts: KeystoreAccounts) => O.Option = (id) => (accounts) => +export const getKeystore: (id: KeystoreId) => (wallets: KeystoreWallets) => O.Option = (id) => (wallets) => FP.pipe( - accounts, - A.filterMap(({ keystore, id: accountId }) => (accountId === id ? O.some(keystore) : O.none)), + wallets, + A.filterMap(({ keystore, id: walletId }) => (walletId === id ? O.some(keystore) : O.none)), A.head ) -export const getKeystoreWalletName: (id: KeystoreId) => (accounts: KeystoreAccounts) => O.Option = - (id) => (accounts) => +export const getKeystoreWalletName: (id: KeystoreId) => (wallets: KeystoreWallets) => O.Option = + (id) => (wallets) => FP.pipe( - accounts, - A.filterMap(({ name, id: accountId }) => (accountId === id ? O.some(name) : O.none)), + wallets, + A.filterMap(({ name, id: walletId }) => (walletId === id ? O.some(name) : O.none)), A.head ) diff --git a/src/renderer/views/app/AppView.tsx b/src/renderer/views/app/AppView.tsx index 063b1d27d..54752163d 100644 --- a/src/renderer/views/app/AppView.tsx +++ b/src/renderer/views/app/AppView.tsx @@ -18,7 +18,7 @@ import { useI18nContext } from '../../contexts/I18nContext' import { useMidgardContext } from '../../contexts/MidgardContext' import { unionChains } from '../../helpers/fp/array' import { rdAltOnPending } from '../../helpers/fpHelpers' -import { useKeystoreAccounts } from '../../hooks/useKeystoreAccounts' +import { useKeystoreWallets } from '../../hooks/useKeystoreWallets' import { useMimirHalt } from '../../hooks/useMimirHalt' import { useTheme } from '../../hooks/useTheme' import { DEFAULT_MIMIR_HALT } from '../../services/thorchain/const' @@ -72,7 +72,7 @@ export const AppView: React.FC = (): JSX.Element => { const prevHaltedChains = useRef([]) const prevMimirHalt = useRef(DEFAULT_MIMIR_HALT) - const { accounts: keystoreAccounts, reload: reloadKeystoreAccounts } = useKeystoreAccounts() + const { wallets: keystoreWallets, reload: reloadKeystoreWallets } = useKeystoreWallets() const { mimirHaltRD } = useMimirHalt() @@ -271,21 +271,21 @@ export const AppView: React.FC = (): JSX.Element => {
{' '} - keystoreAccounts: + keystoreWallets: {FP.pipe( - keystoreAccounts, + keystoreWallets, RD.fold( () => <>init, () => <>loading, (e) => <>error {e.toString()}, - (accounts) => <>accounts {JSON.stringify(accounts)} + (wallets) => <>wallets {JSON.stringify(wallets)} ) )}
- +
) - }, [keystoreAccounts, reloadKeystoreAccounts]) + }, [keystoreWallets, reloadKeystoreWallets]) return ( diff --git a/src/renderer/views/wallet/CreateView/PhraseView.tsx b/src/renderer/views/wallet/CreateView/PhraseView.tsx index dd535a7cd..d954c4d40 100644 --- a/src/renderer/views/wallet/CreateView/PhraseView.tsx +++ b/src/renderer/views/wallet/CreateView/PhraseView.tsx @@ -26,7 +26,7 @@ const NewPhraseConfirmView: React.FC = (): JSX.Element => { return ( keystoreService.addKeystoreAccount({ phrase, password, id, name })} + onConfirm={() => keystoreService.addKeystoreWallet({ phrase, password, id, name })} /> ) } diff --git a/src/renderer/views/wallet/WalletSettingsView.tsx b/src/renderer/views/wallet/WalletSettingsView.tsx index 9ce71b46b..a475cbb6c 100644 --- a/src/renderer/views/wallet/WalletSettingsView.tsx +++ b/src/renderer/views/wallet/WalletSettingsView.tsx @@ -49,8 +49,8 @@ import { } from '../../helpers/chainHelper' import { sequenceTOptionFromArray } from '../../helpers/fpHelpers' import { useCollapsedSetting } from '../../hooks/useCollapsedSetting' -import { useKeystoreAccounts } from '../../hooks/useKeystoreAccounts' import { useKeystoreState } from '../../hooks/useKeystoreState' +import { useKeystoreWallets } from '../../hooks/useKeystoreWallets' import { useLedger } from '../../hooks/useLedger' import { useNetwork } from '../../hooks/useNetwork' import * as walletRoutes from '../../routes/wallet' @@ -67,7 +67,7 @@ export const WalletSettingsView: React.FC = (): JSX.Element => { keystoreService: { exportKeystore, validatePassword$ } } = useWalletContext() - const { accountsUI } = useKeystoreAccounts() + const { walletsUI } = useKeystoreWallets() const { state: keystore, lock, remove } = useKeystoreState() @@ -418,7 +418,7 @@ export const WalletSettingsView: React.FC = (): JSX.Element => { verifyLedgerAddress={verifyLedgerAddressHandler} removeLedgerAddress={removeLedgerAddressHandler} keystore={keystore} - keystoreAccounts={accountsUI} + keystoreWallets={walletsUI} walletAccounts={walletAccounts} clickAddressLinkHandler={clickAddressLinkHandler} validatePassword$={validatePassword$} diff --git a/src/renderer/views/wallet/importsView/ImportsView.tsx b/src/renderer/views/wallet/importsView/ImportsView.tsx index 3811aaeab..07d70c9c8 100644 --- a/src/renderer/views/wallet/importsView/ImportsView.tsx +++ b/src/renderer/views/wallet/importsView/ImportsView.tsx @@ -26,7 +26,7 @@ export const ImportsView: React.FC = (): JSX.Element => { const location = useLocation() const { keystoreService } = useWalletContext() - const { importKeystore, loadKeystore$, addKeystoreAccount, importingKeystoreState$, resetImportingKeystoreState } = + const { importKeystore, loadKeystore$, addKeystoreWallet, importingKeystoreState$, resetImportingKeystoreState } = keystoreService const { clientStates } = useKeystoreClientStates() @@ -76,10 +76,10 @@ export const ImportsView: React.FC = (): JSX.Element => { {intl.formatMessage({ id: 'common.phrase' })} ), - content: + content: } ], - [intl, walletId, loadKeystore$, importKeystore, importingKeystoreState, clientStates, addKeystoreAccount, navigate] + [intl, walletId, loadKeystore$, importKeystore, importingKeystoreState, clientStates, addKeystoreWallet, navigate] ) const matchKeystorePath = useMatch({ path: walletRoutes.imports.keystore.path(), end: false }) const matchPhrasePath = useMatch({ path: walletRoutes.imports.phrase.path(), end: false }) diff --git a/src/shared/api/io.ts b/src/shared/api/io.ts index 1c8671d3f..51996d795 100644 --- a/src/shared/api/io.ts +++ b/src/shared/api/io.ts @@ -190,14 +190,7 @@ export const keystoreIO = new t.Type( t.identity ) -/** - * `Keystore` type - * As same as `Keystore - * @see https://github.com/xchainjs/xchainjs-lib/blob/master/packages/xchain-crypto/src/crypto.ts#L17-L39 - */ -// export type Keystore = ReturnType - -export const ipcKeystoreAccountIO = t.type({ +export const ipcKeystoreWalletIO = t.type({ id: t.number, name: t.string, selected: t.boolean, @@ -205,13 +198,13 @@ export const ipcKeystoreAccountIO = t.type({ }) /** - * Keystore Account + * Keystore Wallet * Created by users by importing or creating keystores in `Wallet` section */ -export type KeystoreAccount = ReturnType +export type KeystoreWallet = ReturnType -export const ipcKeystoreAccountsIO = t.array(ipcKeystoreAccountIO) +export const ipcKeystoreWalletsIO = t.array(ipcKeystoreWalletIO) -export type IPCKeystoreAccounts = t.TypeOf +export type IPCKeystoreWallets = t.TypeOf -export type KeystoreAccounts = ReturnType +export type KeystoreWallets = ReturnType diff --git a/src/shared/api/types.ts b/src/shared/api/types.ts index d2b733fc9..8e86f6afd 100644 --- a/src/shared/api/types.ts +++ b/src/shared/api/types.ts @@ -9,7 +9,7 @@ import * as O from 'fp-ts/Option' import { EthDerivationMode } from '../ethereum/types' import { Locale } from '../i18n/types' import { WalletAddress } from '../wallet/types' -import { KeystoreAccounts, PoolsStorageEncoded } from './io' +import { KeystoreWallets, PoolsStorageEncoded } from './io' // A version number starting from `1` to avoid to load deprecated files export type StorageVersion = { version: string } @@ -37,9 +37,9 @@ export type IPCExportKeystoreParams = { fileName: string; keystore: Keystore } export type IPCSaveKeystoreParams = { id: KeystoreId; keystore: Keystore } export type ApiKeystore = { - saveKeystoreAccounts: (accounts: KeystoreAccounts) => Promise + saveKeystoreWallets: (wallets: KeystoreWallets) => Promise exportKeystore: (params: IPCExportKeystoreParams) => Promise - initKeystoreAccounts: () => Promise> + initKeystoreWallets: () => Promise> load: () => Promise } diff --git a/src/shared/mock/api.ts b/src/shared/mock/api.ts index 329b96c90..41fb3acee 100644 --- a/src/shared/mock/api.ts +++ b/src/shared/mock/api.ts @@ -8,10 +8,10 @@ import { MOCK_KEYSTORE } from './wallet' // Mock "empty" `apiKeystore` export const apiKeystore: ApiKeystore = { - saveKeystoreAccounts: (_) => Promise.resolve(), + saveKeystoreWallets: (_) => Promise.resolve(), exportKeystore: (_: IPCExportKeystoreParams) => Promise.resolve(), load: () => Promise.resolve(MOCK_KEYSTORE), - initKeystoreAccounts: () => Promise.resolve(E.right([])) + initKeystoreWallets: () => Promise.resolve(E.right([])) } // Mock `apiLang`