Skip to content

Commit a9d8ccd

Browse files
authored
Disable Paste button while processing request (#6051)
Task/Issue URL: https://app.asana.com/1/137249556945/project/1203822806345703/task/1210183822217249?focus=true ### Description Disables paste button while processing request. Includes fix: update viewstate to idle after error. ### Steps to test this PR Disables paste button while processing request. Includes fix: update viewstate to idle after error. _Test the connect device sync flow (manually enter code) under the following scenarios_ - [x] using an invalid code - [x] using the recovery code of an deleted account (you can create one, copy code, and delete before testing) - [ ] using a valid recovery code / exchange code / connect code -> ensure in all of them, button is disabled while processing, enabled once finished (error or success) ### UI changes | Before | After | | ------ | ----- | !(Upload before screenshot)|(Upload after screenshot)|
1 parent 3a7b85f commit a9d8ccd

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

sync/sync-impl/src/main/java/com/duckduckgo/sync/impl/ui/EnterCodeActivity.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,17 @@ class EnterCodeActivity : DuckDuckGoActivity() {
8484
AuthState.Error -> {
8585
binding.loadingIndicatorContainer.hide()
8686
binding.errorAuthStateHint.show()
87+
binding.pasteCodeButton.isEnabled = true
8788
}
8889
Idle -> {
8990
binding.loadingIndicatorContainer.hide()
9091
binding.errorAuthStateHint.hide()
92+
binding.pasteCodeButton.isEnabled = true
9193
}
9294
Loading -> {
9395
binding.loadingIndicatorContainer.show()
9496
binding.errorAuthStateHint.hide()
97+
binding.pasteCodeButton.isEnabled = false
9598
}
9699
}
97100
}

sync/sync-impl/src/main/java/com/duckduckgo/sync/impl/ui/EnterCodeViewModel.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ class EnterCodeViewModel @Inject constructor(
177177
INVALID_CODE.code -> R.string.sync_invalid_code_error
178178
else -> null
179179
}?.let { message ->
180+
viewState.value = viewState.value.copy(authState = AuthState.Idle)
180181
command.send(
181182
ShowError(
182183
message = message,
@@ -204,6 +205,7 @@ class EnterCodeViewModel @Inject constructor(
204205
ShowError(message = message, reason = result.reason),
205206
)
206207
}
208+
viewState.value = viewState.value.copy(authState = AuthState.Idle)
207209
} else {
208210
syncPixels.fireUserSwitchedAccount()
209211
command.send(SwitchAccountSuccess)
@@ -212,7 +214,10 @@ class EnterCodeViewModel @Inject constructor(
212214
}
213215

214216
fun onUserCancelledJoiningNewAccount() {
215-
syncPixels.fireUserCancelledSwitchingAccount()
217+
viewModelScope.launch(dispatchers.io()) {
218+
syncPixels.fireUserCancelledSwitchingAccount()
219+
viewState.value = viewState.value.copy(authState = AuthState.Idle)
220+
}
216221
}
217222

218223
fun onUserAskedToSwitchAccount() {

sync/sync-impl/src/test/java/com/duckduckgo/sync/impl/ui/EnterCodeViewModelTest.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ internal class EnterCodeViewModelTest {
241241
}
242242

243243
@Test
244-
fun whenProcessCodeAndLoginFailsThenShowError() = runTest {
244+
fun whenProcessCodeAndLoginFailsThenShowErrorAndUpdateState() = runTest {
245245
whenever(syncAccountRepository.getAccountInfo()).thenReturn(noAccount)
246246
whenever(clipboard.pasteFromClipboard()).thenReturn(jsonRecoveryKeyEncoded)
247247
whenever(syncAccountRepository.parseSyncAuthCode(jsonRecoveryKeyEncoded)).thenReturn(Recovery(RecoveryCode(jsonRecoveryKey, primaryKey)))
@@ -256,6 +256,20 @@ internal class EnterCodeViewModelTest {
256256
}
257257
}
258258

259+
@Test
260+
fun whenProcessCodeAndLoginFailsThenUpdateStateToIdle() = runTest {
261+
whenever(syncAccountRepository.getAccountInfo()).thenReturn(noAccount)
262+
whenever(clipboard.pasteFromClipboard()).thenReturn(jsonRecoveryKeyEncoded)
263+
whenever(syncAccountRepository.processCode(jsonRecoveryKeyEncoded)).thenReturn(Error(code = LOGIN_FAILED.code))
264+
265+
testee.onPasteCodeClicked()
266+
267+
testee.viewState().test {
268+
assertTrue(awaitItem().authState == Idle)
269+
cancelAndIgnoreRemainingEvents()
270+
}
271+
}
272+
259273
@Test
260274
fun whenProcessCodeAndConnectFailsThenShowError() = runTest {
261275
whenever(syncAccountRepository.getAccountInfo()).thenReturn(noAccount)

0 commit comments

Comments
 (0)