-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathstorage.ts
More file actions
135 lines (131 loc) · 5.13 KB
/
Copy pathstorage.ts
File metadata and controls
135 lines (131 loc) · 5.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import { MagicLinkKeys, SessionKeys } from '@/controllers/emailVault/emailVault'
import { Contacts } from '@/interfaces/addressBook'
import { EmailVaultData } from '@/interfaces/emailVault'
import { FeatureFlags } from '../consts/featureFlags'
import { SentToHistory, SignedMessage } from '../controllers/activity/types'
import { SubmittedAccountOp, SubmittedAccountOpLike } from '../libs/accountOp/submittedAccountOp'
import { NetworksWithPositionsByAccounts } from '../libs/defiPositions/types'
import { CustomToken, TokenPreference } from '../libs/portfolio/customToken'
import {
AccountAssetsState as PortfolioAccountAssetsState,
LearnedAssets,
PreviousHintsStorage,
TokenBlacklist
} from '../libs/portfolio/interfaces'
import { Account, AccountId, AccountPreferences } from './account'
import { AutoLoginPoliciesByAccount, AutoLoginSettings } from './autoLogin'
import { Selectors } from './contractInfo'
import { ControllerInterface } from './controller'
import { Dapp, RecentDappEntry } from './dapp'
import { Domains } from './domains'
import { Key, MainKeyEncryptedWithSecret, StoredKey, StoredKeystoreSeed } from './keystore'
import { Network } from './network'
import { SwapAndBridgeActiveRoute } from './swapAndBridge'
export type IStorageController = ControllerInterface<
InstanceType<typeof import('../controllers/storage/storage').StorageController>
>
export type StorageProps = {
// Onboarding
invite: object
isSetupComplete: boolean
onboardingState: object
termsState: object
themeType: string
avatarType: string
logLevel: string
crashAnalyticsEnabledV2: boolean
autoLockTime: number
// Activity
accountsOps: { [key: string]: { [key: string]: SubmittedAccountOp[] } }
externalAccountOps: { [key: string]: { [key: string]: SubmittedAccountOpLike[] } }
signedMessages: { [key: AccountId]: SignedMessage[] }
sentToHistory: SentToHistory
// Migrations
passedMigrations: string[]
migrations: string[]
// Keystore
keyStoreUid: string | null
keystoreSecrets: MainKeyEncryptedWithSecret[]
keyPreferences: { addr: Key['addr']; type: Key['type']; label: string }[]
keystoreKeys: StoredKey[]
keystoreSeeds: StoredKeystoreSeed[]
// Dapps
dappsV2: Dapp[]
dapps: Dapp[]
recentDapps: RecentDappEntry[]
// Selected account
dismissedBanners: (string | number)[]
selectedAccount: string | null
selectedAccountDismissedBannerIds: { [key: string]: string[] }
// Email vault
emailVault: {
email: { [email: string]: EmailVaultData }
criticalError?: Error
errors?: Error[]
}
sessionKeys: SessionKeys
magicLinkKeys: MagicLinkKeys
emailVaultSetupBannerDismissedAt: number
// Portfolio
tokenBlacklist: TokenBlacklist
learnedAssets: LearnedAssets
networksWithAssetsByAccount: { [accountId: string]: PortfolioAccountAssetsState }
networksWithPositionsByAccounts: NetworksWithPositionsByAccounts
tokenPreferences: TokenPreference[]
customTokens: CustomToken[]
previousHints: PreviousHintsStorage
// Auto login
autoLoginPolicies: AutoLoginPoliciesByAccount
autoLoginSettings: AutoLoginSettings
// Address book
contacts: Contacts
// Safe
automaticallyResolvedSafeTxns: { nonce: bigint; txnIds: string[] }[]
rejectedSafeTxns: string[]
// Other
signAccountOpFeeTokenPreference: {
[chainId: string]: string | 'gasTank'
}
networks: { [key: string]: Network }
accounts: Account[]
networkPreferences: { [key: string]: Partial<Network> }
accountPreferences: { [key: AccountId]: AccountPreferences }
lastDappsUpdateVersion: string | null
isPinned: boolean
isPrivacyModeEnabled: boolean
isSidePanelModeEnabled: boolean
phishing: {
version: number
updatedAt: number
domains: string[]
addresses: string[]
}
swapAndBridgeActiveRoutes: SwapAndBridgeActiveRoute[]
// Persisted reverse ENS/Namoshi lookup cache, kept indefinitely so accounts
// don't need to be re-resolved after a service worker restart.
domainsCache: Domains
flags: Partial<FeatureFlags>
isDefaultWallet: boolean
shouldSkipTransactionQueuedModal: boolean
isBatchingEnabled: boolean
surveysRespondedTo: string[]
functionSelectors: Selectors
// Per-controller debug logging toggles. Only enabled ones are stored
debugLogNamespaces: Record<string, boolean>
}
export interface Storage {
// These typescript gymnastics are needed so:
// 1. A warning is shown if a defaultValue is not provided (can be undefined)
// 2. A warning is shown if a defaultValue is provided but is of the wrong type (can be StorageProps[K])
// 3. A warning is shown if a defaultValue is explicitly set to null (can be StorageProps[K] or null), but
// the same warning is not shown if a correct default value is provided
get<K extends keyof StorageProps>(key: K): Promise<StorageProps[K] | undefined>
get<K extends keyof StorageProps>(key: K, defaultValue: StorageProps[K]): Promise<StorageProps[K]>
get<K extends keyof StorageProps>(key: K, defaultValue: null): Promise<StorageProps[K] | null>
get<K extends keyof StorageProps>(
key: K,
defaultValue?: StorageProps[K] | null
): Promise<StorageProps[K] | null | undefined>
set(key: string, value: any): Promise<null>
remove(key: string): Promise<null>
}