@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,160 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
import { numUtils } from '@unisat/base-utils'
|
|
4
|
+
import { ADDRESS_TYPES, KeyringType } from '@unisat/keyring-service/types'
|
|
5
|
+
import { getAccountDerivationPath } from '@unisat/wallet-shared'
|
|
6
|
+
import { AddressType } from '@unisat/wallet-types'
|
|
7
|
+
import {
|
|
8
|
+
useAppDispatch,
|
|
9
|
+
useCurrentAccount,
|
|
10
|
+
useCurrentKeyring,
|
|
11
|
+
useI18n,
|
|
12
|
+
useNavigation,
|
|
13
|
+
useReloadAccounts,
|
|
14
|
+
useTools,
|
|
15
|
+
useWallet,
|
|
16
|
+
} from '..'
|
|
17
|
+
|
|
18
|
+
interface AddressTypeItem {
|
|
19
|
+
address: string
|
|
20
|
+
assets: { total_btc: string; satoshis: number; total_inscription: number }
|
|
21
|
+
name: string
|
|
22
|
+
value: AddressType
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function useAddressTypeScreenLogic() {
|
|
26
|
+
// const isInTab = useExtensionIsInTab()
|
|
27
|
+
const { t } = useI18n()
|
|
28
|
+
|
|
29
|
+
const wallet = useWallet()
|
|
30
|
+
const currentKeyring = useCurrentKeyring()
|
|
31
|
+
const account = useCurrentAccount()
|
|
32
|
+
|
|
33
|
+
const nav = useNavigation()
|
|
34
|
+
const dispatch = useAppDispatch()
|
|
35
|
+
const reloadAccounts = useReloadAccounts()
|
|
36
|
+
const [addresses, setAddresses] = useState<string[]>([])
|
|
37
|
+
const [addressAssets, setAddressAssets] = useState<{
|
|
38
|
+
[key: string]: { total_btc: string; satoshis: number; total_inscription: number }
|
|
39
|
+
}>({})
|
|
40
|
+
|
|
41
|
+
const selfRef = useRef<{
|
|
42
|
+
addressAssets: {
|
|
43
|
+
[key: string]: { total_btc: string; satoshis: number; total_inscription: number }
|
|
44
|
+
}
|
|
45
|
+
}>({
|
|
46
|
+
addressAssets: {},
|
|
47
|
+
})
|
|
48
|
+
const self = selfRef.current
|
|
49
|
+
|
|
50
|
+
const tools = useTools()
|
|
51
|
+
const loadAddresses = async () => {
|
|
52
|
+
try {
|
|
53
|
+
tools.showLoading(true)
|
|
54
|
+
const _res = await wallet.getAllAddresses(currentKeyring, account.index || 0)
|
|
55
|
+
setAddresses(_res)
|
|
56
|
+
const balances = await wallet.getMultiAddressAssets(_res.join(','))
|
|
57
|
+
for (let i = 0; i < _res.length; i++) {
|
|
58
|
+
const address = _res[i]
|
|
59
|
+
const balance = balances[i]
|
|
60
|
+
const satoshis = balance.totalSatoshis
|
|
61
|
+
self.addressAssets[address] = {
|
|
62
|
+
total_btc: numUtils.satoshisToAmount(balance.totalSatoshis),
|
|
63
|
+
satoshis,
|
|
64
|
+
total_inscription: balance.inscriptionCount,
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
setAddressAssets(self.addressAssets)
|
|
68
|
+
} catch (e) {
|
|
69
|
+
console.error(e)
|
|
70
|
+
} finally {
|
|
71
|
+
tools.showLoading(false)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
loadAddresses()
|
|
77
|
+
}, [])
|
|
78
|
+
|
|
79
|
+
const addressTypes = useMemo(() => {
|
|
80
|
+
// Cold wallets do not allow switching address types, only show the current type
|
|
81
|
+
if (currentKeyring.type === KeyringType.ColdWalletKeyring) {
|
|
82
|
+
return ADDRESS_TYPES.filter(v => v.value === currentKeyring.addressType)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (currentKeyring.type === KeyringType.HdKeyring) {
|
|
86
|
+
return ADDRESS_TYPES.filter(v => {
|
|
87
|
+
if (v.displayIndex < 0) {
|
|
88
|
+
return false
|
|
89
|
+
}
|
|
90
|
+
// MagicEden only supports P2WPKH and P2TR
|
|
91
|
+
if (currentKeyring.accountIndexDerivation) {
|
|
92
|
+
return v.value === AddressType.P2WPKH || v.value === AddressType.P2TR
|
|
93
|
+
}
|
|
94
|
+
const address = addresses[v.value]
|
|
95
|
+
const balance = addressAssets[address]
|
|
96
|
+
if (v.isUnisatLegacy) {
|
|
97
|
+
if (!balance || balance.satoshis == 0) {
|
|
98
|
+
return false
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return true
|
|
102
|
+
}).sort((a, b) => a.displayIndex - b.displayIndex)
|
|
103
|
+
} else {
|
|
104
|
+
return ADDRESS_TYPES.filter(v => v.displayIndex >= 0 && v.isUnisatLegacy != true).sort(
|
|
105
|
+
(a, b) => a.displayIndex - b.displayIndex
|
|
106
|
+
)
|
|
107
|
+
}
|
|
108
|
+
}, [currentKeyring.type, currentKeyring.addressType, addressAssets, addresses])
|
|
109
|
+
|
|
110
|
+
const items: AddressTypeItem[] = useMemo(() => {
|
|
111
|
+
return addressTypes.map(v => {
|
|
112
|
+
const address = addresses[v.value]
|
|
113
|
+
const assets = addressAssets[address] || {
|
|
114
|
+
total_btc: '--',
|
|
115
|
+
satoshis: 0,
|
|
116
|
+
total_inscription: 0,
|
|
117
|
+
}
|
|
118
|
+
const derivedPath = getAccountDerivationPath(v.hdPath, account.index || 0, currentKeyring.accountIndexDerivation)
|
|
119
|
+
let name = `${v.name} (${derivedPath})`
|
|
120
|
+
if (currentKeyring.type === KeyringType.SimpleKeyring) {
|
|
121
|
+
name = `${v.name}`
|
|
122
|
+
} else if (currentKeyring.type === KeyringType.ColdWalletKeyring) {
|
|
123
|
+
name = `❄️ ${v.name} (${derivedPath}) - ${t('Fixed by cold wallet')}`
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
address,
|
|
128
|
+
assets,
|
|
129
|
+
name,
|
|
130
|
+
value: v.value,
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
}, [addressTypes])
|
|
134
|
+
|
|
135
|
+
const onClickItem = async (item: AddressTypeItem) => {
|
|
136
|
+
if (item.value == currentKeyring.addressType) {
|
|
137
|
+
return
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Cold wallets do not allow switching address types
|
|
141
|
+
if (currentKeyring.type === KeyringType.ColdWalletKeyring) {
|
|
142
|
+
tools.toastError(t('Cold wallet address type cannot be changed'))
|
|
143
|
+
return
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
await wallet.changeAddressType(item.value)
|
|
147
|
+
reloadAccounts()
|
|
148
|
+
// navigate('MainScreen')
|
|
149
|
+
tools.toastSuccess(t('address_type_changed'))
|
|
150
|
+
|
|
151
|
+
nav.navToTab()
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
currentKeyring,
|
|
156
|
+
items,
|
|
157
|
+
wallet,
|
|
158
|
+
onClickItem,
|
|
159
|
+
}
|
|
160
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { bnUtils, numUtils } from '@unisat/base-utils'
|
|
2
|
+
import { AlkanesBalance, TickPriceItem } from '@unisat/wallet-shared'
|
|
3
|
+
import { useAlkanesIconInfo, useChain } from 'src/hooks'
|
|
4
|
+
|
|
5
|
+
export interface AlkanesBalanceCardProps {
|
|
6
|
+
tokenBalance: AlkanesBalance
|
|
7
|
+
onClick?: () => void
|
|
8
|
+
price?: TickPriceItem
|
|
9
|
+
}
|
|
10
|
+
export function useAlkanesBalanceCardLogic(props: AlkanesBalanceCardProps) {
|
|
11
|
+
const { tokenBalance, onClick, price } = props
|
|
12
|
+
|
|
13
|
+
const chain = useChain()
|
|
14
|
+
const showPrice = chain.showPrice && price !== undefined
|
|
15
|
+
|
|
16
|
+
const balance = bnUtils.toDecimalNumber(tokenBalance.amount, tokenBalance.divisibility)
|
|
17
|
+
let balanceStr = balance.toString()
|
|
18
|
+
if (balance.lt(0.0001)) {
|
|
19
|
+
balanceStr = '<0.0001'
|
|
20
|
+
} else {
|
|
21
|
+
balanceStr = numUtils.showLongNumber(balance.toString())
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const iconInfo = useAlkanesIconInfo(tokenBalance.name, tokenBalance.alkaneid)
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
// balance
|
|
28
|
+
tokenBalance,
|
|
29
|
+
balance,
|
|
30
|
+
balanceStr,
|
|
31
|
+
|
|
32
|
+
// price
|
|
33
|
+
showPrice,
|
|
34
|
+
price,
|
|
35
|
+
|
|
36
|
+
// icon
|
|
37
|
+
iconInfo,
|
|
38
|
+
|
|
39
|
+
onClick,
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { AlkanesCollection } from '@unisat/wallet-shared'
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef } from 'react'
|
|
4
|
+
import {
|
|
5
|
+
AlkanesAssetTabKey,
|
|
6
|
+
getSupportedAssets,
|
|
7
|
+
useAlkanesAssetTabKey,
|
|
8
|
+
useChainType,
|
|
9
|
+
useCurrentAccount,
|
|
10
|
+
useNavigation,
|
|
11
|
+
useWallet,
|
|
12
|
+
useWallTabFocusRefresh,
|
|
13
|
+
} from '..'
|
|
14
|
+
import { useInfiniteList } from './useInfiniteList'
|
|
15
|
+
|
|
16
|
+
export function useAlkanesCollectionListLogic() {
|
|
17
|
+
const nav = useNavigation()
|
|
18
|
+
const wallet = useWallet()
|
|
19
|
+
const currentAccount = useCurrentAccount()
|
|
20
|
+
const chainType = useChainType()
|
|
21
|
+
|
|
22
|
+
const {
|
|
23
|
+
data: items,
|
|
24
|
+
total,
|
|
25
|
+
loading,
|
|
26
|
+
hasMore,
|
|
27
|
+
onRefresh,
|
|
28
|
+
onLoadMore,
|
|
29
|
+
} = useInfiniteList<AlkanesCollection>({
|
|
30
|
+
fetcher: async (page, pageSize) => {
|
|
31
|
+
const supportedAssets = getSupportedAssets(chainType, currentAccount.address)
|
|
32
|
+
if (!supportedAssets.assets.alkanes || currentAccount.address === '') {
|
|
33
|
+
return { list: [], total: 0 }
|
|
34
|
+
}
|
|
35
|
+
const { list, total } = await wallet.getAlkanesCollectionList(
|
|
36
|
+
currentAccount.address,
|
|
37
|
+
page,
|
|
38
|
+
pageSize
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
return { list, total }
|
|
42
|
+
},
|
|
43
|
+
dependencies: [currentAccount.address, chainType],
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
const tabKey = useAlkanesAssetTabKey()
|
|
47
|
+
const isFocus = tabKey === AlkanesAssetTabKey.COLLECTION
|
|
48
|
+
const lastRefreshTimeRef = useRef<number>(0)
|
|
49
|
+
const walletTabFocusRefresh = useWallTabFocusRefresh()
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (!isFocus) return
|
|
52
|
+
|
|
53
|
+
// already refreshed → do nothing
|
|
54
|
+
const alreadyRefreshed = lastRefreshTimeRef.current === walletTabFocusRefresh
|
|
55
|
+
if (alreadyRefreshed) return
|
|
56
|
+
|
|
57
|
+
onRefresh()
|
|
58
|
+
|
|
59
|
+
// mark refreshed
|
|
60
|
+
lastRefreshTimeRef.current = walletTabFocusRefresh
|
|
61
|
+
}, [walletTabFocusRefresh, isFocus])
|
|
62
|
+
|
|
63
|
+
const onClickItem = (item: AlkanesCollection) => {
|
|
64
|
+
nav.navigate('AlkanesCollectionScreen', { collectionId: item.alkaneid })
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return { items, total, loading, hasMore, onRefresh, onLoadMore, onClickItem }
|
|
68
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
import { AlkanesBalance, TickPriceItem } from '@unisat/wallet-shared'
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
AlkanesAssetTabKey,
|
|
7
|
+
getSupportedAssets,
|
|
8
|
+
useAlkanesAssetTabKey,
|
|
9
|
+
useChainType,
|
|
10
|
+
useCurrentAccount,
|
|
11
|
+
useNavigation,
|
|
12
|
+
useWallet,
|
|
13
|
+
useWallTabFocusRefresh,
|
|
14
|
+
} from '..'
|
|
15
|
+
import { useInfiniteList } from './useInfiniteList'
|
|
16
|
+
|
|
17
|
+
export function useAlkanesListLogic() {
|
|
18
|
+
const nav = useNavigation()
|
|
19
|
+
const wallet = useWallet()
|
|
20
|
+
const currentAccount = useCurrentAccount()
|
|
21
|
+
const chainType = useChainType()
|
|
22
|
+
const [priceMap, setPriceMap] = useState<{ [key: string]: TickPriceItem }>({})
|
|
23
|
+
|
|
24
|
+
const {
|
|
25
|
+
data: items,
|
|
26
|
+
total,
|
|
27
|
+
loading,
|
|
28
|
+
hasMore,
|
|
29
|
+
onRefresh,
|
|
30
|
+
onLoadMore,
|
|
31
|
+
} = useInfiniteList<AlkanesBalance>({
|
|
32
|
+
fetcher: async (page, pageSize) => {
|
|
33
|
+
const supportedAssets = getSupportedAssets(chainType, currentAccount.address)
|
|
34
|
+
if (!supportedAssets.assets.alkanes || currentAccount.address === '') {
|
|
35
|
+
return { list: [], total: 0 }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const { list, total } = await wallet.getAlkanesList(currentAccount.address, page, pageSize)
|
|
39
|
+
if (list.length > 0) {
|
|
40
|
+
wallet.getAlkanesPrice(list.map(item => item.alkaneid)).then(setPriceMap)
|
|
41
|
+
}
|
|
42
|
+
return { list, total }
|
|
43
|
+
},
|
|
44
|
+
dependencies: [currentAccount.address, chainType],
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
const tabKey = useAlkanesAssetTabKey()
|
|
48
|
+
const isFocus = tabKey === AlkanesAssetTabKey.TOKEN
|
|
49
|
+
const lastRefreshTimeRef = useRef<number>(0)
|
|
50
|
+
const walletTabFocusRefresh = useWallTabFocusRefresh()
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
if (!isFocus) return
|
|
53
|
+
|
|
54
|
+
// already refreshed → do nothing
|
|
55
|
+
const alreadyRefreshed = lastRefreshTimeRef.current === walletTabFocusRefresh
|
|
56
|
+
if (alreadyRefreshed) return
|
|
57
|
+
|
|
58
|
+
onRefresh()
|
|
59
|
+
|
|
60
|
+
// mark refreshed
|
|
61
|
+
lastRefreshTimeRef.current = walletTabFocusRefresh
|
|
62
|
+
}, [walletTabFocusRefresh, isFocus])
|
|
63
|
+
|
|
64
|
+
const onClickItem = (item: AlkanesBalance) => {
|
|
65
|
+
nav.navigate('AlkanesTokenScreen', { alkaneid: item.alkaneid })
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return { items, total, loading, hasMore, onRefresh, onLoadMore, onClickItem, priceMap }
|
|
69
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { AlkanesInfo } from '@unisat/wallet-shared'
|
|
2
|
+
|
|
3
|
+
import { getSupportedAssets, useChainType, useCurrentAccount, useNavigation, useWallet } from '..'
|
|
4
|
+
import { useInfiniteList } from './useInfiniteList'
|
|
5
|
+
|
|
6
|
+
export function useAlkanesNFTListLogic(collectionId: string) {
|
|
7
|
+
const nav = useNavigation()
|
|
8
|
+
const wallet = useWallet()
|
|
9
|
+
const currentAccount = useCurrentAccount()
|
|
10
|
+
const chainType = useChainType()
|
|
11
|
+
|
|
12
|
+
const {
|
|
13
|
+
data: items,
|
|
14
|
+
total,
|
|
15
|
+
loading,
|
|
16
|
+
hasMore,
|
|
17
|
+
onRefresh,
|
|
18
|
+
onLoadMore,
|
|
19
|
+
} = useInfiniteList<AlkanesInfo>({
|
|
20
|
+
fetcher: async (page, pageSize) => {
|
|
21
|
+
const supportedAssets = getSupportedAssets(chainType, currentAccount.address)
|
|
22
|
+
if (!supportedAssets.assets.alkanes || currentAccount.address === '') {
|
|
23
|
+
return { list: [], total: 0 }
|
|
24
|
+
}
|
|
25
|
+
const { list, total } = await wallet.getAlkanesCollectionItems(
|
|
26
|
+
currentAccount.address,
|
|
27
|
+
collectionId,
|
|
28
|
+
page,
|
|
29
|
+
pageSize
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
return { list, total }
|
|
33
|
+
},
|
|
34
|
+
dependencies: [currentAccount.address, collectionId, chainType],
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
const onClickItem = (item: AlkanesInfo) => {
|
|
38
|
+
nav.navigate('AlkanesNFTScreen', { alkanesInfo: item })
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return { items, total, loading, hasMore, onRefresh, onLoadMore, onClickItem }
|
|
42
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
import { useI18n, useNavigation, useWallet } from 'src/context'
|
|
3
|
+
import { useResetTxState } from 'src/hooks'
|
|
4
|
+
|
|
5
|
+
export function useAlkanesNFTScreenLogic() {
|
|
6
|
+
const nav = useNavigation()
|
|
7
|
+
const { alkanesInfo } = nav.getRouteState<'AlkanesNFTScreen'>()
|
|
8
|
+
|
|
9
|
+
const { t } = useI18n()
|
|
10
|
+
|
|
11
|
+
const resetTxState = useResetTxState()
|
|
12
|
+
|
|
13
|
+
const [availableUtxo, setAvailableUtxo] = useState(0)
|
|
14
|
+
const wallet = useWallet()
|
|
15
|
+
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
const fetchData = async () => {
|
|
18
|
+
const utxos = await wallet.getAssetUtxosAlkanes(alkanesInfo.alkaneid)
|
|
19
|
+
setAvailableUtxo(utxos.length)
|
|
20
|
+
}
|
|
21
|
+
fetchData()
|
|
22
|
+
}, [wallet])
|
|
23
|
+
|
|
24
|
+
const onClickBack = () => {
|
|
25
|
+
nav.goBack()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const onClickSend = () => {
|
|
29
|
+
resetTxState()
|
|
30
|
+
nav.navigate('SendAlkanesNFTScreen', {
|
|
31
|
+
alkanesInfo,
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const disabledSend = availableUtxo <= 0
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
alkanesInfo,
|
|
39
|
+
t,
|
|
40
|
+
availableUtxo,
|
|
41
|
+
onClickBack,
|
|
42
|
+
onClickSend,
|
|
43
|
+
disabledSend,
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
import { AddressAlkanesTokenSummary } from '@unisat/wallet-shared'
|
|
4
|
+
import {
|
|
5
|
+
useAlkanesIconInfo,
|
|
6
|
+
useAlkanesTokenInfoExplorerUrl,
|
|
7
|
+
useCurrentAccount,
|
|
8
|
+
useI18n,
|
|
9
|
+
useNavigation,
|
|
10
|
+
useResetTxState,
|
|
11
|
+
useTools,
|
|
12
|
+
useWallet,
|
|
13
|
+
} from '..'
|
|
14
|
+
|
|
15
|
+
export function useAlkanesTokenScreenLogic() {
|
|
16
|
+
const nav = useNavigation()
|
|
17
|
+
const { alkaneid } = nav.getRouteState<'AlkanesTokenScreen'>()
|
|
18
|
+
const [tokenSummary, setTokenSummary] = useState<AddressAlkanesTokenSummary>({
|
|
19
|
+
tokenBalance: {
|
|
20
|
+
alkaneid: '',
|
|
21
|
+
name: '',
|
|
22
|
+
amount: '',
|
|
23
|
+
symbol: '',
|
|
24
|
+
divisibility: 0,
|
|
25
|
+
available: '',
|
|
26
|
+
},
|
|
27
|
+
tokenInfo: {
|
|
28
|
+
alkaneid: '',
|
|
29
|
+
name: '',
|
|
30
|
+
symbol: '',
|
|
31
|
+
totalSupply: '10000000000000',
|
|
32
|
+
maxSupply: '10000000000000',
|
|
33
|
+
cap: 0,
|
|
34
|
+
mintable: false,
|
|
35
|
+
perMint: '0',
|
|
36
|
+
minted: 0,
|
|
37
|
+
holders: 0,
|
|
38
|
+
aligned: true,
|
|
39
|
+
nftData: {
|
|
40
|
+
collectionId: '',
|
|
41
|
+
},
|
|
42
|
+
logo: '',
|
|
43
|
+
},
|
|
44
|
+
tradeUrl: '',
|
|
45
|
+
mintUrl: '',
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const wallet = useWallet()
|
|
49
|
+
|
|
50
|
+
const account = useCurrentAccount()
|
|
51
|
+
|
|
52
|
+
const [loading, setLoading] = useState(true)
|
|
53
|
+
|
|
54
|
+
const [warning, setWarning] = useState(false)
|
|
55
|
+
|
|
56
|
+
const { t } = useI18n()
|
|
57
|
+
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
wallet.getAddressAlkanesTokenSummary(account.address, alkaneid, false).then(tokenSummary => {
|
|
60
|
+
setTokenSummary(tokenSummary)
|
|
61
|
+
setLoading(false)
|
|
62
|
+
})
|
|
63
|
+
}, [])
|
|
64
|
+
|
|
65
|
+
const resetTxState = useResetTxState()
|
|
66
|
+
|
|
67
|
+
const enableMint = useMemo(() => {
|
|
68
|
+
return tokenSummary.mintUrl && tokenSummary.mintUrl.trim() !== ''
|
|
69
|
+
}, [tokenSummary.mintUrl])
|
|
70
|
+
|
|
71
|
+
const enableTransfer = useMemo(() => {
|
|
72
|
+
let enable = false
|
|
73
|
+
if (tokenSummary.tokenBalance.amount !== '0') {
|
|
74
|
+
enable = true
|
|
75
|
+
}
|
|
76
|
+
return enable
|
|
77
|
+
}, [tokenSummary])
|
|
78
|
+
|
|
79
|
+
const tools = useTools()
|
|
80
|
+
|
|
81
|
+
const enableTrade = useMemo(() => {
|
|
82
|
+
return tokenSummary.tradeUrl && tokenSummary.tradeUrl.trim() !== ''
|
|
83
|
+
}, [tokenSummary.tradeUrl])
|
|
84
|
+
|
|
85
|
+
const onClickMint = () => {
|
|
86
|
+
if (tokenSummary.mintUrl) {
|
|
87
|
+
nav.navToUrl(tokenSummary.mintUrl)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const onClickSend = () => {
|
|
92
|
+
if (tokenSummary.tokenInfo?.aligned === false) {
|
|
93
|
+
// tools.toastError(t('important_to_not_transfer_this_token'));
|
|
94
|
+
setWarning(true)
|
|
95
|
+
return
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
resetTxState()
|
|
99
|
+
nav.navigate('SendAlkanesScreen', {
|
|
100
|
+
tokenBalance: tokenSummary.tokenBalance,
|
|
101
|
+
tokenInfo: tokenSummary.tokenInfo,
|
|
102
|
+
})
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const onClickTrade = () => {
|
|
106
|
+
if (tokenSummary.tradeUrl) {
|
|
107
|
+
nav.navToUrl(tokenSummary.tradeUrl)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const iconInfo = useAlkanesIconInfo(
|
|
112
|
+
tokenSummary.tokenBalance.name,
|
|
113
|
+
tokenSummary.tokenBalance.alkaneid
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
const alkanesExplorerUrl = useAlkanesTokenInfoExplorerUrl(tokenSummary.tokenInfo.alkaneid)
|
|
117
|
+
|
|
118
|
+
const onClickViewOnExplorer = () => {
|
|
119
|
+
nav.navToUrl(alkanesExplorerUrl)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
tokenSummary,
|
|
124
|
+
loading,
|
|
125
|
+
enableMint,
|
|
126
|
+
enableTransfer,
|
|
127
|
+
enableTrade,
|
|
128
|
+
warning,
|
|
129
|
+
setWarning,
|
|
130
|
+
t,
|
|
131
|
+
tools,
|
|
132
|
+
onClickMint,
|
|
133
|
+
onClickSend,
|
|
134
|
+
onClickTrade,
|
|
135
|
+
onClickViewOnExplorer,
|
|
136
|
+
iconInfo,
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
export interface AmountInputProps {}
|
|
4
|
+
|
|
5
|
+
export function useAmountInputLogic(props: {
|
|
6
|
+
value?: string
|
|
7
|
+
runesDecimal?: number
|
|
8
|
+
disableDecimal?: boolean
|
|
9
|
+
enableBrc20Decimal?: boolean
|
|
10
|
+
onAmountInputChange?: (amount: string) => void
|
|
11
|
+
|
|
12
|
+
min?: number
|
|
13
|
+
step?: number
|
|
14
|
+
}) {
|
|
15
|
+
const { disableDecimal, enableBrc20Decimal, runesDecimal, onAmountInputChange, min, step } = props
|
|
16
|
+
|
|
17
|
+
const [inputValue, setInputValue] = useState(props.value || '')
|
|
18
|
+
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
onAmountInputChange(inputValue)
|
|
21
|
+
}, [inputValue])
|
|
22
|
+
|
|
23
|
+
const propValueRef = useRef(props.value)
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (props.value !== propValueRef.current) {
|
|
26
|
+
propValueRef.current = props.value
|
|
27
|
+
setInputValue(props.value || '')
|
|
28
|
+
}
|
|
29
|
+
}, [props.value])
|
|
30
|
+
|
|
31
|
+
const handleInputAmount = useCallback(
|
|
32
|
+
(e: { target: { value: string } } | string) => {
|
|
33
|
+
const raw = typeof e === 'string' ? e : e.target.value
|
|
34
|
+
|
|
35
|
+
let regex: RegExp
|
|
36
|
+
if (disableDecimal) {
|
|
37
|
+
regex = /^[1-9]\d*$/
|
|
38
|
+
} else if (enableBrc20Decimal) {
|
|
39
|
+
regex = /^(0(\.\d{0,18})?|[1-9]\d*\.?\d{0,18})$/
|
|
40
|
+
} else if (runesDecimal !== undefined) {
|
|
41
|
+
regex = new RegExp(`^(0(\\.\\d{0,${runesDecimal}})?|[1-9]\\d*\\.?\\d{0,${runesDecimal}})$`)
|
|
42
|
+
} else {
|
|
43
|
+
regex = /^(0(\.\d{0,8})?|[1-9]\d*\.?\d{0,8})$/
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (regex.test(raw) || raw === '') {
|
|
47
|
+
setInputValue(raw)
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
[disableDecimal, enableBrc20Decimal, runesDecimal]
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
const handleStepUp = useCallback(() => {
|
|
54
|
+
setInputValue(prev => {
|
|
55
|
+
const currentVal = parseFloat(prev) || 0
|
|
56
|
+
const decimal = runesDecimal ?? 2
|
|
57
|
+
return (currentVal + step).toFixed(decimal)
|
|
58
|
+
})
|
|
59
|
+
}, [step, runesDecimal])
|
|
60
|
+
|
|
61
|
+
const handleStepDown = useCallback(() => {
|
|
62
|
+
setInputValue(prev => {
|
|
63
|
+
const currentVal = parseFloat(prev) || 0
|
|
64
|
+
const decimal = runesDecimal ?? 2
|
|
65
|
+
return Math.max(min, currentVal - step).toFixed(decimal)
|
|
66
|
+
})
|
|
67
|
+
}, [step, min, runesDecimal])
|
|
68
|
+
|
|
69
|
+
const handleReset = useCallback(() => {
|
|
70
|
+
setInputValue('')
|
|
71
|
+
}, [])
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
handleInputAmount,
|
|
75
|
+
handleStepUp,
|
|
76
|
+
handleStepDown,
|
|
77
|
+
handleReset,
|
|
78
|
+
inputValue,
|
|
79
|
+
}
|
|
80
|
+
}
|