Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,27 @@ public CurrencyDetails getCurrency(String currencyCode) {
}
return null;
}

/**
* truncate decimals for given value
*
* @param value Any value in string.
* @param noOfDecimals number of decimal to be truncate.
* @return Returns truncated decimal value.
*/
public static String getValueWithTruncateDecimals(String value, int noOfDecimals) {
if (value != null) {
String returnValue = value;
int decimalLength = 0;
if (value.contains(".")) {
decimalLength = value.substring(value.indexOf(".")).length();
}
if (decimalLength > noOfDecimals) {
returnValue = value.substring(0, value.indexOf(".") + noOfDecimals + 1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong implementation, when we are reducing number of decimal places, we can't just truncate the decimals, we either round up or round down values.
Please check in the grooming recording or ask Brandon, as far as I remember we round up

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brandon, conformed only truncating the last two decimals not round up the value.

}
return returnValue;
} else {
return "";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,17 @@ public void testGetNumberOfFractionDigits_NoDigitDecimal(){
int noOfDigits = CurrencyParser.getInstance(context).getNumberOfFractionDigits("JPY");
assertThat(noOfDigits, is(0));
}

@Test
public void testFXRateWithFourDecimal()
{
assertThat("1.2345",is(CurrencyParser.getValueWithTruncateDecimals("1.234567",4)));
assertThat("1.234",is(CurrencyParser.getValueWithTruncateDecimals("1.234",4)));
assertThat("1.0000",is(CurrencyParser.getValueWithTruncateDecimals("1.000056",4)));
assertThat("1",is(CurrencyParser.getValueWithTruncateDecimals("1",4)));
assertThat("",is(CurrencyParser.getValueWithTruncateDecimals(null,4)));
assertThat("1.234",is(CurrencyParser.getValueWithTruncateDecimals("1.234567",3)));
assertThat("1.23",is(CurrencyParser.getValueWithTruncateDecimals("1.234567",2)));
assertThat("1.2",is(CurrencyParser.getValueWithTruncateDecimals("1.234567",1)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
package com.hyperwallet.android.ui.receipt.view;

import static android.text.format.DateUtils.FORMAT_ABBREV_MONTH;
import static android.text.format.DateUtils.FORMAT_ABBREV_WEEKDAY;
import static android.text.format.DateUtils.FORMAT_SHOW_DATE;
import static android.text.format.DateUtils.FORMAT_SHOW_TIME;
import static android.text.format.DateUtils.FORMAT_SHOW_WEEKDAY;
import static android.text.format.DateUtils.FORMAT_SHOW_YEAR;
import static android.text.format.DateUtils.formatDateTime;

import static com.hyperwallet.android.model.receipt.Receipt.Entries.CREDIT;
import static com.hyperwallet.android.model.receipt.Receipt.Entries.DEBIT;
import static com.hyperwallet.android.ui.common.util.CurrencyParser.getValueWithTruncateDecimals;

import android.content.Context;
import android.os.Build;
Expand Down Expand Up @@ -213,8 +212,14 @@ private void setDetailsView(@NonNull final Receipt receipt, @NonNull final View
}

if (!TextUtils.isEmpty(receiptDetails.getNotes())) {
setViewInformation(R.id.receipt_notes_information, R.id.notes_value,
view, receiptDetails.getNotes());
if (receipt.getForeignExchangeRate() != null) {
String fxRate = getValueWithTruncateDecimals(receipt.getForeignExchangeRate(),4);
setViewInformation(R.id.receipt_notes_information, R.id.notes_value,
view, receiptDetails.getNotes().replace(receipt.getForeignExchangeRate(), fxRate));
} else {
setViewInformation(R.id.receipt_notes_information, R.id.notes_value,
view, receiptDetails.getNotes());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ public void onReceive(Context context, Intent intent) {
allOf(withId(R.id.exchange_rate_label), withText(R.string.mobileFXRateLabel))))));
onView(withId(R.id.list_foreign_exchange)).check(
matches(atPosition(0,
hasDescendant(allOf(withId(R.id.exchange_rate_value), withText("$1 USD = $1.291253 CAD"))))));
hasDescendant(allOf(withId(R.id.exchange_rate_value), withText("$1 USD = $1.2912 CAD"))))));
onView(withId(R.id.amount_label)).check(matches(withText(R.string.mobileConfirmDetailsAmount)));
onView(withId(R.id.amount_value)).check(matches(withText("$152.20 CAD")));
onView(withId(R.id.fee_label)).check(matches(withText(R.string.mobileConfirmDetailsFee)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ public void onReceive(Context context, Intent intent) {
allOf(withId(R.id.exchange_rate_label), withText(R.string.mobileFXRateLabel))))));
onView(withId(R.id.list_foreign_exchange)).check(
matches(atPosition(0,
hasDescendant(allOf(withId(R.id.exchange_rate_value), withText("$1 USD = $1.291253 CAD"))))));
hasDescendant(allOf(withId(R.id.exchange_rate_value), withText("$1 USD = $1.2912 CAD"))))));
onView(withId(R.id.amount_label)).check(matches(withText(R.string.mobileConfirmDetailsAmount)));
onView(withId(R.id.amount_value)).check(matches(withText("$152.20 CAD")));
onView(withId(R.id.fee_label)).check(matches(withText(R.string.mobileConfirmDetailsFee)));
Expand Down Expand Up @@ -806,7 +806,7 @@ public void onReceive(Context context, Intent intent) {
allOf(withId(R.id.exchange_rate_label), withText(R.string.mobileFXRateLabel))))));
onView(withId(R.id.list_foreign_exchange)).check(
matches(atPosition(0,
hasDescendant(allOf(withId(R.id.exchange_rate_value), withText("$1 CAD = $0.774400 USD"))))));
hasDescendant(allOf(withId(R.id.exchange_rate_value), withText("$1 CAD = $0.7744 USD"))))));

