Skip to content

Commit ebd1fe1

Browse files
committed
fix: address claude review
1 parent 4033b1e commit ebd1fe1

6 files changed

Lines changed: 67 additions & 53 deletions

File tree

app/src/main/java/to/bitkit/repositories/PubkyRepo.kt

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@ class PubkyRepo @Inject constructor(
6969
}
7070

7171
private val scope = CoroutineScope(ioDispatcher + SupervisorJob())
72+
private val serviceInitializeMutex = Mutex()
7273
private val initializeMutex = Mutex()
7374
private val loadProfileMutex = Mutex()
7475
private val loadContactsMutex = Mutex()
76+
private var isServiceInitialized = false
7577

7678
private val _authState = MutableStateFlow(PubkyAuthState.Idle)
7779

@@ -126,11 +128,15 @@ class PubkyRepo @Inject constructor(
126128
// region Initialization
127129

128130
suspend fun initialize() = withContext(ioDispatcher) {
131+
runCatching {
132+
ensureServiceInitialized()
133+
}.onFailure {
134+
Logger.error("Failed to initialize paykit", it, context = TAG)
135+
}.getOrNull() ?: return@withContext
136+
129137
initializeMutex.withLock {
130138
_sessionRestorationFailed.update { false }
131139
val result = runCatching {
132-
pubkyService.initialize()
133-
134140
val savedSessionSecret = runCatching {
135141
keychain.loadString(Keychain.Key.PAYKIT_SESSION.name)
136142
}.getOrNull()
@@ -166,6 +172,15 @@ class PubkyRepo @Inject constructor(
166172
}
167173
}
168174

175+
private suspend fun ensureServiceInitialized() = withContext(ioDispatcher) {
176+
serviceInitializeMutex.withLock {
177+
if (!isServiceInitialized) {
178+
pubkyService.initialize()
179+
isServiceInitialized = true
180+
}
181+
}
182+
}
183+
169184
private suspend fun resolveSessionInitialization(
170185
savedSessionSecret: String?,
171186
storedSecretKeyHex: String?,
@@ -757,12 +772,14 @@ class PubkyRepo @Inject constructor(
757772

758773
suspend fun restoreSessionBackupState(backup: PubkySessionBackupV1?): Result<Unit> = runCatching {
759774
withContext(ioDispatcher) {
760-
initializeMutex.withLock {
761-
if (backup == null) {
762-
notifyBackupStateChanged()
763-
return@withLock
764-
}
775+
if (backup == null) {
776+
notifyBackupStateChanged()
777+
return@withContext
778+
}
765779

780+
ensureServiceInitialized()
781+
782+
initializeMutex.withLock {
766783
pubkyService.forceSignOut()
767784
clearAuthenticatedState()
768785
runCatching { keychain.delete(Keychain.Key.PAYKIT_SESSION.name) }

app/src/main/java/to/bitkit/ui/components/CenteredProfileHeader.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fun CenteredProfileHeader(
3535
) {
3636
Column(
3737
horizontalAlignment = Alignment.CenterHorizontally,
38-
modifier = modifier,
38+
modifier = modifier
3939
) {
4040
Text13Up(
4141
text = publicKey.ellipsisMiddle(TRUNCATED_PK_LENGTH),
@@ -53,13 +53,13 @@ fun CenteredProfileHeader(
5353
modifier = Modifier
5454
.size(100.dp)
5555
.clip(CircleShape)
56-
.background(Colors.Gray5),
56+
.background(Colors.Gray5)
5757
) {
5858
Icon(
5959
painter = painterResource(R.drawable.ic_user_square),
6060
contentDescription = null,
6161
tint = Colors.White32,
62-
modifier = Modifier.size(50.dp),
62+
modifier = Modifier.size(50.dp)
6363
)
6464
}
6565
}
@@ -71,7 +71,7 @@ fun CenteredProfileHeader(
7171
maxLines = 2,
7272
overflow = TextOverflow.Ellipsis,
7373
textAlign = TextAlign.Center,
74-
modifier = if (nameTestTag != null) Modifier.testTag(nameTestTag) else Modifier,
74+
modifier = if (nameTestTag != null) Modifier.testTag(nameTestTag) else Modifier
7575
)
7676

7777
if (bio.isNotEmpty()) {
@@ -80,7 +80,7 @@ fun CenteredProfileHeader(
8080
text = bio,
8181
color = Colors.White64,
8282
textAlign = TextAlign.Center,
83-
modifier = if (notesTestTag != null) Modifier.testTag(notesTestTag) else Modifier,
83+
modifier = if (notesTestTag != null) Modifier.testTag(notesTestTag) else Modifier
8484
)
8585
}
8686
}

app/src/main/java/to/bitkit/ui/components/ProfileEditForm.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,13 @@ fun ProfileEditForm(
159159
)
160160
IconButton(
161161
onClick = { onRemoveLink(index) },
162-
modifier = Modifier.testTag("ProfileEditLinkRemove_$index"),
162+
modifier = Modifier.testTag("ProfileEditLinkRemove_$index")
163163
) {
164164
Icon(
165165
painter = painterResource(R.drawable.ic_trash),
166166
contentDescription = null,
167167
tint = Colors.White64,
168-
modifier = Modifier.size(16.dp),
168+
modifier = Modifier.size(16.dp)
169169
)
170170
}
171171
}
@@ -279,7 +279,7 @@ fun ProfileEditForm(
279279
modifier = Modifier.size(16.dp)
280280
)
281281
},
282-
modifier = Modifier.testTag("ProfileEditDelete"),
282+
modifier = Modifier.testTag("ProfileEditDelete")
283283
)
284284
}
285285
}

app/src/main/java/to/bitkit/ui/components/Text.kt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fun Display(
3838
maxLines = maxLines,
3939
overflow = overflow,
4040
textAlign = textAlign,
41-
modifier = modifier,
41+
modifier = modifier
4242
)
4343
}
4444

@@ -53,7 +53,7 @@ fun Display(
5353
style = AppTextStyles.Display.merge(
5454
color = color,
5555
),
56-
modifier = modifier,
56+
modifier = modifier
5757
)
5858
}
5959

@@ -68,7 +68,7 @@ fun Headline(
6868
style = AppTextStyles.Headline.merge(
6969
color = color,
7070
),
71-
modifier = modifier,
71+
modifier = modifier
7272
)
7373
}
7474

@@ -86,7 +86,7 @@ fun Headline20(
8686
letterSpacing = (-.5).sp,
8787
color = color,
8888
),
89-
modifier = modifier,
89+
modifier = modifier
9090
)
9191
}
9292

