Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix getAdjustedAmount function, either with explanation on what it does if current behavior is expected or rounding of return data for all cases to match expectation.
rounded = Math.min(maxTradeLimit, rounded - amountByVolumeRoundedToFactor.value); | ||
long reduced = rounded - amountByVolumeRoundedToFactor.value; | ||
if (reduced > Restrictions.getMinTradeAmount().value) | ||
rounded = Math.min(maxTradeLimit, reduced); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the amount is more than factor
more than maxTradeLimit
the returned value will be maxTradeLimit
which is not rounded. This is later rounded down to factor when this function is called again from MutableOfferDataModel:702 so everything works in when running the code.
This is somewhat confusing while reading the code though, I expect getAdjustedAmount
to return a rounded amount for every input value.
@@ -167,20 +168,28 @@ public static Coin getAdjustedAmountForHalCash(Coin amount, Price price, long ma | |||
private static Coin getAdjustedAmount(Coin amount, Price price, long maxTradeLimit, String currencyCode, int factor) { | |||
// Amount must result in a volume of min factor units of the fiat currency, e.g. 1 EUR or 10 EUR in case of Halcash | |||
Volume volumeRoundedToFactor = Volume.parse(String.valueOf(factor), currencyCode); | |||
if (volumeRoundedToFactor.getValue() <= 0) | |||
return Coin.ZERO; | |||
|
|||
Coin amountByVolumeRoundedToFactor = price.getAmountByVolume(volumeRoundedToFactor); | |||
// We set min amount so it has a volume of 10 EUR | |||
if (amount.compareTo(amountByVolumeRoundedToFactor) < 0) | |||
amount = amountByVolumeRoundedToFactor; | |||
|
|||
// We adjust the amount so that the volume is a multiple of 10 EUR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refers to a multiple of factor
@@ -167,20 +168,28 @@ public static Coin getAdjustedAmountForHalCash(Coin amount, Price price, long ma | |||
private static Coin getAdjustedAmount(Coin amount, Price price, long maxTradeLimit, String currencyCode, int factor) { | |||
// Amount must result in a volume of min factor units of the fiat currency, e.g. 1 EUR or 10 EUR in case of Halcash | |||
Volume volumeRoundedToFactor = Volume.parse(String.valueOf(factor), currencyCode); | |||
if (volumeRoundedToFactor.getValue() <= 0) | |||
return Coin.ZERO; | |||
|
|||
Coin amountByVolumeRoundedToFactor = price.getAmountByVolume(volumeRoundedToFactor); | |||
// We set min amount so it has a volume of 10 EUR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These comments refer to a multiple of factor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK
@ManfredKarrer There is no need to make any changes in translation files except English as it will be updated anyways from Transifex when I sync the translations for a release. |
- Move getTxFeeForWithdrawalPerByte to another section - Update other callers of getNumTxOutputsForAddress(address) with checks to 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some initial comments.
@@ -634,6 +634,9 @@ public Transaction getPreparedUnlockTx(TxOutput lockedTxOutput) throws AddressFo | |||
} | |||
|
|||
public Address getUnusedAddress() { | |||
return wallet.freshReceiveAddress(); | |||
return wallet.getIssuedReceiveAddresses().stream() | |||
.filter(address -> getNumTxOutputsForAddress(address) == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on our conversation, I understand that before the commit 4aaad1f, the getUnusedAddress()
method generated a fresh set of addresses on each call, whereas it after the commit only generates fresh addresses if necessary.
(Optional) I feel like the commit ideally should mention this (currently it says only Fix getUnusedAddress method
), and that ideally there should be some tests that cover the behavior before and after the change.
Apart from that, I think that the filtering on getNumTxOutputsForAddress(address) == 0
predicate could be more clear in its semantics if e.g a method for Address
like .hasBeenUsed()
returned true
if there were any tx outputs for that Address
. Alternatively, we could document the semantics of what we're doing with a comment here.
Edit: Ah, I see now that Address
is a bitcoinj class, and it doesn't know about the tx outputs.. adding a utility method in BsqWalletService
is probably best.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK 8010863.
I left some comments with optional suggestions that you may want to review when you have the chance, but I think this is safe to go in with its current state.
* @return The adjusted amount | ||
*/ | ||
@VisibleForTesting | ||
static Coin getAdjustedAmount(Coin amount, Price price, long maxTradeLimit, int factor) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is fairly complex! It would be great if there were tests for it..
I have been working on that (and tests for some of the methods in Coin
) which I will send out for review after this change goes in. I think I understand the behavior of the method, and that it's going to do what you want under normal conditions in terms of making user-provided values from the UI match the expected constraints.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For future reference, those tests I mentioned above were merged in #160.
@@ -2155,7 +2156,7 @@ payment.f2f.info='Face to Face' trades have different rules and come with differ | |||
happened at the meeting. In such cases the BTC funds might get locked up forever or until the trading peers come to \ | |||
an agreement.\n\n\ | |||
To be sure you fully understand the differences with 'Face to Face' trades please read the instructions and \ | |||
recommendations at: 'https://docs.bisq.network/#f2f' | |||
recommendations at: 'https://docs.bisq.network/trading-rules.html#f2f-trading' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Optional) Maybe the URL could be removed from the property, since it's not being translated? Then we could append it to the translated property string in code.
No description provided.