diff --git a/commonui/src/main/java/com/hyperwallet/android/ui/common/util/CurrencyParser.java b/commonui/src/main/java/com/hyperwallet/android/ui/common/util/CurrencyParser.java index 6f11835e7..46998a5fc 100644 --- a/commonui/src/main/java/com/hyperwallet/android/ui/common/util/CurrencyParser.java +++ b/commonui/src/main/java/com/hyperwallet/android/ui/common/util/CurrencyParser.java @@ -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); + } + return returnValue; + } else { + return ""; + } + } } diff --git a/commonui/src/test/java/com/hyperwallet/android/ui/common/util/CurrencyParserTest.java b/commonui/src/test/java/com/hyperwallet/android/ui/common/util/CurrencyParserTest.java index 9637542e8..6c76b40da 100644 --- a/commonui/src/test/java/com/hyperwallet/android/ui/common/util/CurrencyParserTest.java +++ b/commonui/src/test/java/com/hyperwallet/android/ui/common/util/CurrencyParserTest.java @@ -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))); + } } diff --git a/receiptui/src/main/java/com/hyperwallet/android/ui/receipt/view/ReceiptDetailFragment.java b/receiptui/src/main/java/com/hyperwallet/android/ui/receipt/view/ReceiptDetailFragment.java index 71c4753a8..725289a96 100644 --- a/receiptui/src/main/java/com/hyperwallet/android/ui/receipt/view/ReceiptDetailFragment.java +++ b/receiptui/src/main/java/com/hyperwallet/android/ui/receipt/view/ReceiptDetailFragment.java @@ -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; @@ -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()); + } } } } diff --git a/transferui/src/androidTest/java/com/hyperwallet/android/ui/transfer/TransferPPCFundsTest.java b/transferui/src/androidTest/java/com/hyperwallet/android/ui/transfer/TransferPPCFundsTest.java index b42be417b..f2fd9eb7c 100644 --- a/transferui/src/androidTest/java/com/hyperwallet/android/ui/transfer/TransferPPCFundsTest.java +++ b/transferui/src/androidTest/java/com/hyperwallet/android/ui/transfer/TransferPPCFundsTest.java @@ -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))); diff --git a/transferui/src/androidTest/java/com/hyperwallet/android/ui/transfer/TransferUserFundsTest.java b/transferui/src/androidTest/java/com/hyperwallet/android/ui/transfer/TransferUserFundsTest.java index 357ca78e2..109569dda 100644 --- a/transferui/src/androidTest/java/com/hyperwallet/android/ui/transfer/TransferUserFundsTest.java +++ b/transferui/src/androidTest/java/com/hyperwallet/android/ui/transfer/TransferUserFundsTest.java @@ -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))); @@ -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( @@ -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"))); @@ -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( @@ -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"))); diff --git a/transferui/src/main/java/com/hyperwallet/android/ui/transfer/view/ScheduleTransferFragment.java b/transferui/src/main/java/com/hyperwallet/android/ui/transfer/view/ScheduleTransferFragment.java index 3ba2724b9..0e542efcb 100644 --- a/transferui/src/main/java/com/hyperwallet/android/ui/transfer/view/ScheduleTransferFragment.java +++ b/transferui/src/main/java/com/hyperwallet/android/ui/transfer/view/ScheduleTransferFragment.java @@ -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; @@ -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())); } } } diff --git a/transferui/src/main/res/layout/foreign_exchange.xml b/transferui/src/main/res/layout/foreign_exchange.xml index 8ce465d7d..a1ae8be66 100644 --- a/transferui/src/main/res/layout/foreign_exchange.xml +++ b/transferui/src/main/res/layout/foreign_exchange.xml @@ -104,14 +104,16 @@ @@ -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" />