@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.
Files changed (290) hide show
  1. package/LICENSE +0 -5
  2. package/lib/actions/global.d.ts +2 -0
  3. package/lib/actions/global.d.ts.map +1 -0
  4. package/lib/context/ApprovalContext.d.ts +9 -0
  5. package/lib/context/ApprovalContext.d.ts.map +1 -0
  6. package/lib/context/DeviceContext.d.ts +17 -0
  7. package/lib/context/DeviceContext.d.ts.map +1 -0
  8. package/lib/context/I18nContext.d.ts +13 -0
  9. package/lib/context/I18nContext.d.ts.map +1 -0
  10. package/lib/context/NavigationContext.d.ts +218 -0
  11. package/lib/context/NavigationContext.d.ts.map +1 -0
  12. package/lib/context/PriceContext.d.ts +13 -0
  13. package/lib/context/PriceContext.d.ts.map +1 -0
  14. package/lib/context/StorageContext.d.ts +60 -0
  15. package/lib/context/StorageContext.d.ts.map +1 -0
  16. package/lib/context/ToolsContext.d.ts +17 -0
  17. package/lib/context/ToolsContext.d.ts.map +1 -0
  18. package/lib/context/WalletContext.d.ts +493 -0
  19. package/lib/context/WalletContext.d.ts.map +1 -0
  20. package/lib/context/index.d.ts +9 -0
  21. package/lib/context/index.d.ts.map +1 -0
  22. package/lib/hooks/accounts.d.ts +34 -0
  23. package/lib/hooks/accounts.d.ts.map +1 -0
  24. package/lib/hooks/base.d.ts +14 -0
  25. package/lib/hooks/base.d.ts.map +1 -0
  26. package/lib/hooks/browser.d.ts +32 -0
  27. package/lib/hooks/browser.d.ts.map +1 -0
  28. package/lib/hooks/discovery.d.ts +17 -0
  29. package/lib/hooks/discovery.d.ts.map +1 -0
  30. package/lib/hooks/global.d.ts +43 -0
  31. package/lib/hooks/global.d.ts.map +1 -0
  32. package/lib/hooks/index.d.ts +10 -0
  33. package/lib/hooks/index.d.ts.map +1 -0
  34. package/lib/hooks/keyrings.d.ts +5 -0
  35. package/lib/hooks/keyrings.d.ts.map +1 -0
  36. package/lib/hooks/settings.d.ts +43 -0
  37. package/lib/hooks/settings.d.ts.map +1 -0
  38. package/lib/hooks/transactions.d.ts +67 -0
  39. package/lib/hooks/transactions.d.ts.map +1 -0
  40. package/lib/hooks/ui.d.ts +112 -0
  41. package/lib/hooks/ui.d.ts.map +1 -0
  42. package/lib/index.d.mts +2072 -199
  43. package/lib/index.d.ts +31 -946
  44. package/lib/index.d.ts.map +1 -0
  45. package/lib/index.js +7176 -582
  46. package/lib/index.js.map +1 -1
  47. package/lib/index.mjs +6971 -525
  48. package/lib/index.mjs.map +1 -1
  49. package/lib/reducers/accounts.d.ts +49 -0
  50. package/lib/reducers/accounts.d.ts.map +1 -0
  51. package/lib/reducers/browser.d.ts +49 -0
  52. package/lib/reducers/browser.d.ts.map +1 -0
  53. package/lib/reducers/discovery.d.ts +22 -0
  54. package/lib/reducers/discovery.d.ts.map +1 -0
  55. package/lib/reducers/global.d.ts +35 -0
  56. package/lib/reducers/global.d.ts.map +1 -0
  57. package/lib/reducers/index.d.ts +9 -0
  58. package/lib/reducers/index.d.ts.map +1 -0
  59. package/lib/reducers/keyrings.d.ts +10 -0
  60. package/lib/reducers/keyrings.d.ts.map +1 -0
  61. package/lib/reducers/settings.d.ts +16 -0
  62. package/lib/reducers/settings.d.ts.map +1 -0
  63. package/lib/reducers/transactions.d.ts +61 -0
  64. package/lib/reducers/transactions.d.ts.map +1 -0
  65. package/lib/reducers/ui.d.ts +55 -0
  66. package/lib/reducers/ui.d.ts.map +1 -0
  67. package/lib/types/index.d.mts +7 -3
  68. package/lib/types/index.d.ts +3 -30
  69. package/lib/types/index.d.ts.map +1 -0
  70. package/lib/types/index.js +7 -1
  71. package/lib/types/index.js.map +1 -1
  72. package/lib/types/index.mjs +7 -2
  73. package/lib/types/index.mjs.map +1 -1
  74. package/lib/types/ui.d.ts +31 -0
  75. package/lib/types/ui.d.ts.map +1 -0
  76. package/lib/ui-hooks/index.d.ts +55 -0
  77. package/lib/ui-hooks/index.d.ts.map +1 -0
  78. package/lib/ui-hooks/useActionOverviewSectionLogic.d.ts +12 -0
  79. package/lib/ui-hooks/useActionOverviewSectionLogic.d.ts.map +1 -0
  80. package/lib/ui-hooks/useAddressTypeScreenLogic.d.ts +19 -0
  81. package/lib/ui-hooks/useAddressTypeScreenLogic.d.ts.map +1 -0
  82. package/lib/ui-hooks/useAlkanesBalanceCardLogic.d.ts +19 -0
  83. package/lib/ui-hooks/useAlkanesBalanceCardLogic.d.ts.map +1 -0
  84. package/lib/ui-hooks/useAlkanesCollectionListLogic.d.ts +11 -0
  85. package/lib/ui-hooks/useAlkanesCollectionListLogic.d.ts.map +1 -0
  86. package/lib/ui-hooks/useAlkanesListLogic.d.ts +14 -0
  87. package/lib/ui-hooks/useAlkanesListLogic.d.ts.map +1 -0
  88. package/lib/ui-hooks/useAlkanesNFTListLogic.d.ts +11 -0
  89. package/lib/ui-hooks/useAlkanesNFTListLogic.d.ts.map +1 -0
  90. package/lib/ui-hooks/useAlkanesNFTScreenLogic.d.ts +9 -0
  91. package/lib/ui-hooks/useAlkanesNFTScreenLogic.d.ts.map +1 -0
  92. package/lib/ui-hooks/useAlkanesTokenScreenLogic.d.ts +22 -0
  93. package/lib/ui-hooks/useAlkanesTokenScreenLogic.d.ts.map +1 -0
  94. package/lib/ui-hooks/useAmountInputLogic.d.ts +22 -0
  95. package/lib/ui-hooks/useAmountInputLogic.d.ts.map +1 -0
  96. package/lib/ui-hooks/useAnnouncementCardLogic.d.ts +11 -0
  97. package/lib/ui-hooks/useAnnouncementCardLogic.d.ts.map +1 -0
  98. package/lib/ui-hooks/useBRC20BalanceCardLogic.d.ts +26 -0
  99. package/lib/ui-hooks/useBRC20BalanceCardLogic.d.ts.map +1 -0
  100. package/lib/ui-hooks/useBRC20InscribeTransferLogic.d.ts +103 -0
  101. package/lib/ui-hooks/useBRC20InscribeTransferLogic.d.ts.map +1 -0
  102. package/lib/ui-hooks/useBRC20ListLogic.d.ts +14 -0
  103. package/lib/ui-hooks/useBRC20ListLogic.d.ts.map +1 -0
  104. package/lib/ui-hooks/useBRC20ProgListLogic.d.ts +14 -0
  105. package/lib/ui-hooks/useBRC20ProgListLogic.d.ts.map +1 -0
  106. package/lib/ui-hooks/useBRC20SendScreenLogic.d.ts +67 -0
  107. package/lib/ui-hooks/useBRC20SendScreenLogic.d.ts.map +1 -0
  108. package/lib/ui-hooks/useBRC20SingleStepScreenLogic.d.ts +36 -0
  109. package/lib/ui-hooks/useBRC20SingleStepScreenLogic.d.ts.map +1 -0
  110. package/lib/ui-hooks/useBRC20TokenScreenLogic.d.ts +75 -0
  111. package/lib/ui-hooks/useBRC20TokenScreenLogic.d.ts.map +1 -0
  112. package/lib/ui-hooks/useBalanceCardLogic.d.ts +26 -0
  113. package/lib/ui-hooks/useBalanceCardLogic.d.ts.map +1 -0
  114. package/lib/ui-hooks/useBtcDisplayLogic.d.ts +5 -0
  115. package/lib/ui-hooks/useBtcDisplayLogic.d.ts.map +1 -0
  116. package/lib/ui-hooks/useCAT20BalanceCardLogic.d.ts +20 -0
  117. package/lib/ui-hooks/useCAT20BalanceCardLogic.d.ts.map +1 -0
  118. package/lib/ui-hooks/useCAT20ListLogic.d.ts +14 -0
  119. package/lib/ui-hooks/useCAT20ListLogic.d.ts.map +1 -0
  120. package/lib/ui-hooks/useCAT20TokenScreenLogic.d.ts +19 -0
  121. package/lib/ui-hooks/useCAT20TokenScreenLogic.d.ts.map +1 -0
  122. package/lib/ui-hooks/useCAT721ListLogic.d.ts +11 -0
  123. package/lib/ui-hooks/useCAT721ListLogic.d.ts.map +1 -0
  124. package/lib/ui-hooks/useCAT721NFTScreenLogic.d.ts +9 -0
  125. package/lib/ui-hooks/useCAT721NFTScreenLogic.d.ts.map +1 -0
  126. package/lib/ui-hooks/useCreatePasswordScreenLogic.d.ts +27 -0
  127. package/lib/ui-hooks/useCreatePasswordScreenLogic.d.ts.map +1 -0
  128. package/lib/ui-hooks/useCreateWalletLogicImportWordsStep.d.ts +78 -0
  129. package/lib/ui-hooks/useCreateWalletLogicImportWordsStep.d.ts.map +1 -0
  130. package/lib/ui-hooks/useEditAccountNameScreenLogic.d.ts +18 -0
  131. package/lib/ui-hooks/useEditAccountNameScreenLogic.d.ts.map +1 -0
  132. package/lib/ui-hooks/useEditContactScreenLogic.d.ts +24 -0
  133. package/lib/ui-hooks/useEditContactScreenLogic.d.ts.map +1 -0
  134. package/lib/ui-hooks/useEditWalletNameScreenLogic.d.ts +15 -0
  135. package/lib/ui-hooks/useEditWalletNameScreenLogic.d.ts.map +1 -0
  136. package/lib/ui-hooks/useExportMnemonicsScreenLogic.d.ts +18 -0
  137. package/lib/ui-hooks/useExportMnemonicsScreenLogic.d.ts.map +1 -0
  138. package/lib/ui-hooks/useExportPrivateKeyScreenLogic.d.ts +17 -0
  139. package/lib/ui-hooks/useExportPrivateKeyScreenLogic.d.ts.map +1 -0
  140. package/lib/ui-hooks/useFeeRateBarLogic.d.ts +34 -0
  141. package/lib/ui-hooks/useFeeRateBarLogic.d.ts.map +1 -0
  142. package/lib/ui-hooks/useInfiniteList.d.ts +19 -0
  143. package/lib/ui-hooks/useInfiniteList.d.ts.map +1 -0
  144. package/lib/ui-hooks/useInscriptionListLogic.d.ts +11 -0
  145. package/lib/ui-hooks/useInscriptionListLogic.d.ts.map +1 -0
  146. package/lib/ui-hooks/useLockTimePageLogic.d.ts +11 -0
  147. package/lib/ui-hooks/useLockTimePageLogic.d.ts.map +1 -0
  148. package/lib/ui-hooks/useNotificationsLogic.d.ts +14 -0
  149. package/lib/ui-hooks/useNotificationsLogic.d.ts.map +1 -0
  150. package/lib/ui-hooks/useOrdinalsInscriptionScreenLogic.d.ts +27 -0
  151. package/lib/ui-hooks/useOrdinalsInscriptionScreenLogic.d.ts.map +1 -0
  152. package/lib/ui-hooks/useRunesBalanceCardLogic.d.ts +19 -0
  153. package/lib/ui-hooks/useRunesBalanceCardLogic.d.ts.map +1 -0
  154. package/lib/ui-hooks/useRunesListLogic.d.ts +14 -0
  155. package/lib/ui-hooks/useRunesListLogic.d.ts.map +1 -0
  156. package/lib/ui-hooks/useRunesTokenScreenLogic.d.ts +22 -0
  157. package/lib/ui-hooks/useRunesTokenScreenLogic.d.ts.map +1 -0
  158. package/lib/ui-hooks/useSecurityCardLogic.d.ts +1 -0
  159. package/lib/ui-hooks/useSecurityCardLogic.d.ts.map +1 -0
  160. package/lib/ui-hooks/useSendAlkanesNFTScreenLogic.d.ts +32 -0
  161. package/lib/ui-hooks/useSendAlkanesNFTScreenLogic.d.ts.map +1 -0
  162. package/lib/ui-hooks/useSendAlkanesScreenLogic.d.ts +37 -0
  163. package/lib/ui-hooks/useSendAlkanesScreenLogic.d.ts.map +1 -0
  164. package/lib/ui-hooks/useSendCAT20ScreenLogic.d.ts +44 -0
  165. package/lib/ui-hooks/useSendCAT20ScreenLogic.d.ts.map +1 -0
  166. package/lib/ui-hooks/useSendCAT721ScreenLogic.d.ts +40 -0
  167. package/lib/ui-hooks/useSendCAT721ScreenLogic.d.ts.map +1 -0
  168. package/lib/ui-hooks/useSendOrdinalsInscriptionScreenLogic.d.ts +22 -0
  169. package/lib/ui-hooks/useSendOrdinalsInscriptionScreenLogic.d.ts.map +1 -0
  170. package/lib/ui-hooks/useSendRunesScreenLogic.d.ts +30 -0
  171. package/lib/ui-hooks/useSendRunesScreenLogic.d.ts.map +1 -0
  172. package/lib/ui-hooks/useSettingsTabScreenLogic.d.ts +72 -0
  173. package/lib/ui-hooks/useSettingsTabScreenLogic.d.ts.map +1 -0
  174. package/lib/ui-hooks/useSignMessageLogic.d.ts +54 -0
  175. package/lib/ui-hooks/useSignMessageLogic.d.ts.map +1 -0
  176. package/lib/ui-hooks/useSignPsbtLogic.d.ts +82 -0
  177. package/lib/ui-hooks/useSignPsbtLogic.d.ts.map +1 -0
  178. package/lib/ui-hooks/useSplitOrdinalsInscriptionScreenLogic.d.ts +15 -0
  179. package/lib/ui-hooks/useSplitOrdinalsInscriptionScreenLogic.d.ts.map +1 -0
  180. package/lib/ui-hooks/useTxConfirmScreenLogic.d.ts +8 -0
  181. package/lib/ui-hooks/useTxConfirmScreenLogic.d.ts.map +1 -0
  182. package/lib/ui-hooks/useTxCreateScreenLogic.d.ts +28 -0
  183. package/lib/ui-hooks/useTxCreateScreenLogic.d.ts.map +1 -0
  184. package/lib/ui-hooks/useTxFailScreenLogic.d.ts +7 -0
  185. package/lib/ui-hooks/useTxFailScreenLogic.d.ts.map +1 -0
  186. package/lib/ui-hooks/useTxSuccessScreenLogic.d.ts +8 -0
  187. package/lib/ui-hooks/useTxSuccessScreenLogic.d.ts.map +1 -0
  188. package/lib/updater/accounts.d.ts +2 -0
  189. package/lib/updater/accounts.d.ts.map +1 -0
  190. package/lib/updater/index.d.ts +2 -0
  191. package/lib/updater/index.d.ts.map +1 -0
  192. package/lib/utils/bitcoin-utils.d.ts +7 -0
  193. package/lib/utils/bitcoin-utils.d.ts.map +1 -0
  194. package/lib/utils/eventBus.d.ts +12 -0
  195. package/lib/utils/eventBus.d.ts.map +1 -0
  196. package/lib/utils/password-utils.d.ts +12 -0
  197. package/lib/utils/password-utils.d.ts.map +1 -0
  198. package/lib/utils/ui-utils.d.ts +4 -0
  199. package/lib/utils/ui-utils.d.ts.map +1 -0
  200. package/package.json +19 -15
  201. package/src/.DS_Store +0 -0
  202. package/src/context/ApprovalContext.tsx +27 -0
  203. package/src/context/DeviceContext.tsx +36 -0
  204. package/src/context/I18nContext.tsx +14 -172
  205. package/src/context/NavigationContext.tsx +305 -0
  206. package/src/context/PriceContext.tsx +2 -2
  207. package/src/context/StorageContext.tsx +393 -0
  208. package/src/context/ToolsContext.tsx +50 -0
  209. package/src/context/WalletContext.tsx +170 -126
  210. package/src/context/index.ts +17 -2
  211. package/src/hooks/accounts.ts +11 -5
  212. package/src/hooks/browser.ts +11 -0
  213. package/src/hooks/global.ts +170 -7
  214. package/src/hooks/index.ts +1 -2
  215. package/src/hooks/settings.ts +38 -37
  216. package/src/hooks/transactions.ts +45 -151
  217. package/src/hooks/ui.ts +239 -35
  218. package/src/index.ts +33 -24
  219. package/src/reducers/accounts.ts +22 -2
  220. package/src/reducers/browser.ts +223 -0
  221. package/src/reducers/global.ts +67 -1
  222. package/src/reducers/index.ts +1 -0
  223. package/src/reducers/transactions.ts +0 -9
  224. package/src/reducers/ui.ts +144 -4
  225. package/src/types/index.ts +1 -1
  226. package/src/types/ui.ts +6 -1
  227. package/src/ui-hooks/index.ts +107 -0
  228. package/src/ui-hooks/useActionOverviewSectionLogic.ts +150 -0
  229. package/src/ui-hooks/useAddressTypeScreenLogic.ts +160 -0
  230. package/src/ui-hooks/useAlkanesBalanceCardLogic.ts +41 -0
  231. package/src/ui-hooks/useAlkanesCollectionListLogic.ts +68 -0
  232. package/src/ui-hooks/useAlkanesListLogic.ts +69 -0
  233. package/src/ui-hooks/useAlkanesNFTListLogic.ts +42 -0
  234. package/src/ui-hooks/useAlkanesNFTScreenLogic.ts +45 -0
  235. package/src/ui-hooks/useAlkanesTokenScreenLogic.ts +138 -0
  236. package/src/ui-hooks/useAmountInputLogic.ts +80 -0
  237. package/src/ui-hooks/useAnnouncementCardLogic.ts +91 -0
  238. package/src/ui-hooks/useBRC20BalanceCardLogic.ts +115 -0
  239. package/src/ui-hooks/useBRC20InscribeTransferLogic.ts +418 -0
  240. package/src/ui-hooks/useBRC20ListLogic.ts +79 -0
  241. package/src/ui-hooks/useBRC20ProgListLogic.ts +81 -0
  242. package/src/ui-hooks/useBRC20SendScreenLogic.ts +424 -0
  243. package/src/ui-hooks/useBRC20SingleStepScreenLogic.ts +208 -0
  244. package/src/ui-hooks/useBRC20TokenScreenLogic.ts +489 -0
  245. package/src/ui-hooks/useBalanceCardLogic.ts +164 -0
  246. package/src/ui-hooks/useBtcDisplayLogic.ts +16 -0
  247. package/src/ui-hooks/useCAT20BalanceCardLogic.ts +35 -0
  248. package/src/ui-hooks/useCAT20ListLogic.ts +83 -0
  249. package/src/ui-hooks/useCAT20TokenScreenLogic.ts +127 -0
  250. package/src/ui-hooks/useCAT721ListLogic.ts +68 -0
  251. package/src/ui-hooks/useCAT721NFTScreenLogic.ts +37 -0
  252. package/src/ui-hooks/useCreatePasswordScreenLogic.ts +92 -0
  253. package/src/ui-hooks/useCreateWalletLogicImportWordsStep.ts +299 -0
  254. package/src/ui-hooks/useEditAccountNameScreenLogic.ts +71 -0
  255. package/src/ui-hooks/useEditContactScreenLogic.ts +162 -0
  256. package/src/ui-hooks/useEditWalletNameScreenLogic.ts +60 -0
  257. package/src/ui-hooks/useExportMnemonicsScreenLogic.ts +75 -0
  258. package/src/ui-hooks/useExportPrivateKeyScreenLogic.ts +64 -0
  259. package/src/ui-hooks/useFeeRateBarLogic.ts +303 -0
  260. package/src/ui-hooks/useInfiniteList.ts +85 -0
  261. package/src/ui-hooks/useInscriptionListLogic.ts +68 -0
  262. package/src/ui-hooks/useLockTimePageLogic.ts +43 -0
  263. package/src/ui-hooks/useNotificationsLogic.ts +115 -0
  264. package/src/ui-hooks/useOrdinalsInscriptionScreenLogic.ts +130 -0
  265. package/src/ui-hooks/useRunesBalanceCardLogic.ts +44 -0
  266. package/src/ui-hooks/useRunesListLogic.ts +74 -0
  267. package/src/ui-hooks/useRunesTokenScreenLogic.ts +156 -0
  268. package/src/ui-hooks/useSecurityCardLogic.ts +0 -0
  269. package/src/ui-hooks/useSendAlkanesNFTScreenLogic.ts +160 -0
  270. package/src/ui-hooks/useSendAlkanesScreenLogic.ts +208 -0
  271. package/src/ui-hooks/useSendCAT20ScreenLogic.ts +297 -0
  272. package/src/ui-hooks/useSendCAT721ScreenLogic.ts +205 -0
  273. package/src/ui-hooks/useSendOrdinalsInscriptionScreenLogic.ts +152 -0
  274. package/src/ui-hooks/useSendRunesScreenLogic.ts +189 -0
  275. package/src/ui-hooks/useSettingsTabScreenLogic.ts +211 -0
  276. package/src/ui-hooks/useSignMessageLogic.ts +302 -0
  277. package/src/ui-hooks/useSignPsbtLogic.ts +517 -0
  278. package/src/ui-hooks/useSplitOrdinalsInscriptionScreenLogic.ts +109 -0
  279. package/src/ui-hooks/useTxConfirmScreenLogic.ts +47 -0
  280. package/src/ui-hooks/useTxCreateScreenLogic.ts +177 -0
  281. package/src/ui-hooks/useTxFailScreenLogic.ts +26 -0
  282. package/src/ui-hooks/useTxSuccessScreenLogic.ts +33 -0
  283. package/src/updater/accounts.ts +11 -11
  284. package/src/utils/bitcoin-utils.ts +17 -8
  285. package/src/utils/eventBus.ts +2 -1
  286. package/src/utils/password-utils.ts +78 -0
  287. package/src/utils/ui-utils.ts +28 -0
  288. package/src/hooks/approval.ts +0 -72
  289. package/src/hooks/i18n.ts +0 -53
  290. package/src/utils/i18n.ts +0 -41
