|
1 | | -import React, { useCallback, useMemo } from 'react' |
| 1 | +import { useCallback, useMemo } from 'react' |
2 | 2 |
|
3 | | -import { UseToastsReturnType } from '../toasts' |
4 | | -import { UseStorageProps, UseStorageReturnType } from '../useStorage' |
5 | | - |
6 | | -export type onAddAccountOptions = { |
7 | | - shouldRedirect?: boolean |
8 | | - isNew?: boolean |
9 | | - select?: boolean |
10 | | -} |
11 | | - |
12 | | -export type Account = { |
13 | | - baseIdentityAddr: string |
14 | | - bytecode: string |
15 | | - email: string |
16 | | - id: string |
17 | | - identityFactoryAddr: string |
18 | | - primaryKeyBackup: string |
19 | | - salt: string |
20 | | - signer: { |
21 | | - one: string |
22 | | - quickAccManager: string |
23 | | - timelock: number |
24 | | - two: string |
25 | | - // Sometimes passed as an extra prop |
26 | | - address?: string |
27 | | - } |
28 | | -} |
29 | | - |
30 | | -export interface UseAccountsProps { |
31 | | - onAdd: (opts: onAddAccountOptions) => void |
32 | | - onRemoveLastAccount: () => void |
33 | | - useStorage: (p: Omit<UseStorageProps, 'storage'>) => UseStorageReturnType |
34 | | - useToasts: () => UseToastsReturnType |
35 | | -} |
36 | | - |
37 | | -export interface UseAccountsReturnType { |
38 | | - accounts: Account[] |
39 | | - account: Account | {} |
40 | | - selectedAcc: string |
41 | | - onSelectAcc: (accountId: Account['id']) => void |
42 | | - onAddAccount: (acc: Account, opts: onAddAccountOptions) => void |
43 | | - onRemoveAccount: (accountId: Account['id']) => void |
44 | | -} |
| 3 | +import { Account, OnAddAccountOptions, UseAccountsProps, UseAccountsReturnType } from './types' |
45 | 4 |
|
46 | 5 | export default function useAccounts({ |
47 | 6 | onAdd, |
@@ -84,7 +43,7 @@ export default function useAccounts({ |
84 | 43 | ) |
85 | 44 |
|
86 | 45 | const onAddAccount = useCallback( |
87 | | - (acc: Account, _opts: onAddAccountOptions = {}) => { |
| 46 | + (acc: Account, _opts: OnAddAccountOptions = {}) => { |
88 | 47 | const opts = { shouldRedirect: true, ..._opts } |
89 | 48 |
|
90 | 49 | if (!(acc.id && acc.signer)) throw new Error('account: internal err: missing ID or signer') |
|
0 commit comments