@@ -48,16 +48,16 @@ public class SelectTransferMethodPresenter implements SelectTransferMethodContra
4848 private final SelectTransferMethodContract .View mView ;
4949
5050 public SelectTransferMethodPresenter (SelectTransferMethodContract .View view ,
51- @ NonNull final TransferMethodConfigurationRepository transferMethodConfigurationRepository ,
52- @ NonNull final UserRepository userRepository ) {
51+ @ NonNull final TransferMethodConfigurationRepository transferMethodConfigurationRepository ,
52+ @ NonNull final UserRepository userRepository ) {
5353 this .mView = view ;
5454 this .mTransferMethodConfigurationRepository = transferMethodConfigurationRepository ;
5555 this .mUserRepository = userRepository ;
5656 }
5757
5858 @ Override
5959 public void loadTransferMethodConfigurationKeys (final boolean forceUpdate , @ Nullable final String countryCode ,
60- @ Nullable final String currencyCode ) {
60+ @ Nullable final String currencyCode ) {
6161
6262 mView .showProgressBar ();
6363
@@ -146,15 +146,14 @@ public void onKeysLoaded(@Nullable final HyperwalletTransferMethodConfigurationK
146146 if (!mView .isActive ()) {
147147 return ;
148148 }
149- List <Currency > currencies = key .getCurrencies (countryCode ) != null ?
150- new ArrayList <>(key .getCurrencies (countryCode )) :
151- new ArrayList <Currency >();
149+ String selectedCurrencyCode = getDefaultCurrencyCode (key , countryCode );
152150
151+ if (selectedCurrencyCode == null ) {
152+ return ;
153+ }
153154 mView .showTransferMethodCountry (countryCode );
154- mView .showTransferMethodCurrency (currencies .get (0 ).getCode ());
155-
156- loadFeeAndProcessingTimeAndShowTransferMethods (countryCode , currencies .get (0 ).getCode (),
157- user );
155+ mView .showTransferMethodCurrency (selectedCurrencyCode );
156+ loadFeeAndProcessingTimeAndShowTransferMethods (countryCode , selectedCurrencyCode , user );
158157 }
159158
160159 @ Override
@@ -180,7 +179,7 @@ private void showErrorLoadCurrency(@NonNull Errors errors) {
180179
181180 @ Override
182181 public void loadTransferMethodTypes (final boolean forceUpdate ,
183- @ NonNull final String countryCode , @ NonNull final String currencyCode ) {
182+ @ NonNull final String countryCode , @ NonNull final String currencyCode ) {
184183 mView .showProgressBar ();
185184
186185 if (forceUpdate ) {
@@ -226,7 +225,7 @@ public void onError(@NonNull Errors errors) {
226225
227226 @ Override
228227 public void openAddTransferMethod (@ NonNull final String country , @ NonNull final String currency ,
229- @ NonNull final String transferMethodType , @ NonNull final String profileType ) {
228+ @ NonNull final String transferMethodType , @ NonNull final String profileType ) {
230229 mView .showAddTransferMethod (country , currency , transferMethodType , profileType );
231230 }
232231
@@ -293,6 +292,34 @@ public void onError(@NonNull final Errors errors) {
293292 });
294293 }
295294
295+ // Helper method to get the DefaultCurrencyCode
296+ private String getDefaultCurrencyCode (@ NonNull final HyperwalletTransferMethodConfigurationKey keys , @ NonNull final String countryCode ) {
297+ Country selectedCountry = null ;
298+ for (Country country : keys .getCountries ()) {
299+ if (country .getCode ().equals (countryCode )) {
300+ selectedCountry = country ;
301+ break ;
302+ }
303+ }
304+ if (selectedCountry == null ) {
305+ return null ;
306+ }
307+ Set <Currency > currencies = keys .getCurrencies (countryCode );
308+ String defaultCurrencyCode = selectedCountry .getDefaultCurrency ();
309+ if (defaultCurrencyCode != null ) {
310+ for (Currency currency : currencies ) {
311+ if (currency .getCode ().equals (defaultCurrencyCode )) {
312+ return currency .getCode ();
313+ }
314+ }
315+ }
316+ if (!keys .getCurrencies (countryCode ).isEmpty ()) {
317+ return keys .getCurrencies (countryCode ).iterator ().next ().getCode ();
318+ }
319+ return null ;
320+ }
321+
322+
296323 private List <TransferMethodSelectionItem > getTransferMethodSelectionItems (
297324 @ NonNull final String countryCode , @ NonNull final String currencyCode ,
298325 @ NonNull final String userProfileType ,
@@ -309,7 +336,7 @@ private List<TransferMethodSelectionItem> getTransferMethodSelectionItems(
309336 }
310337
311338 private void loadFeeAndProcessingTimeAndShowTransferMethods (final String countryCode , final String currencyCode ,
312- final User user ) {
339+ final User user ) {
313340 mTransferMethodConfigurationRepository .getTransferMethodTypesFeeAndProcessingTime (countryCode , currencyCode ,
314341 new TransferMethodConfigurationRepository .LoadKeysCallback () {
315342 @ Override
0 commit comments