Updated on 2026-08-14
This commit is contained in:
parent
d443530171
commit
0f346ca611
1 changed files with 33 additions and 18 deletions
|
|
@ -65,9 +65,9 @@ internal class ResetCardsModel @Inject constructor(
|
||||||
isWarning = false,
|
isWarning = false,
|
||||||
onClick = {
|
onClick = {
|
||||||
modelScope.launch {
|
modelScope.launch {
|
||||||
repeatUntilTrue { resetPrimaryCard(createdUserWallet, userCodeParams) }
|
|
||||||
continuation.resume(Unit)
|
|
||||||
onDismissRequest()
|
onDismissRequest()
|
||||||
|
resetOrCancel { resetPrimaryCard(createdUserWallet, userCodeParams) }
|
||||||
|
continuation.resume(Unit)
|
||||||
startResetBackupCardsFlow(createdUserWallet, userCodeParams)
|
startResetBackupCardsFlow(createdUserWallet, userCodeParams)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -109,15 +109,16 @@ internal class ResetCardsModel @Inject constructor(
|
||||||
continuation.resume(Unit)
|
continuation.resume(Unit)
|
||||||
},
|
},
|
||||||
onReset = onReset@{
|
onReset = onReset@{
|
||||||
|
this@onReset.onDismissRequest()
|
||||||
|
|
||||||
modelScope.launch {
|
modelScope.launch {
|
||||||
repeatUntilTrue {
|
resetOrCancel {
|
||||||
resetBackupCard(
|
resetBackupCard(
|
||||||
cardNumber = index + 2,
|
cardNumber = index + 2,
|
||||||
params = userCodeParams,
|
params = userCodeParams,
|
||||||
userWalletId = createdUserWallet.walletId,
|
userWalletId = createdUserWallet.walletId,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
this@onReset.onDismissRequest()
|
|
||||||
continuation.resume(Unit)
|
continuation.resume(Unit)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -128,15 +129,17 @@ internal class ResetCardsModel @Inject constructor(
|
||||||
EventMessageAction(
|
EventMessageAction(
|
||||||
title = resourceReference(R.string.card_settings_action_sheet_reset),
|
title = resourceReference(R.string.card_settings_action_sheet_reset),
|
||||||
onClick = {
|
onClick = {
|
||||||
|
onDismissRequest()
|
||||||
|
|
||||||
modelScope.launch {
|
modelScope.launch {
|
||||||
repeatUntilTrue {
|
resetOrCancel {
|
||||||
resetBackupCard(
|
resetBackupCard(
|
||||||
cardNumber = index + 2,
|
cardNumber = index + 2,
|
||||||
params = userCodeParams,
|
params = userCodeParams,
|
||||||
userWalletId = createdUserWallet.walletId,
|
userWalletId = createdUserWallet.walletId,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
onDismissRequest()
|
|
||||||
continuation.resume(Unit)
|
continuation.resume(Unit)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -212,14 +215,32 @@ internal class ResetCardsModel @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private suspend fun resetOrCancel(action: suspend () -> Boolean) {
|
||||||
|
while (true) {
|
||||||
|
if (action()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
suspendCancellableCoroutine { continuation ->
|
||||||
|
recommendResetAgain(
|
||||||
|
onCancel = {
|
||||||
|
callbacks.onCancel()
|
||||||
|
continuation.cancel()
|
||||||
|
},
|
||||||
|
onReset = {
|
||||||
|
continuation.resume(Unit)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private suspend fun resetPrimaryCard(
|
private suspend fun resetPrimaryCard(
|
||||||
createdUserWallet: UserWallet.Cold,
|
createdUserWallet: UserWallet.Cold,
|
||||||
params: ResetCardUserCodeParams,
|
params: ResetCardUserCodeParams,
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val scanResponse = createdUserWallet.scanResponse
|
|
||||||
|
|
||||||
val result = resetCardUseCase.invoke(
|
val result = resetCardUseCase.invoke(
|
||||||
cardId = scanResponse.card.cardId,
|
cardId = createdUserWallet.scanResponse.card.cardId,
|
||||||
params = params,
|
params = params,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -233,14 +254,8 @@ internal class ResetCardsModel @Inject constructor(
|
||||||
): Boolean {
|
): Boolean {
|
||||||
return resetCardUseCase.invoke(
|
return resetCardUseCase.invoke(
|
||||||
cardNumber = cardNumber,
|
cardNumber = cardNumber,
|
||||||
params,
|
params = params,
|
||||||
userWalletId,
|
userWalletId = userWalletId,
|
||||||
).isRight()
|
).getOrNull() == true
|
||||||
}
|
|
||||||
|
|
||||||
private inline fun repeatUntilTrue(action: () -> Boolean) {
|
|
||||||
while (true) {
|
|
||||||
if (action()) break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue