From cd65cbe2c916c8598cdd8e5d68b461f8563b532d Mon Sep 17 00:00:00 2001 From: Eduard Maximovich <130352737+eduardmaximovich@users.noreply.github.com> Date: Thu, 22 Jun 2023 11:53:19 +0400 Subject: [PATCH] PWN-8923 - striga clean phone when country changed (#1866) --- .../striga/signup/StrigaSignUpFirstStepContract.kt | 2 +- .../striga/signup/ui/StrigaSignUpFirstStepFragment.kt | 2 +- .../striga/signup/ui/StrigaSignUpFirstStepPresenter.kt | 10 +++++++--- .../signup/ui/StrigaSignupFirstStepPresenterTest.kt | 5 +++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/p2p/wallet/striga/signup/StrigaSignUpFirstStepContract.kt b/app/src/main/java/org/p2p/wallet/striga/signup/StrigaSignUpFirstStepContract.kt index e698113cbd..654c5dbfc0 100644 --- a/app/src/main/java/org/p2p/wallet/striga/signup/StrigaSignUpFirstStepContract.kt +++ b/app/src/main/java/org/p2p/wallet/striga/signup/StrigaSignUpFirstStepContract.kt @@ -27,7 +27,7 @@ interface StrigaSignUpFirstStepContract { fun onCountryOfBirthClicked() fun saveChanges() fun onSubmit() - fun onPhoneCountryCodeChanged(newCountry: CountryCode) + fun onPhoneCountryCodeChanged(newCountry: CountryCode, changedByUser: Boolean) fun onPhoneNumberChanged(newPhone: String) fun onPhoneCountryCodeClicked() } diff --git a/app/src/main/java/org/p2p/wallet/striga/signup/ui/StrigaSignUpFirstStepFragment.kt b/app/src/main/java/org/p2p/wallet/striga/signup/ui/StrigaSignUpFirstStepFragment.kt index 5f5d3e1a8a..cbf3ac9a21 100644 --- a/app/src/main/java/org/p2p/wallet/striga/signup/ui/StrigaSignUpFirstStepFragment.kt +++ b/app/src/main/java/org/p2p/wallet/striga/signup/ui/StrigaSignUpFirstStepFragment.kt @@ -260,7 +260,7 @@ class StrigaSignUpFirstStepFragment : } bundle.containsKey(RESULT_KEY_PHONE_COUNTRY_CODE) -> { val countryCode = bundle.getParcelableCompat(RESULT_KEY_PHONE_COUNTRY_CODE) ?: return - presenter.onPhoneCountryCodeChanged(countryCode) + presenter.onPhoneCountryCodeChanged(countryCode, changedByUser = true) } } } diff --git a/app/src/main/java/org/p2p/wallet/striga/signup/ui/StrigaSignUpFirstStepPresenter.kt b/app/src/main/java/org/p2p/wallet/striga/signup/ui/StrigaSignUpFirstStepPresenter.kt index e13b74b475..80a81e4c69 100644 --- a/app/src/main/java/org/p2p/wallet/striga/signup/ui/StrigaSignUpFirstStepPresenter.kt +++ b/app/src/main/java/org/p2p/wallet/striga/signup/ui/StrigaSignUpFirstStepPresenter.kt @@ -93,7 +93,7 @@ class StrigaSignUpFirstStepPresenter( } } - override fun onPhoneCountryCodeChanged(newCountry: CountryCode) { + override fun onPhoneCountryCodeChanged(newCountry: CountryCode, changedByUser: Boolean) { phoneCountryCode = newCountry view?.showPhoneCountryCode(phoneCountryCode) @@ -103,6 +103,10 @@ class StrigaSignUpFirstStepPresenter( countryCodeRepository = countryRepository ) ) + + if (changedByUser) { + view?.updateSignupField(StrigaSignupDataType.PHONE_NUMBER, "") + } } override fun onPhoneNumberChanged(newPhone: String) { @@ -156,7 +160,7 @@ class StrigaSignUpFirstStepPresenter( cachedPhoneNumber = signupData[StrigaSignupDataType.PHONE_NUMBER]?.value ) - onPhoneCountryCodeChanged(phoneNumberWithCode.phoneCode) + onPhoneCountryCodeChanged(phoneNumberWithCode.phoneCode, false) // Using the updated phoneCode and selectedPhoneNumber view?.setupPhoneCountryCodePicker( @@ -180,7 +184,7 @@ class StrigaSignUpFirstStepPresenter( signupData[StrigaSignupDataType.PHONE_CODE_WITH_PLUS]?.value?.let { val phoneCountryCode = countryRepository.findCountryCodeByPhoneCode(it) - phoneCountryCode?.let(::onPhoneCountryCodeChanged) + phoneCountryCode?.let { countryCode -> onPhoneCountryCodeChanged(countryCode, false) } } } diff --git a/app/src/test/java/org/p2p/wallet/striga/signup/ui/StrigaSignupFirstStepPresenterTest.kt b/app/src/test/java/org/p2p/wallet/striga/signup/ui/StrigaSignupFirstStepPresenterTest.kt index 390f8ba515..b50d9ec8c0 100644 --- a/app/src/test/java/org/p2p/wallet/striga/signup/ui/StrigaSignupFirstStepPresenterTest.kt +++ b/app/src/test/java/org/p2p/wallet/striga/signup/ui/StrigaSignupFirstStepPresenterTest.kt @@ -272,7 +272,8 @@ class StrigaSignupFirstStepPresenterTest { presenter.attach(view) interactor.setPhoneValidator(PhoneNumberInputValidator("90", countryCodeRepository)) presenter.onPhoneCountryCodeChanged( - CountryCode("tr", "tur", "90", "Turkey", ",") + CountryCode("tr", "tur", "90", "Turkey", ","), + true ) presenter.onPhoneNumberChanged("5556667788") presenter.onFieldChanged(StrigaSignupDataType.PHONE_CODE_WITH_PLUS, "+90") @@ -396,7 +397,7 @@ class StrigaSignupFirstStepPresenterTest { verify(exactly = 1) { view.showPhoneCountryCodePicker(TurkeyCountry) } advanceUntilIdle() - presenter.onPhoneCountryCodeChanged(TurkeyCountry) + presenter.onPhoneCountryCodeChanged(TurkeyCountry, true) verify { view.showPhoneCountryCode(TurkeyCountry) } presenter.detach()