Updated on 2026-08-14
This commit is contained in:
parent
0b43caf853
commit
2e581a252f
6 changed files with 81 additions and 19 deletions
|
|
@ -38,6 +38,7 @@ import com.tangem.domain.transaction.usecase.ValidateWalletAddressUseCase
|
|||
import com.tangem.domain.transaction.usecase.ValidateWalletMemoUseCase
|
||||
import com.tangem.domain.txhistory.usecase.GetFixedTxHistoryItemsUseCase
|
||||
import com.tangem.domain.wallets.usecase.GetWalletsUseCase
|
||||
import com.tangem.features.addressbook.AddressBookFeatureToggles
|
||||
import com.tangem.features.addressbook.AddressBookSendAnalytics
|
||||
import com.tangem.features.addressbook.ContactSelectionListener
|
||||
import com.tangem.features.addressbook.MatchedContact
|
||||
|
|
@ -90,6 +91,7 @@ internal class SendDestinationModel @Inject constructor(
|
|||
private val sendBackupProblemEmailUseCase: SendBackupProblemEmailUseCase,
|
||||
private val addressBookSendAnalytics: AddressBookSendAnalytics,
|
||||
private val syncAddressBooksUseCase: SyncAddressBooksUseCase,
|
||||
private val addressBookFeatureToggles: AddressBookFeatureToggles,
|
||||
getContactsUseCase: GetContactsUseCase,
|
||||
contactSelectionListener: ContactSelectionListener,
|
||||
) : Model(), SendDestinationClickIntents {
|
||||
|
|
@ -141,7 +143,7 @@ internal class SendDestinationModel @Inject constructor(
|
|||
private val backupProblematicWalletCache = AtomicReference<Pair<String, UserWalletId?>?>(null)
|
||||
|
||||
init {
|
||||
modelScope.launch(context = dispatchers.default) { syncAddressBooksUseCase() }
|
||||
syncAddressBooksIfNeeded()
|
||||
subscribeOnQRScannerResult()
|
||||
initialState()
|
||||
resetContactOnEdit()
|
||||
|
|
@ -289,6 +291,12 @@ internal class SendDestinationModel @Inject constructor(
|
|||
}.launchIn(modelScope)
|
||||
}
|
||||
|
||||
private fun syncAddressBooksIfNeeded() {
|
||||
if (addressBookFeatureToggles.isAddressBookEnabled) {
|
||||
modelScope.launch(context = dispatchers.default) { syncAddressBooksUseCase() }
|
||||
}
|
||||
}
|
||||
|
||||
private fun subscribeOnQRScannerResult() {
|
||||
listenToQrScanningUseCase(SourceType.SEND)
|
||||
.getOrElse { emptyFlow() }
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import com.tangem.domain.transaction.usecase.ValidateWalletAddressUseCase
|
|||
import com.tangem.domain.transaction.usecase.ValidateWalletMemoUseCase
|
||||
import com.tangem.domain.txhistory.usecase.GetFixedTxHistoryItemsUseCase
|
||||
import com.tangem.domain.wallets.usecase.GetWalletsUseCase
|
||||
import com.tangem.features.addressbook.AddressBookFeatureToggles
|
||||
import com.tangem.features.addressbook.AddressBookSendAnalytics
|
||||
import com.tangem.features.addressbook.ContactSelectionListener
|
||||
import com.tangem.features.addressbook.MatchedContact
|
||||
|
|
@ -95,6 +96,7 @@ internal class SendDestinationModelTest {
|
|||
private val sendBackupProblemEmailUseCase: SendBackupProblemEmailUseCase = mockk(relaxed = true)
|
||||
private val getContactsUseCase: GetContactsUseCase = mockk(relaxed = true)
|
||||
private val syncAddressBooksUseCase: SyncAddressBooksUseCase = mockk(relaxed = true)
|
||||
private val addressBookFeatureToggles: AddressBookFeatureToggles = mockk(relaxed = true)
|
||||
private val contactSelectionListener: ContactSelectionListener = mockk(relaxed = true)
|
||||
private val addressBookSendAnalytics: AddressBookSendAnalytics = mockk(relaxed = true)
|
||||
private val callback: SendDestinationComponent.ModelCallback = mockk(relaxed = true)
|
||||
|
|
@ -515,6 +517,36 @@ internal class SendDestinationModelTest {
|
|||
)
|
||||
}
|
||||
|
||||
@Nested
|
||||
inner class SyncAddressBooks {
|
||||
|
||||
@Test
|
||||
fun `GIVEN address book enabled WHEN model initialized THEN sync address books`() = runTest {
|
||||
// Arrange
|
||||
every { addressBookFeatureToggles.isAddressBookEnabled } returns true
|
||||
|
||||
// Act
|
||||
buildModel()
|
||||
advanceUntilIdle()
|
||||
|
||||
// Assert
|
||||
coVerify(exactly = 1) { syncAddressBooksUseCase() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN address book disabled WHEN model initialized THEN do NOT sync address books`() = runTest {
|
||||
// Arrange
|
||||
every { addressBookFeatureToggles.isAddressBookEnabled } returns false
|
||||
|
||||
// Act
|
||||
buildModel()
|
||||
advanceUntilIdle()
|
||||
|
||||
// Assert
|
||||
coVerify(exactly = 0) { syncAddressBooksUseCase() }
|
||||
}
|
||||
}
|
||||
|
||||
// region fixtures
|
||||
|
||||
private fun TestScope.buildModel(
|
||||
|
|
@ -574,6 +606,7 @@ internal class SendDestinationModelTest {
|
|||
sendBackupProblemEmailUseCase = sendBackupProblemEmailUseCase,
|
||||
addressBookSendAnalytics = addressBookSendAnalytics,
|
||||
syncAddressBooksUseCase = syncAddressBooksUseCase,
|
||||
addressBookFeatureToggles = addressBookFeatureToggles,
|
||||
getContactsUseCase = getContactsUseCase,
|
||||
contactSelectionListener = contactSelectionListener,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue