@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,71 @@
1
+ import { Account, MAX_ALIAS_NAME_LENGTH } from '@unisat/wallet-shared'
2
+ import { useMemo, useState } from 'react'
3
+ import { useLocation } from 'react-router-dom'
4
+ import { useI18n, useNavigation, useWallet } from 'src/context'
5
+ import { useAppDispatch } from 'src/hooks'
6
+ import { accountActions, keyringsActions } from 'src/reducers'
7
+
8
+ export function useEditAccountNameScreenLogic() {
9
+ const nav = useNavigation()
10
+ const { t } = useI18n()
11
+
12
+ const { state } = useLocation()
13
+ const { account } = state as {
14
+ account: Account
15
+ }
16
+
17
+ const wallet = useWallet()
18
+ const [alianName, setAlianName] = useState(account.alianName || '')
19
+ const dispatch = useAppDispatch()
20
+ const handleOnClick = async () => {
21
+ const newAccount = await wallet.setAccountAlianName(account, alianName)
22
+ // @ts-ignore SAFE
23
+ dispatch(keyringsActions.updateAccountName(newAccount))
24
+ // @ts-ignore SAFE
25
+ dispatch(accountActions.updateAccountName(newAccount))
26
+ nav.goBack()
27
+ }
28
+
29
+ const handleOnKeyUp = (e: React.KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => {
30
+ if ('Enter' == e.key && e.ctrlKey) {
31
+ handleOnClick()
32
+ }
33
+ }
34
+
35
+ const isValidName = useMemo(() => {
36
+ if (alianName.length == 0) {
37
+ return false
38
+ }
39
+ return true
40
+ }, [alianName])
41
+
42
+ const truncatedTitle = useMemo(() => {
43
+ const name = account.alianName || ''
44
+ if (name.length > MAX_ALIAS_NAME_LENGTH) {
45
+ return name.slice(0, MAX_ALIAS_NAME_LENGTH) + '...'
46
+ }
47
+ return name
48
+ }, [account.alianName])
49
+
50
+ const onInputChange = (e: { target: { value: string } } | string) => {
51
+ const value = typeof e === 'string' ? e : e.target.value
52
+ if (value.length <= MAX_ALIAS_NAME_LENGTH) {
53
+ setAlianName(value)
54
+ }
55
+ }
56
+
57
+ const onClickBack = () => {
58
+ nav.goBack()
59
+ }
60
+ return {
61
+ alianName,
62
+ handleOnClick,
63
+ handleOnKeyUp,
64
+ isValidName,
65
+ truncatedTitle,
66
+ t,
67
+ account,
68
+ onInputChange,
69
+ onClickBack,
70
+ }
71
+ }
@@ -0,0 +1,162 @@
1
+ import { CHAINS_MAP } from '@unisat/wallet-shared'
2
+ import { ChainType } from '@unisat/wallet-types'
3
+ import { useEffect, useState } from 'react'
4
+ import { useI18n, useNavigation, useWallet } from 'src/context'
5
+ import { isValidAddress } from 'src/utils/bitcoin-utils'
6
+
7
+ export function useEditContactScreenLogic() {
8
+ const nav = useNavigation()
9
+
10
+ // Required parameters
11
+ const { address, chain, selectedNetworkFilter } = nav.getRouteState<'EditContactScreen'>()
12
+ const wallet = useWallet()
13
+ const [name, setName] = useState('')
14
+ const [contactAddress, setContactAddress] = useState(address || '')
15
+ const [originalAddress, setOriginalAddress] = useState('')
16
+ const [originalChain, setOriginalChain] = useState<ChainType | undefined>()
17
+ const [chainType, setChainType] = useState<ChainType>(ChainType.BITCOIN_MAINNET)
18
+ const [error, setError] = useState('')
19
+ const [loading, setLoading] = useState(false)
20
+ const { t } = useI18n()
21
+
22
+ useEffect(() => {
23
+ if (address) {
24
+ fetchContact()
25
+ } else {
26
+ const preselectedChainType = selectedNetworkFilter as ChainType
27
+
28
+ if (preselectedChainType) {
29
+ setChainType(preselectedChainType)
30
+ }
31
+ }
32
+ }, [address, chain, selectedNetworkFilter])
33
+
34
+ const fetchContact = async () => {
35
+ if (!address || !chain) return
36
+
37
+ try {
38
+ const chainEnum = chain as ChainType
39
+ const contact = await wallet.getContactByAddressAndChain(address, chainEnum)
40
+
41
+ if (contact) {
42
+ setName(contact.name)
43
+ setContactAddress(contact.address)
44
+ setOriginalAddress(contact.address)
45
+ setOriginalChain(contact.chain)
46
+ setChainType(contact.chain)
47
+ } else {
48
+ setError(t('contact_not_found'))
49
+ setTimeout(() => {
50
+ nav.navigate('ContactsScreen', {})
51
+ }, 1500)
52
+ }
53
+ } catch (err) {
54
+ console.error('Error fetching contact:', err)
55
+ setError(t('failed_to_load_contact_information'))
56
+ }
57
+ }
58
+
59
+ const handleSubmit = async () => {
60
+ if (!name.trim()) {
61
+ setError(t('please_enter_name'))
62
+ return
63
+ }
64
+
65
+ if (!contactAddress.trim()) {
66
+ setError(t('please_enter_address'))
67
+ return
68
+ }
69
+
70
+ const networkType = CHAINS_MAP[chainType].networkType
71
+
72
+ if (!isValidAddress(contactAddress, networkType)) {
73
+ setError(t('invalid_address_format_for_selected_network'))
74
+ return
75
+ }
76
+
77
+ setError('')
78
+ setLoading(true)
79
+
80
+ try {
81
+ if (
82
+ originalAddress &&
83
+ originalChain &&
84
+ (originalAddress !== contactAddress.trim() || originalChain !== chainType)
85
+ ) {
86
+ await wallet.removeContact(originalAddress, originalChain)
87
+ }
88
+
89
+ await wallet.updateContact({
90
+ name: name.trim(),
91
+ address: contactAddress.trim(),
92
+ chain: chainType,
93
+ isContact: true,
94
+ isAlias: false,
95
+ })
96
+
97
+ nav.goBack()
98
+ } catch (err) {
99
+ setError(t('failed_to_save_contact'))
100
+ } finally {
101
+ setLoading(false)
102
+ }
103
+ }
104
+
105
+ const handleDelete = async () => {
106
+ if (!address || !originalChain) return
107
+
108
+ setLoading(true)
109
+ try {
110
+ await wallet.removeContact(address, originalChain)
111
+
112
+ nav.navigate('ContactsScreen', {
113
+ returnWithNetwork: chainType,
114
+ })
115
+ } catch (err) {
116
+ setError(t('failed_to_delete_contact'))
117
+ } finally {
118
+ setLoading(false)
119
+ }
120
+ }
121
+
122
+ const handleAddressChange = (e: { target: { value: string } } | string) => {
123
+ const value = (typeof e === 'string' ? e : e.target.value).trim()
124
+ setContactAddress(value)
125
+
126
+ if (error.includes('Invalid address') || !value) {
127
+ setError('')
128
+ }
129
+
130
+ if (value) {
131
+ const networkType = CHAINS_MAP[chainType].networkType
132
+
133
+ if (value.length > 15 && !isValidAddress(value, networkType)) {
134
+ setError(t('invalid_address_format_for_selected_network'))
135
+ }
136
+ }
137
+ }
138
+
139
+ const handleNameChange = (e: { target: { value: string } } | string) => {
140
+ const value = typeof e === 'string' ? e : e.target.value
141
+ setName(value)
142
+ }
143
+
144
+ const onClickBack = () => {
145
+ nav.goBack()
146
+ }
147
+
148
+ return {
149
+ name,
150
+ contactAddress,
151
+ chainType,
152
+ error,
153
+ loading,
154
+ handleNameChange,
155
+ handleAddressChange,
156
+ handleSubmit,
157
+ handleDelete,
158
+ onClickBack,
159
+ address,
160
+ t,
161
+ }
162
+ }
@@ -0,0 +1,60 @@
1
+ import { useMemo, useState } from 'react'
2
+
3
+ import { MAX_ALIAS_NAME_LENGTH } from '@unisat/wallet-shared'
4
+
5
+ import { keyringsActions, useAppDispatch, useI18n, useNavigation, useWallet } from '..'
6
+ export function useEditWalletNameScreenLogic() {
7
+ const nav = useNavigation()
8
+ const { keyring } = nav.getRouteState<'EditWalletNameScreen'>()
9
+ const { t } = useI18n()
10
+ const wallet = useWallet()
11
+ const [alianName, setAlianName] = useState(keyring.alianName || '')
12
+ const dispatch = useAppDispatch()
13
+ const handleOnClick = async () => {
14
+ try {
15
+ const newKeyring = await wallet.setKeyringAlianName(keyring, alianName || keyring.alianName)
16
+ //@ts-ignore SAFE
17
+ dispatch(keyringsActions.updateKeyringName(newKeyring))
18
+ nav.goBack()
19
+ } catch (e) {
20
+ console.log(e)
21
+ }
22
+ }
23
+
24
+ const handleOnKeyUp = (e: React.KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => {
25
+ if ('Enter' == e.key && e.ctrlKey) {
26
+ handleOnClick()
27
+ }
28
+ }
29
+
30
+ const isValidName = useMemo(() => {
31
+ if (alianName.length == 0) {
32
+ return false
33
+ }
34
+ return true
35
+ }, [alianName])
36
+
37
+ const truncatedTitle = useMemo(() => {
38
+ if (keyring.alianName && keyring.alianName.length > MAX_ALIAS_NAME_LENGTH) {
39
+ return keyring.alianName.slice(0, MAX_ALIAS_NAME_LENGTH) + '...'
40
+ }
41
+ return keyring.alianName || ''
42
+ }, [keyring.alianName])
43
+
44
+ const onInputChange = (e: { target: { value: string } } | string) => {
45
+ const value = typeof e === 'string' ? e : e.target.value
46
+ if (value.length <= MAX_ALIAS_NAME_LENGTH) {
47
+ setAlianName(value)
48
+ }
49
+ }
50
+
51
+ return {
52
+ t,
53
+ keyring,
54
+ isValidName,
55
+ truncatedTitle,
56
+ handleOnClick,
57
+ handleOnKeyUp,
58
+ onInputChange,
59
+ }
60
+ }
@@ -0,0 +1,75 @@
1
+ import { ADDRESS_TYPES } from '@unisat/wallet-shared'
2
+ import { useEffect, useState } from 'react'
3
+ import { useI18n, useNavigation, useTools, useWallet } from 'src/context'
4
+ type Status = '' | 'error' | 'warning' | undefined
5
+
6
+ export function useExportMnemonicsScreenLogic() {
7
+ const nav = useNavigation()
8
+ const { keyring } = nav.getRouteState<'ExportMnemonicsScreen'>()
9
+
10
+ const { t } = useI18n()
11
+
12
+ const [password, setPassword] = useState('')
13
+ const [disabled, setDisabled] = useState(true)
14
+
15
+ const [mnemonic, setMnemonic] = useState('')
16
+ const [status, setStatus] = useState<Status>('')
17
+ const [error, setError] = useState('')
18
+ const wallet = useWallet()
19
+ const tools = useTools()
20
+
21
+ const [passphrase, setPassphrase] = useState('')
22
+
23
+ const btnClick = async () => {
24
+ try {
25
+ const { mnemonic, hdPath, passphrase } = await wallet.getMnemonics(password, keyring)
26
+ setMnemonic(mnemonic)
27
+ setPassphrase(passphrase)
28
+ } catch (e) {
29
+ setStatus('error')
30
+ setError((e as any).message)
31
+ }
32
+ }
33
+
34
+ const handleOnKeyUp = (e: React.KeyboardEvent<HTMLInputElement>) => {
35
+ if ('Enter' == e.key) {
36
+ btnClick()
37
+ }
38
+ }
39
+
40
+ useEffect(() => {
41
+ setDisabled(true)
42
+ if (password) {
43
+ setDisabled(false)
44
+ setStatus('')
45
+ setError('')
46
+ }
47
+ }, [password])
48
+
49
+ function copy(str: string) {
50
+ tools.copyToClipboard(str)
51
+ }
52
+ const words = mnemonic.split(' ')
53
+
54
+ const pathName = ADDRESS_TYPES.find(v => v.hdPath === keyring.hdPath)?.name || 'custom'
55
+
56
+ const onClickBack = () => {
57
+ nav.goBack()
58
+ }
59
+
60
+ return {
61
+ words,
62
+ pathName,
63
+ t,
64
+ setPassword,
65
+ disabled,
66
+ btnClick,
67
+ handleOnKeyUp,
68
+ mnemonic,
69
+ passphrase,
70
+ error,
71
+ copy,
72
+ keyring,
73
+ onClickBack,
74
+ }
75
+ }
@@ -0,0 +1,64 @@
1
+ import { useEffect, useState } from 'react'
2
+ import { useI18n, useNavigation, useTools, useWallet } from 'src/context'
3
+
4
+ type Status = '' | 'error' | 'warning' | undefined
5
+ export function useExportPrivateKeyScreenLogic() {
6
+ const { t } = useI18n()
7
+
8
+ const nav = useNavigation()
9
+ const { account } = nav.getRouteState<'ExportPrivateKeyScreen'>()
10
+
11
+ const [password, setPassword] = useState('')
12
+ const [disabled, setDisabled] = useState(true)
13
+
14
+ const [privateKey, setPrivateKey] = useState({ hex: '', wif: '' })
15
+ const [status, setStatus] = useState<Status>('')
16
+ const [error, setError] = useState('')
17
+ const wallet = useWallet()
18
+ const tools = useTools()
19
+
20
+ const btnClick = async () => {
21
+ try {
22
+ const _res = await wallet.getPrivateKey(password, account)
23
+ setPrivateKey(_res)
24
+ } catch (e) {
25
+ setStatus('error')
26
+ setError((e as any).message)
27
+ }
28
+ }
29
+
30
+ const handleOnKeyUp = (e: React.KeyboardEvent<HTMLInputElement>) => {
31
+ if ('Enter' == e.key) {
32
+ btnClick()
33
+ }
34
+ }
35
+
36
+ useEffect(() => {
37
+ setDisabled(true)
38
+ if (password) {
39
+ setDisabled(false)
40
+ setStatus('')
41
+ setError('')
42
+ }
43
+ }, [password])
44
+
45
+ function copy(str: string) {
46
+ tools.copyToClipboard(str)
47
+ }
48
+
49
+ const onClickBack = () => {
50
+ nav.goBack()
51
+ }
52
+
53
+ return {
54
+ t,
55
+ setPassword,
56
+ disabled,
57
+ btnClick,
58
+ handleOnKeyUp,
59
+ privateKey,
60
+ error,
61
+ copy,
62
+ onClickBack,
63
+ }
64
+ }