@unisat/wallet-state 1.0.5 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +0 -5
- package/lib/actions/global.d.ts +2 -0
- package/lib/actions/global.d.ts.map +1 -0
- package/lib/context/ApprovalContext.d.ts +9 -0
- package/lib/context/ApprovalContext.d.ts.map +1 -0
- package/lib/context/DeviceContext.d.ts +17 -0
- package/lib/context/DeviceContext.d.ts.map +1 -0
- package/lib/context/I18nContext.d.ts +13 -0
- package/lib/context/I18nContext.d.ts.map +1 -0
- package/lib/context/NavigationContext.d.ts +218 -0
- package/lib/context/NavigationContext.d.ts.map +1 -0
- package/lib/context/PriceContext.d.ts +13 -0
- package/lib/context/PriceContext.d.ts.map +1 -0
- package/lib/context/StorageContext.d.ts +60 -0
- package/lib/context/StorageContext.d.ts.map +1 -0
- package/lib/context/ToolsContext.d.ts +17 -0
- package/lib/context/ToolsContext.d.ts.map +1 -0
- package/lib/context/WalletContext.d.ts +493 -0
- package/lib/context/WalletContext.d.ts.map +1 -0
- package/lib/context/index.d.ts +9 -0
- package/lib/context/index.d.ts.map +1 -0
- package/lib/hooks/accounts.d.ts +34 -0
- package/lib/hooks/accounts.d.ts.map +1 -0
- package/lib/hooks/base.d.ts +14 -0
- package/lib/hooks/base.d.ts.map +1 -0
- package/lib/hooks/browser.d.ts +32 -0
- package/lib/hooks/browser.d.ts.map +1 -0
- package/lib/hooks/discovery.d.ts +17 -0
- package/lib/hooks/discovery.d.ts.map +1 -0
- package/lib/hooks/global.d.ts +43 -0
- package/lib/hooks/global.d.ts.map +1 -0
- package/lib/hooks/index.d.ts +10 -0
- package/lib/hooks/index.d.ts.map +1 -0
- package/lib/hooks/keyrings.d.ts +5 -0
- package/lib/hooks/keyrings.d.ts.map +1 -0
- package/lib/hooks/settings.d.ts +43 -0
- package/lib/hooks/settings.d.ts.map +1 -0
- package/lib/hooks/transactions.d.ts +67 -0
- package/lib/hooks/transactions.d.ts.map +1 -0
- package/lib/hooks/ui.d.ts +112 -0
- package/lib/hooks/ui.d.ts.map +1 -0
- package/lib/index.d.mts +2072 -199
- package/lib/index.d.ts +31 -946
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +7176 -582
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +6971 -525
- package/lib/index.mjs.map +1 -1
- package/lib/reducers/accounts.d.ts +49 -0
- package/lib/reducers/accounts.d.ts.map +1 -0
- package/lib/reducers/browser.d.ts +49 -0
- package/lib/reducers/browser.d.ts.map +1 -0
- package/lib/reducers/discovery.d.ts +22 -0
- package/lib/reducers/discovery.d.ts.map +1 -0
- package/lib/reducers/global.d.ts +35 -0
- package/lib/reducers/global.d.ts.map +1 -0
- package/lib/reducers/index.d.ts +9 -0
- package/lib/reducers/index.d.ts.map +1 -0
- package/lib/reducers/keyrings.d.ts +10 -0
- package/lib/reducers/keyrings.d.ts.map +1 -0
- package/lib/reducers/settings.d.ts +16 -0
- package/lib/reducers/settings.d.ts.map +1 -0
- package/lib/reducers/transactions.d.ts +61 -0
- package/lib/reducers/transactions.d.ts.map +1 -0
- package/lib/reducers/ui.d.ts +55 -0
- package/lib/reducers/ui.d.ts.map +1 -0
- package/lib/types/index.d.mts +7 -3
- package/lib/types/index.d.ts +3 -30
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +7 -1
- package/lib/types/index.js.map +1 -1
- package/lib/types/index.mjs +7 -2
- package/lib/types/index.mjs.map +1 -1
- package/lib/types/ui.d.ts +31 -0
- package/lib/types/ui.d.ts.map +1 -0
- package/lib/ui-hooks/index.d.ts +55 -0
- package/lib/ui-hooks/index.d.ts.map +1 -0
- package/lib/ui-hooks/useActionOverviewSectionLogic.d.ts +12 -0
- package/lib/ui-hooks/useActionOverviewSectionLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useAddressTypeScreenLogic.d.ts +19 -0
- package/lib/ui-hooks/useAddressTypeScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useAlkanesBalanceCardLogic.d.ts +19 -0
- package/lib/ui-hooks/useAlkanesBalanceCardLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useAlkanesCollectionListLogic.d.ts +11 -0
- package/lib/ui-hooks/useAlkanesCollectionListLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useAlkanesListLogic.d.ts +14 -0
- package/lib/ui-hooks/useAlkanesListLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useAlkanesNFTListLogic.d.ts +11 -0
- package/lib/ui-hooks/useAlkanesNFTListLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useAlkanesNFTScreenLogic.d.ts +9 -0
- package/lib/ui-hooks/useAlkanesNFTScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useAlkanesTokenScreenLogic.d.ts +22 -0
- package/lib/ui-hooks/useAlkanesTokenScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useAmountInputLogic.d.ts +22 -0
- package/lib/ui-hooks/useAmountInputLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useAnnouncementCardLogic.d.ts +11 -0
- package/lib/ui-hooks/useAnnouncementCardLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useBRC20BalanceCardLogic.d.ts +26 -0
- package/lib/ui-hooks/useBRC20BalanceCardLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useBRC20InscribeTransferLogic.d.ts +103 -0
- package/lib/ui-hooks/useBRC20InscribeTransferLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useBRC20ListLogic.d.ts +14 -0
- package/lib/ui-hooks/useBRC20ListLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useBRC20ProgListLogic.d.ts +14 -0
- package/lib/ui-hooks/useBRC20ProgListLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useBRC20SendScreenLogic.d.ts +67 -0
- package/lib/ui-hooks/useBRC20SendScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useBRC20SingleStepScreenLogic.d.ts +36 -0
- package/lib/ui-hooks/useBRC20SingleStepScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useBRC20TokenScreenLogic.d.ts +75 -0
- package/lib/ui-hooks/useBRC20TokenScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useBalanceCardLogic.d.ts +26 -0
- package/lib/ui-hooks/useBalanceCardLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useBtcDisplayLogic.d.ts +5 -0
- package/lib/ui-hooks/useBtcDisplayLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useCAT20BalanceCardLogic.d.ts +20 -0
- package/lib/ui-hooks/useCAT20BalanceCardLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useCAT20ListLogic.d.ts +14 -0
- package/lib/ui-hooks/useCAT20ListLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useCAT20TokenScreenLogic.d.ts +19 -0
- package/lib/ui-hooks/useCAT20TokenScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useCAT721ListLogic.d.ts +11 -0
- package/lib/ui-hooks/useCAT721ListLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useCAT721NFTScreenLogic.d.ts +9 -0
- package/lib/ui-hooks/useCAT721NFTScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useCreatePasswordScreenLogic.d.ts +27 -0
- package/lib/ui-hooks/useCreatePasswordScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useCreateWalletLogicImportWordsStep.d.ts +78 -0
- package/lib/ui-hooks/useCreateWalletLogicImportWordsStep.d.ts.map +1 -0
- package/lib/ui-hooks/useEditAccountNameScreenLogic.d.ts +18 -0
- package/lib/ui-hooks/useEditAccountNameScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useEditContactScreenLogic.d.ts +24 -0
- package/lib/ui-hooks/useEditContactScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useEditWalletNameScreenLogic.d.ts +15 -0
- package/lib/ui-hooks/useEditWalletNameScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useExportMnemonicsScreenLogic.d.ts +18 -0
- package/lib/ui-hooks/useExportMnemonicsScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useExportPrivateKeyScreenLogic.d.ts +17 -0
- package/lib/ui-hooks/useExportPrivateKeyScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useFeeRateBarLogic.d.ts +34 -0
- package/lib/ui-hooks/useFeeRateBarLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useInfiniteList.d.ts +19 -0
- package/lib/ui-hooks/useInfiniteList.d.ts.map +1 -0
- package/lib/ui-hooks/useInscriptionListLogic.d.ts +11 -0
- package/lib/ui-hooks/useInscriptionListLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useLockTimePageLogic.d.ts +11 -0
- package/lib/ui-hooks/useLockTimePageLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useNotificationsLogic.d.ts +14 -0
- package/lib/ui-hooks/useNotificationsLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useOrdinalsInscriptionScreenLogic.d.ts +27 -0
- package/lib/ui-hooks/useOrdinalsInscriptionScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useRunesBalanceCardLogic.d.ts +19 -0
- package/lib/ui-hooks/useRunesBalanceCardLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useRunesListLogic.d.ts +14 -0
- package/lib/ui-hooks/useRunesListLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useRunesTokenScreenLogic.d.ts +22 -0
- package/lib/ui-hooks/useRunesTokenScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useSecurityCardLogic.d.ts +1 -0
- package/lib/ui-hooks/useSecurityCardLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useSendAlkanesNFTScreenLogic.d.ts +32 -0
- package/lib/ui-hooks/useSendAlkanesNFTScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useSendAlkanesScreenLogic.d.ts +37 -0
- package/lib/ui-hooks/useSendAlkanesScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useSendCAT20ScreenLogic.d.ts +44 -0
- package/lib/ui-hooks/useSendCAT20ScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useSendCAT721ScreenLogic.d.ts +40 -0
- package/lib/ui-hooks/useSendCAT721ScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useSendOrdinalsInscriptionScreenLogic.d.ts +22 -0
- package/lib/ui-hooks/useSendOrdinalsInscriptionScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useSendRunesScreenLogic.d.ts +30 -0
- package/lib/ui-hooks/useSendRunesScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useSettingsTabScreenLogic.d.ts +72 -0
- package/lib/ui-hooks/useSettingsTabScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useSignMessageLogic.d.ts +54 -0
- package/lib/ui-hooks/useSignMessageLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useSignPsbtLogic.d.ts +82 -0
- package/lib/ui-hooks/useSignPsbtLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useSplitOrdinalsInscriptionScreenLogic.d.ts +15 -0
- package/lib/ui-hooks/useSplitOrdinalsInscriptionScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useTxConfirmScreenLogic.d.ts +8 -0
- package/lib/ui-hooks/useTxConfirmScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useTxCreateScreenLogic.d.ts +28 -0
- package/lib/ui-hooks/useTxCreateScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useTxFailScreenLogic.d.ts +7 -0
- package/lib/ui-hooks/useTxFailScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useTxSuccessScreenLogic.d.ts +8 -0
- package/lib/ui-hooks/useTxSuccessScreenLogic.d.ts.map +1 -0
- package/lib/updater/accounts.d.ts +2 -0
- package/lib/updater/accounts.d.ts.map +1 -0
- package/lib/updater/index.d.ts +2 -0
- package/lib/updater/index.d.ts.map +1 -0
- package/lib/utils/bitcoin-utils.d.ts +7 -0
- package/lib/utils/bitcoin-utils.d.ts.map +1 -0
- package/lib/utils/eventBus.d.ts +12 -0
- package/lib/utils/eventBus.d.ts.map +1 -0
- package/lib/utils/password-utils.d.ts +12 -0
- package/lib/utils/password-utils.d.ts.map +1 -0
- package/lib/utils/ui-utils.d.ts +4 -0
- package/lib/utils/ui-utils.d.ts.map +1 -0
- package/package.json +19 -15
- package/src/.DS_Store +0 -0
- package/src/context/ApprovalContext.tsx +27 -0
- package/src/context/DeviceContext.tsx +36 -0
- package/src/context/I18nContext.tsx +14 -172
- package/src/context/NavigationContext.tsx +305 -0
- package/src/context/PriceContext.tsx +2 -2
- package/src/context/StorageContext.tsx +393 -0
- package/src/context/ToolsContext.tsx +50 -0
- package/src/context/WalletContext.tsx +170 -126
- package/src/context/index.ts +17 -2
- package/src/hooks/accounts.ts +11 -5
- package/src/hooks/browser.ts +11 -0
- package/src/hooks/global.ts +170 -7
- package/src/hooks/index.ts +1 -2
- package/src/hooks/settings.ts +38 -37
- package/src/hooks/transactions.ts +45 -151
- package/src/hooks/ui.ts +239 -35
- package/src/index.ts +33 -24
- package/src/reducers/accounts.ts +22 -2
- package/src/reducers/browser.ts +223 -0
- package/src/reducers/global.ts +67 -1
- package/src/reducers/index.ts +1 -0
- package/src/reducers/transactions.ts +0 -9
- package/src/reducers/ui.ts +144 -4
- package/src/types/index.ts +1 -1
- package/src/types/ui.ts +6 -1
- package/src/ui-hooks/index.ts +107 -0
- package/src/ui-hooks/useActionOverviewSectionLogic.ts +150 -0
- package/src/ui-hooks/useAddressTypeScreenLogic.ts +160 -0
- package/src/ui-hooks/useAlkanesBalanceCardLogic.ts +41 -0
- package/src/ui-hooks/useAlkanesCollectionListLogic.ts +68 -0
- package/src/ui-hooks/useAlkanesListLogic.ts +69 -0
- package/src/ui-hooks/useAlkanesNFTListLogic.ts +42 -0
- package/src/ui-hooks/useAlkanesNFTScreenLogic.ts +45 -0
- package/src/ui-hooks/useAlkanesTokenScreenLogic.ts +138 -0
- package/src/ui-hooks/useAmountInputLogic.ts +80 -0
- package/src/ui-hooks/useAnnouncementCardLogic.ts +91 -0
- package/src/ui-hooks/useBRC20BalanceCardLogic.ts +115 -0
- package/src/ui-hooks/useBRC20InscribeTransferLogic.ts +418 -0
- package/src/ui-hooks/useBRC20ListLogic.ts +79 -0
- package/src/ui-hooks/useBRC20ProgListLogic.ts +81 -0
- package/src/ui-hooks/useBRC20SendScreenLogic.ts +424 -0
- package/src/ui-hooks/useBRC20SingleStepScreenLogic.ts +208 -0
- package/src/ui-hooks/useBRC20TokenScreenLogic.ts +489 -0
- package/src/ui-hooks/useBalanceCardLogic.ts +164 -0
- package/src/ui-hooks/useBtcDisplayLogic.ts +16 -0
- package/src/ui-hooks/useCAT20BalanceCardLogic.ts +35 -0
- package/src/ui-hooks/useCAT20ListLogic.ts +83 -0
- package/src/ui-hooks/useCAT20TokenScreenLogic.ts +127 -0
- package/src/ui-hooks/useCAT721ListLogic.ts +68 -0
- package/src/ui-hooks/useCAT721NFTScreenLogic.ts +37 -0
- package/src/ui-hooks/useCreatePasswordScreenLogic.ts +92 -0
- package/src/ui-hooks/useCreateWalletLogicImportWordsStep.ts +299 -0
- package/src/ui-hooks/useEditAccountNameScreenLogic.ts +71 -0
- package/src/ui-hooks/useEditContactScreenLogic.ts +162 -0
- package/src/ui-hooks/useEditWalletNameScreenLogic.ts +60 -0
- package/src/ui-hooks/useExportMnemonicsScreenLogic.ts +75 -0
- package/src/ui-hooks/useExportPrivateKeyScreenLogic.ts +64 -0
- package/src/ui-hooks/useFeeRateBarLogic.ts +303 -0
- package/src/ui-hooks/useInfiniteList.ts +85 -0
- package/src/ui-hooks/useInscriptionListLogic.ts +68 -0
- package/src/ui-hooks/useLockTimePageLogic.ts +43 -0
- package/src/ui-hooks/useNotificationsLogic.ts +115 -0
- package/src/ui-hooks/useOrdinalsInscriptionScreenLogic.ts +130 -0
- package/src/ui-hooks/useRunesBalanceCardLogic.ts +44 -0
- package/src/ui-hooks/useRunesListLogic.ts +74 -0
- package/src/ui-hooks/useRunesTokenScreenLogic.ts +156 -0
- package/src/ui-hooks/useSecurityCardLogic.ts +0 -0
- package/src/ui-hooks/useSendAlkanesNFTScreenLogic.ts +160 -0
- package/src/ui-hooks/useSendAlkanesScreenLogic.ts +208 -0
- package/src/ui-hooks/useSendCAT20ScreenLogic.ts +297 -0
- package/src/ui-hooks/useSendCAT721ScreenLogic.ts +205 -0
- package/src/ui-hooks/useSendOrdinalsInscriptionScreenLogic.ts +152 -0
- package/src/ui-hooks/useSendRunesScreenLogic.ts +189 -0
- package/src/ui-hooks/useSettingsTabScreenLogic.ts +211 -0
- package/src/ui-hooks/useSignMessageLogic.ts +302 -0
- package/src/ui-hooks/useSignPsbtLogic.ts +517 -0
- package/src/ui-hooks/useSplitOrdinalsInscriptionScreenLogic.ts +109 -0
- package/src/ui-hooks/useTxConfirmScreenLogic.ts +47 -0
- package/src/ui-hooks/useTxCreateScreenLogic.ts +177 -0
- package/src/ui-hooks/useTxFailScreenLogic.ts +26 -0
- package/src/ui-hooks/useTxSuccessScreenLogic.ts +33 -0
- package/src/updater/accounts.ts +11 -11
- package/src/utils/bitcoin-utils.ts +17 -8
- package/src/utils/eventBus.ts +2 -1
- package/src/utils/password-utils.ts +78 -0
- package/src/utils/ui-utils.ts +28 -0
- package/src/hooks/approval.ts +0 -72
- package/src/hooks/i18n.ts +0 -53
- package/src/utils/i18n.ts +0 -41
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
/* eslint-disable indent */
|
|
2
|
+
import { VersionDetail } from '@unisat/wallet-shared'
|
|
3
|
+
import React, { useContext } from 'react'
|
|
4
|
+
|
|
5
|
+
enum StorageType {
|
|
6
|
+
ENABLE_FACEID = 'FACEIDDEFAULT',
|
|
7
|
+
AUTO_LOCK_TIME = 'AutomaticLockTime',
|
|
8
|
+
ENABLE_EXPLORE = 'ENABLE_EXPLORE',
|
|
9
|
+
UTXO_MANAGE_VISITED = 'UTXO_MANAGE_VISITED',
|
|
10
|
+
BALANCE_HIDDEN = 'HIDE_BALANCE',
|
|
11
|
+
ANNOUNCEMENT_DISMISSED_IDS_KEY = '@announcement_dismissed_ids',
|
|
12
|
+
|
|
13
|
+
I18N_SAVED_LANG = 'i18nextLng',
|
|
14
|
+
|
|
15
|
+
WEB_SEARCH_HISTORY = 'historyList',
|
|
16
|
+
WEB_RISK_WARNING = 'RiskWarning',
|
|
17
|
+
|
|
18
|
+
UNBACKUP_KEYRINGS = 'unbackedup_keyrings',
|
|
19
|
+
|
|
20
|
+
VERSION_DETAIL = 'version_detail',
|
|
21
|
+
|
|
22
|
+
THEME_MODE = 'PREFERENCES',
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type AutoLockTime = {
|
|
26
|
+
id: number
|
|
27
|
+
time: number
|
|
28
|
+
label: string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type WebSearchHistoryItem = string
|
|
32
|
+
|
|
33
|
+
type WebRiskWarningItem = {
|
|
34
|
+
url: string
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const defaultVersionDetail: VersionDetail = {
|
|
38
|
+
version: '',
|
|
39
|
+
title: '',
|
|
40
|
+
changelogs: [],
|
|
41
|
+
notice: '',
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
type ThemeMode = 'light' | 'dark'
|
|
45
|
+
const defaultThemeMode = 'light'
|
|
46
|
+
|
|
47
|
+
export interface BaseStorageProvider {
|
|
48
|
+
// storage should json.parse value after get
|
|
49
|
+
get: (key: string) => Promise<any>
|
|
50
|
+
|
|
51
|
+
// storage should json.stringify value before set
|
|
52
|
+
set: (key: string, value: any) => Promise<void>
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface StorageContextType {
|
|
56
|
+
get: (key: string) => Promise<string>
|
|
57
|
+
set: (key: string, value: string) => Promise<void>
|
|
58
|
+
clear: () => Promise<void>
|
|
59
|
+
|
|
60
|
+
getAutomaticLockTime: () => Promise<AutoLockTime>
|
|
61
|
+
clearAutomaticLockTime: () => Promise<void>
|
|
62
|
+
|
|
63
|
+
getAnnouncementDismissedIds: () => Promise<string[]>
|
|
64
|
+
setAnnouncementDismissedIds: (ids: string[]) => Promise<void>
|
|
65
|
+
clearAnnouncementDismissedIds: () => Promise<void>
|
|
66
|
+
|
|
67
|
+
getI18nSavedLang: () => Promise<string>
|
|
68
|
+
setI18nSavedLang: (lang: string) => Promise<void>
|
|
69
|
+
clearI18nSavedLang: () => Promise<void>
|
|
70
|
+
|
|
71
|
+
getWebSearchHistory: () => Promise<WebSearchHistoryItem[]>
|
|
72
|
+
setWebSearchHistory: (history: WebSearchHistoryItem[]) => Promise<void>
|
|
73
|
+
clearWebSearchHistory: () => Promise<void>
|
|
74
|
+
|
|
75
|
+
getWebRiskWarning: () => Promise<WebRiskWarningItem[]>
|
|
76
|
+
setWebRiskWarning: (warnings: WebRiskWarningItem[]) => Promise<void>
|
|
77
|
+
clearWebRiskWarning: () => Promise<void>
|
|
78
|
+
|
|
79
|
+
getEnableExplore: () => Promise<boolean>
|
|
80
|
+
setEnableExplore: (enable: boolean) => Promise<void>
|
|
81
|
+
clearEnableExplore: () => Promise<void>
|
|
82
|
+
|
|
83
|
+
getUnbackupKeyringIds: () => Promise<string[]>
|
|
84
|
+
setUnbackupKeyringIds: (keyrings: string[]) => Promise<void>
|
|
85
|
+
clearUnbackupKeyringIds: () => Promise<void>
|
|
86
|
+
|
|
87
|
+
getEnableFaceId: () => Promise<boolean>
|
|
88
|
+
setEnableFaceId: (enable: boolean) => Promise<void>
|
|
89
|
+
clearEnableFaceId: () => Promise<void>
|
|
90
|
+
|
|
91
|
+
getBalanceHidden: () => Promise<boolean>
|
|
92
|
+
setBalanceHidden: (enable: boolean) => Promise<void>
|
|
93
|
+
clearBalanceHidden: () => Promise<void>
|
|
94
|
+
|
|
95
|
+
getVersionDetail: () => Promise<VersionDetail>
|
|
96
|
+
setVersionDetail: (detail: VersionDetail) => Promise<void>
|
|
97
|
+
clearVersionDetail: () => Promise<void>
|
|
98
|
+
|
|
99
|
+
getThemeMode: () => Promise<string>
|
|
100
|
+
setThemeMode: (mode: string) => Promise<void>
|
|
101
|
+
clearThemeMode: () => Promise<void>
|
|
102
|
+
|
|
103
|
+
getUtxoManageVisited: () => Promise<boolean>
|
|
104
|
+
setUtxoManageVisited: () => Promise<void>
|
|
105
|
+
clearUtxoManageVisited: () => Promise<void>
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const defaultContext: StorageContextType = {
|
|
109
|
+
async get(key: string) {
|
|
110
|
+
return ''
|
|
111
|
+
},
|
|
112
|
+
async set(key: string, content: string) {},
|
|
113
|
+
|
|
114
|
+
async clear() {},
|
|
115
|
+
|
|
116
|
+
async getAutomaticLockTime() {
|
|
117
|
+
return null
|
|
118
|
+
},
|
|
119
|
+
async clearAutomaticLockTime() {},
|
|
120
|
+
|
|
121
|
+
async getAnnouncementDismissedIds() {
|
|
122
|
+
return []
|
|
123
|
+
},
|
|
124
|
+
async setAnnouncementDismissedIds(ids: string[]) {},
|
|
125
|
+
async clearAnnouncementDismissedIds() {},
|
|
126
|
+
|
|
127
|
+
async getI18nSavedLang() {
|
|
128
|
+
return ''
|
|
129
|
+
},
|
|
130
|
+
async setI18nSavedLang(lang: string) {},
|
|
131
|
+
async clearI18nSavedLang() {},
|
|
132
|
+
|
|
133
|
+
async getWebSearchHistory() {
|
|
134
|
+
return []
|
|
135
|
+
},
|
|
136
|
+
async setWebSearchHistory(history: WebSearchHistoryItem[]) {},
|
|
137
|
+
async clearWebSearchHistory() {},
|
|
138
|
+
|
|
139
|
+
async getWebRiskWarning() {
|
|
140
|
+
return []
|
|
141
|
+
},
|
|
142
|
+
async setWebRiskWarning(warnings: WebRiskWarningItem[]) {},
|
|
143
|
+
async clearWebRiskWarning() {},
|
|
144
|
+
|
|
145
|
+
async getEnableExplore() {
|
|
146
|
+
return false
|
|
147
|
+
},
|
|
148
|
+
async setEnableExplore(enable: boolean) {},
|
|
149
|
+
async clearEnableExplore() {},
|
|
150
|
+
|
|
151
|
+
async getUnbackupKeyringIds() {
|
|
152
|
+
return []
|
|
153
|
+
},
|
|
154
|
+
async setUnbackupKeyringIds(keyringIds: string[]) {},
|
|
155
|
+
async clearUnbackupKeyringIds() {},
|
|
156
|
+
|
|
157
|
+
async getEnableFaceId() {
|
|
158
|
+
return false
|
|
159
|
+
},
|
|
160
|
+
async setEnableFaceId(enable: boolean) {},
|
|
161
|
+
async clearEnableFaceId() {},
|
|
162
|
+
|
|
163
|
+
async getBalanceHidden() {
|
|
164
|
+
return false
|
|
165
|
+
},
|
|
166
|
+
async setBalanceHidden(enable) {},
|
|
167
|
+
async clearBalanceHidden() {},
|
|
168
|
+
|
|
169
|
+
async getVersionDetail() {
|
|
170
|
+
return defaultVersionDetail
|
|
171
|
+
},
|
|
172
|
+
async setVersionDetail(detail: VersionDetail) {},
|
|
173
|
+
async clearVersionDetail() {},
|
|
174
|
+
|
|
175
|
+
async getThemeMode() {
|
|
176
|
+
return defaultThemeMode
|
|
177
|
+
},
|
|
178
|
+
async setThemeMode(mode: string) {},
|
|
179
|
+
async clearThemeMode() {},
|
|
180
|
+
|
|
181
|
+
async getUtxoManageVisited() {
|
|
182
|
+
return false
|
|
183
|
+
},
|
|
184
|
+
async setUtxoManageVisited() {},
|
|
185
|
+
async clearUtxoManageVisited() {},
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function legacyParseObjectValue(val: any) {
|
|
189
|
+
let parsedObj = null
|
|
190
|
+
if (val && typeof val !== 'string') {
|
|
191
|
+
return val
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (typeof val === 'string' && val.length > 0) {
|
|
195
|
+
try {
|
|
196
|
+
parsedObj = JSON.parse(val)
|
|
197
|
+
} catch (e) {
|
|
198
|
+
parsedObj = null
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// legacy double stringify
|
|
203
|
+
val = parsedObj
|
|
204
|
+
if (val && typeof val === 'string' && val.length > 0) {
|
|
205
|
+
try {
|
|
206
|
+
parsedObj = JSON.parse(val)
|
|
207
|
+
} catch (e) {
|
|
208
|
+
parsedObj = null
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return parsedObj
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function isLegacyStringifiedObject(val: any) {
|
|
216
|
+
if (typeof val === 'string' && val.length > 0) {
|
|
217
|
+
try {
|
|
218
|
+
const parsedObj = JSON.parse(val)
|
|
219
|
+
if (parsedObj && typeof parsedObj === 'string' && parsedObj.length > 0) {
|
|
220
|
+
try {
|
|
221
|
+
JSON.parse(parsedObj)
|
|
222
|
+
return true
|
|
223
|
+
} catch (e) {
|
|
224
|
+
return false
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
} catch (e) {
|
|
228
|
+
return false
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return false
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export function createStorageProvider(base: BaseStorageProvider): StorageContextType {
|
|
235
|
+
const funcs = {
|
|
236
|
+
...base,
|
|
237
|
+
|
|
238
|
+
async getAutomaticLockTime(): Promise<AutoLockTime | null> {
|
|
239
|
+
const val = await base.get(StorageType.AUTO_LOCK_TIME)
|
|
240
|
+
return legacyParseObjectValue(val)
|
|
241
|
+
},
|
|
242
|
+
async clearAutomaticLockTime() {
|
|
243
|
+
await base.set(StorageType.AUTO_LOCK_TIME, null)
|
|
244
|
+
},
|
|
245
|
+
|
|
246
|
+
async getAnnouncementDismissedIds(): Promise<string[]> {
|
|
247
|
+
const val = await base.get(StorageType.ANNOUNCEMENT_DISMISSED_IDS_KEY)
|
|
248
|
+
return legacyParseObjectValue(val) || []
|
|
249
|
+
},
|
|
250
|
+
async setAnnouncementDismissedIds(ids: string[]) {
|
|
251
|
+
await base.set(StorageType.ANNOUNCEMENT_DISMISSED_IDS_KEY, ids)
|
|
252
|
+
},
|
|
253
|
+
async clearAnnouncementDismissedIds() {
|
|
254
|
+
await base.set(StorageType.ANNOUNCEMENT_DISMISSED_IDS_KEY, [])
|
|
255
|
+
},
|
|
256
|
+
|
|
257
|
+
async getI18nSavedLang() {
|
|
258
|
+
const val = await base.get(StorageType.I18N_SAVED_LANG)
|
|
259
|
+
return val || ''
|
|
260
|
+
},
|
|
261
|
+
async setI18nSavedLang(lang: string) {
|
|
262
|
+
await base.set(StorageType.I18N_SAVED_LANG, lang)
|
|
263
|
+
},
|
|
264
|
+
async clearI18nSavedLang() {
|
|
265
|
+
await base.set(StorageType.I18N_SAVED_LANG, '')
|
|
266
|
+
},
|
|
267
|
+
|
|
268
|
+
async getWebSearchHistory(): Promise<WebSearchHistoryItem[]> {
|
|
269
|
+
const val = await base.get(StorageType.WEB_SEARCH_HISTORY)
|
|
270
|
+
return legacyParseObjectValue(val) || []
|
|
271
|
+
},
|
|
272
|
+
async setWebSearchHistory(history: WebSearchHistoryItem[]) {
|
|
273
|
+
await base.set(StorageType.WEB_SEARCH_HISTORY, history)
|
|
274
|
+
},
|
|
275
|
+
async clearWebSearchHistory() {
|
|
276
|
+
await base.set(StorageType.WEB_SEARCH_HISTORY, [])
|
|
277
|
+
},
|
|
278
|
+
|
|
279
|
+
async getWebRiskWarning(): Promise<WebRiskWarningItem[]> {
|
|
280
|
+
const val = await base.get(StorageType.WEB_RISK_WARNING)
|
|
281
|
+
return legacyParseObjectValue(val) || []
|
|
282
|
+
},
|
|
283
|
+
async setWebRiskWarning(warnings: WebRiskWarningItem[]) {
|
|
284
|
+
await base.set(StorageType.WEB_RISK_WARNING, warnings)
|
|
285
|
+
},
|
|
286
|
+
async clearWebRiskWarning() {
|
|
287
|
+
await base.set(StorageType.WEB_RISK_WARNING, [])
|
|
288
|
+
},
|
|
289
|
+
|
|
290
|
+
async getEnableExplore() {
|
|
291
|
+
const val = await base.get(StorageType.ENABLE_EXPLORE)
|
|
292
|
+
return val === 'true'
|
|
293
|
+
},
|
|
294
|
+
async setEnableExplore(enable: boolean) {
|
|
295
|
+
await base.set(StorageType.ENABLE_EXPLORE, String(enable))
|
|
296
|
+
},
|
|
297
|
+
async clearEnableExplore() {
|
|
298
|
+
await base.set(StorageType.ENABLE_EXPLORE, 'false')
|
|
299
|
+
},
|
|
300
|
+
|
|
301
|
+
async getUnbackupKeyringIds(): Promise<string[]> {
|
|
302
|
+
const val = await base.get(StorageType.UNBACKUP_KEYRINGS)
|
|
303
|
+
return legacyParseObjectValue(val) || []
|
|
304
|
+
},
|
|
305
|
+
async setUnbackupKeyringIds(keyringIds: string[]) {
|
|
306
|
+
await base.set(StorageType.UNBACKUP_KEYRINGS, keyringIds)
|
|
307
|
+
},
|
|
308
|
+
async clearUnbackupKeyringIds() {
|
|
309
|
+
await base.set(StorageType.UNBACKUP_KEYRINGS, [])
|
|
310
|
+
},
|
|
311
|
+
|
|
312
|
+
//
|
|
313
|
+
async getEnableFaceId() {
|
|
314
|
+
const val = await base.get(StorageType.ENABLE_FACEID)
|
|
315
|
+
return val === 'true' || val == true
|
|
316
|
+
},
|
|
317
|
+
async setEnableFaceId(enable: boolean) {
|
|
318
|
+
await base.set(StorageType.ENABLE_FACEID, String(enable))
|
|
319
|
+
},
|
|
320
|
+
async clearEnableFaceId() {
|
|
321
|
+
await base.set(StorageType.ENABLE_FACEID, 'false')
|
|
322
|
+
},
|
|
323
|
+
|
|
324
|
+
async getBalanceHidden() {
|
|
325
|
+
const val = await base.get(StorageType.BALANCE_HIDDEN)
|
|
326
|
+
return val === 'true'
|
|
327
|
+
},
|
|
328
|
+
async setBalanceHidden(enable: boolean) {
|
|
329
|
+
await base.set(StorageType.BALANCE_HIDDEN, String(enable))
|
|
330
|
+
},
|
|
331
|
+
async clearBalanceHidden() {
|
|
332
|
+
await base.set(StorageType.BALANCE_HIDDEN, 'false')
|
|
333
|
+
},
|
|
334
|
+
|
|
335
|
+
async getVersionDetail() {
|
|
336
|
+
const val = await base.get(StorageType.VERSION_DETAIL)
|
|
337
|
+
return legacyParseObjectValue(val) || defaultVersionDetail
|
|
338
|
+
},
|
|
339
|
+
async setVersionDetail(detail: VersionDetail) {
|
|
340
|
+
await base.set(StorageType.VERSION_DETAIL, detail)
|
|
341
|
+
},
|
|
342
|
+
async clearVersionDetail() {
|
|
343
|
+
await base.set(StorageType.VERSION_DETAIL, defaultVersionDetail)
|
|
344
|
+
},
|
|
345
|
+
|
|
346
|
+
async getThemeMode() {
|
|
347
|
+
const val = await base.get(StorageType.THEME_MODE)
|
|
348
|
+
return val || defaultThemeMode
|
|
349
|
+
},
|
|
350
|
+
async setThemeMode(mode: string) {
|
|
351
|
+
await base.set(StorageType.THEME_MODE, mode)
|
|
352
|
+
},
|
|
353
|
+
async clearThemeMode() {
|
|
354
|
+
await base.set(StorageType.THEME_MODE, defaultThemeMode)
|
|
355
|
+
},
|
|
356
|
+
|
|
357
|
+
async getUtxoManageVisited() {
|
|
358
|
+
const val = await base.get(StorageType.UTXO_MANAGE_VISITED)
|
|
359
|
+
return val === 'true'
|
|
360
|
+
},
|
|
361
|
+
async setUtxoManageVisited() {
|
|
362
|
+
await base.set(StorageType.UTXO_MANAGE_VISITED, 'true')
|
|
363
|
+
},
|
|
364
|
+
async clearUtxoManageVisited() {
|
|
365
|
+
await base.set(StorageType.UTXO_MANAGE_VISITED, 'false')
|
|
366
|
+
},
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
return {
|
|
370
|
+
...funcs,
|
|
371
|
+
async clear() {
|
|
372
|
+
await funcs.clearAutomaticLockTime()
|
|
373
|
+
await funcs.clearAnnouncementDismissedIds()
|
|
374
|
+
await funcs.clearI18nSavedLang()
|
|
375
|
+
await funcs.clearWebSearchHistory()
|
|
376
|
+
await funcs.clearWebRiskWarning()
|
|
377
|
+
await funcs.clearEnableExplore()
|
|
378
|
+
await funcs.clearUnbackupKeyringIds()
|
|
379
|
+
await funcs.clearEnableFaceId()
|
|
380
|
+
await funcs.clearBalanceHidden()
|
|
381
|
+
await funcs.clearVersionDetail()
|
|
382
|
+
await funcs.clearThemeMode()
|
|
383
|
+
await funcs.clearUtxoManageVisited()
|
|
384
|
+
},
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
export const StorageContext = React.createContext<StorageContextType>(defaultContext)
|
|
389
|
+
|
|
390
|
+
export function useStorage() {
|
|
391
|
+
const ctx = useContext(StorageContext)
|
|
392
|
+
return ctx
|
|
393
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/* eslint-disable indent */
|
|
2
|
+
import React, { useCallback, useContext, useRef, useState } from 'react'
|
|
3
|
+
|
|
4
|
+
type ToastFunction = (content: string) => void
|
|
5
|
+
type LoadingFunction = (visible: boolean, content?: string) => void
|
|
6
|
+
|
|
7
|
+
export interface ToolsContextType {
|
|
8
|
+
toast: ToastFunction
|
|
9
|
+
toastSuccess: ToastFunction
|
|
10
|
+
toastError: ToastFunction
|
|
11
|
+
toastWarning: ToastFunction
|
|
12
|
+
showLoading: LoadingFunction
|
|
13
|
+
showTip: ToastFunction
|
|
14
|
+
copyToClipboard: (text: string) => void
|
|
15
|
+
openUrl: (url: string) => void
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const initContext = {
|
|
19
|
+
toast: (content: string) => {
|
|
20
|
+
// todo
|
|
21
|
+
},
|
|
22
|
+
toastSuccess: (content: string) => {
|
|
23
|
+
// todo
|
|
24
|
+
},
|
|
25
|
+
toastError: (content: string) => {
|
|
26
|
+
// todo
|
|
27
|
+
},
|
|
28
|
+
toastWarning: (content: string) => {
|
|
29
|
+
// todo
|
|
30
|
+
},
|
|
31
|
+
showLoading: () => {
|
|
32
|
+
// todo
|
|
33
|
+
},
|
|
34
|
+
showTip: (content: string) => {
|
|
35
|
+
// todo
|
|
36
|
+
},
|
|
37
|
+
copyToClipboard: (text: string) => {
|
|
38
|
+
// todo
|
|
39
|
+
},
|
|
40
|
+
openUrl(url: string) {
|
|
41
|
+
// todo
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const ToolsContext = React.createContext<ToolsContextType>(initContext)
|
|
46
|
+
|
|
47
|
+
export function useTools() {
|
|
48
|
+
const ctx = useContext(ToolsContext)
|
|
49
|
+
return ctx
|
|
50
|
+
}
|