@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,152 @@
1
+ import { Inscription } from '@unisat/wallet-shared'
2
+ import { useEffect, useMemo, useState } from 'react'
3
+ import {
4
+ useFeeRateBar,
5
+ useFetchUtxosCallback,
6
+ useI18n,
7
+ useNavigation,
8
+ useOrdinalsTx,
9
+ usePrepareSendOrdinalsInscriptionCallback,
10
+ useTools,
11
+ useWallet,
12
+ } from '..'
13
+ import { getAddressUtxoDust, isValidAddress } from '../utils/bitcoin-utils'
14
+
15
+ export function useSendOrdinalsInscriptionScreenLogic() {
16
+ const [disabled, setDisabled] = useState(true)
17
+ const nav = useNavigation()
18
+
19
+ const { inscription } = nav.getRouteState<'SendOrdinalsInscriptionScreen'>()
20
+ const ordinalsTx = useOrdinalsTx()
21
+ const [toInfo, setToInfo] = useState({
22
+ address: ordinalsTx.toAddress,
23
+ domain: ordinalsTx.toDomain,
24
+ })
25
+ const { t } = useI18n()
26
+
27
+ const fetchBtcUtxos = useFetchUtxosCallback()
28
+ const tools = useTools()
29
+ useEffect(() => {
30
+ tools.showLoading(true)
31
+ fetchBtcUtxos().finally(() => {
32
+ tools.showLoading(false)
33
+ })
34
+ }, [])
35
+
36
+ const [error, setError] = useState('')
37
+ const prepareSendOrdinalsInscription = usePrepareSendOrdinalsInscriptionCallback()
38
+ const { feeRate } = useFeeRateBar()
39
+ const defaultOutputValue = inscription ? inscription.outputValue : 10000
40
+
41
+ const [outputValue, setOutputValue] = useState(defaultOutputValue)
42
+ const [enableRBF, setEnableRBF] = useState(true)
43
+ const [inscriptions, setInscriptions] = useState<Inscription[]>([])
44
+
45
+ const wallet = useWallet()
46
+ useEffect(() => {
47
+ wallet.getEnableRBF().then(enableRBF => {
48
+ setEnableRBF(enableRBF)
49
+ })
50
+ }, [wallet])
51
+
52
+ useEffect(() => {
53
+ wallet.getInscriptionUtxoDetail(inscription.inscriptionId).then(v => {
54
+ setInscriptions(v.inscriptions)
55
+ })
56
+ }, [])
57
+
58
+ const onEnableRBFChange = (value: boolean) => {
59
+ setEnableRBF(value)
60
+ wallet.setEnableRBF(value)
61
+ }
62
+
63
+ const minOutputValue = useMemo(() => {
64
+ if (toInfo.address) {
65
+ return getAddressUtxoDust(toInfo.address)
66
+ } else {
67
+ return 0
68
+ }
69
+ }, [toInfo.address])
70
+
71
+ useEffect(() => {
72
+ setDisabled(true)
73
+ setError('')
74
+
75
+ if (feeRate <= 0) {
76
+ setError(t('invalid_fee_rate'))
77
+ return
78
+ }
79
+
80
+ let dustUtxo = inscription.outputValue
81
+ try {
82
+ if (toInfo.address) {
83
+ dustUtxo = getAddressUtxoDust(toInfo.address)
84
+ }
85
+ } catch (e) {
86
+ // console.log(e);
87
+ }
88
+
89
+ const maxOffset = inscriptions.reduce((pre, cur) => {
90
+ return Math.max(pre, cur.offset)
91
+ }, 0)
92
+
93
+ const minOutputValue = Math.max(maxOffset + 1, dustUtxo)
94
+
95
+ if (outputValue < minOutputValue) {
96
+ setError(`${t('output_value_must_be_at_least')} ${minOutputValue}`)
97
+ return
98
+ }
99
+
100
+ if (!outputValue) {
101
+ return
102
+ }
103
+
104
+ if (!isValidAddress(toInfo.address)) {
105
+ return
106
+ }
107
+
108
+ setDisabled(false)
109
+ }, [toInfo, feeRate, outputValue, inscriptions])
110
+
111
+ const onAddressInputChange = val => {
112
+ setToInfo(val)
113
+ }
114
+
115
+ const onClickBack = () => {
116
+ nav.goBack()
117
+ }
118
+
119
+ const onClickNext = () => {
120
+ prepareSendOrdinalsInscription({
121
+ toAddressInfo: toInfo,
122
+ inscriptionId: inscription.inscriptionId,
123
+ feeRate,
124
+ outputValue,
125
+ enableRBF,
126
+ })
127
+ .then(toSignData => {
128
+ nav.navigate('TxConfirmScreen', { toSignData })
129
+ })
130
+ .catch(e => {
131
+ console.log(e)
132
+ setError(e.message)
133
+ })
134
+ }
135
+
136
+ return {
137
+ t,
138
+ onAddressInputChange,
139
+ toInfo,
140
+ outputValue,
141
+ enableRBF,
142
+ setEnableRBF: onEnableRBFChange,
143
+ minOutputValue,
144
+ defaultOutputValue,
145
+ setOutputValue,
146
+ inscriptions,
147
+ disabled,
148
+ error,
149
+ onClickBack,
150
+ onClickNext,
151
+ }
152
+ }
@@ -0,0 +1,189 @@
1
+ import { bnUtils } from '@unisat/base-utils'
2
+ import { Inscription } from '@unisat/wallet-shared'
3
+ import BigNumber from 'bignumber.js'
4
+ import { useEffect, useMemo, useState } from 'react'
5
+ import { useI18n, useNavigation, useTools, useWallet } from 'src/context'
6
+ import {
7
+ useCurrentAccount,
8
+ useFeeRateBar,
9
+ useFetchAssetUtxosRunesCallback,
10
+ useFetchUtxosCallback,
11
+ usePrepareSendRunesCallback,
12
+ useRunesTx,
13
+ } from 'src/hooks'
14
+ import { getAddressUtxoDust, isValidAddress } from 'src/utils/bitcoin-utils'
15
+
16
+ export function useSendRunesScreenLogic() {
17
+ const nav = useNavigation()
18
+ const props = nav.getRouteState<'SendRunesScreen'>()
19
+ const { t } = useI18n()
20
+
21
+ const runeBalance = props.runeBalance
22
+
23
+ const runeInfo = props.runeInfo
24
+
25
+ const runesTx = useRunesTx()
26
+ const [inputAmount, setInputAmount] = useState('')
27
+ const [disabled, setDisabled] = useState(true)
28
+ const [toInfo, setToInfo] = useState<{
29
+ address: string
30
+ domain: string
31
+ inscription?: Inscription
32
+ }>({
33
+ address: runesTx.toAddress,
34
+ domain: runesTx.toDomain,
35
+ inscription: undefined,
36
+ })
37
+
38
+ const [availableBalance, setAvailableBalance] = useState('0')
39
+ const [error, setError] = useState('')
40
+
41
+ const defaultOutputValue = 546
42
+
43
+ const currentAccount = useCurrentAccount()
44
+ const [outputValue, setOutputValue] = useState(defaultOutputValue)
45
+ const [enableRBF, setEnableRBF] = useState(true)
46
+ const minOutputValue = useMemo(() => {
47
+ if (toInfo.address) {
48
+ const dust1 = getAddressUtxoDust(currentAccount.address)
49
+ const dust2 = getAddressUtxoDust(toInfo.address)
50
+ return Math.max(dust1, dust2)
51
+ } else {
52
+ return 0
53
+ }
54
+ }, [toInfo.address, currentAccount.address])
55
+
56
+ const fetchUtxos = useFetchUtxosCallback()
57
+ const wallet = useWallet()
58
+
59
+ const fetchAssetUtxosRunes = useFetchAssetUtxosRunesCallback()
60
+ const tools = useTools()
61
+ useEffect(() => {
62
+ fetchUtxos()
63
+ tools.showLoading(true)
64
+ fetchAssetUtxosRunes(runeInfo.runeid)
65
+ .then(utxos => {
66
+ let balance = new BigNumber(0)
67
+ for (let i = 0; i < utxos.length; i++) {
68
+ const utxo = utxos[i]
69
+ if (utxo.runes) {
70
+ utxo.runes.forEach(rune => {
71
+ if (rune.runeid === runeInfo.runeid) {
72
+ balance = balance.plus(new BigNumber(rune.amount))
73
+ }
74
+ })
75
+ }
76
+ }
77
+ setAvailableBalance(balance.toString())
78
+ })
79
+ .finally(() => {
80
+ tools.showLoading(false)
81
+ })
82
+ }, [])
83
+
84
+ const prepareSendRunes = usePrepareSendRunesCallback()
85
+
86
+ const { feeRate } = useFeeRateBar()
87
+
88
+ useEffect(() => {
89
+ wallet.getEnableRBF().then(enableRBF => {
90
+ setEnableRBF(enableRBF)
91
+ })
92
+ }, [wallet])
93
+
94
+ useEffect(() => {
95
+ setError('')
96
+ setDisabled(true)
97
+
98
+ if (!isValidAddress(toInfo.address)) {
99
+ return
100
+ }
101
+ if (!inputAmount) {
102
+ return
103
+ }
104
+
105
+ const runeAmount = bnUtils.fromDecimalAmount(inputAmount, runeInfo.divisibility)
106
+ if (feeRate <= 0) {
107
+ return
108
+ }
109
+
110
+ if (bnUtils.compareAmount(runeAmount, '0') <= 0) {
111
+ return
112
+ }
113
+
114
+ if (bnUtils.compareAmount(runeAmount, availableBalance) > 0) {
115
+ setError(t('insufficient_balance'))
116
+ return
117
+ }
118
+
119
+ if (outputValue < minOutputValue) {
120
+ setError(`${t('output_value_must_be_at_least')} ${minOutputValue}`)
121
+ return
122
+ }
123
+
124
+ if (!outputValue) {
125
+ return
126
+ }
127
+
128
+ setDisabled(false)
129
+ }, [toInfo, inputAmount, feeRate, outputValue, minOutputValue, availableBalance])
130
+
131
+ const totalBalanceStr = useMemo(() => {
132
+ return bnUtils.toDecimalAmount(runeBalance.amount, runeBalance.divisibility)
133
+ }, [runeBalance])
134
+ const availableBalanceStr = useMemo(() => {
135
+ return bnUtils.toDecimalAmount(availableBalance, runeBalance?.divisibility)
136
+ }, [availableBalance, runeBalance])
137
+
138
+ const onClickBack = () => {
139
+ nav.goBack()
140
+ }
141
+
142
+ const onEnableRBFChange = (value: boolean) => {
143
+ setEnableRBF(value)
144
+ wallet.setEnableRBF(value)
145
+ }
146
+
147
+ const onClickNext = () => {
148
+ const runeAmount = bnUtils.fromDecimalAmount(inputAmount, runeInfo.divisibility)
149
+ prepareSendRunes({
150
+ toAddressInfo: toInfo,
151
+ runeid: runeInfo.runeid,
152
+ runeAmount: runeAmount,
153
+ outputValue: outputValue,
154
+ feeRate,
155
+ enableRBF,
156
+ })
157
+ .then(toSignData => {
158
+ nav.navigate('TxConfirmScreen', { toSignData })
159
+ })
160
+ .catch(e => {
161
+ console.log(e)
162
+ setError(e.message)
163
+ })
164
+ }
165
+
166
+ return {
167
+ // info
168
+ runeInfo,
169
+ inputAmount,
170
+ totalBalanceStr,
171
+ availableBalanceStr,
172
+
173
+ setInputAmount,
174
+ disabled,
175
+ toInfo,
176
+ setToInfo,
177
+ error,
178
+ defaultOutputValue,
179
+ minOutputValue,
180
+ setOutputValue,
181
+ enableRBF,
182
+ setEnableRBF: onEnableRBFChange,
183
+ t,
184
+
185
+ // actions
186
+ onClickBack,
187
+ onClickNext,
188
+ }
189
+ }
@@ -0,0 +1,211 @@
1
+ import { KeyringType } from '@unisat/keyring-service/types'
2
+ import { ADDRESS_TYPES, FEEDBACK_URL, PlatformEnv } from '@unisat/wallet-shared'
3
+ import { useMemo, useState } from 'react'
4
+ import { useDevice, useI18n, useNavigation, useTools, useWallet } from 'src/context'
5
+ import { useChain, useCurrentAccount, useCurrentKeyring, useVersionInfo } from 'src/hooks'
6
+
7
+ export interface SettingsItemType {
8
+ key: string
9
+ label?: string
10
+ value?: string
11
+ desc?: string
12
+ danger?: boolean
13
+ right: boolean
14
+ icon?: string
15
+ badge?: string
16
+ onClick?: () => void
17
+ }
18
+
19
+ export function useSettingsTabScreenLogic() {
20
+ const nav = useNavigation()
21
+ const currentKeyring = useCurrentKeyring()
22
+ const currentAccount = useCurrentAccount()
23
+ const chain = useChain()
24
+ const wallet = useWallet()
25
+ const tools = useTools()
26
+ const [connected, setConnected] = useState(false)
27
+ const versionInfo = useVersionInfo()
28
+ const hasUpdate =
29
+ versionInfo.latestVersion && versionInfo.latestVersion !== versionInfo.currentVesion
30
+ const { t } = useI18n()
31
+
32
+ const { isExtensionInExpandView } = useDevice()
33
+
34
+ const isCustomHdPath = useMemo(() => {
35
+ const item = ADDRESS_TYPES[currentKeyring.addressType]
36
+ return currentKeyring.hdPath !== '' && item.hdPath !== currentKeyring.hdPath
37
+ }, [currentKeyring])
38
+
39
+ const settings_connectedSites: SettingsItemType = useMemo(() => {
40
+ const value = connected ? t('connected') : t('not_connected')
41
+ return {
42
+ key: 'settings_connectedSites',
43
+ label: t('connected_sites'),
44
+ value,
45
+ desc: '',
46
+ right: true,
47
+ icon: 'connectedSites',
48
+ onClick: () => {
49
+ nav.navigate('ConnectedSitesScreen')
50
+ },
51
+ }
52
+ }, [t, connected])
53
+
54
+ const settings_addressBook: SettingsItemType = useMemo(() => {
55
+ return {
56
+ key: 'settings_addressBook',
57
+ label: t('address_book'),
58
+ value: t('addressbook_desc'),
59
+ desc: '',
60
+ right: true,
61
+ icon: 'addressBook',
62
+ onClick: () => {
63
+ // todo
64
+ nav.navigate('ContactsScreen', {})
65
+ },
66
+ }
67
+ }, [t])
68
+ const settings_addressType: SettingsItemType = useMemo(() => {
69
+ let value = ''
70
+ const item = ADDRESS_TYPES[currentKeyring.addressType]
71
+ const hdPath = currentKeyring.hdPath || item.hdPath
72
+ if (currentKeyring.type === KeyringType.SimpleKeyring) {
73
+ value = `${item.name}`
74
+ } else {
75
+ value = `${item.name} (${hdPath}/${currentAccount.index})`
76
+ }
77
+ return {
78
+ key: 'settings_addressType',
79
+ label: t('address_type'),
80
+ value,
81
+ desc: '',
82
+ right: true,
83
+ icon: 'addressType',
84
+ onClick: () => {
85
+ if (isCustomHdPath) {
86
+ tools.showTip(
87
+ t(
88
+ 'the_wallet_currently_uses_a_custom_hd_path_and_does_not_support_switching_address_types'
89
+ )
90
+ )
91
+ return
92
+ }
93
+ nav.navigate('AddressTypeScreen')
94
+ },
95
+ }
96
+ }, [t, isCustomHdPath])
97
+
98
+ const settings_advanced = useMemo(() => {
99
+ return {
100
+ key: 'settings_advanced',
101
+ label: t('settings'),
102
+ value: t('advanced_settings'),
103
+ desc: '',
104
+ right: true,
105
+ icon: 'advance',
106
+ onClick: () => {
107
+ nav.navigate('AdvancedScreen')
108
+ },
109
+ }
110
+ }, [t])
111
+
112
+ const settings_feedback = useMemo(() => {
113
+ return {
114
+ key: 'settings_feedback',
115
+ label: t('feedback'),
116
+ value: t('let_us_know_what_you_think'),
117
+ desc: '',
118
+ route: '',
119
+ right: true,
120
+ icon: 'feedback',
121
+ onClick: () => {
122
+ const addressParam = currentAccount.address
123
+
124
+ let feedbackUrl = FEEDBACK_URL
125
+ feedbackUrl += `?address=${addressParam}&category=wallet`
126
+
127
+ nav.navToUrl(feedbackUrl)
128
+ },
129
+ }
130
+ }, [t])
131
+
132
+ const settings_rateus = useMemo(() => {
133
+ return {
134
+ key: 'settings_rateus',
135
+ label: t('rate_us'),
136
+ value: t('like_our_wallet_wed_love_your_rating'),
137
+ desc: '',
138
+ route: '',
139
+ right: true,
140
+ icon: 'rateUs',
141
+ onClick: () => {
142
+ nav.navToUrl(PlatformEnv.REVIEW_URL)
143
+ },
144
+ }
145
+ }, [t])
146
+
147
+ const settings_aboutus = useMemo(() => {
148
+ return {
149
+ key: 'settings_aboutus',
150
+ label: t('about_us'),
151
+ value: '',
152
+ desc: '',
153
+ right: true,
154
+ icon: 'aboutUsLogo',
155
+ badge: hasUpdate ? t('new_version') : undefined,
156
+ onClick: () => {
157
+ nav.navigate('AboutUsScreen')
158
+ },
159
+ }
160
+ }, [t, hasUpdate])
161
+
162
+ const settings_lockwallet = useMemo(() => {
163
+ return {
164
+ key: 'settings_lockwallet',
165
+ label: '',
166
+ value: '',
167
+ desc: t('lock_immediately'),
168
+ right: false,
169
+ onClick: () => {
170
+ wallet.lockWallet()
171
+
172
+ // Add small delay to ensure lock state updates before navigation
173
+ // Prevents race condition where unlock screen might redirect back to main
174
+ setTimeout(() => {
175
+ nav.navToLock({
176
+ autoUnlockByFace: false,
177
+ })
178
+ }, 10)
179
+ return
180
+ },
181
+ }
182
+ }, [t])
183
+
184
+ const settings_expandview = useMemo(() => {
185
+ if (isExtensionInExpandView) {
186
+ return null
187
+ }
188
+ return {
189
+ key: 'settings_expandview',
190
+ label: '',
191
+ value: '',
192
+ desc: t('expand_view'),
193
+ right: false,
194
+ onClick: () => {
195
+ nav.openExtensionInTab()
196
+ },
197
+ }
198
+ }, [t])
199
+
200
+ return {
201
+ settings_connectedSites,
202
+ settings_addressBook,
203
+ settings_addressType,
204
+ settings_advanced,
205
+ settings_feedback,
206
+ settings_rateus,
207
+ settings_aboutus,
208
+ settings_lockwallet,
209
+ settings_expandview,
210
+ }
211
+ }