Skip to content

Commit

Permalink
Merge pull request #118 from UnstoppableSwap/display-tx-fees-init
Browse files Browse the repository at this point in the history
Adjust the displayed minimum amount to account for network fees
  • Loading branch information
binarybaron authored Oct 25, 2022
2 parents 66e2e02 + f3d45a6 commit c6e6bb2
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions .erb/scripts/download-tor-binaries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@ Promise.all(
console.error(
`Failed to download swap binaries! Error: ${JSON.stringify(error)}`
);
console.error(error);
process.exit(1);
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"deposit_address": "tb1qajq94d72k9hhcmtrlwhfuhc5yz0w298uym980g",
"max_giveable": "0.00000000 BTC",
"minimum_amount": "0.00010000 BTC",
"maximum_amount": "0.10000000 BTC"
"maximum_amount": "0.10000000 BTC",
"min_deposit": "0.00011000 BTC"
}
}
2 changes: 2 additions & 0 deletions src/__tests__/store/swapSlice.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ test('should infer correct states from happy-path logs', () => {
maxGiveable: 0,
minimumAmount: 0.0001,
maximumAmount: 0.1,
minDeposit: 0.00011,
price: 0.00610233,
},
provider: exampleProvider,
Expand All @@ -138,6 +139,7 @@ test('should infer correct states from happy-path logs', () => {
maxGiveable: 0.00099878,
minimumAmount: 0.0001,
maximumAmount: 0.1,
minDeposit: 0.00011,
price: 0.00610233,
},
provider: exampleProvider,
Expand Down
1 change: 1 addition & 0 deletions src/models/cliModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface CliLogWaitingForBtcDeposit extends CliLog {
max_giveable: string;
minimum_amount: string;
maximum_amount: string;
min_deposit: string;
};
}

Expand Down
1 change: 1 addition & 0 deletions src/models/storeModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export interface SwapStateWaitingForBtcDeposit extends SwapState {
maxGiveable: number;
minimumAmount: number;
maximumAmount: number;
minDeposit: number;
price: number | null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import { SwapStateWaitingForBtcDeposit } from '../../../../../../models/storeModel';
import DepositAddressInfoBox from '../../transaction/DepositAddressInfoBox';
import BitcoinIcon from '../../../../icons/BitcoinIcon';
import { btcToSats, satsToBtc } from '../../../../../../utils/conversionUtils';

const useStyles = makeStyles((theme) => ({
depositStatusText: {
Expand All @@ -23,6 +24,11 @@ export default function WaitingForBtcDepositPage({
}: WaitingForBtcDepositPageProps) {
const classes = useStyles();

// Convert to integer for accurate arithmetic operations
const fees = satsToBtc(
btcToSats(state.minDeposit) - btcToSats(state.minimumAmount)
);

// TODO: Account for BTC lock tx fees
return (
<Box>
Expand All @@ -41,10 +47,12 @@ export default function WaitingForBtcDepositPage({
variant="subtitle2"
className={classes.depositStatusText}
>
Send any amount between {state.minimumAmount} BTC (and some more
for network fees) and {state.maximumAmount} BTC to the address
above. All Bitcoin sent to this this address will converted into
Monero at an exchance rate of {state.price || 'unknown'} BTC/XMR.
Send any amount between {state.minDeposit} BTC and{' '}
{state.maximumAmount} BTC to the address above. All Bitcoin sent
to this this address will converted into Monero at an exchance
rate of {state.price || 'unknown'} BTC/XMR. The network fee of{' '}
{fees} BTC will automatically be deducted from the deposited
coins.
</Typography>
<Typography variant="subtitle2">
You have deposited enough Bitcoin to swap {state.maxGiveable} BTC
Expand Down
7 changes: 6 additions & 1 deletion src/store/features/swapSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ export const swapSlice = createSlice({
const maxGiveable = extractAmountFromUnitString(
log.fields.max_giveable
);
const minDeposit = extractAmountFromUnitString(
log.fields.min_deposit
);
const minimumAmount = extractAmountFromUnitString(
log.fields.minimum_amount
);
Expand All @@ -97,14 +100,16 @@ export const swapSlice = createSlice({
if (
maxGiveable != null &&
minimumAmount != null &&
maximumAmount != null
maximumAmount != null &&
minDeposit != null
) {
const nextState: SwapStateWaitingForBtcDeposit = {
type: SwapStateType.WAITING_FOR_BTC_DEPOSIT,
depositAddress,
maxGiveable,
minimumAmount,
maximumAmount,
minDeposit,
price,
};

Expand Down

0 comments on commit c6e6bb2

Please sign in to comment.