@unisat/wallet-state 1.0.4 → 1.1.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/index.d.mts +2012 -200
- package/lib/index.d.ts +2012 -200
- package/lib/index.js +6951 -570
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +6754 -517
- package/lib/index.mjs.map +1 -1
- package/lib/types/index.d.mts +1 -1
- package/lib/types/index.d.ts +1 -1
- 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 +119 -108
- 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 +28 -37
- package/src/hooks/transactions.ts +28 -155
- package/src/hooks/ui.ts +232 -36
- package/src/index.ts +33 -24
- package/src/reducers/accounts.ts +19 -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 +127 -8
- package/src/types/index.ts +1 -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 +130 -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 +398 -0
- package/src/ui-hooks/useBRC20ListLogic.ts +75 -0
- package/src/ui-hooks/useBRC20ProgListLogic.ts +77 -0
- package/src/ui-hooks/useBRC20SendScreenLogic.ts +411 -0
- package/src/ui-hooks/useBRC20SingleStepScreenLogic.ts +208 -0
- package/src/ui-hooks/useBRC20TokenScreenLogic.ts +469 -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 +122 -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 +58 -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 +149 -0
- package/src/ui-hooks/useSecurityCardLogic.ts +0 -0
- package/src/ui-hooks/useSendAlkanesNFTScreenLogic.ts +138 -0
- package/src/ui-hooks/useSendAlkanesScreenLogic.ts +192 -0
- package/src/ui-hooks/useSendCAT20ScreenLogic.ts +297 -0
- package/src/ui-hooks/useSendCAT721ScreenLogic.ts +205 -0
- package/src/ui-hooks/useSendOrdinalsInscriptionScreenLogic.ts +137 -0
- package/src/ui-hooks/useSendRunesScreenLogic.ts +172 -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 +95 -0
- package/src/ui-hooks/useTxConfirmScreenLogic.ts +47 -0
- package/src/ui-hooks/useTxCreateScreenLogic.ts +161 -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
package/lib/types/index.d.mts
CHANGED
|
@@ -25,6 +25,6 @@ declare enum NavigationSource {
|
|
|
25
25
|
NORMAL = 1
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
type TabOption = 'home' | 'discover' | 'settings';
|
|
28
|
+
type TabOption = 'home' | 'discover' | 'settings' | 'app';
|
|
29
29
|
|
|
30
30
|
export { AlkanesAssetTabKey, AssetTabKey, CATAssetTabKey, NavigationSource, OrdinalsAssetTabKey, TabOption };
|
package/lib/types/index.d.ts
CHANGED
|
@@ -25,6 +25,6 @@ declare enum NavigationSource {
|
|
|
25
25
|
NORMAL = 1
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
type TabOption = 'home' | 'discover' | 'settings';
|
|
28
|
+
type TabOption = 'home' | 'discover' | 'settings' | 'app';
|
|
29
29
|
|
|
30
30
|
export { AlkanesAssetTabKey, AssetTabKey, CATAssetTabKey, NavigationSource, OrdinalsAssetTabKey, TabOption };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unisat/wallet-state",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Redux state management for UniSat wallet, shared between platforms",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/index.mjs",
|
|
@@ -23,32 +23,36 @@
|
|
|
23
23
|
"README.md"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
+
"bignumber.js": "^9.1.2",
|
|
27
|
+
"bip39": "^3.1.0",
|
|
26
28
|
"loglevel": "^1.8.0",
|
|
27
|
-
"
|
|
28
|
-
"@unisat/
|
|
29
|
-
"@unisat/
|
|
30
|
-
"@unisat/
|
|
31
|
-
"@unisat/
|
|
32
|
-
"@unisat/
|
|
29
|
+
"react-redux": "8.0.1",
|
|
30
|
+
"@unisat/babylon-service": "1.1.0",
|
|
31
|
+
"@unisat/keyring-service": "1.1.0",
|
|
32
|
+
"@unisat/base-utils": "0.2.0",
|
|
33
|
+
"@unisat/wallet-shared": "0.2.0",
|
|
34
|
+
"@unisat/wallet-types": "1.1.0"
|
|
33
35
|
},
|
|
34
36
|
"peerDependencies": {
|
|
35
|
-
"
|
|
37
|
+
"@reduxjs/toolkit": "^1.9.2",
|
|
36
38
|
"compare-versions": "^4.1.3",
|
|
37
|
-
"react-i18next": "^11.16.9",
|
|
38
39
|
"i18next": "^21.8.1",
|
|
40
|
+
"react": "18.2.0",
|
|
41
|
+
"react-i18next": "^11.16.9",
|
|
39
42
|
"react-router-dom": "^6.3.0",
|
|
40
|
-
"
|
|
41
|
-
"react": "^18.0.0",
|
|
42
|
-
"react-redux": "^8.0.0"
|
|
43
|
+
"redux-localstorage-simple": "^2.5.1"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
46
|
+
"@reduxjs/toolkit": "^1.9.2",
|
|
47
|
+
"@testing-library/react": "^13.2.0",
|
|
45
48
|
"@types/node": "^20.0.0",
|
|
46
49
|
"@types/react": "^18.0.0",
|
|
47
50
|
"eslint": "^8.0.0",
|
|
51
|
+
"jsdom": "^27.4.0",
|
|
52
|
+
"react-dom": "18.2.0",
|
|
48
53
|
"tsup": "^7.0.0",
|
|
49
54
|
"typescript": "^5.0.0",
|
|
50
|
-
"vitest": "^0.34.0"
|
|
51
|
-
"@reduxjs/toolkit": "^1.9.2"
|
|
55
|
+
"vitest": "^0.34.0"
|
|
52
56
|
},
|
|
53
57
|
"publishConfig": {
|
|
54
58
|
"access": "public"
|
|
@@ -58,7 +62,7 @@
|
|
|
58
62
|
"build:cjs": "tsup --format cjs",
|
|
59
63
|
"build:esm": "tsup --format esm",
|
|
60
64
|
"build:typed": "tsc --declaration --declarationMap --emitDeclarationOnly --outDir lib",
|
|
61
|
-
"test": "vitest",
|
|
65
|
+
"test": "vitest run",
|
|
62
66
|
"lint": "eslint src"
|
|
63
67
|
}
|
|
64
68
|
}
|
package/src/.DS_Store
ADDED
|
Binary file
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/* eslint-disable indent */
|
|
2
|
+
import React, { useContext } from 'react'
|
|
3
|
+
|
|
4
|
+
export interface ApprovalContextType {
|
|
5
|
+
getApproval: () => Promise<any>
|
|
6
|
+
resolveApproval: (data?: any, stay?: boolean, forceReject?: boolean) => Promise<void>
|
|
7
|
+
rejectApproval: (reason?: string, stay?: boolean, isInternal?: boolean) => Promise<void>
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const initContext = {
|
|
11
|
+
getApproval: () => {
|
|
12
|
+
return Promise.resolve()
|
|
13
|
+
},
|
|
14
|
+
resolveApproval: (data?: any, stay?: boolean, forceReject?: boolean) => {
|
|
15
|
+
return Promise.resolve()
|
|
16
|
+
},
|
|
17
|
+
rejectApproval: (reason?: string, stay?: boolean, isInternal?: boolean) => {
|
|
18
|
+
return Promise.resolve()
|
|
19
|
+
},
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const ApprovalContext = React.createContext<ApprovalContextType>(initContext)
|
|
23
|
+
|
|
24
|
+
export function useApproval() {
|
|
25
|
+
const ctx = useContext(ApprovalContext)
|
|
26
|
+
return ctx
|
|
27
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React, { useContext } from 'react'
|
|
2
|
+
|
|
3
|
+
export interface DeviceContextType {
|
|
4
|
+
isMobile: boolean
|
|
5
|
+
isIOS: boolean
|
|
6
|
+
isAndroid: boolean
|
|
7
|
+
isExtensionInExpandView: boolean
|
|
8
|
+
isExtensionInSideBar: boolean
|
|
9
|
+
isExtension: boolean
|
|
10
|
+
isMobileScreenSize: boolean
|
|
11
|
+
isDesktopScreenSize: boolean
|
|
12
|
+
platform: string
|
|
13
|
+
hasBottomButton: boolean
|
|
14
|
+
cardColumnsInList: number
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const initContext = {
|
|
18
|
+
isMobile: false,
|
|
19
|
+
isIOS: false,
|
|
20
|
+
isAndroid: false,
|
|
21
|
+
isExtension: false,
|
|
22
|
+
isExtensionInExpandView: false,
|
|
23
|
+
isExtensionInSideBar: false,
|
|
24
|
+
isMobileScreenSize: false,
|
|
25
|
+
isDesktopScreenSize: false,
|
|
26
|
+
platform: 'unknown',
|
|
27
|
+
hasBottomButton: false,
|
|
28
|
+
cardColumnsInList: 2,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const DeviceContext = React.createContext<DeviceContextType>(initContext)
|
|
32
|
+
|
|
33
|
+
export function useDevice() {
|
|
34
|
+
const ctx = useContext(DeviceContext)
|
|
35
|
+
return ctx
|
|
36
|
+
}
|
|
@@ -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)
|