@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,81 @@
1
+ import { TickPriceItem, TokenBalance } from '@unisat/wallet-shared'
2
+ import { useEffect, useRef, useState } from 'react'
3
+ import {
4
+ OrdinalsAssetTabKey,
5
+ getSupportedAssets,
6
+ useChainType,
7
+ useCurrentAccount,
8
+ useNavigation,
9
+ useOrdinalsAssetTabKey,
10
+ useWallTabFocusRefresh,
11
+ useWallet,
12
+ } from '..'
13
+ import { useInfiniteList } from './useInfiniteList'
14
+
15
+ export function useBRC20ProgListLogic() {
16
+ const nav = useNavigation()
17
+ const wallet = useWallet()
18
+ const currentAccount = useCurrentAccount()
19
+ const chainType = useChainType()
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
+ const supportedAssets = getSupportedAssets(chainType, currentAccount.address)
42
+ if (!supportedAssets.assets.brc20Prog || currentAccount.address === '') {
43
+ return { list: [], total: 0 }
44
+ }
45
+
46
+ const { list, total } = await wallet.getBRC20ProgList({
47
+ address: currentAccount.address,
48
+ currentPage: page,
49
+ pageSize,
50
+ })
51
+ if (list.length > 0) {
52
+ wallet.getBrc20sPrice(list.map(item => item.ticker)).then(updatePrices)
53
+ }
54
+ return { list, total }
55
+ },
56
+ dependencies: [currentAccount.address, chainType],
57
+ })
58
+
59
+ const tabKey = useOrdinalsAssetTabKey()
60
+ const isFocus = tabKey === OrdinalsAssetTabKey.BRC20_6BYTE
61
+ const lastRefreshTimeRef = useRef<number>(0)
62
+ const walletTabFocusRefresh = useWallTabFocusRefresh()
63
+ useEffect(() => {
64
+ if (!isFocus) return
65
+
66
+ // already refreshed → do nothing
67
+ const alreadyRefreshed = lastRefreshTimeRef.current === walletTabFocusRefresh
68
+ if (alreadyRefreshed) return
69
+
70
+ onRefresh()
71
+
72
+ // mark refreshed
73
+ lastRefreshTimeRef.current = walletTabFocusRefresh
74
+ }, [walletTabFocusRefresh, isFocus])
75
+
76
+ const onClickItem = (item: TokenBalance) => {
77
+ nav.navigate('BRC20TokenScreen', { tokenBalance: item, ticker: item.ticker })
78
+ }
79
+
80
+ return { items, total, loading, hasMore, onRefresh, onLoadMore, onClickItem, priceMap }
81
+ }
@@ -0,0 +1,424 @@
1
+ import {
2
+ RawTxInfo,
3
+ SignPsbtParams,
4
+ TokenBalance,
5
+ TokenInfo,
6
+ TokenTransfer,
7
+ } from '@unisat/wallet-shared'
8
+ import BigNumber from 'bignumber.js'
9
+ import { startTransition, useCallback, useEffect, useMemo, useState } from 'react'
10
+ import { useI18n, useNavigation, useTools, useWallet } from 'src/context'
11
+ import {
12
+ useCurrentAccount,
13
+ useFeeRateBar,
14
+ useFetchUtxosCallback,
15
+ usePrepareSendOrdinalsInscriptionCallback,
16
+ usePrepareSendOrdinalsInscriptionsCallback,
17
+ usePushOrdinalsTxCallback,
18
+ } from 'src/hooks'
19
+ import { getAddressUtxoDust } from 'src/utils/bitcoin-utils'
20
+
21
+ export enum BRC20SendTabKey {
22
+ STEP1,
23
+ STEP2,
24
+ STEP3,
25
+ }
26
+
27
+ export interface ContextData {
28
+ tabKey: BRC20SendTabKey
29
+ tokenBalance: TokenBalance
30
+ transferAmount: string
31
+ transferableList: TokenTransfer[]
32
+ inscriptionIdSet: Set<string>
33
+ receiver: string
34
+ enableRBF: boolean
35
+ rawTxInfo: RawTxInfo
36
+ tokenInfo: TokenInfo
37
+ }
38
+
39
+ export interface UpdateContextDataParams {
40
+ tabKey?: BRC20SendTabKey
41
+ tokenBalance?: TokenBalance
42
+ transferAmount?: string
43
+ transferableList?: TokenTransfer[]
44
+ inscriptionIdSet?: Set<string>
45
+ receiver?: string
46
+ enableRBF?: boolean
47
+ rawTxInfo?: RawTxInfo
48
+ }
49
+
50
+ export interface BRC20SendStepParams {
51
+ contextData: ContextData
52
+ updateContextData: (params: UpdateContextDataParams) => void
53
+ }
54
+
55
+ export function useBRC20SendScreenLogic() {
56
+ const nav = useNavigation()
57
+ const wallet = useWallet()
58
+
59
+ const props = nav.getRouteState<'BRC20SendScreen'>()
60
+
61
+ const tokenBalance = props.tokenBalance
62
+ const selectedInscriptionIds = props.selectedInscriptionIds || []
63
+ const selectedAmount = props.selectedAmount || '0'
64
+
65
+ const [contextData, setContextData] = useState<ContextData>({
66
+ tabKey: BRC20SendTabKey.STEP1,
67
+ tokenBalance,
68
+ transferAmount: selectedAmount,
69
+ transferableList: [],
70
+ inscriptionIdSet: new Set(selectedInscriptionIds),
71
+ receiver: '',
72
+ enableRBF: true,
73
+ rawTxInfo: {
74
+ psbtHex: '',
75
+ rawtx: '',
76
+ },
77
+ tokenInfo: {
78
+ totalSupply: '0',
79
+ totalMinted: '0',
80
+ decimal: 18,
81
+ holder: '',
82
+ inscriptionId: '',
83
+ historyCount: 0,
84
+ holdersCount: 0,
85
+ logo: '',
86
+ },
87
+ })
88
+
89
+ const updateContextData = useCallback((params: UpdateContextDataParams) => {
90
+ setContextData(prev => {
91
+ let changed = false
92
+ const next = { ...prev }
93
+ for (const key in params) {
94
+ if (prev[key] !== params[key]) {
95
+ next[key] = params[key]
96
+ changed = true
97
+ }
98
+ }
99
+
100
+ return changed ? next : prev
101
+ })
102
+ }, [])
103
+
104
+ const onHeaderBack = () => {
105
+ if (contextData.tabKey === BRC20SendTabKey.STEP2) {
106
+ updateContextData({ tabKey: BRC20SendTabKey.STEP1 })
107
+ return
108
+ }
109
+ nav.goBack()
110
+ }
111
+
112
+ const onTabClick = (key: string) => {
113
+ updateContextData({ tabKey: key as any })
114
+ }
115
+
116
+ const { t } = useI18n()
117
+
118
+ useEffect(() => {
119
+ wallet.getEnableRBF().then(enableRBF => {
120
+ updateContextData({ enableRBF })
121
+ })
122
+ }, [wallet, updateContextData])
123
+
124
+ return {
125
+ t,
126
+ contextData,
127
+ updateContextData,
128
+ onHeaderBack,
129
+ onTabClick,
130
+ }
131
+ }
132
+
133
+ export function useBRC20SendScreenLogicStep1({
134
+ contextData,
135
+ updateContextData,
136
+ }: BRC20SendStepParams) {
137
+ const { tokenBalance } = contextData
138
+
139
+ const { t } = useI18n()
140
+
141
+ const [disabled, setDisabled] = useState(true)
142
+
143
+ useEffect(() => {
144
+ setDisabled(true)
145
+ if (new BigNumber(contextData.transferAmount).lte(0)) {
146
+ return
147
+ }
148
+
149
+ setDisabled(false)
150
+ }, [contextData.transferAmount])
151
+
152
+ const onClickNext = () => {
153
+ updateContextData({
154
+ tabKey: BRC20SendTabKey.STEP2,
155
+ })
156
+ }
157
+
158
+ return {
159
+ t,
160
+ disabled,
161
+ tokenBalance,
162
+ onClickNext,
163
+ }
164
+ }
165
+ export function useBRC20SendScreenLogicStep2({
166
+ contextData,
167
+ updateContextData,
168
+ }: BRC20SendStepParams) {
169
+ const nav = useNavigation()
170
+ const fetchUtxos = useFetchUtxosCallback()
171
+ const tools = useTools()
172
+ const { t } = useI18n()
173
+ useEffect(() => {
174
+ tools.showLoading(true)
175
+ fetchUtxos().finally(() => {
176
+ tools.showLoading(false)
177
+ })
178
+ }, [])
179
+
180
+ const feeRateBar = useFeeRateBar()
181
+
182
+ const prepareSendOrdinalsInscriptions = usePrepareSendOrdinalsInscriptionsCallback()
183
+ const prepareSendOrdinalsInscription = usePrepareSendOrdinalsInscriptionCallback()
184
+
185
+ const [disabled, setDisabled] = useState(true)
186
+
187
+ useEffect(() => {
188
+ setDisabled(true)
189
+ if (!contextData.receiver) {
190
+ return
191
+ }
192
+ if (!feeRateBar.feeRate) {
193
+ return
194
+ }
195
+ setDisabled(false)
196
+ }, [contextData.receiver, feeRateBar.feeRate])
197
+
198
+ const onStep2ClickNext = async () => {
199
+ try {
200
+ tools.showLoading(true)
201
+ const inscriptionIds = Array.from(contextData.inscriptionIdSet)
202
+ if (inscriptionIds.length === 1) {
203
+ const toSignData = await prepareSendOrdinalsInscription({
204
+ toAddressInfo: { address: contextData.receiver, domain: '' },
205
+ inscriptionId: inscriptionIds[0],
206
+ feeRate: feeRateBar.feeRate,
207
+ outputValue: getAddressUtxoDust(contextData.receiver),
208
+ enableRBF: contextData.enableRBF,
209
+ })
210
+ nav.navigate('TxConfirmScreen', { toSignData })
211
+ } else {
212
+ const toSignData = await prepareSendOrdinalsInscriptions({
213
+ toAddressInfo: { address: contextData.receiver, domain: '' },
214
+ inscriptionIds,
215
+ feeRate: feeRateBar.feeRate,
216
+ enableRBF: contextData.enableRBF,
217
+ })
218
+ nav.navigate('TxConfirmScreen', { toSignData })
219
+ }
220
+
221
+ // updateContextData({ tabKey: TabKey.STEP3, rawTxInfo: txInfo });
222
+ } catch (e) {
223
+ const error = e as Error
224
+ console.log(error)
225
+ tools.toastError(error.message)
226
+ } finally {
227
+ tools.showLoading(false)
228
+ }
229
+ }
230
+
231
+ const onStep2ClickBack = async () => {
232
+ if (contextData.tabKey === BRC20SendTabKey.STEP2) {
233
+ updateContextData({ tabKey: BRC20SendTabKey.STEP1 })
234
+ }
235
+ }
236
+ return {
237
+ t,
238
+ disabled,
239
+ onStep2ClickNext,
240
+ onStep2ClickBack,
241
+ }
242
+ }
243
+
244
+ export function useBRC20SendScreenLogicStep3({
245
+ contextData,
246
+ updateContextData,
247
+ }: BRC20SendStepParams) {
248
+ const { t } = useI18n()
249
+ const nav = useNavigation()
250
+ const pushOrdinalsTx = usePushOrdinalsTxCallback()
251
+
252
+ const onSignPsbtConfirm = async res => {
253
+ try {
254
+ let txData = ''
255
+
256
+ if (res && res.psbtHex) {
257
+ txData = res.psbtHex
258
+ } else if (res && res.rawtx) {
259
+ txData = res.rawtx
260
+ } else if (contextData.rawTxInfo.rawtx) {
261
+ txData = contextData.rawTxInfo.rawtx
262
+ } else {
263
+ throw new Error(t('invalid_transaction_data'))
264
+ }
265
+
266
+ const { success, txid, error } = await pushOrdinalsTx(txData)
267
+ if (success) {
268
+ nav.navigate('TxSuccessScreen', { txid })
269
+ } else {
270
+ throw new Error(error)
271
+ }
272
+ } catch (e) {
273
+ nav.navigate('TxFailScreen', { error: (e as any).message })
274
+ }
275
+ }
276
+
277
+ const signPsbtParams: SignPsbtParams = {
278
+ data: {
279
+ toSignDatas: [
280
+ {
281
+ psbtHex: contextData.rawTxInfo.psbtHex,
282
+ toSignInputs: undefined,
283
+ autoFinalized: true,
284
+ },
285
+ ],
286
+ },
287
+ }
288
+
289
+ return {
290
+ signPsbtParams,
291
+ onSignPsbtConfirm,
292
+ }
293
+ }
294
+
295
+ export function useTransferableListLogic({ contextData, updateContextData }: BRC20SendStepParams) {
296
+ const wallet = useWallet()
297
+ const currentAccount = useCurrentAccount()
298
+ const { t } = useI18n()
299
+
300
+ const [items, setItems] = useState<TokenTransfer[]>([])
301
+ const [total, setTotal] = useState(0)
302
+ const [loading, setLoading] = useState(false)
303
+ const [loadingLump, setLoadingLump] = useState(false)
304
+ const [pagination, setPagination] = useState({ currentPage: 1, pageSize: 100 })
305
+ const [allSelected, setAllSelected] = useState(false)
306
+
307
+ const tools = useTools()
308
+ const fetchData = async () => {
309
+ try {
310
+ setLoading(true)
311
+ const { list, total } = await wallet.getBRC20TransferableList({
312
+ address: currentAccount.address,
313
+ ticker: contextData.tokenBalance.ticker,
314
+ tickerHex: contextData.tokenBalance.tickerHex,
315
+ currentPage: pagination.currentPage,
316
+ pageSize: pagination.pageSize,
317
+ })
318
+ setItems(list)
319
+ setTotal(total)
320
+ } catch (e) {
321
+ tools.toastError((e as Error).message)
322
+ } finally {
323
+ setLoading(false)
324
+ }
325
+ }
326
+
327
+ useEffect(() => {
328
+ fetchData()
329
+ }, [pagination])
330
+ const totalAmount = items
331
+ .reduce((pre, cur) => new BigNumber(cur.amount).plus(pre), new BigNumber(0))
332
+ .toString()
333
+
334
+ const selectedCount = useMemo(() => contextData.inscriptionIdSet.size, [contextData])
335
+
336
+ const onClickItem = (item: TokenTransfer) => {
337
+ if (contextData.inscriptionIdSet.has(item.inscriptionId)) {
338
+ const inscriptionIdSet = new Set(contextData.inscriptionIdSet)
339
+ inscriptionIdSet.delete(item.inscriptionId)
340
+ const transferAmount = new BigNumber(contextData.transferAmount).minus(
341
+ new BigNumber(item.amount)
342
+ )
343
+ updateContextData({
344
+ inscriptionIdSet,
345
+ transferAmount: transferAmount.toString(),
346
+ })
347
+ if (allSelected) {
348
+ setAllSelected(false)
349
+ }
350
+ } else {
351
+ const inscriptionIdSet = new Set(contextData.inscriptionIdSet)
352
+ inscriptionIdSet.add(item.inscriptionId)
353
+ const transferAmount = new BigNumber(contextData.transferAmount)
354
+ .plus(new BigNumber(item.amount))
355
+ .toString()
356
+ updateContextData({
357
+ inscriptionIdSet,
358
+ transferAmount,
359
+ })
360
+ if (allSelected == false && transferAmount === totalAmount) {
361
+ setAllSelected(true)
362
+ }
363
+ }
364
+ }
365
+
366
+ const onCheckBoxChange = e => {
367
+ const val = e.target.checked
368
+ setAllSelected(val)
369
+ if (val) {
370
+ const inscriptionIdSet = new Set(items.map(v => v.inscriptionId))
371
+ updateContextData({
372
+ inscriptionIdSet,
373
+ transferAmount: totalAmount,
374
+ })
375
+ } else {
376
+ updateContextData({
377
+ inscriptionIdSet: new Set(),
378
+ transferAmount: '0',
379
+ })
380
+ }
381
+ }
382
+
383
+ const onClickCheckBoxInMobile = () => {
384
+ setLoadingLump(true)
385
+ setAllSelected(!allSelected)
386
+ startTransition(() => {
387
+ if (!allSelected) {
388
+ const inscriptionIdSet = new Set(items.map(v => v.inscriptionId))
389
+ updateContextData({
390
+ inscriptionIdSet,
391
+ transferAmount: totalAmount,
392
+ })
393
+ } else {
394
+ updateContextData({
395
+ inscriptionIdSet: new Set(),
396
+ transferAmount: '0',
397
+ })
398
+ }
399
+ })
400
+ setLoadingLump(false)
401
+ }
402
+
403
+ const onClickRefresh = () => {
404
+ fetchData()
405
+ }
406
+
407
+ return {
408
+ // data
409
+ items,
410
+ selectedCount,
411
+ allSelected,
412
+ loading,
413
+ loadingLump,
414
+
415
+ // actions
416
+ onClickItem,
417
+ onCheckBoxChange,
418
+ onClickCheckBoxInMobile,
419
+ onClickRefresh,
420
+
421
+ // tools
422
+ t,
423
+ }
424
+ }
@@ -0,0 +1,208 @@
1
+ import { bnUtils } from '@unisat/base-utils'
2
+ import { Inscription, SignPsbtParams, SignPsbtResult, ToSignData } from '@unisat/wallet-shared'
3
+ import { useEffect, useMemo, useRef, useState } from 'react'
4
+ import { useI18n, useNavigation, useTools, useWallet } from 'src/context'
5
+ import { useCurrentAccount, useFeeRateBar, useRunesTx } from 'src/hooks'
6
+ import { getAddressUtxoDust, isValidAddress } from 'src/utils/bitcoin-utils'
7
+
8
+ export enum BRC20SingleStepKey {
9
+ STEP1 = 'STEP1',
10
+ STEP2 = 'STEP2',
11
+ STEP3 = 'STEP3',
12
+ }
13
+
14
+ export function useBRC20SingleStepScreenLogic() {
15
+ const nav = useNavigation()
16
+ const props = nav.getRouteState<'BRC20SingleStepScreen'>()
17
+ const { t } = useI18n()
18
+
19
+ const tokenBalance = props.tokenBalance
20
+ const tokenInfo = props.tokenInfo
21
+
22
+ const tools = useTools()
23
+
24
+ const runesTx = useRunesTx()
25
+ const [inputAmount, setInputAmount] = useState('')
26
+ const [disabled, setDisabled] = useState(true)
27
+ const [toInfo, setToInfo] = useState<{
28
+ address: string
29
+ domain: string
30
+ inscription?: Inscription
31
+ }>({
32
+ address: runesTx.toAddress,
33
+ domain: runesTx.toDomain,
34
+ inscription: undefined,
35
+ })
36
+
37
+ const [availableBalance, setAvailableBalance] = useState(tokenBalance.overallBalance)
38
+ const [error, setError] = useState('')
39
+
40
+ const defaultOutputValue = 546
41
+
42
+ const currentAccount = useCurrentAccount()
43
+ const [outputValue, setOutputValue] = useState(defaultOutputValue)
44
+ const minOutputValue = useMemo(() => {
45
+ if (toInfo.address) {
46
+ const dust1 = getAddressUtxoDust(currentAccount.address)
47
+ const dust2 = getAddressUtxoDust(toInfo.address)
48
+ return Math.max(dust1, dust2)
49
+ } else {
50
+ return 0
51
+ }
52
+ }, [toInfo.address, currentAccount.address])
53
+
54
+ const { feeRate } = useFeeRateBar()
55
+
56
+ useEffect(() => {
57
+ setError('')
58
+ setDisabled(true)
59
+
60
+ if (!isValidAddress(toInfo.address)) {
61
+ return
62
+ }
63
+ if (!inputAmount) {
64
+ return
65
+ }
66
+
67
+ if (feeRate <= 0) {
68
+ return
69
+ }
70
+
71
+ if (bnUtils.compareAmount(inputAmount, availableBalance)! > 0) {
72
+ setError(t('insufficient_balance'))
73
+ return
74
+ }
75
+
76
+ setDisabled(false)
77
+ }, [toInfo, inputAmount, feeRate, outputValue, minOutputValue, availableBalance])
78
+
79
+ const wallet = useWallet()
80
+ const transferData = useRef<{
81
+ id: string
82
+ commitToSignData: ToSignData
83
+ revealToSignData: ToSignData
84
+ }>({
85
+ id: '',
86
+ commitToSignData: {
87
+ psbtHex: '',
88
+ toSignInputs: [],
89
+ },
90
+ revealToSignData: {
91
+ psbtHex: '',
92
+ toSignInputs: [],
93
+ },
94
+ })
95
+ const [step, setStep] = useState<BRC20SingleStepKey>(BRC20SingleStepKey.STEP1)
96
+
97
+ const signPsbtParamsStep2: SignPsbtParams = {
98
+ data: {
99
+ toSignDatas: [transferData.current.commitToSignData],
100
+ },
101
+ }
102
+
103
+ const signPsbtParamsStep3: SignPsbtParams = {
104
+ data: {
105
+ toSignDatas: [transferData.current.revealToSignData],
106
+ },
107
+ }
108
+
109
+ const onClickBack = () => {
110
+ if (step === BRC20SingleStepKey.STEP1) {
111
+ nav.goBack()
112
+ } else if (step === BRC20SingleStepKey.STEP2) {
113
+ setStep(BRC20SingleStepKey.STEP1)
114
+ } else if (step === BRC20SingleStepKey.STEP3) {
115
+ setStep(BRC20SingleStepKey.STEP2)
116
+ } else {
117
+ nav.goBack()
118
+ }
119
+ }
120
+
121
+ const onClickConfirmStep1 = async () => {
122
+ tools.showLoading(true)
123
+ try {
124
+ const step1 = await wallet.singleStepTransferBRC20Step1({
125
+ userAddress: currentAccount.address,
126
+ userPubkey: currentAccount.pubkey,
127
+ receiver: toInfo.address,
128
+ ticker: tokenBalance.ticker,
129
+ amount: inputAmount,
130
+ feeRate,
131
+ })
132
+ if (step1) {
133
+ transferData.current.id = step1.orderId
134
+ transferData.current.commitToSignData = step1.toSignData
135
+ setStep(BRC20SingleStepKey.STEP2)
136
+ }
137
+ } catch (e) {
138
+ const msg = (e as any).message
139
+ setError((e as any).message)
140
+ } finally {
141
+ tools.showLoading(false)
142
+ }
143
+ }
144
+
145
+ const onClickConfirmStep2 = async (signPsbtResult: SignPsbtResult) => {
146
+ try {
147
+ tools.showLoading(true)
148
+
149
+ const step2 = await wallet.singleStepTransferBRC20Step2({
150
+ orderId: transferData.current.id,
151
+ commitTx: signPsbtResult[0].psbtHex,
152
+ })
153
+
154
+ transferData.current.revealToSignData = step2.toSignData
155
+
156
+ setStep(BRC20SingleStepKey.STEP3)
157
+ } catch (e) {
158
+ console.log(e)
159
+ } finally {
160
+ tools.showLoading(false)
161
+ }
162
+ }
163
+
164
+ const onClickConfirmStep3 = async (signPsbtResult: SignPsbtResult) => {
165
+ tools.showLoading(true)
166
+ try {
167
+ const step3 = await wallet.singleStepTransferBRC20Step3({
168
+ orderId: transferData.current.id,
169
+ revealTx: signPsbtResult[0].psbtHex,
170
+ })
171
+ nav.navigate('TxSuccessScreen', { txid: step3.txid })
172
+ } catch (e) {
173
+ nav.navigate('TxFailScreen', { error: (e as any).message })
174
+ } finally {
175
+ tools.showLoading(false)
176
+ }
177
+ }
178
+
179
+ return {
180
+ // data
181
+ signPsbtParamsStep2,
182
+ signPsbtParamsStep3,
183
+
184
+ availableBalance,
185
+ tokenBalance,
186
+ tokenInfo,
187
+ inputAmount,
188
+ setInputAmount,
189
+ disabled,
190
+ error,
191
+ toInfo,
192
+ setToInfo,
193
+
194
+ // state
195
+ step,
196
+
197
+ // actions
198
+ onClickBack,
199
+
200
+ onClickConfirmStep1,
201
+ onClickConfirmStep2,
202
+ onClickConfirmStep3,
203
+
204
+ // utils
205
+ t,
206
+ tools,
207
+ }
208
+ }