@@ -103,7 +103,7 @@ fun Headline24(
103103
lineHeight = 24.sp,
104104
color = color,
105105
),
106-
modifier = modifier,
106+
modifier = modifier
107107
)
108108
}
109109

@@ -124,7 +124,7 @@ fun Title(
124124
color = color,
125125
textAlign = textAlign,
126126
),
127-
modifier = modifier,
127+
modifier = modifier
128128
)
129129
}
130130

@@ -145,7 +145,7 @@ fun Subtitle(
145145
),
146146
maxLines = maxLines,
147147
overflow = overflow,
148-
modifier = modifier,
148+
modifier = modifier
149149
)
150150
}
151151

@@ -189,7 +189,7 @@ fun BodyM(
189189
maxLines = maxLines,
190190
minLines = minLines,
191191
overflow = overflow,
192-
modifier = modifier,
192+
modifier = modifier
193193
)
194194
}
195195

@@ -229,7 +229,7 @@ fun BodyMSB(
229229
),
230230
maxLines = maxLines,
231231
overflow = overflow,
232-
modifier = modifier,
232+
modifier = modifier
233233
)
234234
}
235235

@@ -250,7 +250,7 @@ fun BodyMB(
250250
),
251251
maxLines = maxLines,
252252
overflow = overflow,
253-
modifier = modifier,
253+
modifier = modifier
254254
)
255255
}
256256

@@ -343,7 +343,7 @@ fun BodySB(
343343
color = color,
344344
textAlign = textAlign,
345345
),
346-
modifier = modifier,
346+
modifier = modifier
347347
)
348348
}
349349

@@ -360,7 +360,7 @@ fun Text13Up(
360360
color = color,
361361
textAlign = textAlign,
362362
),
363-
modifier = modifier,
363+
modifier = modifier
364364
)
365365
}
366366

@@ -381,7 +381,7 @@ fun Caption(
381381
),
382382
maxLines = maxLines,
383383
overflow = overflow,
384-
modifier = modifier,
384+
modifier = modifier
385385
)
386386
}
387387

@@ -438,7 +438,7 @@ fun Caption13Up(
438438
color = color,
439439
textAlign = textAlign,
440440
),
441-
modifier = modifier,
441+
modifier = modifier
442442
)
443443
}
444444

@@ -459,6 +459,6 @@ fun Footnote(
459459
),
460460
maxLines = maxLines,
461461
overflow = overflow,
462-
modifier = modifier,
462+
modifier = modifier
463463
)
464464
}

app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ import to.bitkit.models.NewTransactionSheetDetails
9595
import to.bitkit.models.NewTransactionSheetDirection
9696
import to.bitkit.models.NewTransactionSheetType
9797
import to.bitkit.models.NodeLifecycleState
98+
import to.bitkit.models.PubkyProfile
99+
import to.bitkit.models.PubkyPublicKeyFormat
98100
import to.bitkit.models.Suggestion
99101
import to.bitkit.models.Toast
100102
import to.bitkit.models.TransactionSpeed
@@ -2724,3 +2726,21 @@ sealed interface QuickPayData {
27242726
data class LnurlPay(override val sats: ULong, val callback: String, val amountMsats: ULong) : QuickPayData
27252727
}
27262728
// endregion
2729+
2730+
internal fun resolvePastedPubkyRoute(
2731+
input: String,
2732+
ownPublicKey: String?,
2733+
contacts: List<PubkyProfile>,
2734+
): Routes? {
2735+
val normalizedKey = PubkyPublicKeyFormat.normalized(input) ?: return null
2736+
2737+
if (PubkyPublicKeyFormat.matches(normalizedKey, ownPublicKey)) {
2738+
return Routes.Profile
2739+
}
2740+
2741+
if (contacts.any { PubkyPublicKeyFormat.matches(it.publicKey, normalizedKey) }) {
2742+
return Routes.ContactDetail(normalizedKey)
2743+
}
2744+
2745+
return Routes.AddContact(normalizedKey)
2746+
}

app/src/main/java/to/bitkit/viewmodels/PubkyRouteResolver.kt

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)