Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
57743c4
bug/DTSERWFOUR-170-Remaining-Screen-Updates changes updated
pdamodarannair Nov 16, 2020
c569ebc
bug/DTSERWFOUR-170-Remaining-Screen-Updates - Confirmation screen update
pdamodarannair Nov 18, 2020
7dda117
bug/DTSERWFOUR-170-Remaining-Screen-Updates logic updates
pdamodarannair Nov 19, 2020
2834110
Merge branch 'development' into bug/DTSERWFOUR-170-Remaining-Screen-U…
malaw-hw Nov 19, 2020
a0cfbf1
DTSERWFOUR -170 - formatted currency in details screen.
shanavas123 Nov 20, 2020
ee6ac4e
DTSERWFOUR -170 - Fixed UI Test.
shanavas123 Nov 20, 2020
9b36f30
Merge branch 'development' into bug/DTSERWFOUR-170-Remaining-Screen-U…
pdamodarannair Nov 20, 2020
b6c8c25
DTSERWFOUR -170 - Fixed invalid error.
shanavas123 Nov 23, 2020
67612c5
Merge branches 'bug/DTSERWFOUR-170-Remaining-Screen-Updates' and 'dev…
shanavas123 Nov 23, 2020
7c3517b
DTSERWFOUR -170 - resolve merge conflict
shanavas123 Nov 23, 2020
ac65c02
Merge branch 'development' into bug/DTSERWFOUR-170-Remaining-Screen-U…
malaw-hw Nov 24, 2020
9d368fc
DTSERWFOUR -170 - fixed Currency Symbol in confirm screen.
shanavas123 Nov 24, 2020
2a17ee4
Merge branch 'bug/DTSERWFOUR-170-Remaining-Screen-Updates' of https:/…
shanavas123 Nov 24, 2020
a78da1e
Merge branch 'development' into bug/DTSERWFOUR-170-Remaining-Screen-U…
malaw-hw Nov 24, 2020
9c2587a
Merge branch 'development' into bug/DTSERWFOUR-170-Remaining-Screen-U…
rajkumar-balakrishnasamy Nov 24, 2020
4fda3ce
bug/DTSERWFOUR-170-Remaining-Screen-Updates Fixed JacocoTestcoverage …
pdamodarannair Nov 24, 2020
4388f5a
DTSERWFOUR -170 - fixed TC failure.
shanavas123 Nov 25, 2020
50820bd
DTSERWFOUR -170 - fixed right currency symbols.
shanavas123 Nov 25, 2020
c855ec3
DTSERWFOUR -170 addressed review comments.
shanavas123 Nov 25, 2020
9ebf84d
bug/DTSERWFOUR-170-Remaining-Screen-Updates Code review updates
pdamodarannair Nov 25, 2020
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
@@ -1,13 +1,19 @@
package com.hyperwallet.android.ui.common.util;

import static com.hyperwallet.android.model.transfer.Transfer.EMPTY_STRING;

import android.content.Context;

