diff --git a/src/app/features/psbt-signer/components/psbt-inputs-outputs-totals/components/psbt-address-receive-totals.tsx b/src/app/features/psbt-signer/components/psbt-inputs-outputs-totals/components/psbt-address-receive-totals.tsx
index e5bb48fcf0d..77641c80c81 100644
--- a/src/app/features/psbt-signer/components/psbt-inputs-outputs-totals/components/psbt-address-receive-totals.tsx
+++ b/src/app/features/psbt-signer/components/psbt-inputs-outputs-totals/components/psbt-address-receive-totals.tsx
@@ -1,5 +1,7 @@
import { truncateMiddle } from '@stacks/ui-utils';
+import { removeMinusSign } from '@shared/utils';
+
import { formatMoney, i18nFormatCurrency } from '@app/common/money/format-money';
import { usePsbtSignerContext } from '@app/features/psbt-signer/psbt-signer.context';
import { useCalculateBitcoinFiatValue } from '@app/query/common/market-data/market-data.hooks';
@@ -8,23 +10,44 @@ import { PsbtAddressTotalItem } from './psbt-address-total-item';
import { PsbtInscription } from './psbt-inscription';
interface PsbtAddressTotalsProps {
+ showNativeSegwitTotal: boolean;
showTaprootTotal: boolean;
}
-export function PsbtAddressReceiveTotals({ showTaprootTotal }: PsbtAddressTotalsProps) {
- const { accountInscriptionsBeingReceived, addressTaproot, addressTaprootTotal } =
- usePsbtSignerContext();
+export function PsbtAddressReceiveTotals({
+ showNativeSegwitTotal,
+ showTaprootTotal,
+}: PsbtAddressTotalsProps) {
+ const {
+ accountInscriptionsBeingReceived,
+ addressNativeSegwit,
+ addressNativeSegwitTotal,
+ addressTaproot,
+ addressTaprootTotal,
+ } = usePsbtSignerContext();
const calculateBitcoinFiatValue = useCalculateBitcoinFiatValue();
- const isReceivingInscriptions = accountInscriptionsBeingReceived?.length;
+ const isReceivingInscriptions = accountInscriptionsBeingReceived?.length > 0;
return (
<>
+ {!isReceivingInscriptions && showNativeSegwitTotal ? (
+
+ ) : null}
{!isReceivingInscriptions && showTaprootTotal ? (
) : null}
{isReceivingInscriptions
diff --git a/src/app/features/psbt-signer/components/psbt-inputs-outputs-totals/components/psbt-address-transfer-totals.tsx b/src/app/features/psbt-signer/components/psbt-inputs-outputs-totals/components/psbt-address-transfer-totals.tsx
index 25c9fe3f395..430e1a050db 100644
--- a/src/app/features/psbt-signer/components/psbt-inputs-outputs-totals/components/psbt-address-transfer-totals.tsx
+++ b/src/app/features/psbt-signer/components/psbt-inputs-outputs-totals/components/psbt-address-transfer-totals.tsx
@@ -15,7 +15,7 @@ export function PsbtAddressTransferTotals({ showNativeSegwitTotal }: PsbtAddress
usePsbtSignerContext();
const calculateBitcoinFiatValue = useCalculateBitcoinFiatValue();
- const isTransferringInscriptions = accountInscriptionsBeingTransferred?.length;
+ const isTransferringInscriptions = accountInscriptionsBeingTransferred?.length > 0;
return (
<>
diff --git a/src/app/features/psbt-signer/components/psbt-inputs-outputs-totals/components/psbt-inscription.tsx b/src/app/features/psbt-signer/components/psbt-inputs-outputs-totals/components/psbt-inscription.tsx
index 8f06e8b7106..7c2027aa272 100644
--- a/src/app/features/psbt-signer/components/psbt-inputs-outputs-totals/components/psbt-inscription.tsx
+++ b/src/app/features/psbt-signer/components/psbt-inputs-outputs-totals/components/psbt-inscription.tsx
@@ -27,7 +27,6 @@ export function PsbtInscription({ inscription }: PsbtInscriptionProps) {
/>
);
- //
return (
}
diff --git a/src/app/features/psbt-signer/components/psbt-inputs-outputs-totals/psbt-inputs-outputs-totals.tsx b/src/app/features/psbt-signer/components/psbt-inputs-outputs-totals/psbt-inputs-outputs-totals.tsx
index de0b0cbc2f6..3051b58057b 100644
--- a/src/app/features/psbt-signer/components/psbt-inputs-outputs-totals/psbt-inputs-outputs-totals.tsx
+++ b/src/app/features/psbt-signer/components/psbt-inputs-outputs-totals/psbt-inputs-outputs-totals.tsx
@@ -36,7 +36,10 @@ export function PsbtInputsOutputsTotals() {
{isReceiving ? (
-
+
) : null}
diff --git a/src/app/features/psbt-signer/hooks/use-parsed-psbt.tsx b/src/app/features/psbt-signer/hooks/use-parsed-psbt.tsx
index eaaa02c03ea..81114d13347 100644
--- a/src/app/features/psbt-signer/hooks/use-parsed-psbt.tsx
+++ b/src/app/features/psbt-signer/hooks/use-parsed-psbt.tsx
@@ -1,7 +1,9 @@
-import { useCallback } from 'react';
+import { useCallback, useMemo } from 'react';
import * as btc from '@scure/btc-signer';
+import { createMoney } from '@shared/models/money.model';
+
import { subtractMoney } from '@app/common/money/calculate-money';
import { useCurrentAccountNativeSegwitIndexZeroSigner } from '@app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks';
import { useCurrentAccountTaprootIndexZeroSigner } from '@app/store/accounts/blockchain/bitcoin/taproot-account.hooks';
@@ -50,12 +52,18 @@ export function useParsedPsbt({ inputs, indexesToSign, outputs }: UseParsedPsbtA
return noInputs || noOutputs;
}, [inputs.length, outputs.length]);
+ const fee = useMemo(() => {
+ if (psbtInputsTotal.amount.isGreaterThan(psbtOutputsTotal.amount))
+ return subtractMoney(psbtInputsTotal, psbtOutputsTotal);
+ return createMoney(0, 'BTC');
+ }, [psbtInputsTotal, psbtOutputsTotal]);
+
return {
accountInscriptionsBeingTransferred,
accountInscriptionsBeingReceived,
addressNativeSegwitTotal: subtractMoney(inputsTotalNativeSegwit, outputsTotalNativeSegwit),
addressTaprootTotal: subtractMoney(inputsTotalTaproot, outputsTotalTaproot),
- fee: subtractMoney(psbtInputsTotal, psbtOutputsTotal),
+ fee,
isPsbtMutable,
psbtInputs: parsedInputs,
psbtOutputs: parsedOutputs,
diff --git a/src/app/features/psbt-signer/hooks/use-psbt-inscriptions.tsx b/src/app/features/psbt-signer/hooks/use-psbt-inscriptions.tsx
index 2d3b98f481c..c0dee5213c6 100644
--- a/src/app/features/psbt-signer/hooks/use-psbt-inscriptions.tsx
+++ b/src/app/features/psbt-signer/hooks/use-psbt-inscriptions.tsx
@@ -22,24 +22,33 @@ export function usePsbtInscriptions(psbtInputs: PsbtInput[], psbtOutputs: PsbtOu
[psbtInputs, psbtOutputs]
);
- return useMemo(
- () => ({
- accountInscriptionsBeingTransferred: psbtInputs
- .filter(
- input =>
- input.address === bitcoinAddressNativeSegwit || input.address === bitcoinAddressTaproot
- )
- .map(input => input.inscription)
- .filter(isDefined),
- accountInscriptionsBeingReceived: outputsReceivingInscriptions
- .filter(
- outputWithInscription =>
- outputWithInscription.address === bitcoinAddressNativeSegwit ||
- outputWithInscription.address === bitcoinAddressTaproot
- )
- .map(input => input.inscription)
- .filter(isDefined),
- }),
- [bitcoinAddressNativeSegwit, bitcoinAddressTaproot, outputsReceivingInscriptions, psbtInputs]
- );
+ return useMemo(() => {
+ const accountInscriptionsBeingTransferred = psbtInputs
+ .filter(
+ input =>
+ input.address === bitcoinAddressNativeSegwit || input.address === bitcoinAddressTaproot
+ )
+ .map(input => input.inscription)
+ .filter(isDefined);
+
+ const accountInscriptionsBeingReceived = outputsReceivingInscriptions
+ .filter(
+ outputWithInscription =>
+ outputWithInscription.address === bitcoinAddressNativeSegwit ||
+ outputWithInscription.address === bitcoinAddressTaproot
+ )
+ .map(input => input.inscription)
+ .filter(
+ inscription =>
+ !accountInscriptionsBeingTransferred.find(
+ transferInscription => inscription.id === transferInscription.id
+ )
+ )
+ .filter(isDefined);
+
+ return {
+ accountInscriptionsBeingTransferred,
+ accountInscriptionsBeingReceived,
+ };
+ }, [bitcoinAddressNativeSegwit, bitcoinAddressTaproot, outputsReceivingInscriptions, psbtInputs]);
}
diff --git a/src/shared/utils.ts b/src/shared/utils.ts
index 37ee9fc2ad1..1f14fb31521 100644
--- a/src/shared/utils.ts
+++ b/src/shared/utils.ts
@@ -74,3 +74,7 @@ export function closeWindow() {
export function removeTrailingNullCharacters(s: string) {
return s.replace(/\0*$/g, '');
}
+
+export function removeMinusSign(value: string) {
+ return value.replace('-', '');
+}