Skip to content

Commit

Permalink
chore: update calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
slavastartsev committed Nov 14, 2024
1 parent 99987c7 commit ac182d7
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions packages/sats-wagmi/src/hooks/useBalance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ac182d7

Please sign in to comment.