@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.
Files changed (99) hide show
  1. package/LICENSE +0 -5
  2. package/lib/index.d.mts +2012 -200
  3. package/lib/index.d.ts +2012 -200
  4. package/lib/index.js +6951 -570
  5. package/lib/index.js.map +1 -1
  6. package/lib/index.mjs +6754 -517
  7. package/lib/index.mjs.map +1 -1
  8. package/lib/types/index.d.mts +1 -1
  9. package/lib/types/index.d.ts +1 -1
  10. package/package.json +19 -15
  11. package/src/.DS_Store +0 -0
  12. package/src/context/ApprovalContext.tsx +27 -0
  13. package/src/context/DeviceContext.tsx +36 -0
  14. package/src/context/I18nContext.tsx +14 -172
  15. package/src/context/NavigationContext.tsx +305 -0
  16. package/src/context/PriceContext.tsx +2 -2
  17. package/src/context/StorageContext.tsx +393 -0
  18. package/src/context/ToolsContext.tsx +50 -0
  19. package/src/context/WalletContext.tsx +119 -108
  20. package/src/context/index.ts +17 -2
  21. package/src/hooks/accounts.ts +11 -5
  22. package/src/hooks/browser.ts +11 -0
  23. package/src/hooks/global.ts +170 -7
  24. package/src/hooks/index.ts +1 -2
  25. package/src/hooks/settings.ts +28 -37
  26. package/src/hooks/transactions.ts +28 -155
  27. package/src/hooks/ui.ts +232 -36
  28. package/src/index.ts +33 -24
  29. package/src/reducers/accounts.ts +19 -2
  30. package/src/reducers/browser.ts +223 -0
  31. package/src/reducers/global.ts +67 -1
  32. package/src/reducers/index.ts +1 -0
  33. package/src/reducers/transactions.ts +0 -9
  34. package/src/reducers/ui.ts +127 -8
  35. package/src/types/index.ts +1 -1
  36. package/src/ui-hooks/index.ts +107 -0
  37. package/src/ui-hooks/useActionOverviewSectionLogic.ts +150 -0
  38. package/src/ui-hooks/useAddressTypeScreenLogic.ts +160 -0
  39. package/src/ui-hooks/useAlkanesBalanceCardLogic.ts +41 -0
  40. package/src/ui-hooks/useAlkanesCollectionListLogic.ts +68 -0
  41. package/src/ui-hooks/useAlkanesListLogic.ts +69 -0
  42. package/src/ui-hooks/useAlkanesNFTListLogic.ts +42 -0
  43. package/src/ui-hooks/useAlkanesNFTScreenLogic.ts +45 -0
  44. package/src/ui-hooks/useAlkanesTokenScreenLogic.ts +130 -0
  45. package/src/ui-hooks/useAmountInputLogic.ts +80 -0
  46. package/src/ui-hooks/useAnnouncementCardLogic.ts +91 -0
  47. package/src/ui-hooks/useBRC20BalanceCardLogic.ts +115 -0
  48. package/src/ui-hooks/useBRC20InscribeTransferLogic.ts +398 -0
  49. package/src/ui-hooks/useBRC20ListLogic.ts +75 -0
  50. package/src/ui-hooks/useBRC20ProgListLogic.ts +77 -0
  51. package/src/ui-hooks/useBRC20SendScreenLogic.ts +411 -0
  52. package/src/ui-hooks/useBRC20SingleStepScreenLogic.ts +208 -0
  53. package/src/ui-hooks/useBRC20TokenScreenLogic.ts +469 -0
  54. package/src/ui-hooks/useBalanceCardLogic.ts +164 -0
  55. package/src/ui-hooks/useBtcDisplayLogic.ts +16 -0
  56. package/src/ui-hooks/useCAT20BalanceCardLogic.ts +35 -0
  57. package/src/ui-hooks/useCAT20ListLogic.ts +83 -0
  58. package/src/ui-hooks/useCAT20TokenScreenLogic.ts +122 -0
  59. package/src/ui-hooks/useCAT721ListLogic.ts +68 -0
  60. package/src/ui-hooks/useCAT721NFTScreenLogic.ts +37 -0
  61. package/src/ui-hooks/useCreatePasswordScreenLogic.ts +92 -0
  62. package/src/ui-hooks/useCreateWalletLogicImportWordsStep.ts +299 -0
  63. package/src/ui-hooks/useEditAccountNameScreenLogic.ts +71 -0
  64. package/src/ui-hooks/useEditContactScreenLogic.ts +162 -0
  65. package/src/ui-hooks/useEditWalletNameScreenLogic.ts +58 -0
  66. package/src/ui-hooks/useExportMnemonicsScreenLogic.ts +75 -0
  67. package/src/ui-hooks/useExportPrivateKeyScreenLogic.ts +64 -0
  68. package/src/ui-hooks/useFeeRateBarLogic.ts +303 -0
  69. package/src/ui-hooks/useInfiniteList.ts +85 -0
  70. package/src/ui-hooks/useInscriptionListLogic.ts +68 -0
  71. package/src/ui-hooks/useLockTimePageLogic.ts +43 -0
  72. package/src/ui-hooks/useNotificationsLogic.ts +115 -0
  73. package/src/ui-hooks/useOrdinalsInscriptionScreenLogic.ts +130 -0
  74. package/src/ui-hooks/useRunesBalanceCardLogic.ts +44 -0
  75. package/src/ui-hooks/useRunesListLogic.ts +74 -0
  76. package/src/ui-hooks/useRunesTokenScreenLogic.ts +149 -0
  77. package/src/ui-hooks/useSecurityCardLogic.ts +0 -0
  78. package/src/ui-hooks/useSendAlkanesNFTScreenLogic.ts +138 -0
  79. package/src/ui-hooks/useSendAlkanesScreenLogic.ts +192 -0
  80. package/src/ui-hooks/useSendCAT20ScreenLogic.ts +297 -0
  81. package/src/ui-hooks/useSendCAT721ScreenLogic.ts +205 -0
  82. package/src/ui-hooks/useSendOrdinalsInscriptionScreenLogic.ts +137 -0
  83. package/src/ui-hooks/useSendRunesScreenLogic.ts +172 -0
  84. package/src/ui-hooks/useSettingsTabScreenLogic.ts +211 -0
  85. package/src/ui-hooks/useSignMessageLogic.ts +302 -0
  86. package/src/ui-hooks/useSignPsbtLogic.ts +517 -0
  87. package/src/ui-hooks/useSplitOrdinalsInscriptionScreenLogic.ts +95 -0
  88. package/src/ui-hooks/useTxConfirmScreenLogic.ts +47 -0
  89. package/src/ui-hooks/useTxCreateScreenLogic.ts +161 -0
  90. package/src/ui-hooks/useTxFailScreenLogic.ts +26 -0
  91. package/src/ui-hooks/useTxSuccessScreenLogic.ts +33 -0
  92. package/src/updater/accounts.ts +11 -11
  93. package/src/utils/bitcoin-utils.ts +17 -8
  94. package/src/utils/eventBus.ts +2 -1
  95. package/src/utils/password-utils.ts +78 -0
  96. package/src/utils/ui-utils.ts +28 -0
  97. package/src/hooks/approval.ts +0 -72
  98. package/src/hooks/i18n.ts +0 -53
  99. package/src/utils/i18n.ts +0 -41
