Skip to content

Commit 007da1b

Browse files
committed
fix(flipcash/auth): don't lookup userId/entropy from UserManager prior to account purchase
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent c622833 commit 007da1b

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

apps/flipcash/shared/authentication/src/main/kotlin/com/flipcash/app/auth/internal/credentials/PassphraseCredentialManager.kt

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,32 +113,48 @@ class PassphraseCredentialManager @Inject constructor(
113113
}
114114

115115
suspend fun presentSaveOption(): Result<AccountMetadata> {
116-
val userId = userManager.accountId!!
117-
val entropy = userManager.entropy.orEmpty()
116+
val tempUserId = storage.data.map { it[temporaryUserIdKey] }.firstOrNull()
117+
val entropy = storage.data.map { it[temporaryEntropyKey] }.firstOrNull()
118+
119+
if (tempUserId == null) {
120+
return Result.failure(Throwable("No user id found"))
121+
}
122+
123+
if (entropy == null) {
124+
return Result.failure(Throwable("No entropy found"))
125+
}
126+
127+
val accountId = Base58.decode(tempUserId).toList()
118128

119129
// Store credential
120-
storeCredential(entropy, userId)
130+
storeCredential(entropy, accountId)
121131

122132
// Store metadata
123-
val metadata = AccountMetadata.createFromId(userId, entropy, isUnregistered = true)
133+
val metadata = AccountMetadata.createFromId(accountId, entropy, isUnregistered = true)
124134
storeMetadata(metadata, isSelected = false)
125135

126136
return Result.success(metadata)
127137
}
128138

129139
suspend fun onAccountPurchased(): Result<AccountMetadata> {
130-
val userId = userManager.accountId!!
131-
val entropy = userManager.entropy.orEmpty()
140+
val tempUserId = storage.data.map { it[temporaryUserIdKey] }.firstOrNull()
141+
val entropy = storage.data.map { it[temporaryEntropyKey] }.firstOrNull().orEmpty()
142+
143+
val accountId = runCatching { Base58.decode(tempUserId.orEmpty()).toList() }.getOrNull()
144+
145+
if (accountId == null) {
146+
return Result.failure(Throwable("No user id found"))
147+
}
132148

133149
// remove temporary states
134150
storage.edit {
135151
it.remove(temporaryEntropyKey)
136152
it.remove(temporaryUserIdKey)
137-
it.remove(seenAccessKeyKey(userId.base58))
153+
it.remove(seenAccessKeyKey(accountId.base58))
138154
}
139155

140156
// Store metadata
141-
val metadata = AccountMetadata.createFromId(userId, entropy, isUnregistered = false)
157+
val metadata = AccountMetadata.createFromId(accountId, entropy, isUnregistered = false)
142158
storeMetadata(metadata, isSelected = true)
143159

144160
return Result.success(metadata)

0 commit comments

Comments
 (0)