From c682cf606e7276a0bd32a74d6c580eedbe549488 Mon Sep 17 00:00:00 2001 From: daryl Date: Tue, 3 Sep 2024 11:54:33 +0800 Subject: [PATCH] feat(rgbpp): change apir of asset for rgb++ (#422) Co-authored-by: Chen Yu --- src/pages/Address/BTCAddressComp.tsx | 12 +++++++++++- src/services/ExplorerService/fetcher.ts | 7 ++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/pages/Address/BTCAddressComp.tsx b/src/pages/Address/BTCAddressComp.tsx index 16ea25b80..157eca617 100644 --- a/src/pages/Address/BTCAddressComp.tsx +++ b/src/pages/Address/BTCAddressComp.tsx @@ -18,7 +18,6 @@ enum AssetInfo { export const BTCAddressOverviewCard: FC<{ address: Address }> = ({ address }) => { const { t, i18n } = useTranslation() - const { udtAccounts = [] } = address const [activeTab, setActiveTab] = useState(AssetInfo.RGBPP) const { data } = useQuery(['bitcoin addresses', address], () => @@ -26,6 +25,17 @@ export const BTCAddressOverviewCard: FC<{ address: Address }> = ({ address }) => ) const { boundLiveCellsCount, unboundLiveCellsCount } = data || { boundLiveCellsCount: 0, unboundLiveCellsCount: 0 } + const { data: udtAccounts } = useQuery( + ['bitcoin address udt accounts', address], + async () => { + const data = await explorerService.api.fetchUDTAccountsByBtcAddress(address.bitcoinAddressHash || '') + return data.udtAccounts + }, + { + initialData: [], + }, + ) + const [udts, inscriptions] = udtAccounts.reduce( (acc, cur) => { switch (cur?.udtType) { diff --git a/src/services/ExplorerService/fetcher.ts b/src/services/ExplorerService/fetcher.ts index 775a72fe0..b395471be 100644 --- a/src/services/ExplorerService/fetcher.ts +++ b/src/services/ExplorerService/fetcher.ts @@ -23,7 +23,7 @@ import { Cell } from '../../models/Cell' import { Script } from '../../models/Script' import { Block } from '../../models/Block' import { BtcTx, Transaction } from '../../models/Transaction' -import { Address, AddressType } from '../../models/Address' +import { Address, AddressType, UDTAccount } from '../../models/Address' import { OmigaInscriptionCollection, UDT } from '../../models/UDT' import { XUDT, XUDTHolderAllocation } from '../../models/Xudt' import { HashType } from '../../constants/common' @@ -254,6 +254,11 @@ export const apiFetcher = { fetchBitcoinAddresses: (address: string) => requesterV2.get(`bitcoin_addresses/${address}`).then(res => toCamelcase(res.data)), + fetchUDTAccountsByBtcAddress: (address: string) => + requesterV2 + .get(`bitcoin_addresses/${address}/udt_accounts`) + .then(res => toCamelcase<{ udtAccounts: UDTAccount[] }>(res.data.data)), + fetchCellsByTxHash: (hash: string, type: 'inputs' | 'outputs', page: Record<'no' | 'size', number>) => requesterV2 .get(`ckb_transactions/${hash}/display_${type}`, {