Skip to content

Commit

Permalink
Fix a bug with showSeedSettings result handling (#375)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdlaver authored Nov 27, 2024
1 parent 70a118b commit 0171a0c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,16 @@

package com.solanamobile.seedvaultimpl

import android.content.Context
import com.solanamobile.seedvaultimpl.data.SeedRepository
import com.goterl.lazysodium.LazySodiumAndroid
import com.goterl.lazysodium.SodiumAndroid
import kotlinx.coroutines.CoroutineScope
import java.nio.charset.StandardCharsets

/**
* Dependency injection container scoped to the Application. Contents will be lazily initialized
* where possible.
*/
class ApplicationDependencyContainer(private val applicationContext: Context) {

val seedRepository: SeedRepository by lazy {
SeedRepository(applicationContext)
}
class ApplicationDependencyContainer(val seedRepository: SeedRepository) {

// The companion object contains dependencies which should be globally available, but logically
// are still application dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
package com.solanamobile.seedvaultimpl

import android.app.Application
import com.solanamobile.seedvaultimpl.data.SeedRepository
import dagger.hilt.android.HiltAndroidApp
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import javax.inject.Inject

@HiltAndroidApp
class SeedVaultImplApplication : Application() {
@Inject
lateinit var seedRepository: SeedRepository

// TODO: remove dependencyContainer in favor of hilt/dagger injection
val dependencyContainer: ApplicationDependencyContainer by lazy {
ApplicationDependencyContainer(this)
ApplicationDependencyContainer(seedRepository)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,15 @@ internal class ShowSeedSettingsTestCase @Inject constructor(

try {
Wallet.onShowSeedSettingsResult(Activity.RESULT_OK, null)
logger.warn("Expected an exception when intent is null")
} catch (e: Exception) {
logger.warn("Unexpected exception for result ${Activity.RESULT_OK} when intent is null", e)
return false
} catch (_: Wallet.ActionFailedException) {
// No-op; fall through to next test case
}

try {
Wallet.onShowSeedSettingsResult(Activity.RESULT_CANCELED, null)
} catch (e: Exception) {
logger.warn("Unexpected exception when intent is null", e)
logger.warn("Unexpected exception for result ${Activity.RESULT_CANCELED} when intent is null", e)
return false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,6 @@ public static void onShowSeedSettingsResult(
@Nullable Intent result) throws ActionFailedException {
if (resultCode != Activity.RESULT_OK && resultCode != Activity.RESULT_CANCELED) {
throw new ActionFailedException("showSeedSettings failed with result=" + resultCode);
} else if (result == null) {
throw new ActionFailedException("showSeedSettings failed to return a result");
}
}

Expand Down

0 comments on commit 0171a0c

Please sign in to comment.