@@ -2,12 +2,11 @@ import { useCallback } from 'react'
2
2
 
3
3
  import { AddressType } from '@unisat/wallet-types'
4
4
 
5
- import { AppState } from '..'
6
- import { useAppDispatch, useAppSelector } from './base'
7
- import { globalActions } from '../reducers/global'
5
+ import { AppState, useApproval, useNavigation } from '..'
8
6
  import { useWallet } from '../context/WalletContext'
9
- import { useApproval } from './approval'
7
+ import { globalActions } from '../reducers/global'
10
8
  import { TabOption } from '../types'
9
+ import { useAppDispatch, useAppSelector } from './base'
11
10
 
12
11
  export function useGlobalState(): AppState['global'] {
13
12
  return useAppSelector(state => state.global)
@@ -18,6 +17,25 @@ export function useTab() {
18
17
  return globalState.tab
19
18
  }
20
19
 
20
+ export function useScreenState() {
21
+ const globalState = useGlobalState()
22
+ return globalState.screenState
23
+ }
24
+
25
+ export function useUpdateScreenStateCallback() {
26
+ const dispatch = useAppDispatch()
27
+ return useCallback(
28
+ (screenState: Partial<AppState['global']['screenState']>) => {
29
+ dispatch(
30
+ globalActions['updateScreenState']!({
31
+ screenState,
32
+ })
33
+ )
34
+ },
35
+ [dispatch]
36
+ )
37
+ }
38
+
21
39
  export function useSetTabCallback() {
22
40
  const dispatch = useAppDispatch()
23
41
  return useCallback(
@@ -47,10 +65,153 @@ export function useIsReady() {
47
65
  return globalState.isReady
48
66
  }
49
67
 
68
+ export function useIsRefresh() {
69
+ const globalState = useGlobalState()
70
+ return globalState.isRefresh
71
+ }
72
+
73
+ export function useBackRefresh() {
74
+ const globalState = useGlobalState()
75
+ return globalState.backRefresh
76
+ }
77
+
78
+ export function useWallRefresh() {
79
+ const globalState = useGlobalState()
80
+ return globalState.wallRefresh
81
+ }
82
+
83
+ export function useWallTabRefresh() {
84
+ const globalState = useGlobalState()
85
+ return globalState.wallTabRefresh
86
+ }
87
+
88
+ export function useWallTabFocusRefresh() {
89
+ const globalState = useGlobalState()
90
+ return globalState.wallTabFocusRefresh
91
+ }
92
+
93
+ export function useGoBackRefresh() {
94
+ const globalState = useGlobalState()
95
+ return globalState.goBackRefresh
96
+ }
97
+
98
+ export function useLayerState() {
99
+ const globalState = useGlobalState()
100
+ return globalState.layerState
101
+ }
102
+
103
+ export function useUnlockRefresh() {
104
+ const globalState = useGlobalState()
105
+ return globalState.unlockRefres
106
+ }
107
+
108
+ export function useUnlockRead() {
109
+ const globalState = useGlobalState()
110
+ return globalState.unlockRead
111
+ }
112
+ export function useIsUnlockTimeRefres() {
113
+ const globalState = useGlobalState()
114
+ return globalState.isUnlockTimeRefres
115
+ }
116
+
117
+ export function useInfiniteListScrollOffset() {
118
+ const globalState = useGlobalState()
119
+ return globalState.infiniteListScrollOffset
120
+ }
121
+
122
+ export function useInfiniteListScrollState() {
123
+ const globalState = useGlobalState()
124
+ return {
125
+ offset: globalState.infiniteListScrollOffset,
126
+ direction: globalState.infiniteListScrollDirection,
127
+ activeTime: globalState.infiniteListScrollActiveTime,
128
+ }
129
+ }
130
+
131
+ export function useIsScrollViewTop() {
132
+ const globalState = useGlobalState()
133
+ return globalState.isScrollViewTop
134
+ }
135
+
136
+ export function useIsScrollViewBot() {
137
+ const globalState = useGlobalState()
138
+ return globalState.isScrollViewBot
139
+ }
140
+
141
+ export function useIsBiometricsSupported() {
142
+ const globalState = useGlobalState()
143
+ return globalState.isBiometricsSupported
144
+ }
145
+
146
+ export function useHasBiometricsKey() {
147
+ const globalState = useGlobalState()
148
+ return globalState.hasBiometricsKey
149
+ }
150
+
151
+ export function useSwitchChainModalVisible() {
152
+ const globalState = useGlobalState()
153
+ return globalState.switchChainModalVisible
154
+ }
155
+
156
+ export function useSetLockedOverlayVisibleCallback() {
157
+ const dispatch = useAppDispatch()
158
+ return useCallback(
159
+ (visible: boolean) => {
160
+ dispatch(
161
+ globalActions['update']!({
162
+ isLockedOverlayVisible: visible,
163
+ })
164
+ )
165
+ },
166
+ [dispatch]
167
+ )
168
+ }
169
+
170
+ export function useLockedOverlayVisible() {
171
+ const globalState = useGlobalState()
172
+ return globalState.isLockedOverlayVisible
173
+ }
174
+
175
+ export function useLockCallback() {
176
+ const dispatch = useAppDispatch()
177
+ const wallet = useWallet()
178
+ const navigation = useNavigation()
179
+ return useCallback(async () => {
180
+ dispatch(globalActions.update({ isLockedOverlayVisible: true }))
181
+ await wallet.lockWallet()
182
+ const isBooted = await wallet.isBooted()
183
+ const isUnlocked = await wallet.isUnlocked()
184
+ dispatch(globalActions.update({ isUnlocked: false }))
185
+
186
+ setTimeout(() => {
187
+ dispatch(globalActions.update({ isLockedOverlayVisible: false }))
188
+ }, 300)
189
+
190
+ if (!isBooted) {
191
+ navigation.navToWelcome()
192
+ return
193
+ }
194
+
195
+ if (!isUnlocked && !isBooted) {
196
+ navigation.navToWelcome()
197
+ return
198
+ }
199
+
200
+ if (!isUnlocked && isBooted) {
201
+ navigation.navToLock({ autoUnlockByFace: false })
202
+ return
203
+ }
204
+ const currentAccount = await wallet.getCurrentAccount()
205
+ if (!currentAccount) {
206
+ navigation.navToWelcome()
207
+ }
208
+ }, [dispatch, wallet])
209
+ }
210
+
50
211
  export function useUnlockCallback() {
51
212
  const dispatch = useAppDispatch()
52
213
  const wallet = useWallet()
53
- const [, resolveApproval] = useApproval()
214
+ const { resolveApproval } = useApproval()
54
215
  return useCallback(
55
216
  async (password: string) => {
56
217
  await wallet.unlock(password)
@@ -70,14 +231,16 @@ export function useCreateAccountCallback() {
70
231
  hdPath: string,
71
232
  passphrase: string,
72
233
  addressType: AddressType,
73
- accountCount: number
234
+ accountCount: number,
235
+ accountIndexDerivation = false
74
236
  ) => {
75
237
  await wallet.createKeyringWithMnemonics(
76
238
  mnemonics,
77
239
  hdPath,
78
240
  passphrase,
79
241
  addressType,
80
- accountCount
242
+ accountCount,
243
+ accountIndexDerivation
81
244
  )
82
245
  dispatch(globalActions.update({ isUnlocked: true }))
83
246
  },
@@ -1,10 +1,9 @@
1
1
  export * from './accounts'
2
- export * from './approval'
3
2
  export * from './base'
4
3
  export * from './discovery'
5
4
  export * from './global'
6
- export * from './i18n'
7
5
  export * from './keyrings'
8
6
  export * from './settings'
9
7
  export * from './transactions'
10
8
  export * from './ui'
9
+ export * from './browser'
@@ -1,18 +1,17 @@
1
1
  import compareVersions from 'compare-versions'
2
2
  import { useCallback } from 'react'
3
3
 
4
- import { CHAINS_MAP, CAT_VERSION, VERSION } from '@unisat/wallet-shared'
4
+ import { BABYLON_CONFIG_MAP } from '@unisat/babylon-service/types'
5
+ import { CAT_VERSION, CHAINS_MAP, PlatformEnv } from '@unisat/wallet-shared'
5
6
  import { AddressType, ChainType, NetworkType } from '@unisat/wallet-types'
6
7
  import { useWallet } from '../context/WalletContext'
7
8
  import { getAddressType } from '../utils/bitcoin-utils'
8
- import i18n, { addResourceBundle } from '../utils/i18n'
9
- import { BABYLON_CONFIG_MAP } from '@unisat/babylon-service/types'
10
- import { t } from '@unisat/i18n'
11
9
 
10
+ import { useI18n } from 'src/context/I18nContext'
12
11
  import { AppState } from '..'
13
12
  import { useCurrentAccount } from '../hooks/accounts'
14
- import { useAppDispatch, useAppSelector } from './base'
15
13
  import { settingsActions } from '../reducers/settings'
14
+ import { useAppDispatch, useAppSelector } from './base'
16
15
 
17
16
  export function useSettingsState(): AppState['settings'] {
18
17
  return useAppSelector(state => state.settings)
@@ -26,11 +25,12 @@ export function useLocale() {
26
25
  export function useChangeLocaleCallback() {
27
26
  const dispatch = useAppDispatch()
28
27
  const wallet = useWallet()
28
+ const i18n = useI18n()
29
29
  return useCallback(
30
30
  async (locale: string) => {
31
31
  await wallet.setLocale(locale)
32
- await addResourceBundle(locale)
33
- i18n.changeLanguage(locale)
32
+ await i18n.addResourceBundle(locale)
33
+ i18n.changeLocale(locale)
34
34
  dispatch(
35
35
  (settingsActions as any).updateSettings({
36
36
  locale,
@@ -94,12 +94,12 @@ export function useChangeChainTypeCallback() {
94
94
  const wallet = useWallet()
95
95
  return useCallback(
96
96
  async (type: ChainType) => {
97
+ await wallet.setChainType(type)
97
98
  dispatch(
98
99
  (settingsActions as any).updateSettings({
99
100
  chainType: type,
100
101
  })
101
102
  )
102
- await wallet.setChainType(type)
103
103
  },
104
104
  [dispatch]
105
105
  )
@@ -157,11 +157,21 @@ export function useCAT20TokenInfoExplorerUrl(version: CAT_VERSION, tokenId: stri
157
157
  }
158
158
  }
159
159
 
160
+ export function useBRC20TokenInfoExplorerUrl(ticker: string) {
161
+ const chain = useChain()!
162
+ return `${chain.unisatExplorerUrl}/brc20/${encodeURIComponent(ticker)}`
163
+ }
164
+
160
165
  export function useUnisatWebsite() {
161
166
  const chainType = useChainType()
162
167
  return CHAINS_MAP[chainType]!.unisatUrl
163
168
  }
164
169
 
170
+ export function useIconBaseUrl() {
171
+ const chainType = useChainType()
172
+ return CHAINS_MAP[chainType]!.iconBaseUrl
173
+ }
174
+
165
175
  export function useOrdinalsWebsite() {
166
176
  const chainType = useChainType()
167
177
  return CHAINS_MAP[chainType]!.ordinalsUrl
@@ -177,7 +187,7 @@ export function useVersionInfo() {
177
187
  const walletConfig = accountsState.walletConfig
178
188
  const newVersion = walletConfig.version
179
189
  const skippedVersion = accountsState.skippedVersion
180
- const currentVesion = VERSION!
190
+ const currentVesion = PlatformEnv.VERSION
181
191
  let skipped = false
182
192
  let latestVersion = ''
183
193
  // skip if new version is empty
@@ -191,7 +201,7 @@ export function useVersionInfo() {
191
201
  }
192
202
 
193
203
  // skip if current version is greater or equal to new version
194
- if (newVersion) {
204
+ if (currentVesion && newVersion) {
195
205
  if (compareVersions(currentVesion, newVersion) >= 0) {
196
206
  skipped = true
197
207
  } else {
@@ -208,6 +218,8 @@ export function useVersionInfo() {
208
218
  newVersion,
209
219
  latestVersion,
210
220
  skipped,
221
+ downloadUrl: '',
222
+ isNewest: false,
211
223
  }
212
224
  }
213
225
 
@@ -226,7 +238,12 @@ export function useAutoLockTimeId() {
226
238
  return state.autoLockTimeId
227
239
  }
228
240
 
229
- export function getAddressTips(address: string, chanEnum: ChainType) {
241
+ export function useAddressTips() {
242
+ const chain = useChain()!
243
+ const account = useCurrentAccount()
244
+ const address = account.address
245
+ const chanEnum = chain.enum
246
+ const { t } = useI18n()
230
247
  let ret = {
231
248
  homeTip: '',
232
249
  sendTip: '',
@@ -247,12 +264,6 @@ export function getAddressTips(address: string, chanEnum: ChainType) {
247
264
  return ret
248
265
  }
249
266
 
250
- export function useAddressTips() {
251
- const chain = useChain()!
252
- const account = useCurrentAccount()
253
- return getAddressTips(account.address, chain.enum)
254
- }
255
-
256
267
  export function useCAT721NFTContentBaseUrl(version: CAT_VERSION) {
257
268
  const chainType = useChainType()
258
269
  if (chainType === ChainType.FRACTAL_BITCOIN_MAINNET) {
@@ -268,26 +279,6 @@ export function useCAT721NFTContentBaseUrl(version: CAT_VERSION) {
268
279
  }
269
280
  }
270
281
 
271
- export function useBRC20MarketPlaceWebsite(ticker: string) {
272
- const chainType = useChainType()
273
- if (chainType === ChainType.BITCOIN_MAINNET) {
274
- if (ticker.length == 6) {
275
- return `${CHAINS_MAP[chainType]!.unisatUrl}/market/brc20_prog?tick=${ticker}`
276
- }
277
- }
278
- return `${CHAINS_MAP[chainType]!.unisatUrl}/market/brc20?tick=${ticker}`
279
- }
280
-
281
- export function useRunesMarketPlaceWebsite(ticker: string) {
282
- const chainType = useChainType()
283
- return `${CHAINS_MAP[chainType]!.unisatUrl}/runes/market?tick=${ticker}`
284
- }
285
-
286
- export function useCAT20MarketPlaceWebsite(tokenId: string) {
287
- const chainType = useChainType()
288
- return `${CHAINS_MAP[chainType]!.unisatUrl}/dex/cat20/${tokenId}`
289
- }
290
-
291
282
  export function useBabylonConfig() {
292
283
  const chainType = useChainType()
293
284
  return BABYLON_CONFIG_MAP[chainType] || BABYLON_CONFIG_MAP[ChainType.BITCOIN_MAINNET]