@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,91 @@
1
+ import { Announcement, AnnouncementLinkType } from '@unisat/wallet-shared'
2
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
3
+ import { useStorage, useWallet } from 'src/context'
4
+
5
+ const AUTO_PLAY_INTERVAL = 5000
6
+
7
+ export function useAnnouncementCardLogic() {
8
+ const wallet = useWallet()
9
+ const storage = useStorage()
10
+
11
+ const [activeIndex, setActiveIndex] = useState(0)
12
+ const [dismissedIds, setDismissedIds] = useState<string[]>([])
13
+ const [announcements, setAnnouncements] = useState<Announcement[]>([])
14
+ const [loading, setLoading] = useState(false)
15
+ const [dismissedLoaded, setDismissedLoaded] = useState(false)
16
+ const timerRef = useRef<ReturnType<typeof setInterval> | null>(null)
17
+
18
+ useEffect(() => {
19
+ const init = async () => {
20
+ try {
21
+ await loadDismissedIds()
22
+ await fetchAnnouncements()
23
+ } finally {
24
+ setDismissedLoaded(true)
25
+ }
26
+ }
27
+ init()
28
+ }, [])
29
+
30
+ const fetchAnnouncements = async () => {
31
+ try {
32
+ const response = await wallet.getAnnouncements(0, 10)
33
+ setAnnouncements(Array.isArray(response?.list) ? response.list : [])
34
+ } catch {
35
+ setAnnouncements([])
36
+ }
37
+ }
38
+
39
+ const loadDismissedIds = async () => {
40
+ const saved = await storage.getAnnouncementDismissedIds()
41
+ setDismissedIds(saved)
42
+ }
43
+
44
+ const validAnnouncements = useMemo(
45
+ () =>
46
+ announcements.filter(a => {
47
+ const now = Date.now()
48
+ return now >= a.startTime && now <= a.endTime && !dismissedIds.includes(a.id)
49
+ }),
50
+ [announcements, dismissedIds],
51
+ )
52
+
53
+ // Auto-play: hook is the single timing authority
54
+ useEffect(() => {
55
+ if (validAnnouncements.length <= 1) return undefined
56
+ timerRef.current = setInterval(() => {
57
+ setActiveIndex(prev => (prev + 1) % validAnnouncements.length)
58
+ }, AUTO_PLAY_INTERVAL)
59
+ return () => {
60
+ if (timerRef.current) clearInterval(timerRef.current)
61
+ }
62
+ }, [validAnnouncements.length])
63
+
64
+ const handleDotClick = useCallback((index: number) => {
65
+ setActiveIndex(index)
66
+ }, [])
67
+
68
+ const handleDismissAll = useCallback(async () => {
69
+ const ids = validAnnouncements.map(a => a.id)
70
+ if (ids.length === 0) return
71
+ const newIds = [...dismissedIds, ...ids]
72
+ setDismissedIds(newIds)
73
+ await storage.setAnnouncementDismissedIds(newIds)
74
+ }, [validAnnouncements, dismissedIds, storage])
75
+
76
+ const isLinkable = useCallback((announcement: Announcement) => {
77
+ return announcement.linkType !== AnnouncementLinkType.NONE && !!announcement.link
78
+ }, [])
79
+
80
+ const current = validAnnouncements[activeIndex] ?? validAnnouncements[0]
81
+
82
+ return {
83
+ loading,
84
+ validAnnouncements,
85
+ current,
86
+ activeIndex,
87
+ handleDotClick,
88
+ handleDismissAll,
89
+ isLinkable,
90
+ }
91
+ }
@@ -0,0 +1,115 @@
1
+ import { AddressTokenSummary, TickPriceItem, TokenBalance } from '@unisat/wallet-shared'
2
+ import BigNumber from 'bignumber.js'
3
+ import { useMemo, useState } from 'react'
4
+ import { useI18n } from 'src/context'
5
+ import { useBRC20IconInfo, useChain, useCurrentAccount } from 'src/hooks'
6
+
7
+ export interface BRC20BalanceCardProps {
8
+ tokenBalance: TokenBalance
9
+ onClick?: () => void
10
+ price?: TickPriceItem
11
+ }
12
+ export function useBRC20BalanceCardLogic(props: BRC20BalanceCardProps) {
13
+ const {
14
+ price,
15
+ tokenBalance: {
16
+ ticker,
17
+ overallBalance,
18
+ transferableBalance,
19
+ selfMint,
20
+ displayName,
21
+ tag,
22
+ swapBalance,
23
+ progBalance,
24
+ },
25
+ onClick,
26
+ } = props
27
+
28
+ const account = useCurrentAccount()
29
+ const [tokenSummary, setTokenSummary] = useState<AddressTokenSummary>()
30
+
31
+ const { t } = useI18n()
32
+
33
+ const deploy_count = tokenSummary ? (tokenSummary.tokenInfo.holder == account.address ? 1 : 0) : 0
34
+ let _names: string[] = []
35
+ const _amounts: string[] = []
36
+ if (deploy_count > 0) {
37
+ _names.push('Deploy')
38
+ _amounts.push('')
39
+ }
40
+ if (tokenSummary) {
41
+ tokenSummary.transferableList.forEach(v => {
42
+ _names.push('Transfer')
43
+ _amounts.push(v.amount)
44
+ })
45
+ }
46
+
47
+ for (let i = 0; i < _names.length; i++) {
48
+ if (i == 3) {
49
+ if (_names.length > 4) {
50
+ if (deploy_count > 0) {
51
+ _names[i] = `${_names.length - 3}+`
52
+ } else {
53
+ _names[i] = `${_names.length - 2}+`
54
+ }
55
+ _amounts[i] = ''
56
+ }
57
+ break
58
+ }
59
+ }
60
+ _names = _names.splice(0, 4)
61
+
62
+ const onSwapBalance = swapBalance
63
+ const onProgBalance = progBalance
64
+ const inWalletBalance = overallBalance
65
+
66
+ const totalBalance = useMemo(() => {
67
+ return new BigNumber(inWalletBalance)
68
+ .plus(new BigNumber(onSwapBalance || 0))
69
+ .plus(new BigNumber(onProgBalance || 0))
70
+ .toString()
71
+ }, [inWalletBalance, onSwapBalance, onProgBalance])
72
+
73
+ let hasOutWalletBalance = false
74
+ if (onSwapBalance && onSwapBalance !== '0') {
75
+ hasOutWalletBalance = true
76
+ }
77
+ if (onProgBalance && onProgBalance !== '0') {
78
+ hasOutWalletBalance = true
79
+ }
80
+
81
+ // icon
82
+ const iconInfo = useBRC20IconInfo(ticker)
83
+
84
+ // price
85
+ const chain = useChain()
86
+ const showPrice = chain.showPrice
87
+
88
+ return {
89
+ // info
90
+ ticker,
91
+ displayName,
92
+ selfMint,
93
+ tag,
94
+
95
+ // icon
96
+ iconInfo,
97
+
98
+ // balance
99
+ totalBalance,
100
+ hasOutWalletBalance,
101
+ onProgBalance,
102
+ inWalletBalance,
103
+ onSwapBalance,
104
+
105
+ // price
106
+ price,
107
+ showPrice,
108
+
109
+ // click
110
+ onClick,
111
+
112
+ // others
113
+ t,
114
+ }
115
+ }
@@ -0,0 +1,418 @@
1
+ import { numUtils } from '@unisat/base-utils'
2
+ import {
3
+ InscribeOrder,
4
+ SignedData,
5
+ SignPsbtParams,
6
+ TokenBalance,
7
+ TokenInfo,
8
+ ToSignData,
9
+ } from '@unisat/wallet-shared'
10
+ import BigNumber from 'bignumber.js'
11
+ import { useCallback, useEffect, useMemo, useState } from 'react'
12
+ import { useApproval, useI18n, useNavigation, useTools, useWallet } from 'src/context'
13
+ import {
14
+ useBTCUnit,
15
+ useCurrentAccount,
16
+ useFeeRateBar,
17
+ useFetchUtxosCallback,
18
+ usePrepareSendBypassHeadOffsetsCallback,
19
+ usePushBitcoinTxCallback,
20
+ useUpdateFeeRateBar,
21
+ } from 'src/hooks'
22
+ import { getAddressUtxoDust } from 'src/utils/bitcoin-utils'
23
+
24
+ enum Step {
25
+ STEP1,
26
+ STEP2,
27
+ STEP3,
28
+ STEP4,
29
+ }
30
+
31
+ interface ContextData {
32
+ step: Step
33
+ ticker: string
34
+ session?: any
35
+ tokenBalance?: TokenBalance
36
+ order?: InscribeOrder
37
+ toSignData?: ToSignData
38
+ amount?: string
39
+ isApproval: boolean
40
+ tokenInfo?: TokenInfo
41
+ amountEditable?: boolean
42
+ enableRBF: boolean
43
+ }
44
+
45
+ interface UpdateContextDataParams {
46
+ step?: Step
47
+ ticket?: string
48
+ session?: any
49
+ tokenBalance?: TokenBalance
50
+ order?: InscribeOrder
51
+ toSignData?: ToSignData
52
+ amount?: string
53
+ tokenInfo?: TokenInfo
54
+ amountEditable?: boolean
55
+ enableRBF?: boolean
56
+ }
57
+
58
+ export interface BRC20InscribeTransferParams {
59
+ contextData: ContextData
60
+ updateContextData: (params: UpdateContextDataParams) => void
61
+ }
62
+
63
+ export function useBRC20InscribeTransferLogic() {
64
+ const nav = useNavigation()
65
+ const { ticker } = nav.getRouteState<'BRC20InscribeTransfer'>()
66
+
67
+ const [contextData, setContextData] = useState<ContextData>({
68
+ step: Step.STEP1,
69
+ ticker: ticker,
70
+ isApproval: false,
71
+ enableRBF: true,
72
+ })
73
+ const updateContextData = useCallback((params: UpdateContextDataParams) => {
74
+ setContextData(prev => Object.assign({}, prev, params))
75
+ }, [])
76
+ return {
77
+ contextData,
78
+ updateContextData,
79
+ }
80
+ }
81
+
82
+ export function useBRC20InscribeTransferLogicStep1(params: BRC20InscribeTransferParams) {
83
+ const { contextData, updateContextData } = params
84
+ const { t } = useI18n()
85
+ const nav = useNavigation()
86
+
87
+ const { rejectApproval } = useApproval()
88
+
89
+ const handleCancel = () => {
90
+ rejectApproval(t('user_rejected_the_request'))
91
+ }
92
+
93
+ const wallet = useWallet()
94
+ const account = useCurrentAccount()
95
+ const feeRateBarState = useFeeRateBar()
96
+ const updateFeeRateBar = useUpdateFeeRateBar()
97
+ const [inputAmount, setInputAmount] = useState('')
98
+
99
+ const tools = useTools()
100
+ const prepareSendBypassHeadOffsets = usePrepareSendBypassHeadOffsetsCallback()
101
+
102
+ const fetchUtxos = useFetchUtxosCallback()
103
+
104
+ const [loading, setLoading] = useState(true)
105
+ const [loadingOnly, setLoadingOnly] = useState(false)
106
+ const [inputError, setInputError] = useState('')
107
+ const [inputErrorAvailable, setInputErrorAvailable] = useState('')
108
+
109
+ const [disabled, setDisabled] = useState(true)
110
+
111
+ const [inputDisabled, setInputDisabled] = useState(false)
112
+
113
+ const defaultOutputValue = 546
114
+ // const defaultOutputValue = getAddressUtxoDust(account.address);
115
+
116
+ const [outputValue, setOutputValue] = useState<number>(defaultOutputValue)
117
+
118
+ useEffect(() => {
119
+ if (contextData.amount) {
120
+ setInputAmount(contextData.amount.toString())
121
+ setInputDisabled(true)
122
+ }
123
+ }, [])
124
+
125
+ useEffect(() => {
126
+ wallet.getEnableRBF().then(enableRBF => {
127
+ updateContextData({ enableRBF })
128
+ })
129
+ }, [])
130
+
131
+ useEffect(() => {
132
+ setInputError('')
133
+ setInputErrorAvailable('')
134
+ setDisabled(true)
135
+ if (!inputAmount) {
136
+ return
137
+ }
138
+
139
+ if (inputAmount.split('.').length > 1) {
140
+ const decimal = inputAmount.split('.')[1].length
141
+ const token_decimal = contextData.tokenInfo?.decimal || 0
142
+ if (decimal > token_decimal) {
143
+ setInputError(
144
+ `${t('this_token_only_supports_up_to')} ${token_decimal} ${t('decimal_places')}`
145
+ )
146
+ return
147
+ }
148
+ }
149
+
150
+ const amount = new BigNumber(inputAmount)
151
+ if (!amount) {
152
+ return
153
+ }
154
+
155
+ if (!contextData.tokenBalance) {
156
+ return
157
+ }
158
+
159
+ if (amount.lte(0)) {
160
+ return
161
+ }
162
+
163
+ if (amount.gt(contextData.tokenBalance.availableBalanceSafe)) {
164
+ setInputErrorAvailable(t('insufficient_balance'))
165
+ return
166
+ }
167
+
168
+ if (feeRateBarState.feeRate <= 0) {
169
+ return
170
+ }
171
+
172
+ const dust = getAddressUtxoDust(account.address)
173
+ if (outputValue < dust) {
174
+ setInputError(`${t('output_value_must_be_at_least')} ${dust}`)
175
+ return
176
+ }
177
+
178
+ if (!outputValue) {
179
+ return
180
+ }
181
+
182
+ setDisabled(false)
183
+ }, [inputAmount, feeRateBarState.feeRate, outputValue, contextData.tokenBalance])
184
+
185
+ useEffect(() => {
186
+ fetchUtxos()
187
+
188
+ wallet
189
+ .getBRC20Summary({
190
+ address: account.address,
191
+ ticker: contextData.ticker,
192
+ })
193
+ .then(v => {
194
+ updateContextData({ tokenBalance: v.tokenBalance, tokenInfo: v.tokenInfo })
195
+ setTimeout(() => {
196
+ setLoading(false)
197
+ }, 100)
198
+ })
199
+ .catch(e => {
200
+ tools.toastError(e.message)
201
+ })
202
+ }, [])
203
+
204
+ const onClickInscribe = async () => {
205
+ try {
206
+ tools.showLoading(true)
207
+ const amount = inputAmount
208
+ const order = await wallet.inscribeBRC20Transfer(
209
+ account.address,
210
+ contextData.ticker,
211
+ amount,
212
+ feeRateBarState.feeRate,
213
+ outputValue
214
+ )
215
+
216
+ const toSignData = await prepareSendBypassHeadOffsets({
217
+ toAddressInfo: { address: order.payAddress, domain: '' },
218
+ toAmount: order.totalFee,
219
+ feeRate: feeRateBarState.feeRate,
220
+ enableRBF: contextData.enableRBF,
221
+ })
222
+ updateContextData({ order, amount, toSignData, step: Step.STEP2 })
223
+ } catch (e) {
224
+ tools.toastError((e as Error).message.replace('Error:', ''))
225
+ } finally {
226
+ tools.showLoading(false)
227
+ }
228
+ }
229
+
230
+ return {
231
+ onClickInscribe,
232
+ loading,
233
+ t,
234
+ nav,
235
+ inputAmount,
236
+ inputError,
237
+ setInputAmount,
238
+ inputDisabled,
239
+ inputErrorAvailable,
240
+ defaultOutputValue,
241
+ setOutputValue,
242
+ disabled,
243
+ enableRBF: contextData.enableRBF,
244
+ setEnableRBF: (value: boolean) => {
245
+ updateContextData({ enableRBF: value })
246
+ wallet.setEnableRBF(value)
247
+ },
248
+ loadingOnly,
249
+ handleCancel,
250
+ }
251
+ }
252
+
253
+ export function useBRC20InscribeTransferLogicStep2(params: BRC20InscribeTransferParams) {
254
+ const { contextData } = params
255
+ const { order, tokenBalance, amount, toSignData, session } = contextData
256
+ const btcUnit = useBTCUnit()
257
+ const { t } = useI18n()
258
+
259
+ if (!order || !tokenBalance || !toSignData) {
260
+ return {
261
+ isEmpty: true,
262
+ networkFee: '0',
263
+ outputValue: '0',
264
+ minerFee: '0',
265
+ originServiceFee: '0',
266
+ serviceFee: '0',
267
+ totalFee: '0',
268
+ btcUnit,
269
+ t,
270
+ session,
271
+ amount,
272
+ tokenBalance,
273
+ }
274
+ }
275
+
276
+ const fee = toSignData.estimatedFee || 0
277
+ const networkFee = useMemo(() => numUtils.satoshisToAmount(fee), [fee])
278
+ const outputValue = useMemo(
279
+ () => numUtils.satoshisToAmount(order.outputValue),
280
+ [order.outputValue]
281
+ )
282
+ const minerFee = useMemo(() => numUtils.satoshisToAmount(order.minerFee + fee), [order.minerFee])
283
+ const originServiceFee = useMemo(
284
+ () => numUtils.satoshisToAmount(order.originServiceFee),
285
+ [order.originServiceFee]
286
+ )
287
+ const serviceFee = useMemo(() => numUtils.satoshisToAmount(order.serviceFee), [order.serviceFee])
288
+ const totalFee = useMemo(() => numUtils.satoshisToAmount(order.totalFee + fee), [order.totalFee])
289
+
290
+ return {
291
+ networkFee,
292
+ outputValue,
293
+ minerFee,
294
+ originServiceFee,
295
+ serviceFee,
296
+ totalFee,
297
+ btcUnit,
298
+ t,
299
+ session,
300
+ amount,
301
+ tokenBalance,
302
+ order,
303
+ toSignData,
304
+ }
305
+ }
306
+
307
+ export function useBRC20InscribeTransferLogicStep3(params: BRC20InscribeTransferParams) {
308
+ const { contextData, updateContextData } = params
309
+
310
+ const pushBitcoinTx = usePushBitcoinTxCallback()
311
+ const nav = useNavigation()
312
+
313
+ const onHeaderBack = () => {
314
+ updateContextData({
315
+ step: Step.STEP2,
316
+ })
317
+ }
318
+
319
+ const onSignPsbtHandleCancel = () => {
320
+ updateContextData({
321
+ step: Step.STEP2,
322
+ })
323
+ }
324
+ const signPsbtParams: SignPsbtParams = {
325
+ data: {
326
+ toSignDatas: [contextData.toSignData!],
327
+ },
328
+ }
329
+
330
+ const tools = useTools()
331
+ const onSignPsbtHandleConfirm = async (signedDatas: SignedData[]) => {
332
+ tools.showLoading(true)
333
+ try {
334
+ const { success, error } = await pushBitcoinTx(signedDatas[0].psbtHex)
335
+ if (success) {
336
+ updateContextData({
337
+ step: Step.STEP4,
338
+ })
339
+ } else {
340
+ throw new Error(error)
341
+ }
342
+ return
343
+ } catch (e) {
344
+ nav.navigate('TxFailScreen', { error: (e as any).message })
345
+ } finally {
346
+ tools.showLoading(false)
347
+ }
348
+ }
349
+
350
+ return {
351
+ signPsbtParams,
352
+ onSignPsbtHandleConfirm,
353
+ onSignPsbtHandleCancel,
354
+ onHeaderBack,
355
+ }
356
+ }
357
+
358
+ export function useBRC20InscribeTransferLogicStep4(params: BRC20InscribeTransferParams) {
359
+ const { contextData } = params
360
+ const { tokenBalance, order } = contextData
361
+ const tools = useTools()
362
+ const wallet = useWallet()
363
+ const currentAccount = useCurrentAccount()
364
+ const { resolveApproval, rejectApproval } = useApproval()
365
+ const nav = useNavigation()
366
+ const [result, setResult] = useState<any>()
367
+ const { t } = useI18n()
368
+ const checkResult = async () => {
369
+ const result = await wallet.getInscribeResult(order.orderId)
370
+ if (!result) {
371
+ setTimeout(() => {
372
+ checkResult()
373
+ }, 2000)
374
+ return
375
+ }
376
+ tools.showLoading(false)
377
+ setResult(result)
378
+ }
379
+
380
+ useEffect(() => {
381
+ checkResult()
382
+ }, [])
383
+
384
+ const onClickConfirm = () => {
385
+ tools.showLoading(true)
386
+ wallet
387
+ .getBRC20Summary({
388
+ address: currentAccount.address,
389
+ ticker: tokenBalance.ticker,
390
+ })
391
+ .then(v => {
392
+ if (contextData.isApproval) {
393
+ resolveApproval({
394
+ inscriptionId: result.inscriptionId,
395
+ inscriptionNumber: result.inscriptionNumber,
396
+ ticker: tokenBalance.ticker,
397
+ amount: result.amount,
398
+ })
399
+ } else {
400
+ nav.navigate('BRC20SendScreen', {
401
+ tokenBalance: v.tokenBalance,
402
+ selectedInscriptionIds: [result.inscriptionId],
403
+ selectedAmount: result.amount,
404
+ tokenInfo: v.tokenInfo,
405
+ })
406
+ }
407
+ })
408
+ .finally(() => {
409
+ tools.showLoading(false)
410
+ })
411
+ }
412
+
413
+ return {
414
+ t,
415
+ result,
416
+ onClickConfirm,
417
+ }
418
+ }
@@ -0,0 +1,79 @@
1
+ import { TickPriceItem, TokenBalance } from '@unisat/wallet-shared'
2
+ import { useEffect, useRef, useState } from 'react'
3
+ import {
4
+ OrdinalsAssetTabKey,
5
+ useChainType,
6
+ useCurrentAccount,
7
+ useNavigation,
8
+ useOrdinalsAssetTabKey,
9
+ useWallTabFocusRefresh,
10
+ useWallet,
11
+ } from '..'
12
+ import { useInfiniteList } from './useInfiniteList'
13
+
14
+ export function useBRC20ListLogic() {
15
+ const nav = useNavigation()
16
+ const wallet = useWallet()
17
+ const currentAccount = useCurrentAccount()
18
+ const chainType = useChainType()
19
+
20
+ const [priceMap, setPriceMap] = useState<{ [key: string]: TickPriceItem }>({})
21
+
22
+ const priceMapRef = useRef(priceMap)
23
+ const updatePrices = (res: { [tick: string]: TickPriceItem }) => {
24
+ const newPriceMap = { ...priceMapRef.current }
25
+ Object.keys(res).forEach(tick => {
26
+ newPriceMap[tick] = res[tick]
27
+ })
28
+ priceMapRef.current = newPriceMap
29
+ setPriceMap(newPriceMap)
30
+ }
31
+
32
+ const {
33
+ data: items,
34
+ total,
35
+ loading,
36
+ hasMore,
37
+ onRefresh,
38
+ onLoadMore,
39
+ } = useInfiniteList<TokenBalance>({
40
+ fetcher: async (page, pageSize) => {
41
+ if (currentAccount.address === '') {
42
+ return { list: [], total: 0 }
43
+ }
44
+ const { list, total } = await wallet.getBRC20List({
45
+ address: currentAccount.address,
46
+ currentPage: page,
47
+ pageSize,
48
+ })
49
+ if (list.length > 0) {
50
+ wallet.getBrc20sPrice(list.map(item => item.ticker)).then(updatePrices)
51
+ }
52
+ return { list, total }
53
+ },
54
+ dependencies: [currentAccount.address, chainType],
55
+ })
56
+
57
+ const tabKey = useOrdinalsAssetTabKey()
58
+ const isFocus = tabKey === OrdinalsAssetTabKey.BRC20
59
+ const lastRefreshTimeRef = useRef<number>(0)
60
+ const walletTabFocusRefresh = useWallTabFocusRefresh()
61
+ useEffect(() => {
62
+ if (!isFocus) return
63
+
64
+ // already refreshed → do nothing
65
+ const alreadyRefreshed = lastRefreshTimeRef.current === walletTabFocusRefresh
66
+ if (alreadyRefreshed) return
67
+
68
+ onRefresh()
69
+
70
+ // mark refreshed
71
+ lastRefreshTimeRef.current = walletTabFocusRefresh
72
+ }, [walletTabFocusRefresh, isFocus])
73
+
74
+ const onClickItem = (item: TokenBalance) => {
75
+ nav.navigate('BRC20TokenScreen', { tokenBalance: item, ticker: item.ticker })
76
+ }
77
+
78
+ return { items, total, loading, hasMore, onRefresh, onLoadMore, onClickItem, priceMap }
79
+ }