@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,489 @@
|
|
|
1
|
+
import { AddressTokenSummary, BRC20HistoryItem, Inscription } from '@unisat/wallet-shared'
|
|
2
|
+
import { ChainType } from '@unisat/wallet-types'
|
|
3
|
+
import { useEffect, useMemo, useState } from 'react'
|
|
4
|
+
import {
|
|
5
|
+
useBRC20IconInfo,
|
|
6
|
+
useChain,
|
|
7
|
+
useChainType,
|
|
8
|
+
useCurrentAccount,
|
|
9
|
+
useI18n,
|
|
10
|
+
useNavigation,
|
|
11
|
+
useResetTxState,
|
|
12
|
+
useTools,
|
|
13
|
+
useWallet,
|
|
14
|
+
} from '..'
|
|
15
|
+
import { shortAddress } from '../utils/ui-utils'
|
|
16
|
+
|
|
17
|
+
import BigNumber from 'bignumber.js'
|
|
18
|
+
const SWAP_MODULE_ADDRESS = '6a2095ee19329a210f8d5ded9b5cfa55b74fdd3b1e9af1e202072db6d1be82d45bfd'
|
|
19
|
+
const BRIDGE_BURN_ADDRESS = '6a20ada13e56859a2ab2eeb93cb4dc19c6e3f5e94d0ed38ed95a30ddc43711a0ff14'
|
|
20
|
+
const BRC20PROG_MODULE_ADDRESS = '6a09425243323050524f47'
|
|
21
|
+
export enum BRC20TokenScreenTabKey {
|
|
22
|
+
DETAILS = 'details',
|
|
23
|
+
HISTORY = 'history',
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface BRC20OutWalletBalanceItem {
|
|
27
|
+
key: 'wallet' | 'swap' | 'prog'
|
|
28
|
+
label: string
|
|
29
|
+
amount: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const INSWAP_SWAP_ANCHOR = '#swap'
|
|
33
|
+
|
|
34
|
+
export function useBRC20TokenHistoryLogic(props: { ticker: string; displayName?: string }) {
|
|
35
|
+
const wallet = useWallet()
|
|
36
|
+
const { t } = useI18n()
|
|
37
|
+
|
|
38
|
+
const account = useCurrentAccount()
|
|
39
|
+
|
|
40
|
+
const nav = useNavigation()
|
|
41
|
+
const { ticker, displayName } = props
|
|
42
|
+
|
|
43
|
+
const [items, setItems] = useState<BRC20HistoryItem[]>([])
|
|
44
|
+
|
|
45
|
+
const [loading, setLoading] = useState(true)
|
|
46
|
+
|
|
47
|
+
const [failed, setFailed] = useState(false)
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
wallet
|
|
51
|
+
.getBRC20RecentHistory(account.address, ticker)
|
|
52
|
+
.then(setItems)
|
|
53
|
+
.catch(() => setFailed(true))
|
|
54
|
+
.finally(() => setLoading(false))
|
|
55
|
+
}, [account.address, ticker])
|
|
56
|
+
|
|
57
|
+
const groupedItems = useMemo(() => {
|
|
58
|
+
const groups: { [date: string]: BRC20HistoryItem[] } = {}
|
|
59
|
+
items.forEach(item => {
|
|
60
|
+
let time = item.blocktime
|
|
61
|
+
if (item.blocktime == 0) {
|
|
62
|
+
time = Date.now() / 1000
|
|
63
|
+
}
|
|
64
|
+
const date = new Date(time * 1000).toLocaleDateString()
|
|
65
|
+
if (!groups[date]) {
|
|
66
|
+
groups[date] = []
|
|
67
|
+
}
|
|
68
|
+
groups[date].push(item)
|
|
69
|
+
})
|
|
70
|
+
return Object.entries(groups).map(([date, items]) => ({ date, items }))
|
|
71
|
+
}, [items])
|
|
72
|
+
|
|
73
|
+
const displayItems = useMemo(() => {
|
|
74
|
+
return groupedItems
|
|
75
|
+
.map(({ date, items }) => ({
|
|
76
|
+
date,
|
|
77
|
+
items: items
|
|
78
|
+
.map(item => {
|
|
79
|
+
const key = item.txid + item.type
|
|
80
|
+
|
|
81
|
+
let mainTitle = item.type
|
|
82
|
+
let subTitle = ''
|
|
83
|
+
let icon = ''
|
|
84
|
+
let isPending = false
|
|
85
|
+
if (item.blocktime == 0) {
|
|
86
|
+
isPending = true
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (item.type === 'send') {
|
|
90
|
+
mainTitle = t('brc20_history_type_send')
|
|
91
|
+
subTitle = t('brc20_history_to') + ' ' + shortAddress(item.to)
|
|
92
|
+
icon = 'history_send'
|
|
93
|
+
if (item.to === SWAP_MODULE_ADDRESS) {
|
|
94
|
+
mainTitle = t('brc20_history_type_wrap')
|
|
95
|
+
subTitle = t('brc20_history_to') + ' ' + 'InSwap'
|
|
96
|
+
icon = 'history_wrap'
|
|
97
|
+
} else if (item.to === BRC20PROG_MODULE_ADDRESS) {
|
|
98
|
+
mainTitle = t('brc20_history_type_wrap')
|
|
99
|
+
subTitle = t('brc20_history_to') + ' ' + 'brc2.0'
|
|
100
|
+
icon = 'history_wrap'
|
|
101
|
+
}
|
|
102
|
+
} else if (item.type === 'single-step-transfer') {
|
|
103
|
+
if (item.from === account.address) {
|
|
104
|
+
mainTitle = t('brc20_history_type_send')
|
|
105
|
+
subTitle = t('brc20_history_to') + ' ' + shortAddress(item.to)
|
|
106
|
+
icon = 'history_send'
|
|
107
|
+
} else {
|
|
108
|
+
mainTitle = t('brc20_history_type_receive')
|
|
109
|
+
subTitle = t('brc20_history_from') + ' ' + shortAddress(item.from)
|
|
110
|
+
icon = 'history_receive'
|
|
111
|
+
}
|
|
112
|
+
} else if (item.type === 'receive') {
|
|
113
|
+
mainTitle = t('brc20_history_type_receive')
|
|
114
|
+
subTitle = t('brc20_history_from') + ' ' + shortAddress(item.from)
|
|
115
|
+
icon = 'history_receive'
|
|
116
|
+
} else if (item.type === 'withdraw') {
|
|
117
|
+
mainTitle = t('brc20_history_type_unwrap')
|
|
118
|
+
subTitle = t('brc20_history_from') + ' ' + 'InSwap'
|
|
119
|
+
icon = 'history_unwrap'
|
|
120
|
+
} else if (item.type === 'inscribe-transfer') {
|
|
121
|
+
mainTitle = t('brc20_history_type_inscribe_transfer')
|
|
122
|
+
icon = 'history_inscribe'
|
|
123
|
+
} else if (item.type === 'inscribe-mint') {
|
|
124
|
+
mainTitle = t('brc20_history_type_inscribe_mint')
|
|
125
|
+
icon = 'history_inscribe'
|
|
126
|
+
} else if (item.type === 'inscribe-deploy') {
|
|
127
|
+
mainTitle = t('brc20_history_type_inscribe_deploy')
|
|
128
|
+
icon = 'history_inscribe'
|
|
129
|
+
} else if (item.type === 'brc20prog-withdraw-transfer') {
|
|
130
|
+
mainTitle = t('brc20_history_type_unwrap')
|
|
131
|
+
subTitle = t('brc20_history_from') + ' ' + 'brc2.0'
|
|
132
|
+
icon = 'history_unwrap'
|
|
133
|
+
} else if (item.type === 'brc20prog-withdraw-inscribe') {
|
|
134
|
+
mainTitle = t('brc20_history_type_inscribe_transfer')
|
|
135
|
+
subTitle = t('brc20_history_type_unwrap') + ' brc2.0'
|
|
136
|
+
icon = 'history_inscribe'
|
|
137
|
+
} else {
|
|
138
|
+
const isSendLike = item.from === account.address
|
|
139
|
+
mainTitle = isSendLike
|
|
140
|
+
? t('brc20_history_type_send')
|
|
141
|
+
: t('brc20_history_type_receive')
|
|
142
|
+
subTitle = isSendLike
|
|
143
|
+
? t('brc20_history_to') + ' ' + shortAddress(item.to)
|
|
144
|
+
: t('brc20_history_from') + ' ' + shortAddress(item.from)
|
|
145
|
+
icon = isSendLike ? 'history_send' : 'history_receive'
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const amount = item.amount
|
|
149
|
+
|
|
150
|
+
return {
|
|
151
|
+
key,
|
|
152
|
+
icon,
|
|
153
|
+
mainTitle,
|
|
154
|
+
subTitle,
|
|
155
|
+
amount,
|
|
156
|
+
pending: isPending,
|
|
157
|
+
txid: item.txid,
|
|
158
|
+
}
|
|
159
|
+
})
|
|
160
|
+
.filter(v => v !== null),
|
|
161
|
+
}))
|
|
162
|
+
.filter(group => group.items.length > 0)
|
|
163
|
+
}, [account.address, t, groupedItems])
|
|
164
|
+
|
|
165
|
+
return {
|
|
166
|
+
displayItems,
|
|
167
|
+
isFailed: failed,
|
|
168
|
+
isEmpty: displayItems.length === 0,
|
|
169
|
+
isLoading: loading,
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function useBRC20TokenScreenLogic() {
|
|
174
|
+
const nav = useNavigation()
|
|
175
|
+
const { ticker } = nav.getRouteState<'BRC20TokenScreen'>()
|
|
176
|
+
const { t } = useI18n()
|
|
177
|
+
|
|
178
|
+
const [activeTab, setActiveTab] = useState<BRC20TokenScreenTabKey>(BRC20TokenScreenTabKey.HISTORY)
|
|
179
|
+
|
|
180
|
+
const [tokenSummary, setTokenSummary] = useState<AddressTokenSummary>({
|
|
181
|
+
tokenBalance: {
|
|
182
|
+
ticker,
|
|
183
|
+
tickerHex: Buffer.from(ticker).toString('hex'),
|
|
184
|
+
overallBalance: '',
|
|
185
|
+
availableBalance: '',
|
|
186
|
+
transferableBalance: '',
|
|
187
|
+
availableBalanceSafe: '',
|
|
188
|
+
availableBalanceUnSafe: '',
|
|
189
|
+
selfMint: false,
|
|
190
|
+
},
|
|
191
|
+
tokenInfo: {
|
|
192
|
+
totalSupply: '',
|
|
193
|
+
totalMinted: '',
|
|
194
|
+
decimal: 18,
|
|
195
|
+
holder: '',
|
|
196
|
+
inscriptionId: '',
|
|
197
|
+
holdersCount: 0,
|
|
198
|
+
historyCount: 0,
|
|
199
|
+
logo: 'https://static.unisat.io/icon/brc20/unknown',
|
|
200
|
+
},
|
|
201
|
+
historyList: [],
|
|
202
|
+
transferableList: [],
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
const wallet = useWallet()
|
|
206
|
+
|
|
207
|
+
const account = useCurrentAccount()
|
|
208
|
+
|
|
209
|
+
const [loading, setLoading] = useState(true)
|
|
210
|
+
|
|
211
|
+
const [deployInscription, setDeployInscription] = useState<Inscription>()
|
|
212
|
+
|
|
213
|
+
const resetTxState = useResetTxState()
|
|
214
|
+
useEffect(() => {
|
|
215
|
+
wallet
|
|
216
|
+
.getBRC20Summary({
|
|
217
|
+
address: account.address,
|
|
218
|
+
ticker,
|
|
219
|
+
})
|
|
220
|
+
.then(tokenSummary => {
|
|
221
|
+
if (tokenSummary.tokenInfo.holder == account.address) {
|
|
222
|
+
wallet
|
|
223
|
+
.getInscriptionInfo(tokenSummary.tokenInfo.inscriptionId)
|
|
224
|
+
.then(data => {
|
|
225
|
+
setDeployInscription(data)
|
|
226
|
+
})
|
|
227
|
+
.finally(() => {
|
|
228
|
+
setTokenSummary(tokenSummary)
|
|
229
|
+
setLoading(false)
|
|
230
|
+
})
|
|
231
|
+
} else {
|
|
232
|
+
setTokenSummary(tokenSummary)
|
|
233
|
+
setLoading(false)
|
|
234
|
+
}
|
|
235
|
+
})
|
|
236
|
+
.finally(() => {
|
|
237
|
+
setLoading(false)
|
|
238
|
+
})
|
|
239
|
+
}, [])
|
|
240
|
+
|
|
241
|
+
const enableMint = useMemo(() => {
|
|
242
|
+
let enable = false
|
|
243
|
+
if (tokenSummary.tokenBalance.selfMint) {
|
|
244
|
+
if (tokenSummary.tokenInfo.holder == account.address) {
|
|
245
|
+
if (tokenSummary.tokenInfo.totalMinted != tokenSummary.tokenInfo.totalSupply) {
|
|
246
|
+
enable = true
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
} else {
|
|
250
|
+
if (tokenSummary.tokenInfo.totalMinted != tokenSummary.tokenInfo.totalSupply) {
|
|
251
|
+
enable = true
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return enable
|
|
255
|
+
}, [tokenSummary])
|
|
256
|
+
|
|
257
|
+
const enableTransfer = useMemo(() => {
|
|
258
|
+
let enable = false
|
|
259
|
+
if (
|
|
260
|
+
tokenSummary.tokenBalance.overallBalance !== '0' &&
|
|
261
|
+
tokenSummary.tokenBalance.overallBalance !== ''
|
|
262
|
+
) {
|
|
263
|
+
enable = true
|
|
264
|
+
}
|
|
265
|
+
return enable
|
|
266
|
+
}, [tokenSummary])
|
|
267
|
+
|
|
268
|
+
const tools = useTools()
|
|
269
|
+
const chainType = useChainType()
|
|
270
|
+
const chain = useChain()
|
|
271
|
+
|
|
272
|
+
const isBrc20Prog = useMemo(() => {
|
|
273
|
+
if (chainType === ChainType.BITCOIN_MAINNET || chainType === ChainType.BITCOIN_SIGNET) {
|
|
274
|
+
if (ticker.length == 6) {
|
|
275
|
+
return true
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return false
|
|
279
|
+
}, [ticker, chainType])
|
|
280
|
+
|
|
281
|
+
const enableTrade = useMemo(() => {
|
|
282
|
+
if (
|
|
283
|
+
chainType === ChainType.BITCOIN_MAINNET ||
|
|
284
|
+
chainType === ChainType.FRACTAL_BITCOIN_MAINNET
|
|
285
|
+
) {
|
|
286
|
+
return true
|
|
287
|
+
} else {
|
|
288
|
+
return false
|
|
289
|
+
}
|
|
290
|
+
}, [chainType])
|
|
291
|
+
|
|
292
|
+
const enableHistory = true
|
|
293
|
+
|
|
294
|
+
const tabItems = useMemo(() => {
|
|
295
|
+
if (enableHistory) {
|
|
296
|
+
const items = [
|
|
297
|
+
{
|
|
298
|
+
key: BRC20TokenScreenTabKey.HISTORY,
|
|
299
|
+
label: t('history'),
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
key: BRC20TokenScreenTabKey.DETAILS,
|
|
303
|
+
label: t('details'),
|
|
304
|
+
},
|
|
305
|
+
]
|
|
306
|
+
return items
|
|
307
|
+
} else {
|
|
308
|
+
return [
|
|
309
|
+
{
|
|
310
|
+
key: BRC20TokenScreenTabKey.DETAILS,
|
|
311
|
+
label: t('details'),
|
|
312
|
+
},
|
|
313
|
+
]
|
|
314
|
+
}
|
|
315
|
+
}, [t, enableHistory])
|
|
316
|
+
|
|
317
|
+
const showSwapBalance = chain.isFractal
|
|
318
|
+
const showProgBalance = chain.enableBrc20Prog
|
|
319
|
+
const swapSiteEnabled = chain.enum === ChainType.FRACTAL_BITCOIN_MAINNET
|
|
320
|
+
const progSiteEnabled = chain.enum === ChainType.BITCOIN_MAINNET
|
|
321
|
+
|
|
322
|
+
const onSwapBalance = tokenSummary?.tokenBalance?.swapBalance
|
|
323
|
+
const onProgBalance = tokenSummary?.tokenBalance?.progBalance
|
|
324
|
+
|
|
325
|
+
const inWalletBalance = tokenSummary?.tokenBalance?.overallBalance
|
|
326
|
+
const outWalletBalanceItems = useMemo<BRC20OutWalletBalanceItem[]>(() => {
|
|
327
|
+
const items: BRC20OutWalletBalanceItem[] = [
|
|
328
|
+
{
|
|
329
|
+
key: 'wallet',
|
|
330
|
+
label: t('brc20_in_wallet'),
|
|
331
|
+
amount: inWalletBalance || '0',
|
|
332
|
+
},
|
|
333
|
+
]
|
|
334
|
+
|
|
335
|
+
if (showSwapBalance) {
|
|
336
|
+
items.push({
|
|
337
|
+
key: 'swap',
|
|
338
|
+
label: t('brc20_on_swap'),
|
|
339
|
+
amount: onSwapBalance,
|
|
340
|
+
})
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
if (showProgBalance) {
|
|
344
|
+
items.push({
|
|
345
|
+
key: 'prog',
|
|
346
|
+
label: t('brc20_on_prog'),
|
|
347
|
+
amount: onProgBalance,
|
|
348
|
+
})
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
return items
|
|
352
|
+
}, [inWalletBalance, onProgBalance, onSwapBalance, t])
|
|
353
|
+
const totalBalance = useMemo(() => {
|
|
354
|
+
if (!inWalletBalance) {
|
|
355
|
+
return '--'
|
|
356
|
+
}
|
|
357
|
+
return new BigNumber(inWalletBalance)
|
|
358
|
+
.plus(new BigNumber(onSwapBalance || 0))
|
|
359
|
+
.plus(new BigNumber(onProgBalance || 0))
|
|
360
|
+
.toString()
|
|
361
|
+
}, [onSwapBalance, onProgBalance, inWalletBalance])
|
|
362
|
+
|
|
363
|
+
const brc20prog_ticker = encodeURIComponent(ticker)
|
|
364
|
+
const ensureSiteEnabled = (enabled: boolean) => {
|
|
365
|
+
if (!enabled) {
|
|
366
|
+
tools.toastError(t('not_supported'))
|
|
367
|
+
return false
|
|
368
|
+
}
|
|
369
|
+
return true
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// brc20prog
|
|
373
|
+
const onClickWrapBrc20Prog = () => {
|
|
374
|
+
if (!ensureSiteEnabled(progSiteEnabled)) return
|
|
375
|
+
const url = `https://link.unisat.space/btc/wrap?tick=${brc20prog_ticker}`
|
|
376
|
+
nav.navToUrl(url)
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const onClickUnwrapBrc20Prog = () => {
|
|
380
|
+
if (!ensureSiteEnabled(progSiteEnabled)) return
|
|
381
|
+
const url = `https://link.unisat.space/btc/wrap?action=unwrap&tick=${brc20prog_ticker}`
|
|
382
|
+
nav.navToUrl(url)
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
const onClickSendBrc20Prog = () => {
|
|
386
|
+
if (!ensureSiteEnabled(progSiteEnabled)) return
|
|
387
|
+
const url = `https://bestinslot.xyz/brc2.0/${brc20prog_ticker}/transfer`
|
|
388
|
+
nav.navToUrl(url)
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
const inswap_ticker = encodeURIComponent(ticker)
|
|
392
|
+
|
|
393
|
+
// inswap
|
|
394
|
+
const onClickSwapInSwap = () => {
|
|
395
|
+
if (!ensureSiteEnabled(swapSiteEnabled)) return
|
|
396
|
+
const url = `https://inswap.cc/swap/pools?q=${inswap_ticker}`
|
|
397
|
+
nav.navToUrl(url)
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
const onClickAddLiquidityInSwap = () => {
|
|
401
|
+
if (!ensureSiteEnabled(swapSiteEnabled)) return
|
|
402
|
+
const url = `https://inswap.cc/swap/pools?q=${inswap_ticker}`
|
|
403
|
+
nav.navToUrl(url)
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
const onClickWrapInSwap = () => {
|
|
407
|
+
if (!ensureSiteEnabled(swapSiteEnabled)) return
|
|
408
|
+
const url = `https://inswap.cc/swap?tab=deposit&t=${inswap_ticker}${INSWAP_SWAP_ANCHOR}`
|
|
409
|
+
nav.navToUrl(url)
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const onClickUnwrapInSwap = () => {
|
|
413
|
+
if (!ensureSiteEnabled(swapSiteEnabled)) return
|
|
414
|
+
const url = `https://inswap.cc/swap?tab=withdraw&t=${inswap_ticker}${INSWAP_SWAP_ANCHOR}`
|
|
415
|
+
nav.navToUrl(url)
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
const onClickSendInSwap = () => {
|
|
419
|
+
if (!ensureSiteEnabled(swapSiteEnabled)) return
|
|
420
|
+
const url = `https://inswap.cc/swap/assets/account?tab=assets&t=${inswap_ticker}&action=send`
|
|
421
|
+
nav.navToUrl(url)
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
const onClickMint = () => {
|
|
425
|
+
nav.navToInscribeBrc20(ticker)
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const onClickSend = () => {
|
|
429
|
+
resetTxState()
|
|
430
|
+
nav.navigate('BRC20SendScreen', {
|
|
431
|
+
tokenBalance: tokenSummary.tokenBalance,
|
|
432
|
+
tokenInfo: tokenSummary.tokenInfo,
|
|
433
|
+
})
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
const onClickTrade = () => {
|
|
437
|
+
nav.navToMarketPlaceBrc20(ticker)
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
const onClickSingleStepSend = () => {
|
|
441
|
+
resetTxState()
|
|
442
|
+
nav.navigate('BRC20SingleStepScreen', {
|
|
443
|
+
tokenBalance: tokenSummary.tokenBalance,
|
|
444
|
+
tokenInfo: tokenSummary.tokenInfo,
|
|
445
|
+
})
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
const iconInfo = useBRC20IconInfo(ticker)
|
|
449
|
+
|
|
450
|
+
return {
|
|
451
|
+
totalBalance,
|
|
452
|
+
onSwapBalance,
|
|
453
|
+
onProgBalance,
|
|
454
|
+
inWalletBalance,
|
|
455
|
+
outWalletBalanceItems,
|
|
456
|
+
enableHistory,
|
|
457
|
+
enableTrade,
|
|
458
|
+
enableMint,
|
|
459
|
+
enableTransfer,
|
|
460
|
+
loading,
|
|
461
|
+
tokenSummary,
|
|
462
|
+
deployInscription,
|
|
463
|
+
activeTab,
|
|
464
|
+
setActiveTab,
|
|
465
|
+
tabItems,
|
|
466
|
+
t,
|
|
467
|
+
ticker,
|
|
468
|
+
chain,
|
|
469
|
+
tools,
|
|
470
|
+
isBrc20Prog,
|
|
471
|
+
iconInfo,
|
|
472
|
+
showProgBalance,
|
|
473
|
+
showSwapBalance,
|
|
474
|
+
onClickWrapBrc20Prog,
|
|
475
|
+
onClickUnwrapBrc20Prog,
|
|
476
|
+
onClickSendBrc20Prog,
|
|
477
|
+
|
|
478
|
+
onClickSwapInSwap,
|
|
479
|
+
onClickAddLiquidityInSwap,
|
|
480
|
+
onClickWrapInSwap,
|
|
481
|
+
onClickUnwrapInSwap,
|
|
482
|
+
onClickSendInSwap,
|
|
483
|
+
|
|
484
|
+
onClickMint,
|
|
485
|
+
onClickSend,
|
|
486
|
+
onClickTrade,
|
|
487
|
+
onClickSingleStepSend,
|
|
488
|
+
}
|
|
489
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { numUtils } from '@unisat/base-utils'
|
|
2
|
+
import { ChainType } from '@unisat/wallet-types'
|
|
3
|
+
import { useCallback, useEffect, useMemo, useRef } from 'react'
|
|
4
|
+
import { useDispatch, useSelector } from 'react-redux'
|
|
5
|
+
import { accountActions, AppState, uiActions } from 'src'
|
|
6
|
+
import { useI18n, useNavigation } from '../context'
|
|
7
|
+
import {
|
|
8
|
+
useAccountBalance,
|
|
9
|
+
useBalanceCardDetailExpanded,
|
|
10
|
+
useBTCUnit,
|
|
11
|
+
useChain,
|
|
12
|
+
useFetchBalanceCallback,
|
|
13
|
+
useToggleBalanceCardDetailExpanded,
|
|
14
|
+
useWalletConfig,
|
|
15
|
+
} from '../hooks'
|
|
16
|
+
|
|
17
|
+
const DEBOUNCE_DELAY = 1000
|
|
18
|
+
|
|
19
|
+
export function useBalanceCardLogic() {
|
|
20
|
+
const { t } = useI18n()
|
|
21
|
+
|
|
22
|
+
const walletConfig = useWalletConfig()
|
|
23
|
+
|
|
24
|
+
const accountBalance = useAccountBalance()
|
|
25
|
+
const chain = useChain()
|
|
26
|
+
const dispatch = useDispatch()
|
|
27
|
+
|
|
28
|
+
const fetchBalance = useFetchBalanceCallback()
|
|
29
|
+
|
|
30
|
+
const btcUnit = useBTCUnit()
|
|
31
|
+
const nav = useNavigation()
|
|
32
|
+
|
|
33
|
+
const isBtcMainnet = chain.enum === ChainType.BITCOIN_MAINNET
|
|
34
|
+
|
|
35
|
+
const debounceTimerRef = useRef<NodeJS.Timeout | null>(null)
|
|
36
|
+
|
|
37
|
+
// Detail expand state
|
|
38
|
+
const isDetailExpanded = useBalanceCardDetailExpanded()
|
|
39
|
+
const toggleBalanceCardDetailExpanded = useToggleBalanceCardDetailExpanded()
|
|
40
|
+
const handleExpandToggle = () => {
|
|
41
|
+
toggleBalanceCardDetailExpanded()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Balance visibility
|
|
45
|
+
const isBalanceHidden = useSelector((state: AppState) => state.ui.isBalanceHidden)
|
|
46
|
+
const handleHiddenToggle = (e?: React.MouseEvent) => {
|
|
47
|
+
if (e) e.stopPropagation()
|
|
48
|
+
dispatch(uiActions['setBalanceHidden'](!isBalanceHidden))
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const isCurrentChainBalance = chain.enum == accountBalance.chainType
|
|
52
|
+
const balanceValue = useMemo(() => {
|
|
53
|
+
if (!isCurrentChainBalance) {
|
|
54
|
+
return '--'
|
|
55
|
+
}
|
|
56
|
+
return numUtils.satoshisToAmount(accountBalance.totalBalance)
|
|
57
|
+
}, [accountBalance.totalBalance, isCurrentChainBalance])
|
|
58
|
+
|
|
59
|
+
const unavailableTipText = useMemo(() => {
|
|
60
|
+
let tipText = ''
|
|
61
|
+
tipText += t('unavailable_tooltip')
|
|
62
|
+
|
|
63
|
+
if (walletConfig.disableUtxoTools) {
|
|
64
|
+
tipText += t('future_versions_will_support_spending_these_assets')
|
|
65
|
+
} else {
|
|
66
|
+
tipText += t('you_can_unlock_these_assets_by_using_the_utxos_tools')
|
|
67
|
+
}
|
|
68
|
+
return tipText
|
|
69
|
+
}, [t, walletConfig.disableUtxoTools])
|
|
70
|
+
|
|
71
|
+
const showUtxoToolButton = walletConfig.disableUtxoTools
|
|
72
|
+
? false
|
|
73
|
+
: isCurrentChainBalance && accountBalance.unavailableBalance > 0
|
|
74
|
+
|
|
75
|
+
const totalBalance = accountBalance.totalBalance
|
|
76
|
+
const availableBalance = accountBalance.availableBalance
|
|
77
|
+
const unavailableBalance = accountBalance.unavailableBalance
|
|
78
|
+
|
|
79
|
+
const totalAmount = numUtils.satoshisToAmount(accountBalance.totalBalance)
|
|
80
|
+
const availableAmount = numUtils.satoshisToAmount(accountBalance.availableBalance)
|
|
81
|
+
const unavailableAmount = numUtils.satoshisToAmount(accountBalance.unavailableBalance)
|
|
82
|
+
|
|
83
|
+
const totalAmountMainPart = isBtcMainnet ? totalAmount.slice(0, -4) : totalAmount.slice(0, -8)
|
|
84
|
+
const totalAmountSubPart = isBtcMainnet ? totalAmount.slice(-4) : totalAmount.slice(-8)
|
|
85
|
+
|
|
86
|
+
// Passive refresh every 10 seconds
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
const intervalId = setInterval(() => {
|
|
89
|
+
dispatch(accountActions['expireBalance'](null))
|
|
90
|
+
fetchBalance()
|
|
91
|
+
}, 10000)
|
|
92
|
+
|
|
93
|
+
return () => clearInterval(intervalId)
|
|
94
|
+
}, [dispatch, fetchBalance])
|
|
95
|
+
|
|
96
|
+
const refreshBalance = useCallback(
|
|
97
|
+
(e?: React.MouseEvent) => {
|
|
98
|
+
if (e) {
|
|
99
|
+
e.stopPropagation()
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (debounceTimerRef.current) {
|
|
103
|
+
clearTimeout(debounceTimerRef.current)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
debounceTimerRef.current = setTimeout(() => {
|
|
107
|
+
dispatch((accountActions as any).expireBalance(null))
|
|
108
|
+
fetchBalance()
|
|
109
|
+
debounceTimerRef.current = null
|
|
110
|
+
}, DEBOUNCE_DELAY)
|
|
111
|
+
},
|
|
112
|
+
[dispatch, fetchBalance]
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
useEffect(() => {
|
|
116
|
+
return () => {
|
|
117
|
+
if (debounceTimerRef.current) {
|
|
118
|
+
clearTimeout(debounceTimerRef.current)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}, [])
|
|
122
|
+
|
|
123
|
+
const handleUnlock = (e?: React.MouseEvent) => {
|
|
124
|
+
if (e) e.stopPropagation()
|
|
125
|
+
if (walletConfig.disableUtxoTools) return
|
|
126
|
+
|
|
127
|
+
nav.navToUtxoTools()
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
// state
|
|
132
|
+
totalBalance,
|
|
133
|
+
availableBalance,
|
|
134
|
+
unavailableBalance,
|
|
135
|
+
|
|
136
|
+
totalAmount,
|
|
137
|
+
availableAmount,
|
|
138
|
+
unavailableAmount,
|
|
139
|
+
|
|
140
|
+
totalAmountMainPart,
|
|
141
|
+
totalAmountSubPart,
|
|
142
|
+
|
|
143
|
+
balanceValue,
|
|
144
|
+
unavailableTipText,
|
|
145
|
+
isCurrentChainBalance,
|
|
146
|
+
showUtxoToolButton,
|
|
147
|
+
|
|
148
|
+
// action
|
|
149
|
+
handleUnlock,
|
|
150
|
+
|
|
151
|
+
isDetailExpanded,
|
|
152
|
+
handleExpandToggle,
|
|
153
|
+
|
|
154
|
+
isBalanceHidden,
|
|
155
|
+
handleHiddenToggle,
|
|
156
|
+
|
|
157
|
+
refreshBalance,
|
|
158
|
+
btcUnit,
|
|
159
|
+
isBtcMainnet,
|
|
160
|
+
|
|
161
|
+
chain,
|
|
162
|
+
t,
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ChainType } from '@unisat/wallet-types'
|
|
2
|
+
import { useChainType } from 'src/hooks'
|
|
3
|
+
|
|
4
|
+
export function useBtcDisplayLogic(balance: string) {
|
|
5
|
+
const chainType = useChainType()
|
|
6
|
+
|
|
7
|
+
const totalAmountMainPart =
|
|
8
|
+
chainType === ChainType.BITCOIN_MAINNET ? balance.slice(0, -4) : balance.slice(0, -8)
|
|
9
|
+
const totalAmountSubPart =
|
|
10
|
+
chainType === ChainType.BITCOIN_MAINNET ? balance.slice(-4) : balance.slice(-8)
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
totalAmountMainPart,
|
|
14
|
+
totalAmountSubPart,
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { bnUtils } from '@unisat/base-utils'
|
|
2
|
+
import { CAT20Balance, TickPriceItem } from '@unisat/wallet-shared'
|
|
3
|
+
import { useCAT20IconInfo } from 'src/hooks'
|
|
4
|
+
|
|
5
|
+
export interface CAT20BalanceCardProps {
|
|
6
|
+
tokenBalance: CAT20Balance
|
|
7
|
+
onClick?: () => void
|
|
8
|
+
showPrice?: boolean
|
|
9
|
+
price?: TickPriceItem
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function useCAT20BalanceCardLogic(props: CAT20BalanceCardProps) {
|
|
13
|
+
const { tokenBalance, onClick, showPrice, price } = props
|
|
14
|
+
const balance = bnUtils.toDecimalNumber(tokenBalance.amount, tokenBalance.decimals)
|
|
15
|
+
const balanceStr = balance.toString()
|
|
16
|
+
|
|
17
|
+
const iconInfo = useCAT20IconInfo(tokenBalance.name, tokenBalance.tokenId)
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
// balance
|
|
21
|
+
tokenBalance,
|
|
22
|
+
balance,
|
|
23
|
+
balanceStr,
|
|
24
|
+
|
|
25
|
+
// price
|
|
26
|
+
price,
|
|
27
|
+
showPrice,
|
|
28
|
+
|
|
29
|
+
// icon
|
|
30
|
+
iconInfo,
|
|
31
|
+
|
|
32
|
+
// click
|
|
33
|
+
onClick,
|
|
34
|
+
}
|
|
35
|
+
}
|