@@ -0,0 +1,83 @@
1
+ import { useEffect, useRef, useState } from 'react'
2
+
3
+ import { CAT20Balance, CAT_VERSION, TickPriceItem } from '@unisat/wallet-shared'
4
+
5
+ import {
6
+ CATAssetTabKey,
7
+ getSupportedAssets,
8
+ useCATAssetTabKey,
9
+ useChainType,
10
+ useCurrentAccount,
11
+ useNavigation,
12
+ useWallet,
13
+ useWallTabFocusRefresh,
14
+ } from '..'
15
+ import { useInfiniteList } from './useInfiniteList'
16
+
17
+ export function useCAT20ListLogic(version: CAT_VERSION) {
18
+ const nav = useNavigation()
19
+ const wallet = useWallet()
20
+ const currentAccount = useCurrentAccount()
21
+ const chainType = useChainType()
22
+ const [priceMap, setPriceMap] = useState<{ [key: string]: TickPriceItem }>({})
23
+
24
+ const priceMapRef = useRef(priceMap)
25
+ const updatePrices = (res: { [tick: string]: TickPriceItem }) => {
26
+ const newPriceMap = { ...priceMapRef.current }
27
+ Object.keys(res).forEach(tick => {
28
+ newPriceMap[tick] = res[tick]
29
+ })
30
+ priceMapRef.current = newPriceMap
31
+ setPriceMap(newPriceMap)
32
+ }
33
+
34
+ const {
35
+ data: tokens,
36
+ total,
37
+ loading,
38
+ hasMore,
39
+ onRefresh,
40
+ onLoadMore,
41
+ } = useInfiniteList<CAT20Balance>({
42
+ fetcher: async (page, pageSize) => {
43
+ const supportedAssets = getSupportedAssets(chainType, currentAccount.address)
44
+ if (!supportedAssets.assets.CAT20 || currentAccount.address === '') {
45
+ return { list: [], total: 0 }
46
+ }
47
+ const { list, total } = await wallet.getCAT20List(
48
+ version,
49
+ currentAccount.address,
50
+ page,
51
+ pageSize
52
+ )
53
+ if (list.length > 0) {
54
+ wallet.getCAT20sPrice(list.map(item => item.tokenId)).then(updatePrices)
55
+ }
56
+ return { list, total }
57
+ },
58
+ dependencies: [currentAccount.address, version, chainType],
59
+ })
60
+
61
+ const tabKey = useCATAssetTabKey()
62
+ const isFocus = tabKey === CATAssetTabKey.CAT20 || CATAssetTabKey.CAT20_V2
63
+ const lastRefreshTimeRef = useRef<number>(0)
64
+ const walletTabFocusRefresh = useWallTabFocusRefresh()
65
+ useEffect(() => {
66
+ if (!isFocus) return
67
+
68
+ // already refreshed → do nothing
69
+ const alreadyRefreshed = lastRefreshTimeRef.current === walletTabFocusRefresh
70
+ if (alreadyRefreshed) return
71
+
72
+ onRefresh()
73
+
74
+ // mark refreshed
75
+ lastRefreshTimeRef.current = walletTabFocusRefresh
76
+ }, [walletTabFocusRefresh, isFocus])
77
+
78
+ const onClickItem = (item: CAT20Balance) => {
79
+ nav.navigate('CAT20TokenScreen', { tokenId: item.tokenId, version })
80
+ }
81
+
82
+ return { tokens, total, loading, hasMore, onRefresh, onLoadMore, onClickItem, priceMap }
83
+ }
@@ -0,0 +1,127 @@
1
+ import { KeyringType } from '@unisat/keyring-service/types'
2
+ import { AddressCAT20TokenSummary, CAT_VERSION } from '@unisat/wallet-shared'
3
+ import { ChainType } from '@unisat/wallet-types'
4
+ import { useEffect, useMemo, useState } from 'react'
5
+ import { useI18n, useNavigation, useTools, useWallet } from 'src/context'
6
+ import {
7
+ useCAT20IconInfo,
8
+ useCAT20MarketPlaceWebsite,
9
+ useCAT20TokenInfoExplorerUrl,
10
+ useChainType,
11
+ useCurrentAccount,
12
+ useCurrentKeyring,
13
+ useResetTxState,
14
+ } from 'src/hooks'
15
+
16
+ export function useCAT20TokenScreenLogic() {
17
+ const nav = useNavigation()
18
+ const { tokenId, version } = nav.getRouteState<'CAT20TokenScreen'>()
19
+ const { t } = useI18n()
20
+ const [tokenSummary, setTokenSummary] = useState<AddressCAT20TokenSummary>({
21
+ cat20Balance: {
22
+ tokenId: '',
23
+ amount: '0',
24
+ decimals: 0,
25
+ symbol: '',
26
+ name: '',
27
+ },
28
+ cat20Info: {
29
+ tokenId: '',
30
+ name: '',
31
+ symbol: '',
32
+ max: '0',
33
+ premine: '0',
34
+ limit: 0,
35
+ },
36
+ })
37
+
38
+ const wallet = useWallet()
39
+
40
+ const account = useCurrentAccount()
41
+ const keyring = useCurrentKeyring()
42
+ const [loading, setLoading] = useState(true)
43
+ const tools = useTools()
44
+ useEffect(() => {
45
+ wallet.getAddressCAT20TokenSummary(version, account.address, tokenId).then(tokenSummary => {
46
+ setTokenSummary(tokenSummary)
47
+ setLoading(false)
48
+ })
49
+ }, [])
50
+
51
+ const tokenUrl = useCAT20TokenInfoExplorerUrl(version, tokenSummary.cat20Info.tokenId)
52
+
53
+ const enableTransfer = useMemo(() => {
54
+ let enable = false
55
+ if (tokenSummary.cat20Balance && tokenSummary.cat20Balance.amount !== '0') {
56
+ enable = true
57
+ }
58
+ return enable
59
+ }, [tokenSummary])
60
+
61
+ const chainType = useChainType()
62
+ const enableTrade = useMemo(() => {
63
+ if (chainType === ChainType.FRACTAL_BITCOIN_MAINNET && version === CAT_VERSION.V1) {
64
+ return true
65
+ } else {
66
+ return false
67
+ }
68
+ }, [chainType])
69
+ const marketPlaceUrl = useCAT20MarketPlaceWebsite(tokenId)
70
+
71
+ const resetTxState = useResetTxState()
72
+
73
+ const onClickBack = () => {
74
+ nav.goBack()
75
+ }
76
+
77
+ const onClickMerge = e => {
78
+ if (keyring.type === KeyringType.KeystoneKeyring) {
79
+ tools.toastError(t('merge_utxos_is_not_supported_for_keystone_yet'))
80
+ return
81
+ }
82
+ resetTxState()
83
+ nav.navigate('MergeCAT20Screen', {
84
+ version: version,
85
+ cat20Balance: tokenSummary.cat20Balance,
86
+ cat20Info: tokenSummary.cat20Info,
87
+ })
88
+ }
89
+
90
+ const onClickSend = e => {
91
+ if (keyring.type === KeyringType.KeystoneKeyring) {
92
+ tools.toastError(t('send_cat20_is_not_supported_for_keystone_yet'))
93
+ return
94
+ }
95
+ resetTxState()
96
+ nav.navigate('SendCAT20Screen', {
97
+ version: version,
98
+ cat20Balance: tokenSummary.cat20Balance,
99
+ cat20Info: tokenSummary.cat20Info,
100
+ })
101
+ }
102
+
103
+ const onClickTrade = e => {
104
+ nav.navToUrl(marketPlaceUrl)
105
+ }
106
+
107
+ const onClickViewOnExplorer = e => {
108
+ nav.navToUrl(tokenUrl)
109
+ }
110
+
111
+ const iconInfo = useCAT20IconInfo(tokenSummary.cat20Info.name, tokenSummary.cat20Info.tokenId)
112
+
113
+ return {
114
+ tokenSummary,
115
+ loading,
116
+ tokenUrl,
117
+ enableTransfer,
118
+ enableTrade,
119
+ iconInfo,
120
+ onClickMerge,
121
+ onClickSend,
122
+ onClickTrade,
123
+ onClickBack,
124
+ onClickViewOnExplorer,
125
+ t,
126
+ }
127
+ }
@@ -0,0 +1,68 @@
1
+ import { useEffect, useRef } from 'react'
2
+
3
+ import { CAT721Balance, CAT_VERSION } from '@unisat/wallet-shared'
4
+
5
+ import {
6
+ CATAssetTabKey,
7
+ getSupportedAssets,
8
+ useCATAssetTabKey,
9
+ useChainType,
10
+ useCurrentAccount,
11
+ useNavigation,
12
+ useWallet,
13
+ useWallTabFocusRefresh,
14
+ } from '..'
15
+ import { useInfiniteList } from './useInfiniteList'
16
+
17
+ export function useCAT721ListLogic(version: CAT_VERSION) {
18
+ const nav = useNavigation()
19
+ const wallet = useWallet()
20
+ const currentAccount = useCurrentAccount()
21
+ const chainType = useChainType()
22
+ const {
23
+ data: tokens,
24
+ total,
25
+ loading,
26
+ hasMore,
27
+ onRefresh,
28
+ onLoadMore,
29
+ } = useInfiniteList<CAT721Balance>({
30
+ fetcher: async (page, pageSize) => {
31
+ const supportedAssets = getSupportedAssets(chainType, currentAccount.address)
32
+ if (!supportedAssets.assets.CAT20 || currentAccount.address === '') {
33
+ return { list: [], total: 0 }
34
+ }
35
+ const { list, total } = await wallet.getCAT721List(
36
+ version,
37
+ currentAccount.address,
38
+ page,
39
+ pageSize
40
+ )
41
+ return { list, total }
42
+ },
43
+ dependencies: [currentAccount.address, version, chainType],
44
+ })
45
+
46
+ const tabKey = useCATAssetTabKey()
47
+ const isFocus = tabKey === CATAssetTabKey.CAT721 || CATAssetTabKey.CAT721_V2
48
+ const lastRefreshTimeRef = useRef<number>(0)
49
+ const walletTabFocusRefresh = useWallTabFocusRefresh()
50
+ useEffect(() => {
51
+ if (!isFocus) return
52
+
53
+ // already refreshed → do nothing
54
+ const alreadyRefreshed = lastRefreshTimeRef.current === walletTabFocusRefresh
55
+ if (alreadyRefreshed) return
56
+
57
+ onRefresh()
58
+
59
+ // mark refreshed
60
+ lastRefreshTimeRef.current = walletTabFocusRefresh
61
+ }, [walletTabFocusRefresh, isFocus])
62
+
63
+ const onClickItem = (item: CAT721Balance) => {
64
+ nav.navigate('CAT721CollectionScreen', { collectionId: item.collectionId, version })
65
+ }
66
+
67
+ return { tokens, total, loading, hasMore, onRefresh, onLoadMore, onClickItem }
68
+ }
@@ -0,0 +1,37 @@
1
+ import { useI18n, useNavigation } from 'src/context'
2
+ import { useResetTxState } from 'src/hooks'
3
+
4
+ export function useCAT721NFTScreenLogic() {
5
+ const nav = useNavigation()
6
+ const { collectionInfo, localId, version } = nav.getRouteState<'CAT721NFTScreen'>()
7
+
8
+ const { t } = useI18n()
9
+
10
+ const resetTxState = useResetTxState()
11
+
12
+ const onClickBack = () => {
13
+ nav.goBack()
14
+ }
15
+
16
+ const onClickSend = () => {
17
+ resetTxState()
18
+ nav.navigate('SendCAT721Screen', {
19
+ version: version,
20
+ collectionInfo: collectionInfo,
21
+ localId: localId,
22
+ })
23
+ }
24
+
25
+ return {
26
+ // info
27
+ collectionInfo,
28
+ localId,
29
+ version,
30
+ // i18n
31
+ t,
32
+
33
+ // actions
34
+ onClickBack,
35
+ onClickSend,
36
+ }
37
+ }
@@ -0,0 +1,92 @@
1
+ import { useEffect, useMemo, useState } from 'react'
2
+ import { useI18n, useNavigation, useTools, useWallet } from 'src/context'
3
+ import { getPasswordStrengthWord, MIN_PASSWORD_LENGTH } from 'src/utils/password-utils'
4
+
5
+ export function useCreatePasswordScreenLogic() {
6
+ const nav = useNavigation()
7
+ const { isNewAccount, isKeystone, fromColdWallet } = nav.getRouteState<'CreatePasswordScreen'>()
8
+ const [newPassword, setNewPassword] = useState('')
9
+ const { t } = useI18n()
10
+
11
+ const [confirmPassword, setConfirmPassword] = useState('')
12
+
13
+ const [disabled, setDisabled] = useState(true)
14
+
15
+ const wallet = useWallet()
16
+
17
+ const tools = useTools()
18
+ const bootWithPassword = (password: string) => {
19
+ wallet
20
+ .boot(password)
21
+ .then(() => {
22
+ if (fromColdWallet) {
23
+ nav.navigate('CreateColdWalletScreen', { fromUnlock: true })
24
+ } else if (isKeystone) {
25
+ nav.navigate('CreateKeystoneWalletScreen', { fromUnlock: true })
26
+ } else if (isNewAccount) {
27
+ nav.navigate('CreateHDWalletScreen', { isImport: false, fromUnlock: true })
28
+ } else {
29
+ nav.navigate('CreateHDWalletScreen', { isImport: true, fromUnlock: true })
30
+ }
31
+ })
32
+ .catch(err => {
33
+ tools.toastError(err)
34
+ })
35
+ }
36
+
37
+ useEffect(() => {
38
+ setDisabled(true)
39
+
40
+ if (
41
+ newPassword &&
42
+ newPassword.length >= MIN_PASSWORD_LENGTH &&
43
+ newPassword === confirmPassword
44
+ ) {
45
+ setDisabled(false)
46
+ return
47
+ }
48
+ }, [newPassword, confirmPassword])
49
+
50
+ const strongTextRenderData = useMemo(() => {
51
+ if (!newPassword) {
52
+ return null
53
+ }
54
+ return getPasswordStrengthWord(newPassword, t)
55
+ }, [newPassword, t])
56
+
57
+ const matchTextRenderData = useMemo(() => {
58
+ if (!confirmPassword) {
59
+ return null
60
+ }
61
+
62
+ if (newPassword !== confirmPassword) {
63
+ return {
64
+ text: t('passwords_dont_match'),
65
+ }
66
+ }
67
+ return null
68
+ }, [newPassword, confirmPassword])
69
+
70
+ const onClickConfirm = () => {
71
+ bootWithPassword(newPassword)
72
+ }
73
+
74
+ const onPasswordChange = (e: string | { target: { value: string } }) => {
75
+ const val = typeof e === 'string' ? e : e.target.value
76
+ setNewPassword(val)
77
+ }
78
+
79
+ const onConfirmPasswordChange = (e: string | { target: { value: string } }) => {
80
+ const val = typeof e === 'string' ? e : e.target.value
81
+ setConfirmPassword(val)
82
+ }
83
+
84
+ return {
85
+ disabled,
86
+ strongTextRenderData,
87
+ matchTextRenderData,
88
+ onClickConfirm,
89
+ onPasswordChange,
90
+ onConfirmPasswordChange,
91
+ }
92
+ }
@@ -0,0 +1,299 @@
1
+ import { OW_HD_PATH, RESTORE_WALLETS, RestoreWalletType, WordsType } from '@unisat/wallet-shared'
2
+ import { AddressType } from '@unisat/wallet-types'
3
+ import { useEffect, useMemo, useState } from 'react'
4
+ import { useI18n, useNavigation, useTools, useWallet } from 'src/context'
5
+ import { useAppDispatch, useCreateAccountCallback } from 'src/hooks'
6
+ import { accountActions, keyringsActions } from 'src/reducers'
7
+ import { validateMnemonic } from 'src/utils/bitcoin-utils'
8
+
9
+ export enum TabType {
10
+ STEP1 = 'STEP1',
11
+ STEP2 = 'STEP2',
12
+ CHOOSE_ADDRESS_TYPE = 'CHOOSE_ADDRESS_TYPE',
13
+ }
14
+
15
+ function normalizeWhitespace(str: string) {
16
+ str = str.replace(/[\n\r\t]+/g, ' ')
17
+ str = str.replace(/\s+/g, ' ')
18
+ str = str.trim()
19
+ return str
20
+ }
21
+
22
+ export interface ContextData {
23
+ mnemonics: string
24
+ hdPath: string
25
+ passphrase: string
26
+ addressType: AddressType
27
+ step1Completed: boolean
28
+ tabType: TabType
29
+ restoreWalletType: RestoreWalletType
30
+ isRestore: boolean
31
+ isCustom: boolean
32
+ customHdPath: string
33
+ addressTypeIndex: number
34
+ wordsType: WordsType
35
+ walletName?: string
36
+ }
37
+
38
+ export interface UpdateContextDataParams {
39
+ mnemonics?: string
40
+ hdPath?: string
41
+ passphrase?: string
42
+ addressType?: AddressType
43
+ step1Completed?: boolean
44
+ tabType?: TabType
45
+ restoreWalletType?: RestoreWalletType
46
+ isCustom?: boolean
47
+ customHdPath?: string
48
+ addressTypeIndex?: number
49
+ wordsType?: WordsType
50
+ walletName?: string
51
+ }
52
+
53
+ interface WordsItem {
54
+ key: WordsType
55
+ label: string
56
+ count: number
57
+ }
58
+
59
+ const getWords12Item = t => ({
60
+ key: WordsType.WORDS_12,
61
+ label: t('mnemonics_12_words'),
62
+ count: 12,
63
+ })
64
+
65
+ const getWords24Item = t => ({
66
+ key: WordsType.WORDS_24,
67
+ label: t('mnemonics_24_words'),
68
+ count: 24,
69
+ })
70
+
71
+ interface CreateWalletLogicParams {
72
+ contextData: ContextData
73
+ updateContextData: (params: UpdateContextDataParams) => void
74
+ }
75
+
76
+ function textToWordsArray(text: string) {
77
+ return text.split(' ').filter(v => v.trim() !== '')
78
+ }
79
+
80
+ export function useCreateWalletLogicImportWordsStep(params: CreateWalletLogicParams) {
81
+ const { contextData, updateContextData } = params
82
+ const { t } = useI18n()
83
+
84
+ const walletTypeConfig = RESTORE_WALLETS.find(
85
+ item => item.value === contextData.restoreWalletType
86
+ )
87
+ const wordsItems: Array<WordsItem> = useMemo(() => {
88
+ const supportedWordsItems: WordsItem[] = []
89
+ if (walletTypeConfig) {
90
+ if (walletTypeConfig.wordsTypes.includes(WordsType.WORDS_12)) {
91
+ supportedWordsItems.push(getWords12Item(t))
92
+ }
93
+ if (walletTypeConfig.wordsTypes.includes(WordsType.WORDS_24)) {
94
+ supportedWordsItems.push(getWords24Item(t))
95
+ }
96
+ return supportedWordsItems
97
+ } else {
98
+ return [getWords12Item(t), getWords24Item(t)]
99
+ }
100
+ }, [contextData.restoreWalletType, t])
101
+
102
+ const wallet = useWallet()
103
+
104
+ const [disabled, setDisabled] = useState(true)
105
+
106
+ const [inputWords, setInputWords] = useState<Array<string>>(
107
+ new Array(wordsItems[contextData.wordsType].count).fill('')
108
+ )
109
+ const [inputWordsText, setInputWordsText] = useState('')
110
+ const [inputWordsError, setInputWordsError] = useState(false)
111
+ const tools = useTools()
112
+
113
+ const createAccount = useCreateAccountCallback()
114
+ const nav = useNavigation()
115
+
116
+ const dispatch = useAppDispatch()
117
+ const [loading, setLoading] = useState(false)
118
+
119
+ const [enteredWordsCount, setEnteredWordsCount] = useState(0)
120
+
121
+ const enablePhrase = walletTypeConfig?.phraseSupport
122
+
123
+ const maxWordsCount = wordsItems[contextData.wordsType].count
124
+
125
+ const initKey = async () => {
126
+ let totalKeyringCount = 0
127
+ try {
128
+ totalKeyringCount = await wallet.getTotalKeyringCount()
129
+ } catch (e) {
130
+ const error = e as Error
131
+ tools.toastError(error.message)
132
+ }
133
+ updateContextData({ walletName: `HD Wallet #${totalKeyringCount + 1}` })
134
+ }
135
+
136
+ useEffect(() => {
137
+ initKey()
138
+ }, [])
139
+
140
+ useEffect(() => {
141
+ setDisabled(true)
142
+
143
+ const words = textToWordsArray(inputWordsText)
144
+ if (words.length !== maxWordsCount) {
145
+ return
146
+ }
147
+
148
+ const mnemonic = words.join(' ')
149
+ if (!validateMnemonic(mnemonic)) {
150
+ return
151
+ }
152
+
153
+ setDisabled(false)
154
+ }, [inputWordsText])
155
+
156
+ const updateWords = (words: Array<string>, isEndedWithSpace?: boolean) => {
157
+ setInputWords(words)
158
+ let text = words.join(' ')
159
+ setInputWordsText(isEndedWithSpace ? text + ' ' : text)
160
+
161
+ const enteredWordsCount = words.filter(key => {
162
+ return key.trim() != ''
163
+ }).length
164
+
165
+ setEnteredWordsCount(enteredWordsCount)
166
+
167
+ if (!validateMnemonic(text) && enteredWordsCount >= maxWordsCount) {
168
+ setInputWordsError(true)
169
+ } else {
170
+ setInputWordsError(false)
171
+ }
172
+ }
173
+
174
+ const onInputWordsTextChange = (e: { target: { value: string } } | string) => {
175
+ let value = typeof e === 'string' ? e : e.target.value
176
+ let isEndedWithSpace = /\s$/.test(value)
177
+ value = normalizeWhitespace(value)
178
+
179
+ const wordsArr = textToWordsArray(value)
180
+ updateWords(wordsArr, isEndedWithSpace)
181
+ }
182
+
183
+ const onInputWordsChange = (e: { target: { value: string } } | string, index: number) => {
184
+ let value = typeof e === 'string' ? e : e.target.value
185
+ value = normalizeWhitespace(value)
186
+
187
+ const newKeys = [...inputWords]
188
+ newKeys.splice(index, 1, value)
189
+ updateWords(newKeys)
190
+ }
191
+
192
+ // extension
193
+ const onHandleEventPaste = (event, index: number) => {
194
+ const copyText = event.clipboardData?.getData('text/plain')
195
+ const textArr = normalizeWhitespace(copyText).split(' ')
196
+ const newKeys = [...inputWords]
197
+ if (textArr) {
198
+ for (let i = 0; i < inputWords.length - index; i++) {
199
+ if (textArr.length == i) {
200
+ break
201
+ }
202
+ newKeys[index + i] = textArr[i]
203
+ }
204
+ updateWords(newKeys)
205
+ }
206
+
207
+ event.preventDefault()
208
+ }
209
+
210
+ const onInputWalletNameChange = (e: { target: { value: string } } | string) => {
211
+ const value = typeof e === 'string' ? e : e.target.value
212
+ updateContextData({ walletName: value })
213
+ }
214
+
215
+ const onClickNext = async () => {
216
+ try {
217
+ const mnemonics = inputWords.join(' ')
218
+
219
+ if (contextData.wordsType === WordsType.WORDS_12) {
220
+ if (inputWords.length !== 12) {
221
+ tools.toastError(t('ErrorPrompt_CreateHDwallet_StepImport_Not_12_words'))
222
+ return
223
+ }
224
+ }
225
+
226
+ if (contextData.wordsType === WordsType.WORDS_24) {
227
+ if (inputWords.length !== 24) {
228
+ tools.toastError(t('ErrorPrompt_CreateHDwallet_StepImport_Not_24_words'))
229
+ return
230
+ }
231
+ }
232
+
233
+ if (!validateMnemonic(mnemonics)) {
234
+ tools.toastError(t('ErrorPrompt_CreateHDwallet_StepImport_InvalidMnemonic'))
235
+ return
236
+ }
237
+
238
+ setLoading(true)
239
+
240
+ if (contextData.restoreWalletType === RestoreWalletType.OW) {
241
+ await createAccount(mnemonics, OW_HD_PATH, '', AddressType.P2TR, 1)
242
+ const keyrings = await wallet.getKeyrings()
243
+ const keyring = keyrings[keyrings.length - 1]
244
+ if (contextData.walletName) {
245
+ keyring.alianName = contextData.walletName
246
+ await wallet.setKeyringAlianName(keyring, contextData.walletName)
247
+ }
248
+ await wallet.changeKeyring(keyring)
249
+ const _keyrings = await wallet.getKeyrings()
250
+ // @ts-ignore SAFE
251
+ dispatch(keyringsActions.setKeyrings(_keyrings))
252
+ // @ts-ignore SAFE
253
+ dispatch(keyringsActions.setCurrent(keyring))
254
+ // @ts-ignore SAFE
255
+ dispatch(accountActions.setCurrent(keyring?.accounts[0]))
256
+
257
+ nav.navToTab()
258
+ } else {
259
+ updateContextData({
260
+ walletName: contextData.walletName,
261
+ mnemonics,
262
+ tabType: TabType.CHOOSE_ADDRESS_TYPE,
263
+ })
264
+ }
265
+ } catch (e) {
266
+ tools.toastError((e as any).message)
267
+ } finally {
268
+ setLoading(false)
269
+ }
270
+ }
271
+
272
+ const onClickWordsItem = (wordsItem: WordsItem) => {
273
+ updateContextData({ wordsType: wordsItem.key })
274
+ setInputWordsText('')
275
+ setInputWords(new Array(wordsItem.count).fill(''))
276
+ }
277
+
278
+ const shouldEnteredWordsCount = wordsItems[contextData.wordsType].count
279
+
280
+ return {
281
+ wordsItems,
282
+ t,
283
+ disabled,
284
+ inputWords,
285
+ inputWordsText,
286
+ onHandleEventPaste,
287
+ onClickNext,
288
+ onClickWordsItem,
289
+ inputWordsError,
290
+ onInputWordsTextChange,
291
+ onInputWordsChange,
292
+ loading,
293
+ enablePhrase,
294
+ walletName: contextData.walletName,
295
+ onInputWalletNameChange,
296
+ enteredWordsCount,
297
+ shouldEnteredWordsCount,
298
+ }
299
+ }