From ac182d7282ce4c69a78923e5ea5116f77724cf28 Mon Sep 17 00:00:00 2001 From: Slava Date: Thu, 14 Nov 2024 20:14:10 +0300 Subject: [PATCH] chore: update calculations --- packages/sats-wagmi/src/hooks/useBalance.tsx | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/sats-wagmi/src/hooks/useBalance.tsx b/packages/sats-wagmi/src/hooks/useBalance.tsx index 65eb733..6e7dff8 100644 --- a/packages/sats-wagmi/src/hooks/useBalance.tsx +++ b/packages/sats-wagmi/src/hooks/useBalance.tsx @@ -35,16 +35,19 @@ const useBalance = (props: UseBalanceProps = {}) => { const addressInfo = getAddressInfo(address); if (addressInfo.type === AddressType.p2tr) { - // cardinal = return UTXOs not containing inscriptions or runes - const outputsFromAddress = await ordinalsClient.getOutputsFromAddress(address, 'cardinal'); - const taprootBalance = outputsFromAddress.reduce((acc, cur) => { - return acc + cur.value; - }, 0); + const [{ confirmed, unconfirmed, total }, inscribed, runic] = await Promise.all([ + esploraClient.getBalance(address), + ordinalsClient.getOutputsFromAddress(address, 'inscribed'), + ordinalsClient.getOutputsFromAddress(address, 'runic') + ]); + + const inscribedOutputsTotal = inscribed.reduce((acc, output) => acc + output.value, 0); + const runicOutputsTotal = runic.reduce((acc, output) => acc + output.value, 0); return { - confirmed: BigInt(taprootBalance), - unconfirmed: BigInt(0), - total: BigInt(taprootBalance) + confirmed: BigInt(confirmed - inscribedOutputsTotal - runicOutputsTotal), + unconfirmed: BigInt(unconfirmed), + total: BigInt(total - inscribedOutputsTotal - runicOutputsTotal) }; } else { const { confirmed, unconfirmed, total } = await esploraClient.getBalance(address);