Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 22 additions & 32 deletions src/interfaces/account.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,28 @@
import { STATUS_WRAPPED_METHODS } from '../consts/account'
import { IEventEmitter, Statuses } from './eventEmitter'
import { ControllerInterface } from './controller'
import { Hex } from './hex'
import { Network } from './network'

export interface IAccountsController extends IEventEmitter {
accounts: Account[]
accountStates: AccountStates
accountStatesLoadingState: {
[chainId: string]: Promise<AccountOnchainState[]> | undefined
}
statuses: Statuses<keyof typeof STATUS_WRAPPED_METHODS>
initialLoadPromise: Promise<void>
updateAccountStates(
selectedAccountAddr: string | undefined,
blockTag: string | number,
networks: bigint[]
): Promise<void>
updateAccountState(
accountAddr: Account['addr'],
blockTag?: 'pending' | 'latest',
networks?: bigint[]
): Promise<void>
addAccounts(accounts?: Account[]): Promise<void>
removeAccountData(address: Account['addr']): void
updateAccountPreferences(
accounts: { addr: string; preferences: AccountPreferences }[]
): Promise<void>
reorderAccounts({ fromIndex, toIndex }: { fromIndex: number; toIndex: number }): Promise<void>
areAccountStatesLoading: boolean
getOrFetchAccountStates(addr: string): Promise<{ [chainId: string]: AccountOnchainState }>
getOrFetchAccountOnChainState(addr: string, chainId: bigint): Promise<AccountOnchainState>
resetAccountsNewlyAddedState(): void
forceFetchPendingState(addr: string, chainId: bigint): Promise<AccountOnchainState>
}
export type IAccountsController = ControllerInterface<
import('../controllers/accounts/accounts').AccountsController,
// Public properties
| 'accounts'
| 'accountStates'
| 'accountStatesLoadingState'
| 'statuses'
| 'initialLoadPromise'
| 'areAccountStatesLoading'
// Public methods
| 'updateAccountStates'
| 'updateAccountState'
| 'addAccounts'
| 'removeAccountData'
| 'updateAccountPreferences'
| 'reorderAccounts'
| 'getOrFetchAccountStates'
| 'getOrFetchAccountOnChainState'
| 'resetAccountsNewlyAddedState'
| 'forceFetchPendingState'
>

export type AccountId = string

Expand Down
132 changes: 49 additions & 83 deletions src/interfaces/accountPicker.ts
Original file line number Diff line number Diff line change
@@ -1,84 +1,50 @@
import { HD_PATH_TEMPLATE_TYPE } from '../consts/derivation'
import { Account, AccountOnPage, SelectedAccountForImport } from './account'
import { IEventEmitter } from './eventEmitter'
import { KeyIterator } from './keyIterator'
import { ReadyToAddKeys } from './keystore'
import { ControllerInterface } from './controller'

