This commit is contained in:
SatoshiQaziMuhammed authored and GitHub committed 2026-11-04 01:46:40 +00:00
commit 00bd5c043d
8 files changed
+1954 -2628

No files matched your search

@@ -3,6 +3,7 @@ package io.novafoundation.nova.app
import android.app.Application
import android.content.Context
import android.content.res.Configuration
import android.util.Log
import com.walletconnect.android.Core
import com.walletconnect.android.CoreClient
import com.walletconnect.android.relay.ConnectionType
@@ -14,6 +15,7 @@ import io.novafoundation.nova.common.di.CommonApi
import io.novafoundation.nova.common.di.FeatureContainer
import io.novafoundation.nova.common.resources.ContextManager
import io.novafoundation.nova.common.resources.LanguagesHolder
import io.novafoundation.nova.common.utils.LOG_TAG
import io.novafoundation.nova.common.utils.coroutines.RootScope
import io.novafoundation.nova.feature_wallet_connect_impl.BuildConfig
import javax.inject.Inject
@@ -85,13 +87,15 @@ open class App : Application(), FeatureContainer {
)
CoreClient.initialize(relayServerUrl = serverUrl, connectionType = connectionType, application = this, metaData = appMetaData) { error ->
// TODO maybe re-initialize client
// Initialization fails only on bad configuration (project id, metadata), which a retry would not fix.
// The relay itself connects later, on demand, in RealWalletConnectService
Log.e(LOG_TAG, "Failed to initialize Wallet Connect core", error.throwable)
}
val initParams = Wallet.Params.Init(core = CoreClient)
Web3Wallet.initialize(initParams) { error ->
// TODO maybe re-initialize client
Log.e(LOG_TAG, "Failed to initialize Web3Wallet", error.throwable)
}
}
}
@@ -29,8 +29,8 @@ class BaseException(
return BaseException(Kind.NETWORK, message, exception)
}
fun unexpectedError(exception: Throwable): BaseException {
return BaseException(Kind.UNEXPECTED, exception.message ?: "", exception)
fun unexpectedError(fallbackMessage: String, exception: Throwable): BaseException {
return BaseException(Kind.UNEXPECTED, exception.message ?: fallbackMessage, exception)
}
}
}
@@ -1,5 +1,6 @@
package io.novafoundation.nova.common.base.errors
import io.novafoundation.nova.common.R
import io.novafoundation.nova.common.resources.ResourceManager
class NovaException(
@@ -16,11 +17,7 @@ class NovaException(
companion object {
fun networkError(resourceManager: ResourceManager, throwable: Throwable): NovaException {
return NovaException(Kind.NETWORK, "", throwable) // TODO: add common error text to resources
}
fun unexpectedError(exception: Throwable): NovaException {
return NovaException(Kind.UNEXPECTED, exception.message ?: "", exception) // TODO: add common error text to resources
return NovaException(Kind.NETWORK, resourceManager.getString(R.string.connection_error_message_v2_2_0), throwable)
}
}
}
@@ -28,7 +28,7 @@ class HttpExceptionHandler(
BaseException.httpError(errorCode, resourceManager.getString(R.string.common_undefined_error_message))
}
is IOException -> BaseException.networkError(resourceManager.getString(R.string.connection_error_message_v2_2_0), exception)
else -> BaseException.unexpectedError(exception)
else -> BaseException.unexpectedError(resourceManager.getString(R.string.common_undefined_error_message), exception)
}
}
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,46 @@
package io.novafoundation.nova.common.data.network
import io.novafoundation.nova.common.R
import io.novafoundation.nova.common.base.BaseException
import io.novafoundation.nova.common.base.errors.NovaException
import io.novafoundation.nova.common.resources.ResourceManager
import org.junit.Assert.assertEquals
import org.junit.Test
import org.mockito.Mockito
import java.io.IOException
class HttpExceptionHandlerTest {
private val resourceManager = Mockito.mock(ResourceManager::class.java).also {
Mockito.`when`(it.getString(R.string.common_undefined_error_message)).thenReturn(UNDEFINED)
Mockito.`when`(it.getString(R.string.connection_error_message_v2_2_0)).thenReturn(CONNECTION)
}
private val handler = HttpExceptionHandler(resourceManager)
@Test
fun `an unexpected error without a message gets the common error text`() {
val error = handler.transformException(IllegalStateException())
assertEquals(BaseException.Kind.UNEXPECTED, error.kind)
assertEquals(UNDEFINED, error.message)
}
@Test
fun `an unexpected error keeps its own message`() {
assertEquals("boom", handler.transformException(IllegalStateException("boom")).message)
}
@Test
fun `a socket network error carries the connection error text`() {
val error = NovaException.networkError(resourceManager, IOException())
assertEquals(NovaException.Kind.NETWORK, error.kind)
assertEquals(CONNECTION, error.message)
}
private companion object {
const val UNDEFINED = "undefined"
const val CONNECTION = "connection"
}
}
@@ -68,8 +68,6 @@ interface AccountRepository {
suspend fun getAccountOrNull(address: String): Account?
suspend fun getMyAccounts(query: String, chainId: String): Set<Account>
suspend fun isCodeSet(): Boolean
suspend fun savePinCode(code: String)
@@ -193,16 +193,6 @@ class AccountRepositoryImpl(
return accountDao.getAccount(address)?.let { mapAccountLocalToAccount(it) }
}
override suspend fun getMyAccounts(query: String, chainId: String): Set<Account> {
// return withContext(Dispatchers.Default) {
// accountDao.getAccounts(query, networkType)
// .map { mapAccountLocalToAccount(it) }
// .toSet()
// }
return emptySet() // TODO wallet
}
override suspend fun isCodeSet(): Boolean {
return accountDataSource.getPinCode() != null
}