@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.
- package/LICENSE +0 -5
- package/lib/actions/global.d.ts +2 -0
- package/lib/actions/global.d.ts.map +1 -0
- package/lib/context/ApprovalContext.d.ts +9 -0
- package/lib/context/ApprovalContext.d.ts.map +1 -0
- package/lib/context/DeviceContext.d.ts +17 -0
- package/lib/context/DeviceContext.d.ts.map +1 -0
- package/lib/context/I18nContext.d.ts +13 -0
- package/lib/context/I18nContext.d.ts.map +1 -0
- package/lib/context/NavigationContext.d.ts +218 -0
- package/lib/context/NavigationContext.d.ts.map +1 -0
- package/lib/context/PriceContext.d.ts +13 -0
- package/lib/context/PriceContext.d.ts.map +1 -0
- package/lib/context/StorageContext.d.ts +60 -0
- package/lib/context/StorageContext.d.ts.map +1 -0
- package/lib/context/ToolsContext.d.ts +17 -0
- package/lib/context/ToolsContext.d.ts.map +1 -0
- package/lib/context/WalletContext.d.ts +493 -0
- package/lib/context/WalletContext.d.ts.map +1 -0
- package/lib/context/index.d.ts +9 -0
- package/lib/context/index.d.ts.map +1 -0
- package/lib/hooks/accounts.d.ts +34 -0
- package/lib/hooks/accounts.d.ts.map +1 -0
- package/lib/hooks/base.d.ts +14 -0
- package/lib/hooks/base.d.ts.map +1 -0
- package/lib/hooks/browser.d.ts +32 -0
- package/lib/hooks/browser.d.ts.map +1 -0
- package/lib/hooks/discovery.d.ts +17 -0
- package/lib/hooks/discovery.d.ts.map +1 -0
- package/lib/hooks/global.d.ts +43 -0
- package/lib/hooks/global.d.ts.map +1 -0
- package/lib/hooks/index.d.ts +10 -0
- package/lib/hooks/index.d.ts.map +1 -0
- package/lib/hooks/keyrings.d.ts +5 -0
- package/lib/hooks/keyrings.d.ts.map +1 -0
- package/lib/hooks/settings.d.ts +43 -0
- package/lib/hooks/settings.d.ts.map +1 -0
- package/lib/hooks/transactions.d.ts +67 -0
- package/lib/hooks/transactions.d.ts.map +1 -0
- package/lib/hooks/ui.d.ts +112 -0
- package/lib/hooks/ui.d.ts.map +1 -0
- package/lib/index.d.mts +2072 -199
- package/lib/index.d.ts +31 -946
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +7176 -582
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +6971 -525
- package/lib/index.mjs.map +1 -1
- package/lib/reducers/accounts.d.ts +49 -0
- package/lib/reducers/accounts.d.ts.map +1 -0
- package/lib/reducers/browser.d.ts +49 -0
- package/lib/reducers/browser.d.ts.map +1 -0
- package/lib/reducers/discovery.d.ts +22 -0
- package/lib/reducers/discovery.d.ts.map +1 -0
- package/lib/reducers/global.d.ts +35 -0
- package/lib/reducers/global.d.ts.map +1 -0
- package/lib/reducers/index.d.ts +9 -0
- package/lib/reducers/index.d.ts.map +1 -0
- package/lib/reducers/keyrings.d.ts +10 -0
- package/lib/reducers/keyrings.d.ts.map +1 -0
- package/lib/reducers/settings.d.ts +16 -0
- package/lib/reducers/settings.d.ts.map +1 -0
- package/lib/reducers/transactions.d.ts +61 -0
- package/lib/reducers/transactions.d.ts.map +1 -0
- package/lib/reducers/ui.d.ts +55 -0
- package/lib/reducers/ui.d.ts.map +1 -0
- package/lib/types/index.d.mts +7 -3
- package/lib/types/index.d.ts +3 -30
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +7 -1
- package/lib/types/index.js.map +1 -1
- package/lib/types/index.mjs +7 -2
- package/lib/types/index.mjs.map +1 -1
- package/lib/types/ui.d.ts +31 -0
- package/lib/types/ui.d.ts.map +1 -0
- package/lib/ui-hooks/index.d.ts +55 -0
- package/lib/ui-hooks/index.d.ts.map +1 -0
- package/lib/ui-hooks/useActionOverviewSectionLogic.d.ts +12 -0
- package/lib/ui-hooks/useActionOverviewSectionLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useAddressTypeScreenLogic.d.ts +19 -0
- package/lib/ui-hooks/useAddressTypeScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useAlkanesBalanceCardLogic.d.ts +19 -0
- package/lib/ui-hooks/useAlkanesBalanceCardLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useAlkanesCollectionListLogic.d.ts +11 -0
- package/lib/ui-hooks/useAlkanesCollectionListLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useAlkanesListLogic.d.ts +14 -0
- package/lib/ui-hooks/useAlkanesListLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useAlkanesNFTListLogic.d.ts +11 -0
- package/lib/ui-hooks/useAlkanesNFTListLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useAlkanesNFTScreenLogic.d.ts +9 -0
- package/lib/ui-hooks/useAlkanesNFTScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useAlkanesTokenScreenLogic.d.ts +22 -0
- package/lib/ui-hooks/useAlkanesTokenScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useAmountInputLogic.d.ts +22 -0
- package/lib/ui-hooks/useAmountInputLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useAnnouncementCardLogic.d.ts +11 -0
- package/lib/ui-hooks/useAnnouncementCardLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useBRC20BalanceCardLogic.d.ts +26 -0
- package/lib/ui-hooks/useBRC20BalanceCardLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useBRC20InscribeTransferLogic.d.ts +103 -0
- package/lib/ui-hooks/useBRC20InscribeTransferLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useBRC20ListLogic.d.ts +14 -0
- package/lib/ui-hooks/useBRC20ListLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useBRC20ProgListLogic.d.ts +14 -0
- package/lib/ui-hooks/useBRC20ProgListLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useBRC20SendScreenLogic.d.ts +67 -0
- package/lib/ui-hooks/useBRC20SendScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useBRC20SingleStepScreenLogic.d.ts +36 -0
- package/lib/ui-hooks/useBRC20SingleStepScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useBRC20TokenScreenLogic.d.ts +75 -0
- package/lib/ui-hooks/useBRC20TokenScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useBalanceCardLogic.d.ts +26 -0
- package/lib/ui-hooks/useBalanceCardLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useBtcDisplayLogic.d.ts +5 -0
- package/lib/ui-hooks/useBtcDisplayLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useCAT20BalanceCardLogic.d.ts +20 -0
- package/lib/ui-hooks/useCAT20BalanceCardLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useCAT20ListLogic.d.ts +14 -0
- package/lib/ui-hooks/useCAT20ListLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useCAT20TokenScreenLogic.d.ts +19 -0
- package/lib/ui-hooks/useCAT20TokenScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useCAT721ListLogic.d.ts +11 -0
- package/lib/ui-hooks/useCAT721ListLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useCAT721NFTScreenLogic.d.ts +9 -0
- package/lib/ui-hooks/useCAT721NFTScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useCreatePasswordScreenLogic.d.ts +27 -0
- package/lib/ui-hooks/useCreatePasswordScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useCreateWalletLogicImportWordsStep.d.ts +78 -0
- package/lib/ui-hooks/useCreateWalletLogicImportWordsStep.d.ts.map +1 -0
- package/lib/ui-hooks/useEditAccountNameScreenLogic.d.ts +18 -0
- package/lib/ui-hooks/useEditAccountNameScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useEditContactScreenLogic.d.ts +24 -0
- package/lib/ui-hooks/useEditContactScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useEditWalletNameScreenLogic.d.ts +15 -0
- package/lib/ui-hooks/useEditWalletNameScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useExportMnemonicsScreenLogic.d.ts +18 -0
- package/lib/ui-hooks/useExportMnemonicsScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useExportPrivateKeyScreenLogic.d.ts +17 -0
- package/lib/ui-hooks/useExportPrivateKeyScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useFeeRateBarLogic.d.ts +34 -0
- package/lib/ui-hooks/useFeeRateBarLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useInfiniteList.d.ts +19 -0
- package/lib/ui-hooks/useInfiniteList.d.ts.map +1 -0
- package/lib/ui-hooks/useInscriptionListLogic.d.ts +11 -0
- package/lib/ui-hooks/useInscriptionListLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useLockTimePageLogic.d.ts +11 -0
- package/lib/ui-hooks/useLockTimePageLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useNotificationsLogic.d.ts +14 -0
- package/lib/ui-hooks/useNotificationsLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useOrdinalsInscriptionScreenLogic.d.ts +27 -0
- package/lib/ui-hooks/useOrdinalsInscriptionScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useRunesBalanceCardLogic.d.ts +19 -0
- package/lib/ui-hooks/useRunesBalanceCardLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useRunesListLogic.d.ts +14 -0
- package/lib/ui-hooks/useRunesListLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useRunesTokenScreenLogic.d.ts +22 -0
- package/lib/ui-hooks/useRunesTokenScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useSecurityCardLogic.d.ts +1 -0
- package/lib/ui-hooks/useSecurityCardLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useSendAlkanesNFTScreenLogic.d.ts +32 -0
- package/lib/ui-hooks/useSendAlkanesNFTScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useSendAlkanesScreenLogic.d.ts +37 -0
- package/lib/ui-hooks/useSendAlkanesScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useSendCAT20ScreenLogic.d.ts +44 -0
- package/lib/ui-hooks/useSendCAT20ScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useSendCAT721ScreenLogic.d.ts +40 -0
- package/lib/ui-hooks/useSendCAT721ScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useSendOrdinalsInscriptionScreenLogic.d.ts +22 -0
- package/lib/ui-hooks/useSendOrdinalsInscriptionScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useSendRunesScreenLogic.d.ts +30 -0
- package/lib/ui-hooks/useSendRunesScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useSettingsTabScreenLogic.d.ts +72 -0
- package/lib/ui-hooks/useSettingsTabScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useSignMessageLogic.d.ts +54 -0
- package/lib/ui-hooks/useSignMessageLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useSignPsbtLogic.d.ts +82 -0
- package/lib/ui-hooks/useSignPsbtLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useSplitOrdinalsInscriptionScreenLogic.d.ts +15 -0
- package/lib/ui-hooks/useSplitOrdinalsInscriptionScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useTxConfirmScreenLogic.d.ts +8 -0
- package/lib/ui-hooks/useTxConfirmScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useTxCreateScreenLogic.d.ts +28 -0
- package/lib/ui-hooks/useTxCreateScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useTxFailScreenLogic.d.ts +7 -0
- package/lib/ui-hooks/useTxFailScreenLogic.d.ts.map +1 -0
- package/lib/ui-hooks/useTxSuccessScreenLogic.d.ts +8 -0
- package/lib/ui-hooks/useTxSuccessScreenLogic.d.ts.map +1 -0
- package/lib/updater/accounts.d.ts +2 -0
- package/lib/updater/accounts.d.ts.map +1 -0
- package/lib/updater/index.d.ts +2 -0
- package/lib/updater/index.d.ts.map +1 -0
- package/lib/utils/bitcoin-utils.d.ts +7 -0
- package/lib/utils/bitcoin-utils.d.ts.map +1 -0
- package/lib/utils/eventBus.d.ts +12 -0
- package/lib/utils/eventBus.d.ts.map +1 -0
- package/lib/utils/password-utils.d.ts +12 -0
- package/lib/utils/password-utils.d.ts.map +1 -0
- package/lib/utils/ui-utils.d.ts +4 -0
- package/lib/utils/ui-utils.d.ts.map +1 -0
- package/package.json +19 -15
- package/src/.DS_Store +0 -0
- package/src/context/ApprovalContext.tsx +27 -0
- package/src/context/DeviceContext.tsx +36 -0
- package/src/context/I18nContext.tsx +14 -172
- package/src/context/NavigationContext.tsx +305 -0
- package/src/context/PriceContext.tsx +2 -2
- package/src/context/StorageContext.tsx +393 -0
- package/src/context/ToolsContext.tsx +50 -0
- package/src/context/WalletContext.tsx +170 -126
- package/src/context/index.ts +17 -2
- package/src/hooks/accounts.ts +11 -5
- package/src/hooks/browser.ts +11 -0
- package/src/hooks/global.ts +170 -7
- package/src/hooks/index.ts +1 -2
- package/src/hooks/settings.ts +38 -37
- package/src/hooks/transactions.ts +45 -151
- package/src/hooks/ui.ts +239 -35
- package/src/index.ts +33 -24
- package/src/reducers/accounts.ts +22 -2
- package/src/reducers/browser.ts +223 -0
- package/src/reducers/global.ts +67 -1
- package/src/reducers/index.ts +1 -0
- package/src/reducers/transactions.ts +0 -9
- package/src/reducers/ui.ts +144 -4
- package/src/types/index.ts +1 -1
- package/src/types/ui.ts +6 -1
- package/src/ui-hooks/index.ts +107 -0
- package/src/ui-hooks/useActionOverviewSectionLogic.ts +150 -0
- package/src/ui-hooks/useAddressTypeScreenLogic.ts +160 -0
- package/src/ui-hooks/useAlkanesBalanceCardLogic.ts +41 -0
- package/src/ui-hooks/useAlkanesCollectionListLogic.ts +68 -0
- package/src/ui-hooks/useAlkanesListLogic.ts +69 -0
- package/src/ui-hooks/useAlkanesNFTListLogic.ts +42 -0
- package/src/ui-hooks/useAlkanesNFTScreenLogic.ts +45 -0
- package/src/ui-hooks/useAlkanesTokenScreenLogic.ts +138 -0
- package/src/ui-hooks/useAmountInputLogic.ts +80 -0
- package/src/ui-hooks/useAnnouncementCardLogic.ts +91 -0
- package/src/ui-hooks/useBRC20BalanceCardLogic.ts +115 -0
- package/src/ui-hooks/useBRC20InscribeTransferLogic.ts +418 -0
- package/src/ui-hooks/useBRC20ListLogic.ts +79 -0
- package/src/ui-hooks/useBRC20ProgListLogic.ts +81 -0
- package/src/ui-hooks/useBRC20SendScreenLogic.ts +424 -0
- package/src/ui-hooks/useBRC20SingleStepScreenLogic.ts +208 -0
- package/src/ui-hooks/useBRC20TokenScreenLogic.ts +489 -0
- package/src/ui-hooks/useBalanceCardLogic.ts +164 -0
- package/src/ui-hooks/useBtcDisplayLogic.ts +16 -0
- package/src/ui-hooks/useCAT20BalanceCardLogic.ts +35 -0
- package/src/ui-hooks/useCAT20ListLogic.ts +83 -0
- package/src/ui-hooks/useCAT20TokenScreenLogic.ts +127 -0
- package/src/ui-hooks/useCAT721ListLogic.ts +68 -0
- package/src/ui-hooks/useCAT721NFTScreenLogic.ts +37 -0
- package/src/ui-hooks/useCreatePasswordScreenLogic.ts +92 -0
- package/src/ui-hooks/useCreateWalletLogicImportWordsStep.ts +299 -0
- package/src/ui-hooks/useEditAccountNameScreenLogic.ts +71 -0
- package/src/ui-hooks/useEditContactScreenLogic.ts +162 -0
- package/src/ui-hooks/useEditWalletNameScreenLogic.ts +60 -0
- package/src/ui-hooks/useExportMnemonicsScreenLogic.ts +75 -0
- package/src/ui-hooks/useExportPrivateKeyScreenLogic.ts +64 -0
- package/src/ui-hooks/useFeeRateBarLogic.ts +303 -0
- package/src/ui-hooks/useInfiniteList.ts +85 -0
- package/src/ui-hooks/useInscriptionListLogic.ts +68 -0
- package/src/ui-hooks/useLockTimePageLogic.ts +43 -0
- package/src/ui-hooks/useNotificationsLogic.ts +115 -0
- package/src/ui-hooks/useOrdinalsInscriptionScreenLogic.ts +130 -0
- package/src/ui-hooks/useRunesBalanceCardLogic.ts +44 -0
- package/src/ui-hooks/useRunesListLogic.ts +74 -0
- package/src/ui-hooks/useRunesTokenScreenLogic.ts +156 -0
- package/src/ui-hooks/useSecurityCardLogic.ts +0 -0
- package/src/ui-hooks/useSendAlkanesNFTScreenLogic.ts +160 -0
- package/src/ui-hooks/useSendAlkanesScreenLogic.ts +208 -0
- package/src/ui-hooks/useSendCAT20ScreenLogic.ts +297 -0
- package/src/ui-hooks/useSendCAT721ScreenLogic.ts +205 -0
- package/src/ui-hooks/useSendOrdinalsInscriptionScreenLogic.ts +152 -0
- package/src/ui-hooks/useSendRunesScreenLogic.ts +189 -0
- package/src/ui-hooks/useSettingsTabScreenLogic.ts +211 -0
- package/src/ui-hooks/useSignMessageLogic.ts +302 -0
- package/src/ui-hooks/useSignPsbtLogic.ts +517 -0
- package/src/ui-hooks/useSplitOrdinalsInscriptionScreenLogic.ts +109 -0
- package/src/ui-hooks/useTxConfirmScreenLogic.ts +47 -0
- package/src/ui-hooks/useTxCreateScreenLogic.ts +177 -0
- package/src/ui-hooks/useTxFailScreenLogic.ts +26 -0
- package/src/ui-hooks/useTxSuccessScreenLogic.ts +33 -0
- package/src/updater/accounts.ts +11 -11
- package/src/utils/bitcoin-utils.ts +17 -8
- package/src/utils/eventBus.ts +2 -1
- package/src/utils/password-utils.ts +78 -0
- package/src/utils/ui-utils.ts +28 -0
- package/src/hooks/approval.ts +0 -72
- package/src/hooks/i18n.ts +0 -53
- 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
|
+
}
|