mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 16:05:20 +00:00
refactor getAndUpdateMintInfo
This commit is contained in:
@@ -55,22 +55,11 @@ class CashuService {
|
|||||||
return mints.any { it.url == mintUrl }
|
return mints.any { it.url == mintUrl }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private suspend fun getAndUpdateMintInfo(mintUrl: String): Result<MintInfo> {
|
||||||
* Add a mint if authorized (autoAdd = true)
|
|
||||||
*/
|
|
||||||
private suspend fun addMintIfAuthorized(mintUrl: String, autoAdd: Boolean): Result<Boolean> {
|
|
||||||
return withContext(Dispatchers.IO) {
|
return withContext(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
if (!autoAdd) {
|
|
||||||
Log.d(TAG, "Auto-add not authorized for mint: $mintUrl")
|
|
||||||
return@withContext Result.success(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
initializeRepository()
|
initializeRepository()
|
||||||
val repo = repository ?: return@withContext Result.failure(Exception("Repository not available"))
|
val repo = repository ?: return@withContext Result.failure(Exception("Repository not available"))
|
||||||
|
|
||||||
Log.d(TAG, "Adding mint automatically: $mintUrl")
|
|
||||||
|
|
||||||
val mintInfoResult = getMintInfo(mintUrl)
|
val mintInfoResult = getMintInfo(mintUrl)
|
||||||
if (mintInfoResult.isFailure) {
|
if (mintInfoResult.isFailure) {
|
||||||
val error = mintInfoResult.exceptionOrNull() ?: Exception("Unknown error")
|
val error = mintInfoResult.exceptionOrNull() ?: Exception("Unknown error")
|
||||||
@@ -94,6 +83,37 @@ class CashuService {
|
|||||||
Log.e(TAG, "Failed to save mint: $mintUrl", error)
|
Log.e(TAG, "Failed to save mint: $mintUrl", error)
|
||||||
return@withContext Result.failure(error)
|
return@withContext Result.failure(error)
|
||||||
}
|
}
|
||||||
|
return@withContext Result.success(mintInfo)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, "Exception while getting and updating mint info: $mintUrl", e)
|
||||||
|
return@withContext Result.failure(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a mint if authorized (autoAdd = true)
|
||||||
|
*/
|
||||||
|
private suspend fun addMintIfAuthorized(mintUrl: String, autoAdd: Boolean): Result<Boolean> {
|
||||||
|
return withContext(Dispatchers.IO) {
|
||||||
|
try {
|
||||||
|
if (!autoAdd) {
|
||||||
|
Log.d(TAG, "Auto-add not authorized for mint: $mintUrl")
|
||||||
|
return@withContext Result.success(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
initializeRepository()
|
||||||
|
val repo = repository ?: return@withContext Result.failure(Exception("Repository not available"))
|
||||||
|
|
||||||
|
Log.d(TAG, "Adding mint automatically: $mintUrl")
|
||||||
|
|
||||||
|
val mintInfoResult = getAndUpdateMintInfo(mintUrl)
|
||||||
|
if (mintInfoResult.isFailure) {
|
||||||
|
val error = mintInfoResult.exceptionOrNull() ?: Exception("Unknown error")
|
||||||
|
Log.e(TAG, "Failed to get mint info for: $mintUrl", error)
|
||||||
|
return@withContext Result.failure(error)
|
||||||
|
}
|
||||||
|
val mintInfo = mintInfoResult.getOrThrow()
|
||||||
|
|
||||||
Log.d(TAG, "Successfully added mint: $mintUrl")
|
Log.d(TAG, "Successfully added mint: $mintUrl")
|
||||||
return@withContext Result.success(true)
|
return@withContext Result.success(true)
|
||||||
|
|||||||
Reference in New Issue
Block a user