Skip to content

Commit

Permalink
Bugfix/AND-134 Show confetti animation once account is finalized on c…
Browse files Browse the repository at this point in the history
…hain (#229)

* Add finalizing account state for account creation

* Reduce CountDownTimer interval when account is finalizing

* Update CountDownTimer
  • Loading branch information
zaiatsartem authored Dec 13, 2024
1 parent 6c78b30 commit f584461
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 14 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ android {
buildConfigField("boolean", "INCL_DEV_OPTIONS", "false")
buildConfigField("boolean", "SHOW_GTU_DROP", "false")
buildConfigField("Long", "ACCOUNT_UPDATE_FREQUENCY_SEC", "60l")
buildConfigField("Long", "FAST_ACCOUNT_UPDATE_FREQUENCY_SEC", "5l")
buildConfigField("boolean", "FAIL_IDENTITY_CREATION", "false")
buildConfigField("boolean", "FORCE_NO_EMAIL_CLIENTS", "false")
buildConfigField("boolean", "SHOW_NEWSFEED", "true")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class AccountsOverviewFragment : BaseFragment() {
override fun onResume() {
super.onResume()
viewModel.updateState()
viewModel.initiateFrequentUpdater()
viewModel.initiateUpdater()
}

override fun onDestroy() {
Expand All @@ -124,7 +124,7 @@ class AccountsOverviewFragment : BaseFragment() {

override fun onPause() {
super.onPause()
viewModel.stopFrequentUpdater()
viewModel.stopUpdater()
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class AccountsOverviewViewModel(application: Application) : AndroidViewModel(app
private val ccdOnrampSiteRepository: CcdOnrampSiteRepository
private val accountsObserver: Observer<List<AccountWithIdentity>>
private val notificationsPreferences: NotificationsPreferences
private var updater: CountDownTimer? = null

private val updateNotificationsSubscriptionUseCase by lazy {
UpdateNotificationsSubscriptionUseCase(application)
Expand Down Expand Up @@ -105,6 +106,10 @@ class AccountsOverviewViewModel(application: Application) : AndroidViewModel(app
App.appCore.session.setAccountsBackedUp(false)
}
}
viewModelScope.launch {
postState(OnboardingState.DONE)
restartUpdater(BuildConfig.ACCOUNT_UPDATE_FREQUENCY_SEC)
}
}

override fun onError(stringRes: Int) {
Expand Down Expand Up @@ -185,10 +190,7 @@ class AccountsOverviewViewModel(application: Application) : AndroidViewModel(app
_identityFlow.emit(identity)
postState(OnboardingState.CREATE_ACCOUNT, zeroAccountBalances, notifyWaitingLiveData)
} else {
App.appCore.session.hasCompletedOnboarding()
postState(OnboardingState.DONE, notifyWaitingLiveData = notifyWaitingLiveData)
showSingleDialogIfNeeded()
updateSubmissionStatesAndBalances()
handleAccountCreation(notifyWaitingLiveData)
}
}

Expand All @@ -204,20 +206,36 @@ class AccountsOverviewViewModel(application: Application) : AndroidViewModel(app
}
}

private suspend fun handleAccountCreation(notifyWaitingLiveData: Boolean) {
val allAccounts = accountRepository.getAll()
if (allAccounts.any { it.transactionStatus == TransactionStatus.FINALIZED }) {
App.appCore.session.hasCompletedOnboarding()
postState(OnboardingState.DONE, notifyWaitingLiveData = notifyWaitingLiveData)
showSingleDialogIfNeeded()
} else {
postState(
state = OnboardingState.FINALIZING_ACCOUNT,
notifyWaitingLiveData = notifyWaitingLiveData
)
viewModelScope.launch { restartUpdater(BuildConfig.FAST_ACCOUNT_UPDATE_FREQUENCY_SEC) }
}
updateSubmissionStatesAndBalances()
}

private fun updateSubmissionStatesAndBalances(notifyWaitingLiveData: Boolean = true) {
if (notifyWaitingLiveData) {
_waitingLiveData.postValue(true)
}
accountUpdater.updateForAllAccounts()
}

fun initiateFrequentUpdater() {
updater.cancel()
updater.start()
fun initiateUpdater() {
startUpdater()
}

fun stopFrequentUpdater() {
updater.cancel()
fun stopUpdater() {
updater?.cancel()
updater = null
}

fun hasShowedInitialAnimation(): Boolean {
Expand All @@ -228,8 +246,9 @@ class AccountsOverviewViewModel(application: Application) : AndroidViewModel(app
App.appCore.session.setHasShowedInitialAnimation()
}

private var updater =
object : CountDownTimer(Long.MAX_VALUE, BuildConfig.ACCOUNT_UPDATE_FREQUENCY_SEC * 1000) {
private fun startUpdater(countdownInterval: Long = BuildConfig.ACCOUNT_UPDATE_FREQUENCY_SEC) {
stopUpdater()
updater = object : CountDownTimer(Long.MAX_VALUE, countdownInterval * 1000) {
private var first = true
override fun onTick(millisUntilFinished: Long) {
if (first) { // ignore first tick
Expand All @@ -244,7 +263,12 @@ class AccountsOverviewViewModel(application: Application) : AndroidViewModel(app

override fun onFinish() {
}
}
}.also { it.start() }
}

private fun restartUpdater(newInterval: Long) {
startUpdater(newInterval)
}

private fun isRegularUpdateNeeded(): Boolean {
this.accountRepository.allAccountsWithIdentity.value?.forEach { accountWithIdentity ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,22 @@ class OnboardingDataProvider(val context: Context) {
showInnerActionButton = true,
innerActionButtonTitle = context.getString(R.string.accounts_overview_create_account),
innerActionButtonBackground = R.drawable.ccx_button_primary_green_background
),
OnboardingStateModel(
state = OnboardingState.FINALIZING_ACCOUNT,
statusTitle = context.getString(R.string.onboarding_finalizing_account),
statusTextColor = context.getColor(R.color.cryptox_green_main),
statusDescription = "",
verificationStatusIcon = context.getDrawable(R.drawable.ccx_finalizing_account),
showVerificationStatusIcon = true,
identityVerificationStatus = IdentityStatus.DONE,
animateStatusIcon = true,
showProgressBar = false,
showActionButton = false,
actionButtonTitle = "",
showInnerActionButton = true,
innerActionButtonTitle = context.getString(R.string.accounts_overview_create_account),
innerActionButtonBackground = R.drawable.ccx_button_primary_green_inactive_background
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ class OnboardingFragment @JvmOverloads constructor(
}
}

OnboardingState.FINALIZING_ACCOUNT -> {
binding.onboardingInnerActionButton.setOnClickListener(null)
}

else -> {}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ enum class OnboardingState {
IDENTITY_IN_PROGRESS,
IDENTITY_UNSUCCESSFUL,
CREATE_ACCOUNT,
FINALIZING_ACCOUNT,
DONE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#067258" />
<corners android:radius="28dp" />
<stroke
android:width="1dp"
android:color="#1A0C0E11" />
</shape>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ccx_finalizing_account.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="11dp"
android:height="12dp"
android:viewportWidth="11"
android:viewportHeight="12">
<path
android:pathData="M11,6C11,9.038 8.538,11.5 5.5,11.5C2.462,11.5 0,9.038 0,6C0,2.962 2.462,0.5 5.5,0.5C8.538,0.5 11,2.962 11,6Z"
android:fillColor="#09CFA0"/>
</vector>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1181,5 +1181,6 @@
<string name="onboarding_identity_verification_in_progress">Verification in progress</string>
<string name="onboarding_identity_verification_completed">Verification completed</string>
<string name="onboarding_identity_verification_unsuccessful">Verification unsuccessful</string>
<string name="onboarding_finalizing_account">Finalizing account</string>
<string name="onboarding_identity_verification_status_icon">Identity verification status icon</string>
</resources>

0 comments on commit f584461

Please sign in to comment.