-
Notifications
You must be signed in to change notification settings - Fork 4
fix: align pubky and paykit ui #1097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ovitrif
merged 3 commits into
codex/paykit-watch-only-accounts
from
codex/970-pubky-paykit-ui-parity
Jul 27, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
app/src/androidTest/java/to/bitkit/ui/components/TagButtonTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package to.bitkit.ui.components | ||
|
|
||
| import androidx.compose.ui.test.assertHasClickAction | ||
| import androidx.compose.ui.test.junit4.createComposeRule | ||
| import androidx.compose.ui.test.onNodeWithContentDescription | ||
| import androidx.compose.ui.test.onNodeWithTag | ||
| import dagger.hilt.android.testing.HiltAndroidRule | ||
| import dagger.hilt.android.testing.HiltAndroidTest | ||
| import org.junit.Before | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
| import to.bitkit.test.annotations.ComposeUi | ||
| import to.bitkit.ui.theme.AppThemeSurface | ||
|
|
||
| @HiltAndroidTest | ||
| @ComposeUi | ||
| class TagButtonTest { | ||
| @get:Rule | ||
| val hiltRule = HiltAndroidRule(this) | ||
|
|
||
| @get:Rule | ||
| val composeTestRule = createComposeRule() | ||
|
|
||
| @Before | ||
| fun setup() { | ||
| hiltRule.inject() | ||
| } | ||
|
|
||
| @Test | ||
| fun removableTagExposesItsAction() { | ||
| composeTestRule.setContent { | ||
| AppThemeSurface { | ||
| TagButton( | ||
| text = "Founder", | ||
| onClick = {}, | ||
| accessibilityLabel = "Remove Founder tag", | ||
| displayIconClose = true, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| composeTestRule.onNodeWithContentDescription("Remove Founder tag") | ||
| .assertHasClickAction() | ||
| composeTestRule.onNodeWithTag("Tag-Founder") | ||
| .assertHasClickAction() | ||
| } | ||
| } |
90 changes: 90 additions & 0 deletions
90
app/src/androidTest/java/to/bitkit/ui/components/settings/SettingsSwitchRowTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| package to.bitkit.ui.components.settings | ||
|
|
||
| import androidx.compose.ui.semantics.Role | ||
| import androidx.compose.ui.semantics.SemanticsProperties | ||
| import androidx.compose.ui.test.SemanticsMatcher | ||
| import androidx.compose.ui.test.assert | ||
| import androidx.compose.ui.test.assertHasClickAction | ||
| import androidx.compose.ui.test.assertIsEnabled | ||
| import androidx.compose.ui.test.assertIsNotEnabled | ||
| import androidx.compose.ui.test.assertIsOff | ||
| import androidx.compose.ui.test.assertIsOn | ||
| import androidx.compose.ui.test.junit4.createComposeRule | ||
| import androidx.compose.ui.test.onNodeWithTag | ||
| import dagger.hilt.android.testing.HiltAndroidRule | ||
| import dagger.hilt.android.testing.HiltAndroidTest | ||
| import org.junit.Before | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
| import to.bitkit.test.annotations.ComposeUi | ||
| import to.bitkit.ui.theme.AppThemeSurface | ||
|
|
||
| @HiltAndroidTest | ||
| @ComposeUi | ||
| class SettingsSwitchRowTest { | ||
| @get:Rule | ||
| val hiltRule = HiltAndroidRule(this) | ||
|
|
||
| @get:Rule | ||
| val composeTestRule = createComposeRule() | ||
|
|
||
| @Before | ||
| fun setup() { | ||
| hiltRule.inject() | ||
| } | ||
|
|
||
| @Test | ||
| fun switchSemanticsReflectCheckedState() { | ||
| composeTestRule.setContent { | ||
| AppThemeSurface { | ||
| SettingsSwitchRow( | ||
| title = "Contact payments", | ||
| isChecked = true, | ||
| onClick = {}, | ||
| switchTestTag = "ContactPaymentsSwitch", | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| composeTestRule.onNodeWithTag("ContactPaymentsSwitch") | ||
| .assertIsOn() | ||
| .assertIsEnabled() | ||
| .assertHasClickAction() | ||
| .assert(SemanticsMatcher.expectValue(SemanticsProperties.Role, Role.Switch)) | ||
| } | ||
|
|
||
| @Test | ||
| fun switchSemanticsReflectUncheckedState() { | ||
| composeTestRule.setContent { | ||
| AppThemeSurface { | ||
| SettingsSwitchRow( | ||
| title = "Contact payments", | ||
| isChecked = false, | ||
| onClick = {}, | ||
| switchTestTag = "ContactPaymentsSwitch", | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| composeTestRule.onNodeWithTag("ContactPaymentsSwitch").assertIsOff() | ||
| } | ||
|
|
||
| @Test | ||
| fun switchSemanticsReflectDisabledState() { | ||
| composeTestRule.setContent { | ||
| AppThemeSurface { | ||
| SettingsSwitchRow( | ||
| title = "Contact payments", | ||
| isChecked = false, | ||
| onClick = {}, | ||
| enabled = false, | ||
| switchTestTag = "ContactPaymentsSwitch", | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| composeTestRule.onNodeWithTag("ContactPaymentsSwitch") | ||
| .assertIsOff() | ||
| .assertIsNotEnabled() | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
170 changes: 170 additions & 0 deletions
170
app/src/main/java/to/bitkit/repositories/ContactPaymentSettingsRepo.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| package to.bitkit.repositories | ||
|
|
||
| import kotlinx.coroutines.CoroutineDispatcher | ||
| import kotlinx.coroutines.flow.Flow | ||
| import kotlinx.coroutines.flow.first | ||
| import kotlinx.coroutines.flow.map | ||
| import kotlinx.coroutines.withContext | ||
| import to.bitkit.data.SettingsData | ||
| import to.bitkit.data.SettingsStore | ||
| import to.bitkit.data.areContactPaymentsEnabled | ||
| import to.bitkit.di.IoDispatcher | ||
| import to.bitkit.ext.runSuspendCatching | ||
| import javax.inject.Inject | ||
| import javax.inject.Singleton | ||
|
|
||
| @Singleton | ||
| class ContactPaymentSettingsRepo @Inject constructor( | ||
| private val settingsStore: SettingsStore, | ||
| private val publicPaykitRepo: PublicPaykitRepo, | ||
| private val privatePaykitRepo: PrivatePaykitRepo, | ||
| private val pubkyRepo: PubkyRepo, | ||
| @IoDispatcher private val ioDispatcher: CoroutineDispatcher, | ||
| ) { | ||
| val isEnabled: Flow<Boolean> = settingsStore.data.map { it.areContactPaymentsEnabled() } | ||
|
|
||
| suspend fun setEnabled(isEnabled: Boolean): Result<Unit> = withContext(ioDispatcher) { | ||
| val contacts = pubkyRepo.contacts.value.map { it.publicKey } | ||
| if (isEnabled) enable(contacts) else disable(contacts) | ||
| } | ||
|
|
||
| private suspend fun enable(contacts: List<String>): Result<Unit> { | ||
| val previous = settingsStore.data.first() | ||
| val canUsePrivateContactPayments = pubkyRepo.hasSecretKey() | ||
| return runSuspendCatching { | ||
| settingsStore.update { | ||
| it.copy( | ||
| hasConfirmedPublicPaykitEndpoints = true, | ||
| sharesPublicPaykitEndpoints = true, | ||
| sharesPrivatePaykitEndpoints = canUsePrivateContactPayments, | ||
| publicPaykitLightningEnabled = true, | ||
| publicPaykitOnchainEnabled = true, | ||
| ) | ||
| } | ||
| publicPaykitRepo.syncPublishedEndpoints(publish = true).getOrThrow() | ||
|
|
||
| if (canUsePrivateContactPayments) { | ||
| privatePaykitRepo.enableSharingAndPrepareSavedContacts( | ||
| publicKeys = contacts, | ||
| requireImmediatePublication = true, | ||
| ).getOrThrow() | ||
| } | ||
| }.onFailure { rollbackEnabled(previous, contacts, it) } | ||
| } | ||
|
|
||
| private suspend fun rollbackEnabled( | ||
| previous: SettingsData, | ||
| contacts: List<String>, | ||
| error: Throwable, | ||
| ) { | ||
| runSuspendCatching { | ||
| settingsStore.update { | ||
| it.copy( | ||
| hasConfirmedPublicPaykitEndpoints = previous.hasConfirmedPublicPaykitEndpoints, | ||
| sharesPublicPaykitEndpoints = previous.sharesPublicPaykitEndpoints, | ||
| sharesPrivatePaykitEndpoints = previous.sharesPrivatePaykitEndpoints, | ||
| publicPaykitLightningEnabled = previous.publicPaykitLightningEnabled, | ||
| publicPaykitOnchainEnabled = previous.publicPaykitOnchainEnabled, | ||
| ) | ||
| } | ||
| }.onFailure(error::addSuppressed) | ||
| publicPaykitRepo.syncPublishedEndpoints(publish = previous.sharesPublicPaykitEndpoints) | ||
| .onFailure { | ||
| error.addSuppressed(it) | ||
| markPublicPaykitRetry(error) | ||
| } | ||
| if (previous.sharesPrivatePaykitEndpoints) { | ||
| privatePaykitRepo.enableSharingAndPrepareSavedContacts( | ||
| publicKeys = contacts, | ||
| requireImmediatePublication = true, | ||
| ).onFailure(error::addSuppressed) | ||
| } else { | ||
| privatePaykitRepo.disableSharingAndPruneUnsavedContactState(contacts) | ||
| .onFailure(error::addSuppressed) | ||
| } | ||
| } | ||
|
|
||
| private suspend fun disable(contacts: List<String>): Result<Unit> { | ||
| val previous = settingsStore.data.first() | ||
| runSuspendCatching { | ||
| settingsStore.update { | ||
| it.copy( | ||
| hasConfirmedPublicPaykitEndpoints = true, | ||
| sharesPublicPaykitEndpoints = false, | ||
| sharesPrivatePaykitEndpoints = false, | ||
| publicPaykitLightningEnabled = true, | ||
| publicPaykitOnchainEnabled = true, | ||
| ) | ||
| } | ||
| }.onFailure { | ||
| return Result.failure(it) | ||
| } | ||
|
|
||
| var publicCleanupError: Throwable? = null | ||
| var privateCleanupError: Throwable? = null | ||
| publicPaykitRepo.syncPublishedEndpoints(publish = false) | ||
| .onFailure { publicCleanupError = it } | ||
|
|
||
| privatePaykitRepo.disableSharingAndPruneUnsavedContactState(contacts) | ||
| .onFailure { privateCleanupError = it } | ||
|
|
||
| publicCleanupError?.let { error -> | ||
| runSuspendCatching { | ||
| settingsStore.update { settings -> | ||
| settings.copy(sharesPublicPaykitEndpoints = previous.sharesPublicPaykitEndpoints) | ||
| } | ||
| }.onFailure(error::addSuppressed) | ||
| publicPaykitRepo.syncPublishedEndpoints(publish = previous.sharesPublicPaykitEndpoints) | ||
| .onFailure { | ||
| error.addSuppressed(it) | ||
| markPublicPaykitRetry(error) | ||
| } | ||
| } | ||
| privateCleanupError?.let { error -> | ||
| if (previous.sharesPrivatePaykitEndpoints) { | ||
| restorePrivate(contacts, error) | ||
| } else { | ||
| updatePrivatePreference(isEnabled = false, error = error) | ||
| } | ||
| } | ||
|
|
||
| val cleanupError = publicCleanupError ?: privateCleanupError | ||
| publicCleanupError?.let { publicError -> | ||
| privateCleanupError?.let { publicError.addSuppressed(it) } | ||
| } | ||
| cleanupError?.let { return Result.failure(it) } | ||
|
|
||
| return Result.success(Unit) | ||
| } | ||
|
|
||
| private suspend fun restorePrivate( | ||
| contacts: List<String>, | ||
| error: Throwable, | ||
| ) { | ||
| if (!updatePrivatePreference(isEnabled = true, error = error)) return | ||
|
|
||
| privatePaykitRepo.enableSharingAndPrepareSavedContacts( | ||
| publicKeys = contacts, | ||
| requireImmediatePublication = true, | ||
| ).exceptionOrNull()?.let { | ||
| error.addSuppressed(it) | ||
| updatePrivatePreference(isEnabled = false, error = error) | ||
| return | ||
| } | ||
|
|
||
| publicPaykitRepo.syncLocalReceiverMarker().onFailure(error::addSuppressed) | ||
| } | ||
|
|
||
| private suspend fun markPublicPaykitRetry(error: Throwable) { | ||
| runSuspendCatching { | ||
| settingsStore.update { it.copy(publicPaykitCleanupPending = true) } | ||
| }.onFailure(error::addSuppressed) | ||
| } | ||
|
|
||
| private suspend fun updatePrivatePreference( | ||
| isEnabled: Boolean, | ||
| error: Throwable, | ||
| ): Boolean = runSuspendCatching { | ||
| settingsStore.update { it.copy(sharesPrivatePaykitEndpoints = isEnabled) } | ||
| }.onFailure(error::addSuppressed).isSuccess | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this repository should follow the existing repository pattern and own an application-lived scope composed from
ioDispatcher, for examplescope = appScope(ioDispatcher, TAG).setEnabled()updates the persisted settings and publishes or removes the Paykit endpoints → that work should run in the repository scope so navigating away and clearing the calling ViewModel does not cancel it midway.Not blocking.