@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
|
@@ -1,23 +1,15 @@
|
|
|
1
|
+
import { FALLBACK_LOCALE } from '@unisat/wallet-shared'
|
|
1
2
|
import log from 'loglevel'
|
|
2
|
-
import React, { createContext, useEffect, useState } from 'react'
|
|
3
|
+
import React, { createContext, useContext, useEffect, useState } from 'react'
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
changeLanguage,
|
|
7
|
-
FALLBACK_LOCALE,
|
|
8
|
-
getSupportedLocales,
|
|
9
|
-
initI18n,
|
|
10
|
-
LOCALE_NAMES,
|
|
11
|
-
t as translate,
|
|
12
|
-
} from '@unisat/i18n'
|
|
13
|
-
import { useWallet } from './WalletContext'
|
|
14
|
-
|
|
15
|
-
interface I18nContextType {
|
|
16
|
-
t: (key: string, substitutions?: string | string[]) => string
|
|
5
|
+
export interface I18nContextType {
|
|
6
|
+
t: (key: string, substitutions?: string | string[] | Record<string, string | number>) => string
|
|
17
7
|
locale: string
|
|
18
8
|
supportedLocales: string[]
|
|
19
9
|
localeNames: Record<string, string>
|
|
20
10
|
changeLocale: (locale: string) => Promise<void>
|
|
11
|
+
addResourceBundle?: (locale: string) => Promise<void>
|
|
12
|
+
isSpecialLocale: boolean
|
|
21
13
|
}
|
|
22
14
|
|
|
23
15
|
// Create context
|
|
@@ -26,166 +18,16 @@ export const I18nContext = createContext<I18nContextType>({
|
|
|
26
18
|
locale: FALLBACK_LOCALE,
|
|
27
19
|
supportedLocales: [],
|
|
28
20
|
localeNames: {},
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
30
21
|
changeLocale: async () => {},
|
|
22
|
+
addResourceBundle: async () => {},
|
|
23
|
+
isSpecialLocale: false,
|
|
31
24
|
})
|
|
32
25
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
// Initialize i18n
|
|
41
|
-
useEffect(() => {
|
|
42
|
-
const initialize = async () => {
|
|
43
|
-
try {
|
|
44
|
-
let localeToUse = FALLBACK_LOCALE
|
|
45
|
-
// @ts-ignore
|
|
46
|
-
const userSelectedLanguage = localStorage.getItem('userSelectedLanguage') === 'true'
|
|
47
|
-
|
|
48
|
-
if (userSelectedLanguage) {
|
|
49
|
-
// @ts-ignore
|
|
50
|
-
const savedLocale = localStorage.getItem('i18nextLng')
|
|
51
|
-
if (savedLocale && getSupportedLocales().includes(savedLocale)) {
|
|
52
|
-
localeToUse = savedLocale
|
|
53
|
-
log.debug(`Using user selected language: ${savedLocale}`)
|
|
54
|
-
}
|
|
55
|
-
} else {
|
|
56
|
-
try {
|
|
57
|
-
const isFirstOpen = await wallet.getIsFirstOpen()
|
|
58
|
-
|
|
59
|
-
if (isFirstOpen) {
|
|
60
|
-
// @ts-ignore
|
|
61
|
-
const browserLang = navigator.language
|
|
62
|
-
log.debug(`New user - Browser language: ${browserLang}`)
|
|
63
|
-
|
|
64
|
-
const mappedLocale = BROWSER_TO_APP_LOCALE_MAP[browserLang]
|
|
65
|
-
if (mappedLocale && getSupportedLocales().includes(mappedLocale)) {
|
|
66
|
-
localeToUse = mappedLocale
|
|
67
|
-
log.debug(`Using mapped browser language: ${mappedLocale}`)
|
|
68
|
-
} else if (getSupportedLocales().includes(browserLang)) {
|
|
69
|
-
localeToUse = browserLang
|
|
70
|
-
log.debug(`Using browser language: ${browserLang}`)
|
|
71
|
-
} else {
|
|
72
|
-
const mainLang = browserLang.split('-')[0]
|
|
73
|
-
if (getSupportedLocales().includes(mainLang)) {
|
|
74
|
-
localeToUse = mainLang
|
|
75
|
-
log.debug(`Using browser main language: ${mainLang}`)
|
|
76
|
-
} else {
|
|
77
|
-
log.debug(`Browser language not supported, using default: ${FALLBACK_LOCALE}`)
|
|
78
|
-
localeToUse = FALLBACK_LOCALE
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
} else {
|
|
82
|
-
log.debug('Existing user - Using default English')
|
|
83
|
-
localeToUse = FALLBACK_LOCALE
|
|
84
|
-
}
|
|
85
|
-
} catch (error) {
|
|
86
|
-
log.error('Failed to get user status, using default language:', error)
|
|
87
|
-
localeToUse = FALLBACK_LOCALE
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// @ts-ignore
|
|
92
|
-
localStorage.setItem('i18nextLng', localeToUse)
|
|
93
|
-
await initI18n(localeToUse)
|
|
94
|
-
|
|
95
|
-
chrome.storage.local.set({ i18nextLng: localeToUse })
|
|
96
|
-
await initI18n(localeToUse)
|
|
97
|
-
// const currentLocale = await getCurrentLocale();
|
|
98
|
-
|
|
99
|
-
// setLocale(currentLocale);
|
|
100
|
-
setIsInitialized(true)
|
|
101
|
-
} catch (error) {
|
|
102
|
-
log.error('Failed to initialize i18n:', error)
|
|
103
|
-
|
|
104
|
-
setLocale(FALLBACK_LOCALE)
|
|
105
|
-
setIsInitialized(true)
|
|
106
|
-
setError(error instanceof Error ? error : new Error('Unknown error'))
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
initialize()
|
|
111
|
-
}, [wallet])
|
|
112
|
-
|
|
113
|
-
// Change language
|
|
114
|
-
const changeLocale = async (newLocale: string) => {
|
|
115
|
-
try {
|
|
116
|
-
await changeLanguage(newLocale)
|
|
117
|
-
setLocale(newLocale)
|
|
118
|
-
// @ts-ignore
|
|
119
|
-
localStorage.setItem('userSelectedLanguage', 'true')
|
|
120
|
-
// @ts-ignore
|
|
121
|
-
localStorage.setItem('i18nextLng', newLocale)
|
|
122
|
-
chrome.storage.local.set({ i18nextLng: newLocale })
|
|
123
|
-
} catch (error) {
|
|
124
|
-
setError(error instanceof Error ? error : new Error('Unknown error'))
|
|
125
|
-
}
|
|
26
|
+
export function useI18n() {
|
|
27
|
+
const context = useContext(I18nContext)
|
|
28
|
+
if (!context) {
|
|
29
|
+
throw Error('Feature flag hooks can only be used by children of BridgeProvider.')
|
|
30
|
+
} else {
|
|
31
|
+
return context
|
|
126
32
|
}
|
|
127
|
-
|
|
128
|
-
// Translation function
|
|
129
|
-
const t = (key: string, substitutions?: string | string[]) => {
|
|
130
|
-
try {
|
|
131
|
-
return translate(key, substitutions)
|
|
132
|
-
} catch (error) {
|
|
133
|
-
log.error(`Translation error for key "${key}":`, error)
|
|
134
|
-
return key
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// If not yet initialized, show loading
|
|
139
|
-
if (!isInitialized) {
|
|
140
|
-
return (
|
|
141
|
-
<div
|
|
142
|
-
style={{
|
|
143
|
-
display: 'flex',
|
|
144
|
-
flexDirection: 'column',
|
|
145
|
-
width: '100vw',
|
|
146
|
-
height: '100vh',
|
|
147
|
-
overflowY: 'auto',
|
|
148
|
-
overflowX: 'hidden',
|
|
149
|
-
}}
|
|
150
|
-
>
|
|
151
|
-
<div
|
|
152
|
-
style={{
|
|
153
|
-
display: 'flex',
|
|
154
|
-
flex: 1,
|
|
155
|
-
flexDirection: 'column',
|
|
156
|
-
justifyItems: 'center',
|
|
157
|
-
alignItems: 'center',
|
|
158
|
-
}}
|
|
159
|
-
>
|
|
160
|
-
<div />
|
|
161
|
-
</div>
|
|
162
|
-
</div>
|
|
163
|
-
)
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// If there is an error, show error message in development environment
|
|
167
|
-
// @ts-ignore
|
|
168
|
-
if (error && process.env.NODE_ENV === 'development') {
|
|
169
|
-
return (
|
|
170
|
-
<div style={{ color: 'red', padding: '20px' }}>
|
|
171
|
-
<h2>Error initializing i18n</h2>
|
|
172
|
-
<p>{error.message}</p>
|
|
173
|
-
<pre>{error.stack}</pre>
|
|
174
|
-
</div>
|
|
175
|
-
)
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
return (
|
|
179
|
-
<I18nContext.Provider
|
|
180
|
-
value={{
|
|
181
|
-
t,
|
|
182
|
-
locale,
|
|
183
|
-
supportedLocales: getSupportedLocales(),
|
|
184
|
-
localeNames: LOCALE_NAMES,
|
|
185
|
-
changeLocale,
|
|
186
|
-
}}
|
|
187
|
-
>
|
|
188
|
-
{children}
|
|
189
|
-
</I18nContext.Provider>
|
|
190
|
-
)
|
|
191
33
|
}
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Account,
|
|
3
|
+
AlkanesBalance,
|
|
4
|
+
AlkanesInfo,
|
|
5
|
+
BabylonTxInfo,
|
|
6
|
+
CAT20Balance,
|
|
7
|
+
CAT20TokenInfo,
|
|
8
|
+
CAT721CollectionInfo,
|
|
9
|
+
CAT_VERSION,
|
|
10
|
+
Inscription,
|
|
11
|
+
RuneBalance,
|
|
12
|
+
RuneInfo,
|
|
13
|
+
TokenBalance,
|
|
14
|
+
TokenInfo,
|
|
15
|
+
ToSignData,
|
|
16
|
+
WalletKeyring,
|
|
17
|
+
} from '@unisat/wallet-shared'
|
|
18
|
+
import { ChainType } from '@unisat/wallet-types'
|
|
19
|
+
import React, { useContext } from 'react'
|
|
20
|
+
|
|
21
|
+
export type RouteParamList = {
|
|
22
|
+
WelcomeScreen: undefined
|
|
23
|
+
UnlockScreen: {
|
|
24
|
+
autoUnlockByFace: boolean
|
|
25
|
+
}
|
|
26
|
+
CreatePasswordScreen: {
|
|
27
|
+
isNewAccount?: boolean
|
|
28
|
+
isKeystone?: boolean
|
|
29
|
+
fromColdWallet?: boolean
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
MainScreen: undefined
|
|
33
|
+
|
|
34
|
+
// tabs
|
|
35
|
+
WalletTabScreen: undefined
|
|
36
|
+
AppTabScreen: undefined
|
|
37
|
+
TabMainScreen: undefined
|
|
38
|
+
DiscoverTabScreen: undefined
|
|
39
|
+
SettingsTabScreen: undefined
|
|
40
|
+
|
|
41
|
+
// WALLET
|
|
42
|
+
CreateHDWalletScreen: {
|
|
43
|
+
restoreTiTle?: boolean
|
|
44
|
+
topTitle?: boolean
|
|
45
|
+
finalButton?: string
|
|
46
|
+
existingMnemonic?: string
|
|
47
|
+
isBackupFlow?: boolean
|
|
48
|
+
|
|
49
|
+
isImport?: boolean
|
|
50
|
+
comeFrom?: string
|
|
51
|
+
fromUnlock?: boolean
|
|
52
|
+
goBack?: boolean
|
|
53
|
+
}
|
|
54
|
+
CreateSimpleWalletScreen: undefined
|
|
55
|
+
CreateWatchWalletScreen: undefined
|
|
56
|
+
CreateColdWalletScreen: {
|
|
57
|
+
fromUnlock?: boolean
|
|
58
|
+
}
|
|
59
|
+
CreateKeystoneWalletScreen: {
|
|
60
|
+
fromUnlock?: boolean
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
EditWalletNameScreen: {
|
|
64
|
+
keyring: WalletKeyring
|
|
65
|
+
}
|
|
66
|
+
ExportMnemonicsScreen: { keyring: WalletKeyring }
|
|
67
|
+
ExportPrivateKeyScreen: {
|
|
68
|
+
account: Account
|
|
69
|
+
}
|
|
70
|
+
SwitchAccountScreen: undefined
|
|
71
|
+
ReceiveScreen: undefined
|
|
72
|
+
HistoryScreen: undefined
|
|
73
|
+
KeyringOrAccountScreen: undefined
|
|
74
|
+
AddKeyringScreen: undefined
|
|
75
|
+
ImportHDWalletScreen: {
|
|
76
|
+
comeFrom?: string
|
|
77
|
+
}
|
|
78
|
+
CreateAccountScreen: {
|
|
79
|
+
keyringKey?: string
|
|
80
|
+
}
|
|
81
|
+
CreateKeystoneScreen: {
|
|
82
|
+
comeFrom?: string
|
|
83
|
+
goBack?: boolean
|
|
84
|
+
}
|
|
85
|
+
EditAccountNameScreen: {
|
|
86
|
+
account: Account
|
|
87
|
+
}
|
|
88
|
+
KeyringDetailScreen: {
|
|
89
|
+
keyringKey?: string
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Settings
|
|
93
|
+
ConnectedSitesScreen: undefined
|
|
94
|
+
AddressTypeScreen: undefined
|
|
95
|
+
AdvancedScreen: undefined
|
|
96
|
+
ContactsScreen: {
|
|
97
|
+
returnWithNetwork?: ChainType
|
|
98
|
+
lastEditedContactAddress?: string
|
|
99
|
+
}
|
|
100
|
+
EditContactScreen: {
|
|
101
|
+
address?: string
|
|
102
|
+
chain?: string
|
|
103
|
+
selectedNetworkFilter: string
|
|
104
|
+
}
|
|
105
|
+
AboutUsScreen: undefined
|
|
106
|
+
LanguageScreen: undefined
|
|
107
|
+
ChangePasswordScreen: undefined
|
|
108
|
+
ModuleAssets: undefined
|
|
109
|
+
NotificationListScreen: undefined
|
|
110
|
+
|
|
111
|
+
// Tools
|
|
112
|
+
UtxoToolsMainScreen: undefined
|
|
113
|
+
ScanScreen: {
|
|
114
|
+
from?: string
|
|
115
|
+
}
|
|
116
|
+
BrowserScreen: {
|
|
117
|
+
info: any
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// BTC
|
|
121
|
+
TxCreateScreen: undefined
|
|
122
|
+
|
|
123
|
+
// INSCRIPTIONS
|
|
124
|
+
OrdinalsInscriptionScreen: {
|
|
125
|
+
inscription: Inscription
|
|
126
|
+
inscriptionId?: string
|
|
127
|
+
withSend?: boolean
|
|
128
|
+
}
|
|
129
|
+
SendOrdinalsInscriptionScreen: {
|
|
130
|
+
inscription: Inscription
|
|
131
|
+
inscriptionId?: string
|
|
132
|
+
}
|
|
133
|
+
SplitOrdinalsInscriptionScreen: {
|
|
134
|
+
inscription: Inscription
|
|
135
|
+
inscriptionId?: string
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// BRC20
|
|
139
|
+
BRC20TokenScreen: {
|
|
140
|
+
ticker: string
|
|
141
|
+
tokenBalance?: TokenBalance
|
|
142
|
+
}
|
|
143
|
+
BRC20SendScreen: {
|
|
144
|
+
tokenBalance: TokenBalance
|
|
145
|
+
tokenInfo: TokenInfo
|
|
146
|
+
selectedInscriptionIds?: string[]
|
|
147
|
+
selectedAmount?: string
|
|
148
|
+
}
|
|
149
|
+
BRC20InscribeTransfer: {
|
|
150
|
+
ticker: string
|
|
151
|
+
}
|
|
152
|
+
BRC20SingleStepScreen: {
|
|
153
|
+
tokenBalance: TokenBalance
|
|
154
|
+
tokenInfo: TokenInfo
|
|
155
|
+
}
|
|
156
|
+
InscribeTransferScreen: {
|
|
157
|
+
ticker: string
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// RUNES
|
|
161
|
+
RunesTokenScreen: {
|
|
162
|
+
runeid: string
|
|
163
|
+
}
|
|
164
|
+
SendRunesScreen: {
|
|
165
|
+
runeBalance: RuneBalance
|
|
166
|
+
runeInfo: RuneInfo
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Alkanes
|
|
170
|
+
AlkanesTokenScreen: {
|
|
171
|
+
alkaneid: string
|
|
172
|
+
}
|
|
173
|
+
SendAlkanesScreen: {
|
|
174
|
+
tokenBalance: AlkanesBalance
|
|
175
|
+
tokenInfo: AlkanesInfo
|
|
176
|
+
}
|
|
177
|
+
AlkanesCollectionScreen: {
|
|
178
|
+
collectionId: string
|
|
179
|
+
}
|
|
180
|
+
AlkanesNFTScreen: {
|
|
181
|
+
alkanesInfo: AlkanesInfo
|
|
182
|
+
}
|
|
183
|
+
SendAlkanesNFTScreen: {
|
|
184
|
+
alkanesInfo: AlkanesInfo
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// CAT
|
|
188
|
+
CAT20TokenScreen: {
|
|
189
|
+
tokenId: string
|
|
190
|
+
version: CAT_VERSION
|
|
191
|
+
}
|
|
192
|
+
SendCAT20Screen: {
|
|
193
|
+
version: CAT_VERSION
|
|
194
|
+
cat20Balance: CAT20Balance
|
|
195
|
+
cat20Info: CAT20TokenInfo
|
|
196
|
+
}
|
|
197
|
+
MergeCAT20Screen: {
|
|
198
|
+
version: CAT_VERSION
|
|
199
|
+
cat20Balance: CAT20Balance
|
|
200
|
+
cat20Info: CAT20TokenInfo
|
|
201
|
+
}
|
|
202
|
+
CAT721CollectionScreen: {
|
|
203
|
+
collectionId: string
|
|
204
|
+
version: CAT_VERSION
|
|
205
|
+
}
|
|
206
|
+
CAT721NFTScreen: {
|
|
207
|
+
version: CAT_VERSION
|
|
208
|
+
collectionInfo: CAT721CollectionInfo
|
|
209
|
+
localId: string
|
|
210
|
+
}
|
|
211
|
+
SendCAT721Screen: {
|
|
212
|
+
version: CAT_VERSION
|
|
213
|
+
collectionInfo: CAT721CollectionInfo
|
|
214
|
+
localId: string
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Babylon
|
|
218
|
+
BabylonTxConfirmScreen: {
|
|
219
|
+
txInfo: BabylonTxInfo
|
|
220
|
+
}
|
|
221
|
+
BabylonStakingScreen: undefined
|
|
222
|
+
SendBabyScreen: undefined
|
|
223
|
+
|
|
224
|
+
// TX
|
|
225
|
+
TxConfirmScreen: {
|
|
226
|
+
toSignData: ToSignData
|
|
227
|
+
}
|
|
228
|
+
TxSuccessScreen: {
|
|
229
|
+
txid: string
|
|
230
|
+
}
|
|
231
|
+
TxFailScreen: {
|
|
232
|
+
error: string
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export type RouteTypes = keyof RouteParamList
|
|
237
|
+
|
|
238
|
+
type NavigateArgs<T extends RouteTypes> = RouteParamList[T] extends undefined
|
|
239
|
+
? [screenName: T]
|
|
240
|
+
: [screenName: T, params: RouteParamList[T]]
|
|
241
|
+
|
|
242
|
+
export interface NavigationContextType {
|
|
243
|
+
navigate<T extends RouteTypes>(...args: NavigateArgs<T>): void
|
|
244
|
+
|
|
245
|
+
replace<T extends RouteTypes>(...args: NavigateArgs<T>): void
|
|
246
|
+
|
|
247
|
+
poptotop: () => void
|
|
248
|
+
goBack: () => void
|
|
249
|
+
navToTab: () => void
|
|
250
|
+
navToTest: () => void
|
|
251
|
+
navToLock: (params?: any) => void
|
|
252
|
+
navToWelcome: () => void
|
|
253
|
+
|
|
254
|
+
getRouteState<T extends RouteTypes>(): RouteParamList[T]
|
|
255
|
+
|
|
256
|
+
navToUtxoTools: () => void
|
|
257
|
+
navToUrl: (url: string, externalBrowser?: boolean) => void
|
|
258
|
+
|
|
259
|
+
navToExplorerTx: (txid: string) => void
|
|
260
|
+
navToExplorerAddress: (address: string) => void
|
|
261
|
+
|
|
262
|
+
navToMarketPlace: () => void
|
|
263
|
+
navToMarketPlaceBrc20: (ticker: string) => void
|
|
264
|
+
navToInscribeBrc20: (ticker: string) => void
|
|
265
|
+
|
|
266
|
+
openExtensionInTab?: () => void // in extension only
|
|
267
|
+
navToRootHome: () => void // in extension only
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const initContext = {
|
|
271
|
+
navigate: () => {},
|
|
272
|
+
poptotop: () => {},
|
|
273
|
+
goBack: () => {},
|
|
274
|
+
replace: () => {},
|
|
275
|
+
navToTab: () => {},
|
|
276
|
+
navToTest: () => {},
|
|
277
|
+
navToLock: () => {},
|
|
278
|
+
navToWelcome: () => {},
|
|
279
|
+
|
|
280
|
+
getRouteState<T>(): T {
|
|
281
|
+
// todo
|
|
282
|
+
return undefined as T
|
|
283
|
+
},
|
|
284
|
+
|
|
285
|
+
navToUtxoTools: () => {},
|
|
286
|
+
|
|
287
|
+
navToUrl: (url: string, externalBrowser?: boolean) => {},
|
|
288
|
+
navToExplorerTx: (txid: string) => {},
|
|
289
|
+
navToExplorerAddress: (address: string) => {},
|
|
290
|
+
|
|
291
|
+
navToMarketPlace: () => {},
|
|
292
|
+
navToMarketPlaceBrc20: (ticker: string) => {},
|
|
293
|
+
navToInscribeBrc20: (ticker: string) => {},
|
|
294
|
+
|
|
295
|
+
// in extension only
|
|
296
|
+
openExtensionInTab: () => {},
|
|
297
|
+
navToRootHome: () => {},
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export const NavigationContext = React.createContext<NavigationContextType>(initContext)
|
|
301
|
+
|
|
302
|
+
export function useNavigation() {
|
|
303
|
+
const ctx = useContext(NavigationContext)
|
|
304
|
+
return ctx
|
|
305
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import React, { ReactNode, useCallback, useContext, useEffect, useState } from 'react'
|
|
2
2
|
|
|
3
3
|
import { CoinPrice } from '@unisat/wallet-shared'
|
|
4
4
|
import { useWallet } from './WalletContext'
|
|
@@ -11,7 +11,7 @@ interface PriceContextType {
|
|
|
11
11
|
refreshCoinPrice: () => void
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
const PriceContext = createContext<PriceContextType>({} as PriceContextType)
|
|
14
|
+
const PriceContext = React.createContext<PriceContextType>({} as PriceContextType)
|
|
15
15
|
|
|
16
16
|
export function usePrice() {
|
|
17
17
|
const context = useContext(PriceContext)
|