import androidx.annotation.VisibleForTesting;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.io.InputStream;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Currency;
Expand All @@ -17,6 +23,8 @@ public class CurrencyParser {
private static CurrencyParser instance;
private static final String CURRENCY_LIST = "currency.json";
private List<CurrencyDetails> currencyList;
private static final String REGEX_REMOVE_EMPTY_SPACE = "^\\s+|\\s+$";


private CurrencyParser(Context context) {
currencyList = populateCurrencyList(readJSONFromAsset(context));
Expand Down Expand Up @@ -80,7 +88,8 @@ public String formatCurrency(String currency, String amount) {
return format.format(Double.parseDouble(amount));
}

private int getNumberOfFractionDigits(String currencyCode) {
@VisibleForTesting
int getNumberOfFractionDigits(String currencyCode) {
for (CurrencyDetails list : currencyList) {
if (list.getCurrencyCode().equals(currencyCode)) {
return list.getDecimals();
Expand All @@ -89,4 +98,33 @@ private int getNumberOfFractionDigits(String currencyCode) {

return 0;
}

/**
* Formats the currency as per currency.json code.
*
* @param currency Any currency symbol.
* @param amount Any valid number in decimal.
* @return Returns the formatted number as per currency.json.
*/

public String formatCurrencyWithSymbol(String currency, String amount) {
DecimalFormat currencyFormatter = (DecimalFormat) DecimalFormat.getCurrencyInstance();
CurrencyDetails currencyDetails = getCurrency(currency);
currencyFormatter.setMinimumFractionDigits(currencyDetails == null ? 0 : currencyDetails.getDecimals());
currencyFormatter.setCurrency(Currency.getInstance(currency));
DecimalFormatSymbols decimalFormatSymbols = currencyFormatter.getDecimalFormatSymbols();
decimalFormatSymbols.setCurrencySymbol("");
currencyFormatter.setDecimalFormatSymbols(decimalFormatSymbols);
String formattedAmount = currencyFormatter.format(Double.parseDouble(amount)).replaceAll(REGEX_REMOVE_EMPTY_SPACE, EMPTY_STRING);
return currencyDetails == null ? "" : currencyDetails.getSymbol() + formattedAmount;
}

public CurrencyDetails getCurrency(String currencyCode) {
for (CurrencyDetails list : currencyList) {
if (list.getCurrencyCode().equals(currencyCode)) {
return list;
}
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,33 @@ public void testAllCurrencyFormats() {
assertThat(currency, is(currencyMap.getValue()));
}
}

@Test
public void testCurrencyFormatWithSymbol() {
String amount = "1000000";
Context context = ApplicationProvider.getApplicationContext();
String currency = CurrencyParser.getInstance(context).formatCurrencyWithSymbol("USD", amount);
assertThat(currency, is("$1,000,000.00"));
}
@Test
public void testGetNumberOfFractionDigits_ThreeDigitDecimal(){
Context context = ApplicationProvider.getApplicationContext();
int noOfDigits = CurrencyParser.getInstance(context).getNumberOfFractionDigits("TND");
assertThat(noOfDigits, is(3));
}

@Test
public void testGetCurrency() {
Context context = ApplicationProvider.getApplicationContext();
CurrencyDetails currencyDetails = CurrencyParser.getInstance(context).getCurrency("TND");
assertThat(currencyDetails.getSymbol(), is("د.ت"));
assertThat(currencyDetails.getDecimals(),is(3));
}

@Test
public void testGetNumberOfFractionDigits_NoDigitDecimal(){
Context context = ApplicationProvider.getApplicationContext();
int noOfDigits = CurrencyParser.getInstance(context).getNumberOfFractionDigits("JPY");
assertThat(noOfDigits, is(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public void testSelectDestination_verifyDestinationNotUpdatedWhenClickingBackBut
onView(withId(R.id.transfer_destination_description_2)).check(matches(withText("ending in 0616")));

onView(withId(R.id.transfer_summary)).perform(nestedScrollTo()).check(matches(isDisplayed()));
String availableFundUSD = getAvailableFund("998.00", "USD");
String availableFundUSD = getAvailableFund("$","998.00", "USD");
onView(withId(R.id.transfer_summary)).check(matches(withText(availableFundUSD)));

onView(withId(R.id.transfer_destination_title)).perform(click());
Expand Down Expand Up @@ -280,7 +280,7 @@ public void testSelectDestination_verifyDestinationUpdatedUponAddingNewExternalA
onView(withId(R.id.transfer_destination_description_2)).check(matches(withText("ending in 5121")));

onView(withId(R.id.transfer_summary)).perform(nestedScrollTo()).check(matches(isDisplayed()));
String availableFundCAD = getAvailableFund("1,157.40", "CAD");
String availableFundCAD = getAvailableFund("$","1,157.40", "CAD");
onView(withId(R.id.transfer_summary)).check(matches(withText(availableFundCAD)));

}
Expand All @@ -306,7 +306,7 @@ public void testSelectDestination_verifyDestinationUpdatedUponSelection() {
onView(withId(R.id.transfer_destination_description_2)).check(matches(withText("ending in 0616")));

onView(withId(R.id.transfer_summary)).perform(nestedScrollTo()).check(matches(isDisplayed()));
String availableFundUSD = getAvailableFund("998.00", "USD");
String availableFundUSD = getAvailableFund("$","998.00", "USD");
onView(withId(R.id.transfer_summary)).check(matches(withText(availableFundUSD)));

onView(withId(R.id.transfer_destination_title)).perform(click());
Expand All @@ -326,7 +326,7 @@ public void testSelectDestination_verifyDestinationUpdatedUponSelection() {
onView(withId(R.id.transfer_all_funds)).perform(nestedScrollTo()).check(matches(isDisplayed()));
onView(withId(R.id.transfer_all_funds)).check(matches(not(isSelected())));
onView(withId(R.id.transfer_summary)).perform(nestedScrollTo()).check(matches(isDisplayed()));
String availableFundUSD2 = getAvailableFund("1000.00", "USD");
String availableFundUSD2 = getAvailableFund("$","1,000.00", "USD");
onView(withId(R.id.transfer_summary)).check(matches(withText(availableFundUSD2)));

onView(withId(R.id.transfer_notes)).perform(nestedScrollTo()).check(matches(isDisplayed()));
Expand Down Expand Up @@ -425,9 +425,9 @@ public void testSelectDestination_listTransferMethodsConnectionError() {

}

private String getAvailableFund(String amount, String currency) {
private String getAvailableFund(String symbol,String amount, String currency) {
String availableFund = String.format(InstrumentationRegistry.getInstrumentation().getTargetContext()
.getString(R.string.mobileAvailableBalance), amount , currency);
.getString(R.string.mobileAvailableBalance),symbol, amount , currency);
return availableFund;
}

Expand Down
Loading