onView(withId(R.id.list_foreign_exchange)).check(
matches(atPosition(1, hasDescendant(
Expand All @@ -823,7 +823,7 @@ public void onReceive(Context context, Intent intent) {
allOf(withId(R.id.exchange_rate_label), withText(R.string.mobileFXRateLabel))))));
onView(withId(R.id.list_foreign_exchange)).check(
matches(atPosition(1,
hasDescendant(allOf(withId(R.id.exchange_rate_value), withText("€1 EUR = $1.126100 USD"))))));
hasDescendant(allOf(withId(R.id.exchange_rate_value), withText("€1 EUR = $1.1261 USD"))))));

onView(withId(R.id.amount_label)).check(matches(withText(R.string.mobileConfirmDetailsAmount)));
onView(withId(R.id.amount_value)).check(matches(withText("$290.05 USD")));
Expand Down Expand Up @@ -919,7 +919,7 @@ public void onReceive(Context context, Intent intent) {
allOf(withId(R.id.exchange_rate_label), withText(R.string.mobileFXRateLabel))))));
onView(withId(R.id.list_foreign_exchange)).check(
matches(atPosition(0,
hasDescendant(allOf(withId(R.id.exchange_rate_value), withText("$1 CAD = $0.784400 USD"))))));
hasDescendant(allOf(withId(R.id.exchange_rate_value), withText("$1 CAD = $0.7844 USD"))))));

onView(withId(R.id.list_foreign_exchange)).check(
matches(atPosition(1, hasDescendant(
Expand All @@ -936,7 +936,7 @@ public void onReceive(Context context, Intent intent) {
allOf(withId(R.id.exchange_rate_label), withText(R.string.mobileFXRateLabel))))));
onView(withId(R.id.list_foreign_exchange)).check(
matches(atPosition(1,
hasDescendant(allOf(withId(R.id.exchange_rate_value), withText("€1 EUR = $1.136100 USD"))))));
hasDescendant(allOf(withId(R.id.exchange_rate_value), withText("€1 EUR = $1.1361 USD"))))));

onView(withId(R.id.amount_label)).check(matches(withText(R.string.mobileConfirmDetailsAmount)));
onView(withId(R.id.amount_value)).check(matches(withText("$194.05 USD")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static com.hyperwallet.android.model.transfermethod.TransferMethod.TransferMethodFields.TRANSFER_METHOD_COUNTRY;
import static com.hyperwallet.android.model.transfermethod.TransferMethod.TransferMethodFields.TYPE;
import static com.hyperwallet.android.model.transfermethod.TransferMethod.TransferMethodTypes.PREPAID_CARD;
import static com.hyperwallet.android.ui.common.util.CurrencyParser.getValueWithTruncateDecimals;
import static com.hyperwallet.android.ui.common.view.TransferMethodUtils.getStringFontIcon;
import static com.hyperwallet.android.ui.common.view.TransferMethodUtils.getStringResourceByName;
import static com.hyperwallet.android.ui.common.view.TransferMethodUtils.getTransferMethodDetail;
Expand Down Expand Up @@ -327,7 +328,8 @@ void bind(@NonNull final ForeignExchange fx) {
buyValue.setText(itemView.getContext().getString(R.string.amount_currency_format,
buyFormattedAmount, fx.getDestinationCurrency()));
exchangeRateValue.setText(itemView.getContext().getString(R.string.exchange_rate_format,
sourceCurrency.getSymbol(),fx.getSourceCurrency(), destinationCurrency.getSymbol(),fx.getRate(), fx.getDestinationCurrency()));
sourceCurrency.getSymbol(),fx.getSourceCurrency(), destinationCurrency.getSymbol(),
getValueWithTruncateDecimals(fx.getRate(), 4), fx.getDestinationCurrency()));
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions transferui/src/main/res/layout/foreign_exchange.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,16 @@

<TextView
android:id="@+id/exchange_rate_label"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/grid_margin_left"
android:layout_marginTop="@dimen/grid_margin_top"
android:layout_marginEnd="@dimen/grid_margin_left"
android:layout_marginBottom="@dimen/grid_margin_bottom"
android:text="@string/mobileFXRateLabel"
android:textAppearance="@style/TextAppearance.Hyperwallet.Body1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/exchange_rate_value"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>

Expand All @@ -127,7 +129,6 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:textDirection="ltr"
tools:text="@string/foreign_exchange_rate_placeholder" />

<View
Expand Down