From 8e3fa415fafe11b171dea563e78d526e13911765 Mon Sep 17 00:00:00 2001 From: michael1011 Date: Tue, 28 May 2024 17:07:56 +0200 Subject: [PATCH] fix: chain swaps to unconfidential Liquid addresses --- src/components/Fees.tsx | 26 ++++++++++++++++---------- tests/components/Fees.spec.tsx | 30 +++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/src/components/Fees.tsx b/src/components/Fees.tsx index 09b690a5..7849169e 100644 --- a/src/components/Fees.tsx +++ b/src/components/Fees.tsx @@ -37,6 +37,11 @@ const Fees = () => { addressValid, } = useCreateContext(); + const isToUnconfidentialLiquid = () => + assetReceive() === LBTC && + addressValid() && + !isConfidentialAddress(onchainAddress()); + createEffect(() => { if (pairs()) { const cfg = getPair( @@ -62,25 +67,26 @@ const Fees = () => { let fee = reverseCfg.fees.minerFees.claim + reverseCfg.fees.minerFees.lockup; - if ( - assetReceive() === LBTC && - addressValid() && - !isConfidentialAddress(onchainAddress()) - ) { + if (isToUnconfidentialLiquid()) { fee += 1; } setMinerFee(fee); break; - case SwapType.Chain: + case SwapType.Chain: { const chainCfg = cfg as ChainPairTypeTaproot; - setMinerFee( + let fee = chainCfg.fees.minerFees.server + - chainCfg.fees.minerFees.user.lockup + - chainCfg.fees.minerFees.user.claim, - ); + chainCfg.fees.minerFees.user.lockup + + chainCfg.fees.minerFees.user.claim; + if (isToUnconfidentialLiquid()) { + fee += 1; + } + + setMinerFee(fee); break; + } } const calculateLimit = (limit: number): number => { diff --git a/tests/components/Fees.spec.tsx b/tests/components/Fees.spec.tsx index 0f674e05..aa2e3cbc 100644 --- a/tests/components/Fees.spec.tsx +++ b/tests/components/Fees.spec.tsx @@ -70,7 +70,7 @@ describe("Fees component", () => { ); }); - test("should increase the miner fee by 1 when sending to an unconfidential Liquid address", () => { + test("should increase the miner fee for reverse swaps by 1 when sending to an unconfidential Liquid address", () => { render( () => ( <> @@ -93,4 +93,32 @@ describe("Fees component", () => { fees.minerFees.lockup + fees.minerFees.claim + 1, ); }); + + test("should increase the miner fee for chain swaps by 1 when sending to an unconfidential Liquid address", () => { + render( + () => ( + <> + + + + ), + { wrapper: contextWrapper }, + ); + + globalSignals.setPairs(pairs); + signals.setAssetSend(BTC); + signals.setAssetReceive(LBTC); + signals.setAddressValid(true); + signals.setOnchainAddress( + "ert1q2vf850cshpedhvn9x0lv33j8az4ela04afuzp0", + ); + + const fees = pairs.chain[BTC][LBTC].fees; + expect(signals.minerFee()).toEqual( + fees.minerFees.server + + fees.minerFees.user.lockup + + fees.minerFees.user.claim + + 1, + ); + }); });