export interface IAccountPickerController extends IEventEmitter {
// initParams: {
// keyIterator: KeyIterator | null
// hdPathTemplate: HD_PATH_TEMPLATE_TYPE
// page?: number
// pageSize?: number
// shouldSearchForLinkedAccounts?: boolean
// shouldGetAccountsUsedOnNetworks?: boolean
// shouldAddNextAccountAutomatically?: boolean
// } | null
keyIterator?: KeyIterator | null
hdPathTemplate?: HD_PATH_TEMPLATE_TYPE
isInitialized: boolean
shouldSearchForLinkedAccounts: boolean
shouldGetAccountsUsedOnNetworks: boolean
shouldAddNextAccountAutomatically: boolean
page: number
pageSize: number
pageError: null | string
selectedAccountsFromCurrentSession: SelectedAccountForImport[]
readyToAddAccounts: Account[]
readyToRemoveAccounts: Account[]
readyToAddKeys: ReadyToAddKeys
addAccountsStatus: 'LOADING' | 'SUCCESS' | 'INITIAL'
selectNextAccountStatus: 'LOADING' | 'SUCCESS' | 'INITIAL'
accountsLoading: boolean
linkedAccountsLoading: boolean
networksWithAccountStateError: bigint[]
addAccountsPromise?: Promise<void>
findAndSetLinkedAccountsPromise?: Promise<void>
accountsOnPage: AccountOnPage[]
allKeysOnPage: string[]
selectedAccounts: SelectedAccountForImport[]
addedAccountsFromCurrentSession: Account[]
setInitParams: (params: {
keyIterator: KeyIterator | null
hdPathTemplate: HD_PATH_TEMPLATE_TYPE
page?: number
pageSize?: number
shouldSearchForLinkedAccounts?: boolean
shouldGetAccountsUsedOnNetworks?: boolean
shouldAddNextAccountAutomatically?: boolean
}) => void
init: () => void
type: 'internal' | 'trezor' | 'ledger' | 'lattice' | undefined
subType: 'seed' | 'private-key' | 'hw' | undefined
reset: (resetInitParams?: boolean) => Promise<void>
resetAccountsSelection: () => void
setHDPathTemplate: ({
hdPathTemplate
}: {
hdPathTemplate: HD_PATH_TEMPLATE_TYPE
}) => Promise<void>
selectAccount: (account: Account) => void
deselectAccount: (account: Account) => void
retrieveInternalKeysOfSelectedAccounts: (
internalKeys: {
addr: string
type: 'internal'
label: string
privateKey: string
dedicatedToOneSA: boolean
meta: {
createdAt: number
}
}[]
) => void
isPageLocked: boolean
setPage: (params: {
page: number
pageSize?: number
shouldSearchForLinkedAccounts?: boolean
shouldGetAccountsUsedOnNetworks?: boolean
}) => Promise<void>
addAccounts: (accounts?: SelectedAccountForImport[]) => Promise<void>
selectNextAccount: () => Promise<void>
removeNetworkData(chainId: bigint): void
}
export type IAccountPickerController = ControllerInterface<
import('../controllers/accountPicker/accountPicker').AccountPickerController,
// Public properties
| 'initParams'
| 'keyIterator'
| 'hdPathTemplate'
| 'isInitialized'
| 'shouldSearchForLinkedAccounts'
| 'shouldGetAccountsUsedOnNetworks'
| 'shouldAddNextAccountAutomatically'
| 'page'
| 'pageSize'
| 'pageError'
| 'selectedAccountsFromCurrentSession'
| 'readyToAddAccounts'
| 'readyToRemoveAccounts'
| 'readyToAddKeys'
| 'addAccountsStatus'
| 'selectNextAccountStatus'
| 'accountsLoading'
| 'linkedAccountsLoading'
| 'networksWithAccountStateError'
| 'addAccountsPromise'
| 'findAndSetLinkedAccountsPromise'
// Public getters
| 'accountsOnPage'
| 'allKeysOnPage'
| 'selectedAccounts'
| 'addedAccountsFromCurrentSession'
| 'type'
| 'subType'
| 'isPageLocked'
// Public methods
| 'setInitParams'
| 'init'
| 'reset'
| 'resetAccountsSelection'
| 'setHDPathTemplate'
| 'selectAccount'
| 'deselectAccount'
| 'retrieveInternalKeysOfSelectedAccounts'
| 'setPage'
| 'addAccounts'
| 'selectNextAccount'
| 'createAndAddEmailAccount'
| 'addExistingEmailAccounts'
| 'removeNetworkData'
>
22 changes: 22 additions & 0 deletions src/interfaces/controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { IEventEmitter } from './eventEmitter'

/**
* Utility type for creating controller interfaces from class implementations.
* This eliminates the need for manual interface synchronization.
*
* @template ControllerClass - The controller class implementation
* @template PublicMembers - Union of public property/method names to expose
*/
export type ControllerInterface<
ControllerClass,
PublicMembers extends keyof ControllerClass
> = Pick<ControllerClass, PublicMembers> & IEventEmitter

/**
* Example usage:
*
* export type IMyController = ControllerInterface<
* import('../controllers/my/my').MyController,
* 'property1' | 'property2' | 'method1' | 'method2'
* >
*/