diff --git a/src/models/cliModel.ts b/src/models/cliModel.ts index 5ff63c2..9d51b63 100644 --- a/src/models/cliModel.ts +++ b/src/models/cliModel.ts @@ -98,10 +98,13 @@ export interface CliLogWaitingForBtcDeposit extends CliLog { fields: { message: 'Waiting for Bitcoin deposit'; deposit_address: string; + min_deposit_until_swap_will_start: string; + max_deposit_until_maximum_amount_is_reached: string; max_giveable: string; minimum_amount: string; maximum_amount: string; - min_deposit: string; + min_bitcoin_lock_tx_fee: string; + price: string; }; } diff --git a/src/models/storeModel.ts b/src/models/storeModel.ts index c0ba61f..63f75a2 100644 --- a/src/models/storeModel.ts +++ b/src/models/storeModel.ts @@ -69,6 +69,8 @@ export interface SwapStateWaitingForBtcDeposit extends SwapState { minimumAmount: number; maximumAmount: number; minDeposit: number; + maxDeposit: number; + minBitcoinLockTxFee: number; price: number | null; } @@ -80,6 +82,10 @@ export function isSwapStateWaitingForBtcDeposit( export interface SwapStateStarted extends SwapState { type: SwapStateType.STARTED; + txLockDetails: { + amount: number; + fees: number; + } | null; } export function isSwapStateStarted( diff --git a/src/renderer/components/modal/swap/CircularProgressWithSubtitle.tsx b/src/renderer/components/modal/swap/CircularProgressWithSubtitle.tsx index 8926b06..f82eab8 100644 --- a/src/renderer/components/modal/swap/CircularProgressWithSubtitle.tsx +++ b/src/renderer/components/modal/swap/CircularProgressWithSubtitle.tsx @@ -4,6 +4,7 @@ import { makeStyles, Typography, } from '@material-ui/core'; +import { ReactNode } from 'react'; const useStyles = makeStyles((theme) => ({ subtitle: { @@ -14,7 +15,7 @@ const useStyles = makeStyles((theme) => ({ export default function CircularProgressWithSubtitle({ description, }: { - description: string; + description: string | ReactNode; }) { const classes = useStyles(); diff --git a/src/renderer/components/modal/swap/pages/SwapStatePage.tsx b/src/renderer/components/modal/swap/pages/SwapStatePage.tsx index af90d4d..c657c26 100644 --- a/src/renderer/components/modal/swap/pages/SwapStatePage.tsx +++ b/src/renderer/components/modal/swap/pages/SwapStatePage.tsx @@ -59,7 +59,7 @@ export default function SwapStatePage({ return ; } if (isSwapStateStarted(swapState)) { - return ; + return ; } if (isSwapStateBtcLockInMempool(swapState)) { return ; diff --git a/src/renderer/components/modal/swap/pages/in_progress/StartedPage.tsx b/src/renderer/components/modal/swap/pages/in_progress/StartedPage.tsx index fed3ae1..cfb0656 100644 --- a/src/renderer/components/modal/swap/pages/in_progress/StartedPage.tsx +++ b/src/renderer/components/modal/swap/pages/in_progress/StartedPage.tsx @@ -1,5 +1,15 @@ +import { SwapStateStarted } from 'models/storeModel'; import CircularProgressWithSubtitle from '../../CircularProgressWithSubtitle'; +import { BitcoinAmount } from 'renderer/components/other/Units'; -export default function StartedPage() { - return ; +export default function StartedPage({ state}: { state: SwapStateStarted }) { + const description = state.txLockDetails ? ( + <> + Locking with a network fee of + + ) : ( + 'Locking Bitcoin' + ); + + return ; } diff --git a/src/renderer/components/modal/swap/pages/init/DepositAmountHelper.tsx b/src/renderer/components/modal/swap/pages/init/DepositAmountHelper.tsx index f474a89..ad830fe 100644 --- a/src/renderer/components/modal/swap/pages/init/DepositAmountHelper.tsx +++ b/src/renderer/components/modal/swap/pages/init/DepositAmountHelper.tsx @@ -30,10 +30,8 @@ function calcBtcAmountWithoutFees(amount: number, fees: number) { export default function DepositAmountHelper({ state, - btcFees, }: { state: SwapStateWaitingForBtcDeposit; - btcFees: number; }) { const classes = useStyles(); const [amount, setAmount] = useState(state.minDeposit); @@ -56,13 +54,13 @@ export default function DepositAmountHelper({ if (state.price == null) return null; console.log( - `Calculating calcBtcAmountWithoutFees(${getTotalAmountAfterDeposit()}, ${btcFees}) / ${ + `Calculating calcBtcAmountWithoutFees(${getTotalAmountAfterDeposit()}, ${state.minBitcoinLockTxFee}) / ${ state.price } - ${MONERO_FEE}` ); return ( - calcBtcAmountWithoutFees(getTotalAmountAfterDeposit(), btcFees) / + calcBtcAmountWithoutFees(getTotalAmountAfterDeposit(), state.minBitcoinLockTxFee) / state.price - MONERO_FEE ); diff --git a/src/renderer/components/modal/swap/pages/init/WaitingForBitcoinDepositPage.tsx b/src/renderer/components/modal/swap/pages/init/WaitingForBitcoinDepositPage.tsx index aa61230..745e75f 100644 --- a/src/renderer/components/modal/swap/pages/init/WaitingForBitcoinDepositPage.tsx +++ b/src/renderer/components/modal/swap/pages/init/WaitingForBitcoinDepositPage.tsx @@ -34,13 +34,6 @@ export default function WaitingForBtcDepositPage({ const classes = useStyles(); const bitcoinBalance = useAppSelector((s) => s.rpc.state.balance) || 0; - // Convert to integer for accurate arithmetic operations - const fees = satsToBtc( - btcToSats(state.minDeposit) - - btcToSats(state.minimumAmount) + - bitcoinBalance - ); - // TODO: Account for BTC lock tx fees return ( @@ -61,7 +54,7 @@ export default function WaitingForBtcDepositPage({ Send any amount between{' '} and{' '} {' '} to the address above {bitcoinBalance > 0 && ( @@ -75,7 +68,7 @@ export default function WaitingForBtcDepositPage({
  • The network fee of{' '} - = 0 ? fees : null} /> will + will automatically be deducted from the deposited coins
  • @@ -84,7 +77,7 @@ export default function WaitingForBtcDepositPage({
  • - +
    } icon={} diff --git a/src/store/features/swapSlice.ts b/src/store/features/swapSlice.ts index 8b55178..d173cb4 100644 --- a/src/store/features/swapSlice.ts +++ b/src/store/features/swapSlice.ts @@ -101,7 +101,10 @@ export const swapSlice = createSlice({ log.fields.max_giveable ); const minDeposit = extractAmountFromUnitString( - log.fields.min_deposit + log.fields.min_deposit_until_swap_will_start + ); + const maxDeposit = extractAmountFromUnitString( + log.fields.max_deposit_until_maximum_amount_is_reached ); const minimumAmount = extractAmountFromUnitString( log.fields.minimum_amount @@ -109,17 +112,21 @@ export const swapSlice = createSlice({ const maximumAmount = extractAmountFromUnitString( log.fields.maximum_amount ); + const minBitcoinLockTxFee = extractAmountFromUnitString( + log.fields.min_bitcoin_lock_tx_fee + ); + const price = extractAmountFromUnitString(log.fields.price); const depositAddress = log.fields.deposit_address; - const price = isSwapStateReceivedQuote(slice.state) - ? slice.state.price - : null; if ( maxGiveable != null && minimumAmount != null && maximumAmount != null && - minDeposit != null + minDeposit != null && + maxDeposit != null && + minBitcoinLockTxFee != null && + price != null ) { const nextState: SwapStateWaitingForBtcDeposit = { type: SwapStateType.WAITING_FOR_BTC_DEPOSIT, @@ -128,34 +135,33 @@ export const swapSlice = createSlice({ minimumAmount, maximumAmount, minDeposit, + maxDeposit, price, + minBitcoinLockTxFee, }; slice.state = nextState; } - } else if (isCliLogReceivedBtc(log)) { - const maxGiveable = extractAmountFromUnitString( - log.fields.max_giveable - ); - - if ( - isSwapStateWaitingForBtcDeposit(slice.state) && - maxGiveable != null - ) { - slice.state.maxGiveable = maxGiveable; - } } else if (isCliLogDeterminedSwapAmount(log)) { - const nextState: SwapStateStarted = { - type: SwapStateType.STARTED, - }; + const amount = extractAmountFromUnitString(log.fields.amount); + const fees = extractAmountFromUnitString(log.fields.fees); - slice.state = nextState; - } else if (isCliLogStartedSwap(log)) { const nextState: SwapStateStarted = { type: SwapStateType.STARTED, + txLockDetails: (amount != null && fees != null) ? { amount, fees } : null, }; slice.state = nextState; + } else if (isCliLogStartedSwap(log)) { + if(slice.state?.type !== SwapStateType.STARTED) { + const nextState: SwapStateStarted = { + type: SwapStateType.STARTED, + txLockDetails: null, + }; + + slice.state = nextState; + } + slice.swapId = log.fields.swap_id; } else if (isCliLogPublishedBtcTx(log)) { if (log.fields.kind === 'lock') {