diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index f6de8d9d5..caadaf61d 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -10,6 +10,121 @@ #Firebase Crashlytics -keep,includedescriptorclasses public class * extends java.lang.Exception +########### +-keep public class * extends jp.co.soramitsu.common.util.ParseModel { + ; + ; + } + + # This is generated automatically by the Android Gradle plugin. + -dontwarn build.IgnoreJava8API + -dontwarn java.awt.Component + -dontwarn java.awt.GraphicsEnvironment + -dontwarn java.awt.HeadlessException + -dontwarn java.awt.Window + -dontwarn java.beans.ConstructorProperties + -dontwarn java.beans.Transient + -dontwarn java.lang.management.ManagementFactory + -dontwarn java.lang.management.RuntimeMXBean + -dontwarn java.lang.management.ThreadMXBean + -dontwarn javax.servlet.ServletContextListener + -dontwarn lombok.NonNull + -dontwarn org.apache.avalon.framework.logger.Logger + -dontwarn org.apache.log.Hierarchy + -dontwarn org.apache.log.Logger + -dontwarn org.apache.log4j.Level + -dontwarn org.apache.log4j.Logger + -dontwarn org.apache.log4j.Priority + -dontwarn org.apache.xml.resolver.Catalog + -dontwarn org.apache.xml.resolver.CatalogManager + -dontwarn org.apache.xml.resolver.readers.CatalogReader + -dontwarn org.apache.xml.resolver.readers.SAXCatalogReader + -dontwarn org.ietf.jgss.GSSContext + -dontwarn org.ietf.jgss.GSSCredential + -dontwarn org.ietf.jgss.GSSException + -dontwarn org.ietf.jgss.GSSManager + -dontwarn org.ietf.jgss.GSSName + -dontwarn org.ietf.jgss.Oid + -dontwarn org.slf4j.impl.StaticLoggerBinder + -dontwarn org.slf4j.impl.StaticMDCBinder + -dontwarn org.slf4j.impl.StaticMarkerBinder + -dontwarn org.w3c.dom.events.DocumentEvent + -dontwarn org.w3c.dom.events.Event + -dontwarn org.w3c.dom.events.EventException + -dontwarn org.w3c.dom.events.EventListener + -dontwarn org.w3c.dom.events.EventTarget + -dontwarn org.w3c.dom.events.MouseEvent + -dontwarn org.w3c.dom.events.MutationEvent + -dontwarn org.w3c.dom.events.UIEvent + -dontwarn org.w3c.dom.html.HTMLAnchorElement + -dontwarn org.w3c.dom.html.HTMLAppletElement + -dontwarn org.w3c.dom.html.HTMLAreaElement + -dontwarn org.w3c.dom.html.HTMLBRElement + -dontwarn org.w3c.dom.html.HTMLBaseElement + -dontwarn org.w3c.dom.html.HTMLBaseFontElement + -dontwarn org.w3c.dom.html.HTMLBodyElement + -dontwarn org.w3c.dom.html.HTMLButtonElement + -dontwarn org.w3c.dom.html.HTMLCollection + -dontwarn org.w3c.dom.html.HTMLDListElement + -dontwarn org.w3c.dom.html.HTMLDirectoryElement + -dontwarn org.w3c.dom.html.HTMLDivElement + -dontwarn org.w3c.dom.html.HTMLDocument + -dontwarn org.w3c.dom.html.HTMLElement + -dontwarn org.w3c.dom.html.HTMLFieldSetElement + -dontwarn org.w3c.dom.html.HTMLFontElement + -dontwarn org.w3c.dom.html.HTMLFormElement + -dontwarn org.w3c.dom.html.HTMLFrameElement + -dontwarn org.w3c.dom.html.HTMLFrameSetElement + -dontwarn org.w3c.dom.html.HTMLHRElement + -dontwarn org.w3c.dom.html.HTMLHeadElement + -dontwarn org.w3c.dom.html.HTMLHeadingElement + -dontwarn org.w3c.dom.html.HTMLHtmlElement + -dontwarn org.w3c.dom.html.HTMLIFrameElement + -dontwarn org.w3c.dom.html.HTMLImageElement + -dontwarn org.w3c.dom.html.HTMLInputElement + -dontwarn org.w3c.dom.html.HTMLIsIndexElement + -dontwarn org.w3c.dom.html.HTMLLIElement + -dontwarn org.w3c.dom.html.HTMLLabelElement + -dontwarn org.w3c.dom.html.HTMLLegendElement + -dontwarn org.w3c.dom.html.HTMLLinkElement + -dontwarn org.w3c.dom.html.HTMLMapElement + -dontwarn org.w3c.dom.html.HTMLMenuElement + -dontwarn org.w3c.dom.html.HTMLMetaElement + -dontwarn org.w3c.dom.html.HTMLModElement + -dontwarn org.w3c.dom.html.HTMLOListElement + -dontwarn org.w3c.dom.html.HTMLObjectElement + -dontwarn org.w3c.dom.html.HTMLOptGroupElement + -dontwarn org.w3c.dom.html.HTMLOptionElement + -dontwarn org.w3c.dom.html.HTMLParagraphElement + -dontwarn org.w3c.dom.html.HTMLParamElement + -dontwarn org.w3c.dom.html.HTMLPreElement + -dontwarn org.w3c.dom.html.HTMLQuoteElement + -dontwarn org.w3c.dom.html.HTMLScriptElement + -dontwarn org.w3c.dom.html.HTMLSelectElement + -dontwarn org.w3c.dom.html.HTMLStyleElement + -dontwarn org.w3c.dom.html.HTMLTableCaptionElement + -dontwarn org.w3c.dom.html.HTMLTableCellElement + -dontwarn org.w3c.dom.html.HTMLTableColElement + -dontwarn org.w3c.dom.html.HTMLTableElement + -dontwarn org.w3c.dom.html.HTMLTableRowElement + -dontwarn org.w3c.dom.html.HTMLTableSectionElement + -dontwarn org.w3c.dom.html.HTMLTextAreaElement + -dontwarn org.w3c.dom.html.HTMLTitleElement + -dontwarn org.w3c.dom.html.HTMLUListElement + -dontwarn org.w3c.dom.ls.LSSerializerFilter + -dontwarn org.w3c.dom.ranges.DocumentRange + -dontwarn org.w3c.dom.ranges.Range + -dontwarn org.w3c.dom.ranges.RangeException + -dontwarn org.w3c.dom.traversal.DocumentTraversal + -dontwarn org.w3c.dom.traversal.NodeFilter + -dontwarn org.w3c.dom.traversal.NodeIterator + -dontwarn org.w3c.dom.traversal.TreeWalker + -dontwarn org.web3j.abi.datatypes.generated.AbiTypes + -dontwarn org.webrtc.Dav1dDecoder + -dontwarn sun.security.x509.X509Key + +-dontwarn java.lang.invoke.StringConcatFactory + # Gson -keep,allowobfuscation,allowoptimization class * { @com.google.gson.annotations.SerializedName ; diff --git a/build.gradle b/build.gradle index 268da1a74..8eeec9925 100644 --- a/build.gradle +++ b/build.gradle @@ -44,7 +44,7 @@ buildscript { composeMaterial : '1.4.3', composeCompiler : '1.5.3', composeConstraintLayout: '1.1.0-alpha05', - uiCore : '0.2.0', + uiCore : '24.0.2.6', soraCard : '0.1.45', lazySodium : '5.0.2', jna : '5.8.0', @@ -90,9 +90,6 @@ buildscript { daggerDep = "com.google.dagger:hilt-android:$versions.dagger" daggerKaptDep = "com.google.dagger:hilt-compiler:$versions.dagger" hiltUiTestDep = "com.google.dagger:hilt-android-testing:$versions.dagger" - hiltUiTestKaptDep = "com.google.dagger:hilt-compiler:$versions.dagger" - hiltUnitTestDep = "com.google.dagger:hilt-android-testing:$versions.dagger" - hiltUnitTestKaptDep = "com.google.dagger:hilt-compiler:$versions.dagger" hiltNavComposeDep = "androidx.hilt:hilt-navigation-compose:$versions.hiltCompose" hiltWorkManagerDep = "androidx.hilt:hilt-work:$versions.hiltWorkManager" hiltWorkManagerKaptDep = "androidx.hilt:hilt-compiler:$versions.hiltWorkManager" @@ -154,10 +151,10 @@ buildscript { jUnitDep = "junit:junit:$versions.jUnit" mockitoDep = "org.mockito:mockito-inline:$versions.mockito" - mockitoKotlinDep = "org.mockito.kotlin:mockito-kotlin:4.1.0" + mockitoKotlinDep = "org.mockito.kotlin:mockito-kotlin:5.1.0" // https://github.com/mockk/mockk/issues/243 - mockkDep = "io.mockk:mockk:1.13.5" + mockkDep = "io.mockk:mockk:1.13.8" // powerMockDep = "org.powermock:powermock-module-junit4:2.0.2" // powerMockMockitoDep = "org.powermock:powermock-api-mockito2:2.0.2" @@ -221,7 +218,7 @@ buildscript { dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}" classpath "org.jetbrains.kotlin:kotlin-serialization:${versions.kotlin}" - classpath 'com.android.tools.build:gradle:8.2.0-beta05' + classpath 'com.android.tools.build:gradle:8.2.0-beta06' classpath 'com.google.gms:google-services:4.3.15' classpath 'com.google.firebase:firebase-appdistribution-gradle:3.2.0' classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.4' @@ -232,6 +229,7 @@ buildscript { plugins { id "org.sonarqube" version "2.7" + id 'com.google.devtools.ksp' version '1.9.10-1.0.13' apply false } apply from: 'secrets.gradle' diff --git a/common/src/main/java/jp/co/soramitsu/common/base/SoraBaseFragment.kt b/common/src/main/java/jp/co/soramitsu/common/base/SoraBaseFragment.kt index b69bf8d29..479a637cd 100644 --- a/common/src/main/java/jp/co/soramitsu/common/base/SoraBaseFragment.kt +++ b/common/src/main/java/jp/co/soramitsu/common/base/SoraBaseFragment.kt @@ -39,7 +39,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.Toast -import androidx.activity.compose.BackHandler +import androidx.activity.addCallback import androidx.compose.animation.ExperimentalAnimationApi import androidx.compose.foundation.ScrollState import androidx.compose.foundation.layout.fillMaxSize @@ -69,7 +69,7 @@ import androidx.navigation.compose.rememberNavController import androidx.navigation.findNavController import javax.inject.Inject import jp.co.soramitsu.common.R -import jp.co.soramitsu.common.domain.BarsColorhandler +import jp.co.soramitsu.common.domain.BarsColorHandler import jp.co.soramitsu.common.domain.DarkThemeManager import jp.co.soramitsu.common.presentation.compose.components.AlertDialogContent import jp.co.soramitsu.common.presentation.compose.components.Toolbar @@ -94,9 +94,16 @@ abstract class SoraBaseFragment : Fragment() { @Inject lateinit var darkThemeManager: DarkThemeManager + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + activity?.onBackPressedDispatcher?.addCallback(this) { + onBack() + } + } + override fun onResume() { super.onResume() - activity?.safeCast()?.setColor(backgroundColor()) + activity?.safeCast()?.setColor(backgroundColor()) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -149,6 +156,19 @@ abstract class SoraBaseFragment : Fragment() { it.second.invoke(this) } } + viewModel.navToStart.observe { + with(navController) { + popBackStack(graph.startDestinationId, true) + graph.setStartDestination(it) + navigate(it) + } +// with(navController) { +// navigate(it) { +// popUpTo(graph.startDestinationId) {inclusive = true} +// } +// graph.setStartDestination(it) +// } + } viewModel.errorLiveData.observe { openAlertDialog.value = AlertDialogData( title = R.string.common_error_general_title, @@ -208,9 +228,6 @@ abstract class SoraBaseFragment : Fragment() { ) } ) { padding -> - BackHandler { - onBack() - } NavHost( modifier = Modifier .padding(padding) diff --git a/common/src/main/java/jp/co/soramitsu/common/data/network/dto/SwapFeeDto.kt b/common/src/main/java/jp/co/soramitsu/common/data/network/dto/SwapFeeDto.kt index f2cde61e6..396c1aa7f 100644 --- a/common/src/main/java/jp/co/soramitsu/common/data/network/dto/SwapFeeDto.kt +++ b/common/src/main/java/jp/co/soramitsu/common/data/network/dto/SwapFeeDto.kt @@ -32,12 +32,11 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.common.data.network.dto -import androidx.annotation.Keep import java.math.BigInteger +import jp.co.soramitsu.common.util.ParseModel -@Keep data class SwapFeeDto( val amount: BigInteger, val fee: BigInteger, val route: List? = null, -) +) : ParseModel() diff --git a/common/src/main/java/jp/co/soramitsu/common/domain/Asset.kt b/common/src/main/java/jp/co/soramitsu/common/domain/Asset.kt index 54a779f75..3e8f7a474 100644 --- a/common/src/main/java/jp/co/soramitsu/common/domain/Asset.kt +++ b/common/src/main/java/jp/co/soramitsu/common/domain/Asset.kt @@ -32,7 +32,6 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.common.domain -import android.net.Uri import android.os.Parcelable import java.math.BigDecimal import jp.co.soramitsu.common.R @@ -87,7 +86,7 @@ data class Token( val symbol: String, val precision: Int, val isHidable: Boolean, - val iconFile: Uri?, + val iconFile: String?, val fiatPrice: Double?, val fiatPriceChange: Double?, val fiatSymbol: String?, @@ -136,7 +135,7 @@ fun List.getByIdOrEmpty(id: String): Token = it.id == id } ?: AssetHolder.emptyToken -fun Token.iconUri(): Uri = this.iconFile ?: DEFAULT_ICON_URI +fun Token.iconUri(): String = this.iconFile ?: DEFAULT_ICON_URI fun Token.isMatchFilter(filter: String): Boolean = name.lowercase().contains(filter.lowercase()) || @@ -144,4 +143,4 @@ fun Token.isMatchFilter(filter: String): Boolean = id.lowercase().contains(filter.lowercase()) val DEFAULT_ICON: Int = R.drawable.ic_token_default -val DEFAULT_ICON_URI = Uri.parse("file:///android_asset/ic_token_default.png") +val DEFAULT_ICON_URI = "file:///android_asset/ic_token_default.png" diff --git a/common/src/main/java/jp/co/soramitsu/common/domain/BottomBarController.kt b/common/src/main/java/jp/co/soramitsu/common/domain/BottomBarController.kt index 95b65cd6e..0dcfe4294 100644 --- a/common/src/main/java/jp/co/soramitsu/common/domain/BottomBarController.kt +++ b/common/src/main/java/jp/co/soramitsu/common/domain/BottomBarController.kt @@ -43,7 +43,7 @@ interface BottomBarController { fun isBottomBarVisible(): Boolean } -interface BarsColorhandler { +interface BarsColorHandler { fun setColor(@AttrRes color: Int) } diff --git a/common/src/main/java/jp/co/soramitsu/common/domain/WhitelistTokensManager.kt b/common/src/main/java/jp/co/soramitsu/common/domain/WhitelistTokensManager.kt index 76e5953e2..256fdbb83 100644 --- a/common/src/main/java/jp/co/soramitsu/common/domain/WhitelistTokensManager.kt +++ b/common/src/main/java/jp/co/soramitsu/common/domain/WhitelistTokensManager.kt @@ -32,7 +32,6 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.common.domain -import android.net.Uri import javax.inject.Inject import javax.inject.Singleton import jp.co.soramitsu.common.io.FileManager @@ -78,13 +77,14 @@ class WhitelistTokensManager @Inject constructor( } } - fun getTokenIconUri(tokenId: String): Uri { + fun getTokenIconUri(tokenId: String): String { val type = curWhitelist.find { it.id == tokenId }?.type - return if (type == null) { + val u = if (type == null) { DEFAULT_ICON_URI } else { fileManager.readInternalCacheFileAsUri("$tokenId.$type") ?: DEFAULT_ICON_URI } + return u.toString() } suspend fun updateWhitelistStorage() { diff --git a/common/src/main/java/jp/co/soramitsu/common/inappupdate/InAppUpdateManager.kt b/common/src/main/java/jp/co/soramitsu/common/inappupdate/InAppUpdateManager.kt index c63a2d88f..371508eb6 100644 --- a/common/src/main/java/jp/co/soramitsu/common/inappupdate/InAppUpdateManager.kt +++ b/common/src/main/java/jp/co/soramitsu/common/inappupdate/InAppUpdateManager.kt @@ -35,9 +35,8 @@ package jp.co.soramitsu.common.inappupdate import android.app.Activity import android.content.Context import androidx.lifecycle.Lifecycle -import androidx.lifecycle.LifecycleObserver +import androidx.lifecycle.LifecycleEventObserver import androidx.lifecycle.LifecycleOwner -import androidx.lifecycle.OnLifecycleEvent import com.google.android.play.core.appupdate.AppUpdateInfo import com.google.android.play.core.appupdate.AppUpdateManagerFactory import com.google.android.play.core.install.InstallStateUpdatedListener @@ -54,7 +53,7 @@ import kotlin.coroutines.suspendCoroutine class InAppUpdateManager( context: Context, private val soraPreferences: SoraPreferences -) : LifecycleObserver { +) : LifecycleEventObserver { interface UpdateManagerListener : LifecycleOwner { fun readyToShowFlexible(): Int? @@ -74,6 +73,7 @@ class InAppUpdateManager( InstallStatus.DOWNLOADED -> { mainActivity?.askUserToInstall() } + else -> { } } @@ -127,6 +127,7 @@ class InAppUpdateManager( ) } } + AppUpdateType.IMMEDIATE -> { soraPreferences.putLong(ARG_TIME, now) googleUpdateManager.startUpdateFlowForResult( @@ -136,6 +137,7 @@ class InAppUpdateManager( 1 ) } + else -> { } } @@ -171,9 +173,10 @@ class InAppUpdateManager( ) == true } - @OnLifecycleEvent(Lifecycle.Event.ON_STOP) - fun onStop() { - mainActivity?.lifecycle?.removeObserver(this) - mainActivity = null + override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) { + if (event == Lifecycle.Event.ON_STOP) { + mainActivity?.lifecycle?.removeObserver(this) + mainActivity = null + } } } diff --git a/common/src/main/java/jp/co/soramitsu/common/presentation/compose/TokenIcon.kt b/common/src/main/java/jp/co/soramitsu/common/presentation/compose/TokenIcon.kt index 2cd314f4c..a96d5ea58 100644 --- a/common/src/main/java/jp/co/soramitsu/common/presentation/compose/TokenIcon.kt +++ b/common/src/main/java/jp/co/soramitsu/common/presentation/compose/TokenIcon.kt @@ -32,6 +32,7 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.common.presentation.compose +import android.graphics.drawable.Drawable import androidx.compose.foundation.layout.size import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier @@ -40,16 +41,33 @@ import androidx.compose.ui.unit.Dp import coil.compose.AsyncImage import coil.imageLoader import coil.request.ImageRequest +import jp.co.soramitsu.common.R @Composable fun TokenIcon( modifier: Modifier = Modifier, - uri: Any, + uri: String?, size: Dp, ) { AsyncImage( model = ImageRequest.Builder(LocalContext.current) - .data(uri).build(), + .data(uri ?: R.drawable.ic_token_default).build(), + modifier = modifier + .size(size = size), + contentDescription = null, + imageLoader = LocalContext.current.imageLoader, + ) +} + +@Composable +fun AccountIcon( + modifier: Modifier = Modifier, + drawable: Drawable?, + size: Dp, +) { + AsyncImage( + model = ImageRequest.Builder(LocalContext.current) + .data(drawable ?: R.drawable.ic_token_default).build(), modifier = modifier .size(size = size), contentDescription = null, diff --git a/common/src/main/java/jp/co/soramitsu/common/presentation/compose/components/AccountWithIcon.kt b/common/src/main/java/jp/co/soramitsu/common/presentation/compose/components/AccountWithIcon.kt index a5a7505f7..6282d99f6 100644 --- a/common/src/main/java/jp/co/soramitsu/common/presentation/compose/components/AccountWithIcon.kt +++ b/common/src/main/java/jp/co/soramitsu/common/presentation/compose/components/AccountWithIcon.kt @@ -48,8 +48,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource import jp.co.soramitsu.common.R -import jp.co.soramitsu.common.domain.DEFAULT_ICON_URI -import jp.co.soramitsu.common.presentation.compose.TokenIcon +import jp.co.soramitsu.common.presentation.compose.AccountIcon import jp.co.soramitsu.ui_core.component.button.properties.Size import jp.co.soramitsu.ui_core.resources.Dimens import jp.co.soramitsu.ui_core.theme.customColors @@ -75,7 +74,7 @@ fun AccountWithIcon( ), verticalAlignment = Alignment.CenterVertically, ) { - TokenIcon(uri = accountIcon ?: DEFAULT_ICON_URI, size = Size.Small) + AccountIcon(drawable = accountIcon, size = Size.Small) Text( modifier = Modifier .weight(1f) diff --git a/common/src/main/java/jp/co/soramitsu/common/presentation/compose/components/AssetAmount.kt b/common/src/main/java/jp/co/soramitsu/common/presentation/compose/components/AssetAmount.kt index 4b5e59a01..af7ca89f3 100644 --- a/common/src/main/java/jp/co/soramitsu/common/presentation/compose/components/AssetAmount.kt +++ b/common/src/main/java/jp/co/soramitsu/common/presentation/compose/components/AssetAmount.kt @@ -32,6 +32,7 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.common.presentation.compose.components +import android.content.res.Configuration import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.background import androidx.compose.foundation.border @@ -68,6 +69,7 @@ import jp.co.soramitsu.common.R import jp.co.soramitsu.common.domain.AssetAmountInputState import jp.co.soramitsu.common.domain.OptionsProvider import jp.co.soramitsu.common.presentation.compose.TokenIcon +import jp.co.soramitsu.common.presentation.compose.theme.SoraAppTheme import jp.co.soramitsu.common.util.ext.orZero import jp.co.soramitsu.common.util.ext.testTagAsId import jp.co.soramitsu.ui_core.component.button.properties.Size @@ -108,7 +110,7 @@ fun AssetAmountInput( verticalAlignment = Alignment.CenterVertically, ) { TokenIcon( - uri = state?.token?.iconFile ?: R.drawable.ic_token_default, + uri = state?.token?.iconFile, size = Size.Small, modifier = Modifier .testTagAsId("TokenIcon") @@ -156,7 +158,7 @@ fun AssetAmountInput( focusedInput.value = it onFocusChange.invoke(it) }, - textStyle = MaterialTheme.customTypography.displayS.copy(textAlign = TextAlign.End), + textStyle = MaterialTheme.customTypography.displayS.copy(textAlign = TextAlign.End, color = MaterialTheme.customColors.fgPrimary), enabled = state?.let { it.enabled && !it.readOnly } ?: false, precision = state?.token?.precision ?: OptionsProvider.defaultScale, defaultCursorPosition = DefaultCursorPosition.START, @@ -224,45 +226,92 @@ val previewAssetAmountInputState = AssetAmountInputState( errorHint = "", ) -@Preview(showBackground = true) +@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO) @Composable -private fun PreviewAssetAmountInput() { - Column( - modifier = Modifier - .fillMaxWidth() - .wrapContentHeight() - .background(color = Color.Red) - .padding(10.dp) - ) { - val bb = remember { mutableStateOf(BigDecimal.valueOf(12345.67890988765)) } - val state = remember { mutableStateOf(previewAssetAmountInputState) } - Button(onClick = { - state.value = state.value.copy( - amount = bb.value, +private fun PreviewAssetAmountInput01() { + SoraAppTheme { + Column( + modifier = Modifier + .fillMaxWidth() + .wrapContentHeight() + .background(color = MaterialTheme.customColors.bgPage) + .padding(10.dp) + ) { + val bb = remember { mutableStateOf(BigDecimal.valueOf(12345.67890988765)) } + val state = remember { mutableStateOf(previewAssetAmountInputState) } + Button(onClick = { + state.value = state.value.copy( + amount = bb.value, + ) + bb.value = bb.value.plus(BigDecimal.ONE) + }) { + Text(text = "click") + } + AssetAmountInput( + modifier = Modifier, + state = state.value, + onAmountChange = { + state.value = state.value.copy( + amount = it, + ) + }, + onSelectToken = {}, + onFocusChange = {}, + ) + Spacer(modifier = Modifier.size(10.dp)) + Text(text = state.value.amount.orZero().toPlainString()) + AssetAmountInput( + modifier = Modifier, + state = previewAssetAmountInputState, + onAmountChange = {}, + onSelectToken = {}, + onFocusChange = {}, ) - bb.value = bb.value.plus(BigDecimal.ONE) - }) { - Text(text = "click") } - AssetAmountInput( - modifier = Modifier, - state = state.value, - onAmountChange = { + } +} + +@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun PreviewAssetAmountInput02() { + SoraAppTheme { + Column( + modifier = Modifier + .fillMaxWidth() + .wrapContentHeight() + .background(color = MaterialTheme.customColors.bgPage) + .padding(10.dp) + ) { + val bb = remember { mutableStateOf(BigDecimal.valueOf(12345.67890988765)) } + val state = remember { mutableStateOf(previewAssetAmountInputState) } + Button(onClick = { state.value = state.value.copy( - amount = it, + amount = bb.value, ) - }, - onSelectToken = {}, - onFocusChange = {}, - ) - Spacer(modifier = Modifier.size(10.dp)) - Text(text = state.value.amount.orZero().toPlainString()) - AssetAmountInput( - modifier = Modifier, - state = previewAssetAmountInputState, - onAmountChange = {}, - onSelectToken = {}, - onFocusChange = {}, - ) + bb.value = bb.value.plus(BigDecimal.ONE) + }) { + Text(text = "click") + } + AssetAmountInput( + modifier = Modifier, + state = state.value, + onAmountChange = { + state.value = state.value.copy( + amount = it, + ) + }, + onSelectToken = {}, + onFocusChange = {}, + ) + Spacer(modifier = Modifier.size(10.dp)) + Text(text = state.value.amount.orZero().toPlainString()) + AssetAmountInput( + modifier = Modifier, + state = previewAssetAmountInputState, + onAmountChange = {}, + onSelectToken = {}, + onFocusChange = {}, + ) + } } } diff --git a/common/src/main/java/jp/co/soramitsu/common/presentation/compose/components/ContentCardEndless.kt b/common/src/main/java/jp/co/soramitsu/common/presentation/compose/components/ContentCardEndless.kt deleted file mode 100644 index e141967c2..000000000 --- a/common/src/main/java/jp/co/soramitsu/common/presentation/compose/components/ContentCardEndless.kt +++ /dev/null @@ -1,108 +0,0 @@ -/* -This file is part of the SORA network and Polkaswap app. - -Copyright (c) 2020, 2021, Polka Biome Ltd. All rights reserved. -SPDX-License-Identifier: BSD-4-Clause - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -Redistributions of source code must retain the above copyright notice, this list -of conditions and the following disclaimer. -Redistributions in binary form must reproduce the above copyright notice, this -list of conditions and the following disclaimer in the documentation and/or other -materials provided with the distribution. - -All advertising materials mentioning features or use of this software must display -the following acknowledgement: This product includes software developed by Polka Biome -Ltd., SORA, and Polkaswap. - -Neither the name of the Polka Biome Ltd. nor the names of its contributors may be used -to endorse or promote products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY Polka Biome Ltd. AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Polka Biome Ltd. BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -package jp.co.soramitsu.common.presentation.compose.components - -import androidx.compose.foundation.background -import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.PaddingValues -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material.Card -import androidx.compose.material.MaterialTheme -import androidx.compose.material.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.clip -import androidx.compose.ui.draw.shadow -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.dp -import jp.co.soramitsu.ui_core.modifier.applyIf -import jp.co.soramitsu.ui_core.resources.Dimens -import jp.co.soramitsu.ui_core.theme.borderRadius -import jp.co.soramitsu.ui_core.theme.customColors - -@Composable -fun ContentCardEndless( - modifier: Modifier = Modifier, - innerPadding: PaddingValues = PaddingValues(0.dp), - onClick: (() -> Unit)? = null, - content: @Composable () -> Unit, -) { - Card( - modifier = modifier - .shadow( - elevation = Dimens.x4, - ambientColor = Color(0xFF999999), - spotColor = Color(0xFF999999), - shape = RoundedCornerShape( - topStart = MaterialTheme.borderRadius.xl, - topEnd = MaterialTheme.borderRadius.xl, - ), - ) - .clip( - RoundedCornerShape( - topStart = MaterialTheme.borderRadius.xl, - topEnd = MaterialTheme.borderRadius.xl, - ) - ) - .applyIf(onClick != null) { - clickable { onClick?.invoke() } - } - .background(MaterialTheme.customColors.bgSurface) - .padding(innerPadding), - elevation = 0.dp, - content = content, - ) -} - -@Preview(showBackground = true) -@Composable -private fun Preview() { - Box( - modifier = Modifier.fillMaxSize() - ) { - ContentCardEndless( - modifier = Modifier.padding(8.dp), - innerPadding = PaddingValues(18.dp), - ) { - Text( - text = "df\nfgfg", - modifier = Modifier.fillMaxWidth() - ) - } - } -} diff --git a/common/src/main/java/jp/co/soramitsu/common/presentation/compose/components/DetailsItem.kt b/common/src/main/java/jp/co/soramitsu/common/presentation/compose/components/DetailsItem.kt index ce8e322aa..c167cff9a 100644 --- a/common/src/main/java/jp/co/soramitsu/common/presentation/compose/components/DetailsItem.kt +++ b/common/src/main/java/jp/co/soramitsu/common/presentation/compose/components/DetailsItem.kt @@ -32,7 +32,6 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.common.presentation.compose.components -import android.net.Uri import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column @@ -79,7 +78,7 @@ fun DetailsItem( value1: String, value2: String? = null, value1Bold: Boolean = false, - value1Uri: Uri? = null, + value1Uri: String? = null, value1Percent: Float? = null, hint: String? = null, valueColor: Color = MaterialTheme.customColors.fgPrimary, @@ -93,6 +92,7 @@ fun DetailsItem( ) { if (hintVisible && hint != null) { AlertDialog( + backgroundColor = MaterialTheme.customColors.bgPage, title = { Text( text = text, diff --git a/common/src/main/java/jp/co/soramitsu/common/presentation/compose/components/PolkaswapDisclaimer.kt b/common/src/main/java/jp/co/soramitsu/common/presentation/compose/components/PolkaswapDisclaimer.kt index 2414160c0..7f9f1f5eb 100644 --- a/common/src/main/java/jp/co/soramitsu/common/presentation/compose/components/PolkaswapDisclaimer.kt +++ b/common/src/main/java/jp/co/soramitsu/common/presentation/compose/components/PolkaswapDisclaimer.kt @@ -32,6 +32,7 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.common.presentation.compose.components +import android.content.res.Configuration import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.fillMaxWidth @@ -46,6 +47,7 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.viewinterop.AndroidView import jp.co.soramitsu.common.R +import jp.co.soramitsu.common.presentation.compose.theme.SoraAppTheme import jp.co.soramitsu.common.presentation.view.PolkaswapDisclaimerView import jp.co.soramitsu.common.util.ext.testTagAsId import jp.co.soramitsu.ui_core.component.button.TonalButton @@ -102,10 +104,22 @@ fun PolkaswapDisclaimer( } } -@Preview(showBackground = true) +@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_NO) @Composable -private fun PreviewPolkaswapDisclaimer() { - PolkaswapDisclaimer( - onDisclaimerClose = {}, - ) +private fun PreviewPolkaswapDisclaimer01() { + SoraAppTheme { + PolkaswapDisclaimer( + onDisclaimerClose = {}, + ) + } +} + +@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun PreviewPolkaswapDisclaimer02() { + SoraAppTheme { + PolkaswapDisclaimer( + onDisclaimerClose = {}, + ) + } } diff --git a/common/src/main/java/jp/co/soramitsu/common/presentation/compose/theme/tokens/NightThemeColors.kt b/common/src/main/java/jp/co/soramitsu/common/presentation/compose/theme/tokens/NightThemeColors.kt index 9237eb289..4013523e0 100644 --- a/common/src/main/java/jp/co/soramitsu/common/presentation/compose/theme/tokens/NightThemeColors.kt +++ b/common/src/main/java/jp/co/soramitsu/common/presentation/compose/theme/tokens/NightThemeColors.kt @@ -33,11 +33,11 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.common.presentation.compose.theme.tokens import jp.co.soramitsu.common.presentation.compose.theme.tokens.Colors.Brown30 -import jp.co.soramitsu.common.presentation.compose.theme.tokens.Colors.Brown5 import jp.co.soramitsu.common.presentation.compose.theme.tokens.Colors.Green40 import jp.co.soramitsu.common.presentation.compose.theme.tokens.Colors.Green5 import jp.co.soramitsu.common.presentation.compose.theme.tokens.Colors.Grey5 import jp.co.soramitsu.common.presentation.compose.theme.tokens.Colors.Grey50 +import jp.co.soramitsu.common.presentation.compose.theme.tokens.Colors.Grey60 import jp.co.soramitsu.common.presentation.compose.theme.tokens.Colors.Grey70 import jp.co.soramitsu.common.presentation.compose.theme.tokens.Colors.Grey80 import jp.co.soramitsu.common.presentation.compose.theme.tokens.Colors.Grey90 @@ -78,7 +78,7 @@ object NightThemeColors { val FgInverted = Grey90 - val FgOutline = Brown5 + val FgOutline = Grey60 val StatusSuccess = Green40 diff --git a/common/src/main/java/jp/co/soramitsu/common/presentation/viewmodel/BaseViewModel.kt b/common/src/main/java/jp/co/soramitsu/common/presentation/viewmodel/BaseViewModel.kt index 26c4b3d22..fd3cd8c10 100644 --- a/common/src/main/java/jp/co/soramitsu/common/presentation/viewmodel/BaseViewModel.kt +++ b/common/src/main/java/jp/co/soramitsu/common/presentation/viewmodel/BaseViewModel.kt @@ -63,6 +63,9 @@ open class BaseViewModel : ViewModel() { protected val _navEvent = SingleLiveEvent Unit>>() val navEvent: LiveData Unit>> = _navEvent + protected val _navToStart = SingleLiveEvent() + val navToStart: LiveData = _navToStart + protected var currentDestination: String = "" get() = field.ifEmpty { startScreen() } diff --git a/common/src/main/java/jp/co/soramitsu/common/util/Const.kt b/common/src/main/java/jp/co/soramitsu/common/util/Const.kt index d92fd6efa..6d037115e 100644 --- a/common/src/main/java/jp/co/soramitsu/common/util/Const.kt +++ b/common/src/main/java/jp/co/soramitsu/common/util/Const.kt @@ -32,6 +32,8 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.common.util +open class ParseModel + object Const { const val SORA = "SORA" diff --git a/common/src/main/res/drawable-night-hdpi/ic_polkaswap_full_title.png b/common/src/main/res/drawable-night-hdpi/ic_polkaswap_full_title.png new file mode 100644 index 000000000..0969c6254 Binary files /dev/null and b/common/src/main/res/drawable-night-hdpi/ic_polkaswap_full_title.png differ diff --git a/common/src/main/res/drawable-night-mdpi/ic_polkaswap_full_title.png b/common/src/main/res/drawable-night-mdpi/ic_polkaswap_full_title.png new file mode 100644 index 000000000..b18e2f701 Binary files /dev/null and b/common/src/main/res/drawable-night-mdpi/ic_polkaswap_full_title.png differ diff --git a/common/src/main/res/drawable-night-xhdpi/ic_polkaswap_full_title.png b/common/src/main/res/drawable-night-xhdpi/ic_polkaswap_full_title.png new file mode 100644 index 000000000..3eae3095d Binary files /dev/null and b/common/src/main/res/drawable-night-xhdpi/ic_polkaswap_full_title.png differ diff --git a/common/src/main/res/drawable-night-xxhdpi/ic_polkaswap_full_title.png b/common/src/main/res/drawable-night-xxhdpi/ic_polkaswap_full_title.png new file mode 100644 index 000000000..6b8e61c74 Binary files /dev/null and b/common/src/main/res/drawable-night-xxhdpi/ic_polkaswap_full_title.png differ diff --git a/common/src/main/res/drawable-night-xxxhdpi/ic_polkaswap_full_title.png b/common/src/main/res/drawable-night-xxxhdpi/ic_polkaswap_full_title.png new file mode 100644 index 000000000..e9dc8bda9 Binary files /dev/null and b/common/src/main/res/drawable-night-xxxhdpi/ic_polkaswap_full_title.png differ diff --git a/common/src/main/res/layout/polkaswap_disclaimer_view.xml b/common/src/main/res/layout/polkaswap_disclaimer_view.xml index e7108c03b..fc86f6554 100644 --- a/common/src/main/res/layout/polkaswap_disclaimer_view.xml +++ b/common/src/main/res/layout/polkaswap_disclaimer_view.xml @@ -26,6 +26,7 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:letterSpacing="-0.02" + android:textColor="?attr/redesignTokenName" app:layout_constraintEnd_toEndOf="@id/glPolkaswapRight" app:layout_constraintStart_toStartOf="@id/glPolkaswapLeft" app:layout_constraintTop_toTopOf="parent" @@ -40,6 +41,7 @@ android:layout_marginTop="@dimen/x2" android:letterSpacing="-0.02" android:text="@string/polkaswap_info_text_2" + android:textColor="?attr/redesignTokenName" app:layout_constraintEnd_toEndOf="@id/glPolkaswapRight" app:layout_constraintStart_toStartOf="@id/glPolkaswapLeft" app:layout_constraintTop_toBottomOf="@id/tvPolkaswapText1" @@ -60,6 +62,7 @@ android:layout_marginTop="@dimen/x2" android:letterSpacing="-0.02" android:text="1." + android:textColor="?attr/redesignTokenName" app:layout_constraintStart_toStartOf="@id/glPolkaswapLeft" app:layout_constraintTop_toBottomOf="@id/tvPolkaswapText2" tools:textSize="12sp" /> @@ -72,6 +75,7 @@ android:layout_marginStart="@dimen/x1" android:letterSpacing="-0.02" android:text="@string/polkaswap_info_text_3" + android:textColor="?attr/redesignTokenName" app:layout_constraintEnd_toEndOf="@id/glPolkaswapRight" app:layout_constraintStart_toStartOf="@id/brPolkaswapInfo" app:layout_constraintTop_toTopOf="@id/tvPolkaswapTextItem1" @@ -85,6 +89,7 @@ android:layout_marginTop="@dimen/x2" android:letterSpacing="-0.02" android:text="2." + android:textColor="?attr/redesignTokenName" app:layout_constraintStart_toStartOf="@id/glPolkaswapLeft" app:layout_constraintTop_toBottomOf="@id/tvPolkaswapText3" tools:textSize="12sp" /> @@ -97,6 +102,7 @@ android:layout_marginStart="@dimen/x1" android:letterSpacing="-0.02" android:text="@string/polkaswap_info_text_4" + android:textColor="?attr/redesignTokenName" app:layout_constraintEnd_toEndOf="@id/glPolkaswapRight" app:layout_constraintStart_toStartOf="@id/brPolkaswapInfo" app:layout_constraintTop_toTopOf="@id/tvPolkaswapTextItem2" @@ -110,6 +116,7 @@ android:layout_marginTop="@dimen/x2" android:letterSpacing="-0.02" android:text="3." + android:textColor="?attr/redesignTokenName" app:layout_constraintStart_toStartOf="@id/glPolkaswapLeft" app:layout_constraintTop_toBottomOf="@id/tvPolkaswapText4" tools:textSize="12sp" /> @@ -122,6 +129,7 @@ android:layout_marginStart="@dimen/x1" android:letterSpacing="-0.02" android:text="@string/polkaswap_info_text_5" + android:textColor="?attr/redesignTokenName" app:layout_constraintEnd_toEndOf="@id/glPolkaswapRight" app:layout_constraintStart_toStartOf="@id/brPolkaswapInfo" app:layout_constraintTop_toTopOf="@id/tvPolkaswapTextItem3" @@ -136,6 +144,7 @@ android:layout_marginTop="@dimen/x2" android:letterSpacing="-0.02" android:text="@string/polkaswap_info_text_6" + android:textColor="?attr/redesignTokenName" app:layout_constraintEnd_toEndOf="@id/glPolkaswapRight" app:layout_constraintStart_toStartOf="@id/brPolkaswapInfo" app:layout_constraintTop_toBottomOf="@id/tvPolkaswapText5" diff --git a/common/src/main/res/values-night/styles.xml b/common/src/main/res/values-night/styles.xml index 8e73a84a9..e5907cde0 100644 --- a/common/src/main/res/values-night/styles.xml +++ b/common/src/main/res/values-night/styles.xml @@ -55,8 +55,8 @@ @color/neu_positive @color/neu_negative @color/neu_fiat_balance_color - @color/neu_tint_dark - @color/neu_bottom_menu_inactive + @color/neu_bottom_menu_inactive_night + @color/neu_bottom_menu_inactive_night @color/neu_tint_light @color/neu_on_background @color/neu_selected_primary diff --git a/common/src/main/res/values/colors.xml b/common/src/main/res/values/colors.xml index 706ea2fdd..500d4bfb7 100644 --- a/common/src/main/res/values/colors.xml +++ b/common/src/main/res/values/colors.xml @@ -69,6 +69,7 @@ #DD0066 #9D8181 #443333 + #808080 #f0ecec #d0c5c5 #efe9e9 diff --git a/common_wallet/src/main/java/jp/co/soramitsu/common_wallet/presentation/compose/BasicPoolListItem.kt b/common_wallet/src/main/java/jp/co/soramitsu/common_wallet/presentation/compose/BasicPoolListItem.kt index 5be15dd8b..60cd6034e 100644 --- a/common_wallet/src/main/java/jp/co/soramitsu/common_wallet/presentation/compose/BasicPoolListItem.kt +++ b/common_wallet/src/main/java/jp/co/soramitsu/common_wallet/presentation/compose/BasicPoolListItem.kt @@ -32,7 +32,6 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.common_wallet.presentation.compose -import android.net.Uri import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement @@ -68,8 +67,8 @@ import jp.co.soramitsu.ui_core.theme.customTypography data class BasicPoolListItemState( val ids: StringPair, val number: String, - val token1Icon: Uri, - val token2Icon: Uri, + val token1Icon: String, + val token2Icon: String, val text1: String, val text2: String, val text3: String, diff --git a/common_wallet/src/main/java/jp/co/soramitsu/common_wallet/presentation/compose/components/AssetItem.kt b/common_wallet/src/main/java/jp/co/soramitsu/common_wallet/presentation/compose/components/AssetItem.kt index 463d94d0c..91ccb82f9 100644 --- a/common_wallet/src/main/java/jp/co/soramitsu/common_wallet/presentation/compose/components/AssetItem.kt +++ b/common_wallet/src/main/java/jp/co/soramitsu/common_wallet/presentation/compose/components/AssetItem.kt @@ -32,6 +32,7 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.common_wallet.presentation.compose.components +import android.net.Uri import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding @@ -63,7 +64,7 @@ fun AssetItem( modifier = Modifier .testTagAsId(testTag) .padding(horizontal = Dimens.x3), - icon = assetState.tokenIcon, + icon = Uri.parse(assetState.tokenIcon), name = assetState.tokenName, balance = assetState.assetAmount, symbol = "", @@ -100,7 +101,7 @@ fun AssetItemEnumerated( Asset( modifier = Modifier .testTagAsId(testTag), - icon = assetState.tokenIcon, + icon = Uri.parse(assetState.tokenIcon), name = assetState.tokenName, balance = assetState.assetAmount, symbol = "", diff --git a/common_wallet/src/main/java/jp/co/soramitsu/common_wallet/presentation/compose/states/CardState.kt b/common_wallet/src/main/java/jp/co/soramitsu/common_wallet/presentation/compose/states/CardState.kt index bb5ad7453..1084ddb4b 100644 --- a/common_wallet/src/main/java/jp/co/soramitsu/common_wallet/presentation/compose/states/CardState.kt +++ b/common_wallet/src/main/java/jp/co/soramitsu/common_wallet/presentation/compose/states/CardState.kt @@ -32,7 +32,6 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.common_wallet.presentation.compose.states -import android.net.Uri import androidx.annotation.StringRes import java.math.BigDecimal import jp.co.soramitsu.androidfoundation.format.formatFiatSuffix @@ -70,7 +69,7 @@ class FavoriteAssetsCardState( ) : AssetCardState data class AssetItemCardState( - val tokenIcon: Uri, + val tokenIcon: String, val tokenId: String, val tokenName: String, val tokenSymbol: String, diff --git a/common_wallet/src/main/java/jp/co/soramitsu/common_wallet/presentation/compose/states/PoolsListState.kt b/common_wallet/src/main/java/jp/co/soramitsu/common_wallet/presentation/compose/states/PoolsListState.kt index 366172e8e..739dfdd8c 100644 --- a/common_wallet/src/main/java/jp/co/soramitsu/common_wallet/presentation/compose/states/PoolsListState.kt +++ b/common_wallet/src/main/java/jp/co/soramitsu/common_wallet/presentation/compose/states/PoolsListState.kt @@ -32,7 +32,6 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.common_wallet.presentation.compose.states -import android.net.Uri import jp.co.soramitsu.common.domain.AssetHolder import jp.co.soramitsu.common.domain.formatFiat import jp.co.soramitsu.common.domain.formatFiatChange @@ -47,8 +46,8 @@ class PoolsListState( ) data class PoolsListItemState( - val token1Icon: Uri, - val token2Icon: Uri, + val token1Icon: String, + val token2Icon: String, val poolName: String, val poolAmounts: String, val fiat: String, diff --git a/core_db/build.gradle b/core_db/build.gradle index f92b277c1..7e75b6e3c 100644 --- a/core_db/build.gradle +++ b/core_db/build.gradle @@ -1,7 +1,10 @@ -apply plugin: 'com.android.library' -apply plugin: 'dagger.hilt.android.plugin' -apply plugin: 'kotlin-android' -apply plugin: 'kotlin-kapt' +plugins { + id 'com.android.library' + id 'dagger.hilt.android.plugin' + id 'kotlin-android' + id 'kotlin-kapt' + id 'com.google.devtools.ksp' +} apply from: '../tests.gradle' kotlin { @@ -15,13 +18,13 @@ android { minSdkVersion minVersion targetSdkVersion targetVersion - javaCompileOptions { - annotationProcessorOptions { - arguments += [ - "room.schemaLocation":"$projectDir/schemas".toString(), - "room.incremental":"true"] - } - } +// javaCompileOptions { +// annotationProcessorOptions { +// arguments += [ +// "room.schemaLocation":"$projectDir/schemas".toString(), +// "room.incremental":"true"] +// } +// } testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } @@ -63,6 +66,28 @@ android { namespace 'com.example.core_db' } +class RoomSchemaArgProvider implements CommandLineArgumentProvider { + + @InputDirectory + @PathSensitive(PathSensitivity.RELATIVE) + File schemaDir + + RoomSchemaArgProvider(File schemaDir) { + this.schemaDir = schemaDir + } + + @Override + Iterable asArguments() { + // Note: If you're using KSP, change the line below to return + // ["room.schemaLocation=${schemaDir.path}".toString()]. + return ["room.schemaLocation=${schemaDir.path}".toString()] + } +} + +ksp { + arg(new RoomSchemaArgProvider(new File(projectDir, "schemas"))) +} + dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) @@ -76,7 +101,7 @@ dependencies { implementation roomDep implementation roomKtxDep - kapt roomKaptDep + ksp roomKaptDep androidTestImplementation project(":test_shared") androidTestImplementation project(":test_data") diff --git a/core_db/src/main/java/jp/co/soramitsu/core_db/dao/AssetDao.kt b/core_db/src/main/java/jp/co/soramitsu/core_db/dao/AssetDao.kt index 3e1602f7d..d38d01c1d 100644 --- a/core_db/src/main/java/jp/co/soramitsu/core_db/dao/AssetDao.kt +++ b/core_db/src/main/java/jp/co/soramitsu/core_db/dao/AssetDao.kt @@ -101,6 +101,13 @@ interface AssetDao { whitelist: String = AssetHolder.DEFAULT_WHITE_LIST_NAME ): List + @Query(QUERY_ASSET_TOKEN_ACTIVE) + suspend fun getAssetsActive( + address: String, + isoCode: String, + whitelist: String = AssetHolder.DEFAULT_WHITE_LIST_NAME + ): List + @Query(QUERY_ASSET_TOKEN_VISIBLE) fun subscribeAssetsVisible( address: String, diff --git a/demeter/build.gradle b/demeter/build.gradle index 39548390f..2c210e430 100644 --- a/demeter/build.gradle +++ b/demeter/build.gradle @@ -81,7 +81,7 @@ dependencies { implementation roomDep implementation roomKtxDep - kapt roomKaptDep + //kapt roomKaptDep implementation sharedUtilsDep implementation xNetworkingDep diff --git a/feature_assets_api/src/main/java/jp/co/soramitsu/feature_assets_api/data/AssetsRepository.kt b/feature_assets_api/src/main/java/jp/co/soramitsu/feature_assets_api/data/AssetsRepository.kt index f72d2408a..2773f20ac 100644 --- a/feature_assets_api/src/main/java/jp/co/soramitsu/feature_assets_api/data/AssetsRepository.kt +++ b/feature_assets_api/src/main/java/jp/co/soramitsu/feature_assets_api/data/AssetsRepository.kt @@ -60,11 +60,7 @@ interface AssetsRepository { suspend fun getAsset(assetId: String, address: String): Asset? - suspend fun getAssetsFavorite(address: String,): List - - suspend fun getAssetsVisible( - address: String, - ): List + suspend fun getAssetsActive(address: String,): List suspend fun getAssetsWhitelist(address: String): List diff --git a/feature_assets_api/src/main/java/jp/co/soramitsu/feature_assets_api/domain/AssetsInteractor.kt b/feature_assets_api/src/main/java/jp/co/soramitsu/feature_assets_api/domain/AssetsInteractor.kt index 8b8eed006..79f98c78c 100644 --- a/feature_assets_api/src/main/java/jp/co/soramitsu/feature_assets_api/domain/AssetsInteractor.kt +++ b/feature_assets_api/src/main/java/jp/co/soramitsu/feature_assets_api/domain/AssetsInteractor.kt @@ -56,8 +56,6 @@ interface AssetsInteractor { suspend fun getPublicKeyHex(withPrefix: Boolean = false): String - suspend fun getVisibleAssets(): List - suspend fun getWhitelistAssets(): List suspend fun getXorBalance(precision: Int): XorAssetBalance diff --git a/feature_assets_api/src/main/java/jp/co/soramitsu/feature_assets_api/presentation/selectsearchtoken/SelectSearchToken.kt b/feature_assets_api/src/main/java/jp/co/soramitsu/feature_assets_api/presentation/selectsearchtoken/SelectSearchToken.kt index 54f8ba94a..7ff091519 100644 --- a/feature_assets_api/src/main/java/jp/co/soramitsu/feature_assets_api/presentation/selectsearchtoken/SelectSearchToken.kt +++ b/feature_assets_api/src/main/java/jp/co/soramitsu/feature_assets_api/presentation/selectsearchtoken/SelectSearchToken.kt @@ -56,10 +56,10 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import jp.co.soramitsu.common.R -import jp.co.soramitsu.common.presentation.compose.components.ContentCardEndless import jp.co.soramitsu.common_wallet.presentation.compose.components.AssetItem import jp.co.soramitsu.common_wallet.presentation.compose.states.AssetItemCardState import jp.co.soramitsu.common_wallet.presentation.compose.states.previewAssetItemCardStateList +import jp.co.soramitsu.ui_core.component.card.ContentCardEndless import jp.co.soramitsu.ui_core.resources.Dimens import jp.co.soramitsu.ui_core.theme.customColors import jp.co.soramitsu.ui_core.theme.customTypography diff --git a/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/data/AssetsRepositoryImpl.kt b/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/data/AssetsRepositoryImpl.kt index b7e92b224..d8fa08d54 100644 --- a/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/data/AssetsRepositoryImpl.kt +++ b/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/data/AssetsRepositoryImpl.kt @@ -147,17 +147,9 @@ class AssetsRepositoryImpl @Inject constructor( } } - override suspend fun getAssetsFavorite(address: String): List { + override suspend fun getAssetsActive(address: String): List { val selectedCurrency = soraConfigManager.getSelectedCurrency() - return db.assetDao().getAssetsFavorite(address, selectedCurrency.code) - .map { - assetLocalToAssetMapper.map(it) - } - } - - override suspend fun getAssetsVisible(address: String): List { - val selectedCurrency = soraConfigManager.getSelectedCurrency() - return db.assetDao().getAssetsVisible(address, selectedCurrency.code) + return db.assetDao().getAssetsActive(address, selectedCurrency.code) .map { assetLocalToAssetMapper.map(it) } @@ -352,7 +344,7 @@ class AssetsRepositoryImpl @Inject constructor( tokensDeferred.await() val selectedCurrency = soraConfigManager.getSelectedCurrency() checkDefaultNeed(address, selectedCurrency.code) - val assets = db.assetDao().getAssetsVisible(address, selectedCurrency.code) + val assets = db.assetDao().getAssetsActive(address, selectedCurrency.code) insertAssetsInternal(address, assets, true) } } diff --git a/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/domain/AssetsInteractorImpl.kt b/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/domain/AssetsInteractorImpl.kt index 1115d0b59..1b34597da 100644 --- a/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/domain/AssetsInteractorImpl.kt +++ b/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/domain/AssetsInteractorImpl.kt @@ -104,11 +104,6 @@ class AssetsInteractorImpl constructor( .toHexString(withPrefix) } - override suspend fun getVisibleAssets(): List { - val address = userRepository.getCurSoraAccount().substrateAddress - return assetsRepository.getAssetsFavorite(address) - } - override suspend fun getWhitelistAssets(): List { val address = userRepository.getCurSoraAccount().substrateAddress return assetsRepository.getAssetsWhitelist(address) diff --git a/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/presentation/components/compose/assetdetails/AssetDetailsTokenPriceCard.kt b/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/presentation/components/compose/assetdetails/AssetDetailsTokenPriceCard.kt index c628d5d1c..fd007ea3b 100644 --- a/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/presentation/components/compose/assetdetails/AssetDetailsTokenPriceCard.kt +++ b/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/presentation/components/compose/assetdetails/AssetDetailsTokenPriceCard.kt @@ -32,7 +32,6 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.feature_assets_impl.presentation.components.compose.assetdetails -import android.net.Uri import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues @@ -53,6 +52,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp +import jp.co.soramitsu.common.domain.DEFAULT_ICON_URI import jp.co.soramitsu.common.presentation.compose.TokenIcon import jp.co.soramitsu.ui_core.component.asset.changePriceColor import jp.co.soramitsu.ui_core.component.card.ContentCard @@ -66,7 +66,7 @@ internal fun AssetDetailsTokenPriceCard( tokenSymbol: String, tokenPrice: String, tokenPriceChange: String, - iconUri: Uri, + iconUri: String, ) { Box( modifier = Modifier @@ -141,6 +141,6 @@ private fun PreviewAssetDetailsTokenPriceCard() { tokenSymbol = "XOR", tokenPrice = "$12.34", tokenPriceChange = "+4.5%", - iconUri = Uri.EMPTY, + iconUri = DEFAULT_ICON_URI, ) } diff --git a/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/presentation/components/compose/receive/ReceiveScreen.kt b/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/presentation/components/compose/receive/ReceiveScreen.kt index 2c170cb15..567b14150 100644 --- a/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/presentation/components/compose/receive/ReceiveScreen.kt +++ b/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/presentation/components/compose/receive/ReceiveScreen.kt @@ -58,7 +58,7 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import jp.co.soramitsu.common.R -import jp.co.soramitsu.common.presentation.compose.TokenIcon +import jp.co.soramitsu.common.presentation.compose.AccountIcon import jp.co.soramitsu.common.presentation.compose.previewDrawable import jp.co.soramitsu.ui_core.component.button.FilledButton import jp.co.soramitsu.ui_core.component.button.properties.Order @@ -112,8 +112,8 @@ internal fun ReceiveScreen( .wrapContentHeight(), verticalAlignment = Alignment.CenterVertically, ) { - TokenIcon( - uri = avatar, + AccountIcon( + drawable = avatar, size = Size.Small, ) Spacer(modifier = Modifier.size(Dimens.x1)) diff --git a/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/presentation/states/AssetCardState.kt b/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/presentation/states/AssetCardState.kt index baf8b027b..7ccc665aa 100644 --- a/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/presentation/states/AssetCardState.kt +++ b/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/presentation/states/AssetCardState.kt @@ -32,7 +32,6 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.feature_assets_impl.presentation.states -import android.net.Uri import jp.co.soramitsu.common.domain.DEFAULT_ICON_URI import jp.co.soramitsu.common_wallet.presentation.compose.states.PoolsListState import jp.co.soramitsu.feature_blockexplorer_api.presentation.txhistory.EventUiModel @@ -45,7 +44,7 @@ internal data class AssetCardState( internal data class AssetCardStateData( val tokenId: String, val tokenName: String, - val tokenIcon: Uri, + val tokenIcon: String, val tokenSymbol: String, val price: String, val priceChange: String, diff --git a/feature_assets_impl/src/test/java/jp/co/soramitsu/feature_assets_impl/data/AssetsRepositoryTest.kt b/feature_assets_impl/src/test/java/jp/co/soramitsu/feature_assets_impl/data/AssetsRepositoryTest.kt index 02937d1b1..9bb4e77ca 100644 --- a/feature_assets_impl/src/test/java/jp/co/soramitsu/feature_assets_impl/data/AssetsRepositoryTest.kt +++ b/feature_assets_impl/src/test/java/jp/co/soramitsu/feature_assets_impl/data/AssetsRepositoryTest.kt @@ -99,7 +99,7 @@ class AssetsRepositoryTest { @Mock private lateinit var soraConfigManager: SoraConfigManager - private val mockedUri = Mockito.mock(Uri::class.java) + private val mockedUri = DEFAULT_ICON_URI private lateinit var assetsRepository: AssetsRepository @@ -134,7 +134,7 @@ class AssetsRepositoryTest { @Test fun `get assets`() = runTest { BDDMockito.given( - assetDao.getAssetsFavorite( + assetDao.getAssetsActive( BDDMockito.anyString(), BDDMockito.anyString(), BDDMockito.anyString() @@ -142,7 +142,7 @@ class AssetsRepositoryTest { ).willReturn( assetTokenList() ) - val assets = assetsRepository.getAssetsFavorite("address") + val assets = assetsRepository.getAssetsActive("address") val expected = assetList().subList(0, 2) Assert.assertEquals(expected.size, assets.size) repeat(2) { diff --git a/feature_assets_impl/src/test/java/jp/co/soramitsu/feature_assets_impl/domain/AssetsInteractorTest.kt b/feature_assets_impl/src/test/java/jp/co/soramitsu/feature_assets_impl/domain/AssetsInteractorTest.kt index 3e4eec481..46a27c98e 100644 --- a/feature_assets_impl/src/test/java/jp/co/soramitsu/feature_assets_impl/domain/AssetsInteractorTest.kt +++ b/feature_assets_impl/src/test/java/jp/co/soramitsu/feature_assets_impl/domain/AssetsInteractorTest.kt @@ -116,12 +116,6 @@ class AssetsInteractorTest { ) } - @Test - fun `get assets`() = runTest { - coEvery { assetsRepository.getAssetsFavorite("address") } returns assetList() - Assert.assertEquals(assetList(), interactor.getVisibleAssets()) - } - @Test fun `just transfer`() = runTest { val kp = Sr25519Keypair(ByteArray(32), ByteArray(32), ByteArray(32)) diff --git a/feature_assets_impl/src/test/java/jp/co/soramitsu/feature_assets_impl/presentation/assetsettings/AssetSettingsViewModelTest.kt b/feature_assets_impl/src/test/java/jp/co/soramitsu/feature_assets_impl/presentation/assetsettings/AssetSettingsViewModelTest.kt index a6fdbba3f..cf5ef200f 100644 --- a/feature_assets_impl/src/test/java/jp/co/soramitsu/feature_assets_impl/presentation/assetsettings/AssetSettingsViewModelTest.kt +++ b/feature_assets_impl/src/test/java/jp/co/soramitsu/feature_assets_impl/presentation/assetsettings/AssetSettingsViewModelTest.kt @@ -39,6 +39,7 @@ import io.mockk.mockkObject import io.mockk.mockkStatic import jp.co.soramitsu.common.domain.Asset import jp.co.soramitsu.common.domain.AssetHolder +import jp.co.soramitsu.common.domain.DEFAULT_ICON_URI import jp.co.soramitsu.common.domain.Token import jp.co.soramitsu.common.domain.iconUri import jp.co.soramitsu.common.util.NumbersFormatter @@ -90,7 +91,7 @@ class AssetSettingsViewModelTest { @Mock private lateinit var router: AssetsRouter - private val mockedUri = Mockito.mock(Uri::class.java) + private val mockedUri = DEFAULT_ICON_URI private val nf = NumbersFormatter() @@ -98,16 +99,8 @@ class AssetSettingsViewModelTest { @Before fun setUp() = runTest { - mockkStatic(Uri::parse) - every { Uri.parse(any()) } returns mockedUri - mockkStatic(Token::iconUri) mockkObject(AssetHolder) every { AssetHolder.knownCount() } returns 5 - every { xorToken.iconUri() } returns mockedUri - every { valToken.iconUri() } returns mockedUri - every { pswapToken.iconUri() } returns mockedUri - every { xstusdToken.iconUri() } returns mockedUri - every { xstToken.iconUri() } returns mockedUri } private suspend fun setUpStartList( diff --git a/feature_assets_impl/src/test/java/jp/co/soramitsu/feature_assets_impl/presentation/send/TransferAmountViewModelTest.kt b/feature_assets_impl/src/test/java/jp/co/soramitsu/feature_assets_impl/presentation/send/TransferAmountViewModelTest.kt index e577df282..ab6af2ff8 100644 --- a/feature_assets_impl/src/test/java/jp/co/soramitsu/feature_assets_impl/presentation/send/TransferAmountViewModelTest.kt +++ b/feature_assets_impl/src/test/java/jp/co/soramitsu/feature_assets_impl/presentation/send/TransferAmountViewModelTest.kt @@ -101,8 +101,6 @@ class TransferAmountViewModelTest { @MockK private lateinit var avatarGenerator: AccountAvatarGenerator - private val mockedUri = mockk() - @MockK private lateinit var clipboardManager: BasicClipboardManager @@ -114,11 +112,6 @@ class TransferAmountViewModelTest { @Before fun setUp() = runTest { - mockkStatic(Uri::parse) - every { Uri.parse(any()) } returns mockedUri - mockkStatic(Token::iconUri) - every { TestTokens.xorToken.iconUri() } returns mockedUri - every { TestTokens.valToken.iconUri() } returns mockedUri every { resourceManager.getString(R.string.error_transaction_fee_title) } returns "Not enough funds" every { avatarGenerator.createAvatar(any(), any()) } returns drawable coEvery { diff --git a/feature_blockexplorer_api/src/main/java/jp/co/soramitsu/feature_blockexplorer_api/presentation/screen/TxHistoryListScreen.kt b/feature_blockexplorer_api/src/main/java/jp/co/soramitsu/feature_blockexplorer_api/presentation/screen/TxHistoryListScreen.kt index 2ac455184..b7bf66a86 100644 --- a/feature_blockexplorer_api/src/main/java/jp/co/soramitsu/feature_blockexplorer_api/presentation/screen/TxHistoryListScreen.kt +++ b/feature_blockexplorer_api/src/main/java/jp/co/soramitsu/feature_blockexplorer_api/presentation/screen/TxHistoryListScreen.kt @@ -57,7 +57,6 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import jp.co.soramitsu.common.R -import jp.co.soramitsu.common.presentation.compose.components.ContentCardEndless import jp.co.soramitsu.common.util.ext.safeCast import jp.co.soramitsu.common.view.LoadMoreHandler import jp.co.soramitsu.feature_blockexplorer_api.domain.HistoryState @@ -65,6 +64,7 @@ import jp.co.soramitsu.feature_blockexplorer_api.presentation.txhistory.EventUiM import jp.co.soramitsu.ui_core.component.button.FilledButton import jp.co.soramitsu.ui_core.component.button.properties.Order import jp.co.soramitsu.ui_core.component.button.properties.Size +import jp.co.soramitsu.ui_core.component.card.ContentCardEndless import jp.co.soramitsu.ui_core.resources.Dimens import jp.co.soramitsu.ui_core.theme.customColors import jp.co.soramitsu.ui_core.theme.customTypography diff --git a/feature_blockexplorer_api/src/main/java/jp/co/soramitsu/feature_blockexplorer_api/presentation/txdetails/TxDetailsLiquidity.kt b/feature_blockexplorer_api/src/main/java/jp/co/soramitsu/feature_blockexplorer_api/presentation/txdetails/TxDetailsLiquidity.kt index 691f6c1ab..f3fe9e10a 100644 --- a/feature_blockexplorer_api/src/main/java/jp/co/soramitsu/feature_blockexplorer_api/presentation/txdetails/TxDetailsLiquidity.kt +++ b/feature_blockexplorer_api/src/main/java/jp/co/soramitsu/feature_blockexplorer_api/presentation/txdetails/TxDetailsLiquidity.kt @@ -32,7 +32,6 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.feature_blockexplorer_api.presentation.txdetails -import android.net.Uri import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding @@ -63,8 +62,8 @@ fun TxDetailsLiquidity( isAmountGreen: Boolean, amount1: String, amount2: String, - icon1: Uri, - icon2: Uri, + icon1: String, + icon2: String, onCloseClick: () -> Unit, onCopyClick: (String) -> Unit, ) { diff --git a/feature_blockexplorer_api/src/main/java/jp/co/soramitsu/feature_blockexplorer_api/presentation/txdetails/TxDetailsReferralAndTransfer.kt b/feature_blockexplorer_api/src/main/java/jp/co/soramitsu/feature_blockexplorer_api/presentation/txdetails/TxDetailsReferralAndTransfer.kt index 88acc5ec9..c611d7f3e 100644 --- a/feature_blockexplorer_api/src/main/java/jp/co/soramitsu/feature_blockexplorer_api/presentation/txdetails/TxDetailsReferralAndTransfer.kt +++ b/feature_blockexplorer_api/src/main/java/jp/co/soramitsu/feature_blockexplorer_api/presentation/txdetails/TxDetailsReferralAndTransfer.kt @@ -32,7 +32,6 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.feature_blockexplorer_api.presentation.txdetails -import android.net.Uri import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.wrapContentHeight @@ -53,7 +52,7 @@ import jp.co.soramitsu.ui_core.theme.customTypography fun TxDetailsReferralOrTransferScreen( modifier: Modifier, state: BasicTxDetailsState, - icon: Uri, + icon: String, isAmountGreen: Boolean = false, amount: String, onCloseClick: () -> Unit, diff --git a/feature_blockexplorer_api/src/main/java/jp/co/soramitsu/feature_blockexplorer_api/presentation/txdetails/TxDetailsScreenState.kt b/feature_blockexplorer_api/src/main/java/jp/co/soramitsu/feature_blockexplorer_api/presentation/txdetails/TxDetailsScreenState.kt index fc8d8118a..c14c17e85 100644 --- a/feature_blockexplorer_api/src/main/java/jp/co/soramitsu/feature_blockexplorer_api/presentation/txdetails/TxDetailsScreenState.kt +++ b/feature_blockexplorer_api/src/main/java/jp/co/soramitsu/feature_blockexplorer_api/presentation/txdetails/TxDetailsScreenState.kt @@ -32,7 +32,6 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.feature_blockexplorer_api.presentation.txdetails -import android.net.Uri import jp.co.soramitsu.common.R import jp.co.soramitsu.common.domain.DEFAULT_ICON_URI import jp.co.soramitsu.feature_blockexplorer_api.presentation.txhistory.TransactionStatus @@ -64,8 +63,8 @@ data class TxDetailsScreenState( val amount1: String, val amount2: String? = null, val amountFiat: String, - val icon1: Uri, - val icon2: Uri? = null, + val icon1: String, + val icon2: String? = null, val isAmountGreen: Boolean = false, val txType: TxType ) diff --git a/feature_blockexplorer_api/src/main/java/jp/co/soramitsu/feature_blockexplorer_api/presentation/txdetails/TxDetailsSwap.kt b/feature_blockexplorer_api/src/main/java/jp/co/soramitsu/feature_blockexplorer_api/presentation/txdetails/TxDetailsSwap.kt index 85a124c7c..559688a05 100644 --- a/feature_blockexplorer_api/src/main/java/jp/co/soramitsu/feature_blockexplorer_api/presentation/txdetails/TxDetailsSwap.kt +++ b/feature_blockexplorer_api/src/main/java/jp/co/soramitsu/feature_blockexplorer_api/presentation/txdetails/TxDetailsSwap.kt @@ -32,7 +32,6 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.feature_blockexplorer_api.presentation.txdetails -import android.net.Uri import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding @@ -62,8 +61,8 @@ fun TxDetailsSwap( state: BasicTxDetailsState, amount1: String, amount2: String, - icon1: Uri, - icon2: Uri, + icon1: String, + icon2: String, onCloseClick: () -> Unit, onCopyClick: (String) -> Unit, ) { diff --git a/feature_blockexplorer_api/src/main/java/jp/co/soramitsu/feature_blockexplorer_api/presentation/txhistory/SoraTransaction.kt b/feature_blockexplorer_api/src/main/java/jp/co/soramitsu/feature_blockexplorer_api/presentation/txhistory/SoraTransaction.kt index a3a10a6c2..2145aa191 100644 --- a/feature_blockexplorer_api/src/main/java/jp/co/soramitsu/feature_blockexplorer_api/presentation/txhistory/SoraTransaction.kt +++ b/feature_blockexplorer_api/src/main/java/jp/co/soramitsu/feature_blockexplorer_api/presentation/txhistory/SoraTransaction.kt @@ -32,7 +32,6 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.feature_blockexplorer_api.presentation.txhistory -import android.net.Uri import androidx.annotation.StringRes sealed class EventUiModel { @@ -49,7 +48,7 @@ sealed class EventUiModel { hash: String, timestamp: Long, status: TransactionStatus, - val tokenIcon: Uri, + val tokenIcon: String, @StringRes val title: Int, val description: String, val plusAmount: Boolean, @@ -61,8 +60,8 @@ sealed class EventUiModel { hash: String, timestamp: Long, status: TransactionStatus, - val tokenUri: Uri, - val ethTokenUri: Uri, + val tokenUri: String, + val ethTokenUri: String, val dateTime: String, val amountFormatted: String, val fiatFormatted: String, @@ -72,7 +71,7 @@ sealed class EventUiModel { class EventTransferInUiModel( hash: String, - val tokenIcon: Uri, + val tokenIcon: String, val peerAddress: String, val dateTime: String, timestamp: Long, @@ -83,7 +82,7 @@ sealed class EventUiModel { class EventTransferOutUiModel( hash: String, - val tokenIcon: Uri, + val tokenIcon: String, val peerAddress: String, val dateTime: String, timestamp: Long, @@ -94,8 +93,8 @@ sealed class EventUiModel { class EventLiquiditySwapUiModel( hash: String, - val iconFrom: Uri, - val iconTo: Uri, + val iconFrom: String, + val iconTo: String, val amountFrom: String, val amountTo: String, val tickers: String, @@ -110,8 +109,8 @@ sealed class EventUiModel { timestamp: Long, status: TransactionStatus, val dateTime: String, - val icon1: Uri, - val icon2: Uri, + val icon1: String, + val icon2: String, val amounts: String, val type: String, val tickers: String, diff --git a/feature_blockexplorer_impl/src/test/java/jp/co/soramitsu/feature_blockexplorer_impl/TransactionMappersTest.kt b/feature_blockexplorer_impl/src/test/java/jp/co/soramitsu/feature_blockexplorer_impl/TransactionMappersTest.kt index e01f05671..ded101198 100644 --- a/feature_blockexplorer_impl/src/test/java/jp/co/soramitsu/feature_blockexplorer_impl/TransactionMappersTest.kt +++ b/feature_blockexplorer_impl/src/test/java/jp/co/soramitsu/feature_blockexplorer_impl/TransactionMappersTest.kt @@ -37,6 +37,7 @@ import com.google.common.truth.Truth.assertThat import io.mockk.every import io.mockk.mockkStatic import jp.co.soramitsu.common.date.DateTimeFormatter +import jp.co.soramitsu.common.domain.DEFAULT_ICON_URI import jp.co.soramitsu.common.domain.Token import jp.co.soramitsu.common.resourses.ResourceManager import jp.co.soramitsu.common.util.NumbersFormatter @@ -75,7 +76,7 @@ class TransactionMappersTest { "token symbol", 18, true, - mockedUri, + DEFAULT_ICON_URI, null, null, null @@ -100,7 +101,7 @@ class TransactionMappersTest { private val transactionsWithHeaders = listOf( EventUiModel.EventTxUiModel.EventTransferInUiModel( "", - mockedUri, + DEFAULT_ICON_URI, "peerId", "01 Jan 1970 00:00", 1000000, diff --git a/feature_blockexplorer_impl/src/test/java/jp/co/soramitsu/feature_blockexplorer_impl/domain/TransactionHistoryHandlerTest.kt b/feature_blockexplorer_impl/src/test/java/jp/co/soramitsu/feature_blockexplorer_impl/domain/TransactionHistoryHandlerTest.kt index 778f99c15..74b55ff14 100644 --- a/feature_blockexplorer_impl/src/test/java/jp/co/soramitsu/feature_blockexplorer_impl/domain/TransactionHistoryHandlerTest.kt +++ b/feature_blockexplorer_impl/src/test/java/jp/co/soramitsu/feature_blockexplorer_impl/domain/TransactionHistoryHandlerTest.kt @@ -33,16 +33,13 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.feature_blockexplorer_impl.domain import android.net.Uri -import androidx.arch.core.executor.testing.InstantTaskExecutorRule -import io.mockk.coEvery import io.mockk.every -import io.mockk.impl.annotations.MockK -import io.mockk.junit4.MockKRule import io.mockk.mockk import io.mockk.mockkStatic -import io.mockk.verify import jp.co.soramitsu.common.date.DateTimeFormatter +import jp.co.soramitsu.common.domain.Asset import jp.co.soramitsu.common.domain.CoroutineManager +import jp.co.soramitsu.common.domain.DEFAULT_ICON_URI import jp.co.soramitsu.common.domain.Token import jp.co.soramitsu.common.domain.iconUri import jp.co.soramitsu.common.resourses.LanguagesHolder @@ -67,7 +64,6 @@ import jp.co.soramitsu.test_shared.MainCoroutineRule import jp.co.soramitsu.test_shared.test import junit.framework.TestCase.assertEquals import junit.framework.TestCase.assertTrue -import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.flow @@ -77,51 +73,54 @@ import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Rule import org.junit.Test -import org.junit.rules.TestRule -import java.util.Locale +import org.junit.runner.RunWith +import org.mockito.Mock +import org.mockito.Mockito +import org.mockito.junit.MockitoJUnitRunner +import org.mockito.kotlin.any +import org.mockito.kotlin.anyOrNull +import org.mockito.kotlin.doReturn +import org.mockito.kotlin.mock +import org.mockito.kotlin.stub +import org.mockito.kotlin.verify +import org.mockito.kotlin.whenever @ExperimentalCoroutinesApi +@RunWith(MockitoJUnitRunner::class) class TransactionHistoryHandlerTest { - @Rule - @JvmField - val rule: TestRule = InstantTaskExecutorRule() - @get:Rule var mainCoroutineRule = MainCoroutineRule() - @get:Rule - val mockkRule = MockKRule(this) +// @get:Rule +// val mockkRule = MockKRule(this) - @MockK + @Mock private lateinit var assetsRepository: AssetsRepository - @MockK + @Mock private lateinit var transactionHistoryRepository: TransactionHistoryRepository - @MockK + @Mock private lateinit var resourceManager: ResourceManager - @MockK + @Mock private lateinit var userRepository: UserRepository - @MockK + @Mock private lateinit var language: LanguagesHolder - @MockK + @Mock private lateinit var coroutineManager: CoroutineManager - @MockK - private lateinit var coroutineScope: CoroutineScope - - @MockK + @Mock private lateinit var dateTimeFormatter: DateTimeFormatter private val txMapper: TransactionMappers by lazy { TransactionMappersImpl(resourceManager, NumbersFormatter(), dateTimeFormatter) } - private val mockedUri = mockk() + private var mockedUri = DEFAULT_ICON_URI private val tokens = listOf(TestTokens.xorToken) private val txHash = "txHash" @@ -154,43 +153,71 @@ class TransactionHistoryHandlerTest { @Before fun setUp() = runTest { - mockkStatic(Uri::parse) - every { Uri.parse(any()) } returns mockedUri - mockkStatic(Token::iconUri) - every { TestTokens.xorToken.iconUri() } returns mockedUri - every { TestTokens.valToken.iconUri() } returns mockedUri - every { language.getCurrentLocale() } returns Locale.ENGLISH - every { dateTimeFormatter.formatTimeWithoutSeconds(any()) } returns "01 Feb 1970" - every { dateTimeFormatter.dateToDayWithoutCurrentYear(any(), any(), any()) } returns "01 Feb 1970" - every { resourceManager.getString(any()) } returns "" - every { transactionHistoryRepository.state } returns flowOf(true) - every { coroutineManager.applicationScope } returns coroutineScope - every { coroutineScope.coroutineContext } returns coroutineContext - every { transactionHistoryRepository.onSoraAccountChange() } returns Unit - coEvery { assetsRepository.tokensList() } returns tokens - every { userRepository.flowCurSoraAccount() } returns flow { +// mockkStatic(Uri::parse) +// every { Uri.parse(any()) } returns mockedUri +// mockkStatic(Token::iconUri) +// every { TestTokens.xorToken.iconUri() } returns mockedUri +// every { TestTokens.valToken.iconUri() } returns mockedUri + +// Mockito.mockStatic(Token::class.java).use { mocked -> +// mocked.`when` { Token.iconUri() }.thenReturn(mockedUri) +// } + + //whenever(language.getCurrentLocale()).thenReturn(Locale.ENGLISH) + whenever(dateTimeFormatter.formatTimeWithoutSeconds(any())).thenReturn("01 Feb 1970") + whenever( + dateTimeFormatter.dateToDayWithoutCurrentYear( + any(), + any(), + any() + ) + ).thenReturn("01 Feb 1970") + whenever(resourceManager.getString(any())).thenReturn("") + whenever(transactionHistoryRepository.state).thenReturn(flowOf(true)) + whenever(coroutineManager.applicationScope).thenReturn(this) + //whenever(transactionHistoryRepository.onSoraAccountChange()).thenReturn(Unit) + assetsRepository.stub { + onBlocking { tokensList() } doReturn tokens + } + whenever(userRepository.flowCurSoraAccount()).thenReturn(flow { emit(TestAccounts.soraAccount) emit(TestAccounts.soraAccount2) + }) + transactionHistoryRepository.stub { + onBlocking { + getTransaction( + txHash, + tokens, + TestAccounts.soraAccount + ) + } doReturn TestTransactions.sendSuccessfulTx } - coEvery { - transactionHistoryRepository.getTransaction(txHash, tokens, TestAccounts.soraAccount) - } returns TestTransactions.sendSuccessfulTx - coEvery { userRepository.getCurSoraAccount() } returns TestAccounts.soraAccount - coEvery { - transactionHistoryRepository.getTransactionHistory(any(), any(), any(), any()) - } returns TransactionsInfo( - listOf(TestTransactions.sendSuccessfulTx), - true - ) - coEvery { - transactionHistoryRepository.getLastTransactions( - TestAccounts.soraAccount, - listOf(TestTokens.xorToken), - 1, - null + userRepository.stub { + onBlocking { getCurSoraAccount() } doReturn TestAccounts.soraAccount + } + transactionHistoryRepository.stub { + onBlocking { + getTransactionHistory( + anyOrNull(), + anyOrNull(), + anyOrNull(), + anyOrNull(), + ) + } doReturn TransactionsInfo( + listOf(TestTransactions.sendSuccessfulTx), + true ) - } returns listOf(TestTransactions.sendFailedTx) - + } + transactionHistoryRepository.stub { + onBlocking { + getLastTransactions( + TestAccounts.soraAccount, + listOf(TestTokens.xorToken), + 1, + null + ) + } doReturn listOf(TestTransactions.sendFailedTx) + } transactionHistoryHandler = TransactionHistoryHandlerImpl( assetsRepository, txMapper, @@ -227,7 +254,8 @@ class TransactionHistoryHandlerTest { @Test fun `init successful`() = runTest { - verify { transactionHistoryRepository.onSoraAccountChange() } + advanceUntilIdle() + verify(transactionHistoryRepository).onSoraAccountChange() } @Test diff --git a/feature_blockexplorer_impl/src/test/java/jp/co/soramitsu/feature_blockexplorer_impl/presentation/txdetails/TxDetailsViewModelTest.kt b/feature_blockexplorer_impl/src/test/java/jp/co/soramitsu/feature_blockexplorer_impl/presentation/txdetails/TxDetailsViewModelTest.kt index 16adbf192..fb252fe8a 100644 --- a/feature_blockexplorer_impl/src/test/java/jp/co/soramitsu/feature_blockexplorer_impl/presentation/txdetails/TxDetailsViewModelTest.kt +++ b/feature_blockexplorer_impl/src/test/java/jp/co/soramitsu/feature_blockexplorer_impl/presentation/txdetails/TxDetailsViewModelTest.kt @@ -44,6 +44,7 @@ import io.mockk.verify import jp.co.soramitsu.androidfoundation.phone.BasicClipboardManager import jp.co.soramitsu.common.R import jp.co.soramitsu.common.date.DateTimeFormatter +import jp.co.soramitsu.common.domain.DEFAULT_ICON_URI import jp.co.soramitsu.common.domain.Token import jp.co.soramitsu.common.domain.iconUri import jp.co.soramitsu.common.domain.printFiat @@ -110,7 +111,7 @@ class TxDetailsViewModelTest { private val nf = NumbersFormatter() - private val mockedUri = mockk() + private val mockedUri = DEFAULT_ICON_URI private val txHash = "txHash" private val date = "10 Jan. 2021 12:12" @@ -155,11 +156,6 @@ class TxDetailsViewModelTest { @Before fun setUp() = runTest { - mockkStatic(Uri::parse) - every { Uri.parse(any()) } returns mockedUri - mockkStatic(Token::iconUri) - every { TestTokens.xorToken.iconUri() } returns mockedUri - every { TestTokens.valToken.iconUri() } returns mockedUri coEvery { assetsInteractor.getCurSoraAccount() } returns TestAccounts.soraAccount coEvery { walletInteractor.getFeeToken() } returns TestTokens.xorToken coEvery { router.popBackStackFragment() } returns Unit diff --git a/feature_ecosystem_impl/src/main/java/jp/co/soramitsu/feature_ecosystem_impl/presentation/allcurrencies/AllCurrenciesScreen.kt b/feature_ecosystem_impl/src/main/java/jp/co/soramitsu/feature_ecosystem_impl/presentation/allcurrencies/AllCurrenciesScreen.kt index 43aa31694..6b31f5087 100644 --- a/feature_ecosystem_impl/src/main/java/jp/co/soramitsu/feature_ecosystem_impl/presentation/allcurrencies/AllCurrenciesScreen.kt +++ b/feature_ecosystem_impl/src/main/java/jp/co/soramitsu/feature_ecosystem_impl/presentation/allcurrencies/AllCurrenciesScreen.kt @@ -44,10 +44,10 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle -import jp.co.soramitsu.common.presentation.compose.components.ContentCardEndless import jp.co.soramitsu.common_wallet.presentation.compose.components.AssetItemEnumerated import jp.co.soramitsu.common_wallet.presentation.compose.states.previewAssetItemCardStateList import jp.co.soramitsu.feature_ecosystem_impl.presentation.EcoSystemTokensState +import jp.co.soramitsu.ui_core.component.card.ContentCardEndless import jp.co.soramitsu.ui_core.resources.Dimens @Composable diff --git a/feature_ecosystem_impl/src/main/java/jp/co/soramitsu/feature_ecosystem_impl/presentation/allpools/AllPoolsScreen.kt b/feature_ecosystem_impl/src/main/java/jp/co/soramitsu/feature_ecosystem_impl/presentation/allpools/AllPoolsScreen.kt index 00e2e4c99..06cdd1e23 100644 --- a/feature_ecosystem_impl/src/main/java/jp/co/soramitsu/feature_ecosystem_impl/presentation/allpools/AllPoolsScreen.kt +++ b/feature_ecosystem_impl/src/main/java/jp/co/soramitsu/feature_ecosystem_impl/presentation/allpools/AllPoolsScreen.kt @@ -44,11 +44,11 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle -import jp.co.soramitsu.common.presentation.compose.components.ContentCardEndless import jp.co.soramitsu.common.util.StringPair import jp.co.soramitsu.common_wallet.presentation.compose.BasicPoolListItem import jp.co.soramitsu.common_wallet.presentation.compose.previewBasicPoolListItemState import jp.co.soramitsu.feature_ecosystem_impl.presentation.EcoSystemPoolsState +import jp.co.soramitsu.ui_core.component.card.ContentCardEndless import jp.co.soramitsu.ui_core.resources.Dimens @Composable diff --git a/feature_ethereum_impl/build.gradle b/feature_ethereum_impl/build.gradle index 0bc2bc6a2..2ac930c20 100644 --- a/feature_ethereum_impl/build.gradle +++ b/feature_ethereum_impl/build.gradle @@ -75,7 +75,7 @@ dependencies { //implementation irohaDep implementation roomDep - kapt roomKaptDep + //kapt roomKaptDep testImplementation project(":test_shared") } \ No newline at end of file diff --git a/feature_main_impl/src/main/java/jp/co/soramitsu/feature_main_impl/presentation/MainActivity.kt b/feature_main_impl/src/main/java/jp/co/soramitsu/feature_main_impl/presentation/MainActivity.kt index 1d71335f1..c30d18203 100644 --- a/feature_main_impl/src/main/java/jp/co/soramitsu/feature_main_impl/presentation/MainActivity.kt +++ b/feature_main_impl/src/main/java/jp/co/soramitsu/feature_main_impl/presentation/MainActivity.kt @@ -58,7 +58,7 @@ import dev.chrisbanes.insetter.applyInsetter import dev.chrisbanes.insetter.windowInsetTypesOf import java.util.Date import javax.inject.Inject -import jp.co.soramitsu.common.domain.BarsColorhandler +import jp.co.soramitsu.common.domain.BarsColorHandler import jp.co.soramitsu.common.domain.BottomBarController import jp.co.soramitsu.common.domain.DarkThemeManager import jp.co.soramitsu.common.inappupdate.InAppUpdateManager @@ -83,7 +83,7 @@ import kotlinx.coroutines.launch class MainActivity : ToolbarActivity(), BottomBarController, - BarsColorhandler, + BarsColorHandler, OnboardingNavigator, InAppUpdateManager.UpdateManagerListener { @@ -292,15 +292,6 @@ class MainActivity : } } - override fun onNewIntent(intent: Intent?) { - super.onNewIntent(intent) - intent?.let { -// if (ACTION_INVITE == it.action) { -// viewModel.startedWithInviteAction() -// } - } - } - override fun setColor(@AttrRes color: Int) { curBarsColor = color window.statusBarColor = attrColor(color) @@ -381,6 +372,7 @@ class MainActivity : } override fun onTrimMemory(i: Int) { + super.onTrimMemory(i) if (i == ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) { timeInBackground = Date() } diff --git a/feature_main_impl/src/test/java/jp/co/soramitsu/feature_main_impl/presentation/MainViewModelTest.kt b/feature_main_impl/src/test/java/jp/co/soramitsu/feature_main_impl/presentation/MainViewModelTest.kt index 9a1644174..0de8cd32f 100644 --- a/feature_main_impl/src/test/java/jp/co/soramitsu/feature_main_impl/presentation/MainViewModelTest.kt +++ b/feature_main_impl/src/test/java/jp/co/soramitsu/feature_main_impl/presentation/MainViewModelTest.kt @@ -33,21 +33,16 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.feature_main_impl.presentation import androidx.arch.core.executor.testing.InstantTaskExecutorRule -import io.mockk.coEvery -import io.mockk.coVerify import io.mockk.every -import io.mockk.impl.annotations.MockK -import io.mockk.junit4.MockKRule import io.mockk.mockkObject -import io.mockk.verify import jp.co.soramitsu.common.domain.CoroutineManager import jp.co.soramitsu.common.domain.RepeatStrategy import jp.co.soramitsu.common.domain.RepeatStrategyBuilder import jp.co.soramitsu.feature_assets_api.domain.AssetsInteractor +import jp.co.soramitsu.feature_blockexplorer_api.data.BlockExplorerManager import jp.co.soramitsu.feature_main_impl.domain.PinCodeInteractor import jp.co.soramitsu.feature_main_impl.domain.subs.GlobalSubscriptionManager import jp.co.soramitsu.feature_select_node_api.NodeManager -import jp.co.soramitsu.feature_blockexplorer_api.data.BlockExplorerManager import jp.co.soramitsu.test_data.TestAccounts import jp.co.soramitsu.test_shared.MainCoroutineRule import jp.co.soramitsu.test_shared.getOrAwaitValue @@ -61,8 +56,15 @@ import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.rules.TestRule +import org.junit.runner.RunWith +import org.mockito.Mock +import org.mockito.junit.MockitoJUnitRunner +import org.mockito.kotlin.times +import org.mockito.kotlin.verify +import org.mockito.kotlin.whenever @ExperimentalCoroutinesApi +@RunWith(MockitoJUnitRunner::class) class MainViewModelTest { @Rule @@ -72,25 +74,22 @@ class MainViewModelTest { @get:Rule var mainCoroutineRule = MainCoroutineRule() - @get:Rule - val mockkRule = MockKRule(this) - - @MockK + @Mock private lateinit var nodeManager: NodeManager - @MockK + @Mock private lateinit var assetsInteractor: AssetsInteractor - @MockK + @Mock private lateinit var pinCodeInteractor: PinCodeInteractor - @MockK + @Mock private lateinit var globalSubscriptionManager: GlobalSubscriptionManager - @MockK + @Mock private lateinit var blockExplorerManager: BlockExplorerManager - @MockK + @Mock private lateinit var coroutineManager: CoroutineManager private lateinit var mainViewModel: MainViewModel @@ -98,15 +97,13 @@ class MainViewModelTest { @OptIn(ExperimentalStdlibApi::class) @Before fun setUp() = runTest { - every { globalSubscriptionManager.start() } returns flowOf("") - every { nodeManager.connectionState } returns flowOf(true) - every { assetsInteractor.flowCurSoraAccount() } returns flowOf(TestAccounts.soraAccount) - coEvery { assetsInteractor.getCurSoraAccount() } returns TestAccounts.soraAccount - every { coroutineManager.io } returns this.coroutineContext[CoroutineDispatcher]!! - coEvery { blockExplorerManager.updateFiat() } returns Unit - coEvery { assetsInteractor.updateWhitelistBalances() } returns Unit - coEvery { assetsInteractor.getTokensList() } returns emptyList() - coEvery { blockExplorerManager.getTokensLiquidity(emptyList()) } returns emptyList() + whenever(globalSubscriptionManager.start()).thenReturn(flowOf("")) + whenever(nodeManager.connectionState).thenReturn(flowOf(true)) + whenever(assetsInteractor.flowCurSoraAccount()).thenReturn(flowOf(TestAccounts.soraAccount)) + whenever(coroutineManager.io).thenReturn(this.coroutineContext[CoroutineDispatcher]!!) + whenever(assetsInteractor.getTokensList()).thenReturn(emptyList()) + whenever(blockExplorerManager.getTokensLiquidity(emptyList())).thenReturn(emptyList()) + mockkObject(RepeatStrategyBuilder) every { RepeatStrategyBuilder.infinite() } returns object : RepeatStrategy { override suspend fun repeat(block: suspend () -> Unit) { @@ -128,9 +125,9 @@ class MainViewModelTest { coroutineManager ) advanceTimeBy(22000) - verify { globalSubscriptionManager.start() } - coVerify { assetsInteractor.updateWhitelistBalances() } - coVerify(exactly = 3) { blockExplorerManager.updateFiat() } + verify(globalSubscriptionManager).start() + verify(assetsInteractor).updateWhitelistBalances() + verify(blockExplorerManager, times(3)).updateFiat() assertFalse(mainViewModel.badConnectionVisibilityLiveData.getOrAwaitValue()) } } diff --git a/feature_multiaccount_impl/build.gradle b/feature_multiaccount_impl/build.gradle index b46cb4b6b..a3cf4fb43 100644 --- a/feature_multiaccount_impl/build.gradle +++ b/feature_multiaccount_impl/build.gradle @@ -23,9 +23,10 @@ android { // sourceCompatibility JavaVersion.VERSION_1_8 // targetCompatibility JavaVersion.VERSION_1_8 // } -// kotlinOptions { + kotlinOptions { // jvmTarget = JavaVersion.VERSION_1_8 -// } + freeCompilerArgs += ["-Xstring-concat=inline"] + } composeOptions { kotlinCompilerExtensionVersion versions.composeCompiler diff --git a/feature_multiaccount_impl/src/main/java/jp/co/soramitsu/feature_multiaccount_impl/presentation/export_account/account_details/AccountDetailsScreen.kt b/feature_multiaccount_impl/src/main/java/jp/co/soramitsu/feature_multiaccount_impl/presentation/export_account/account_details/AccountDetailsScreen.kt index 7e5895fab..102d42aab 100644 --- a/feature_multiaccount_impl/src/main/java/jp/co/soramitsu/feature_multiaccount_impl/presentation/export_account/account_details/AccountDetailsScreen.kt +++ b/feature_multiaccount_impl/src/main/java/jp/co/soramitsu/feature_multiaccount_impl/presentation/export_account/account_details/AccountDetailsScreen.kt @@ -32,21 +32,21 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.feature_multiaccount_impl.presentation.export_account.account_details -import androidx.compose.foundation.background +import android.content.res.Configuration import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.wrapContentHeight -import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.text.KeyboardActions import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.material.MaterialTheme import androidx.compose.material.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color +import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.platform.LocalFocusManager import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource @@ -56,6 +56,7 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.tooling.preview.Preview import jp.co.soramitsu.common.R import jp.co.soramitsu.common.presentation.compose.components.Option +import jp.co.soramitsu.common.presentation.compose.theme.SoraAppTheme import jp.co.soramitsu.common.util.ext.testTagAsId import jp.co.soramitsu.ui_core.component.button.LoaderWrapper import jp.co.soramitsu.ui_core.component.button.properties.Size @@ -63,7 +64,6 @@ import jp.co.soramitsu.ui_core.component.card.ContentCard import jp.co.soramitsu.ui_core.component.input.InputText import jp.co.soramitsu.ui_core.component.input.InputTextState import jp.co.soramitsu.ui_core.resources.Dimens -import jp.co.soramitsu.ui_core.theme.borderRadius import jp.co.soramitsu.ui_core.theme.customColors import jp.co.soramitsu.ui_core.theme.customTypography @@ -73,20 +73,15 @@ internal fun AccountName( onValueChanged: (TextFieldValue) -> Unit, ) { val focusManager = LocalFocusManager.current + val focusRequester = remember { FocusRequester() } InputText( - modifier = Modifier - .background( - color = MaterialTheme.customColors.bgSurface, - shape = RoundedCornerShape(MaterialTheme.borderRadius.ml) - ) - .fillMaxWidth() - .wrapContentHeight(), + modifier = Modifier.fillMaxWidth(), maxLines = 1, singleLine = true, state = inputTextState, onValueChange = onValueChanged, - onFocusChanged = { if (!it.isFocused) focusManager.clearFocus() }, + focusRequester = focusRequester, keyboardActions = KeyboardActions( onDone = { focusManager.clearFocus() @@ -173,7 +168,7 @@ internal fun BackupOptions( icon = painterResource(R.drawable.ic_arrow_up_rectangle_24), label = stringResource(R.string.export_protection_json_title), onClick = onExportJson, - bottomDivider = false, + bottomDivider = isBackupAvailable != null, ) isBackupAvailable?.let { @@ -193,7 +188,7 @@ internal fun BackupOptions( icon = painterResource(R.drawable.ic_arrow_up_rectangle_24), label = text, onClick = onBackupGoogle, - textColor = if (isBackupAvailable) MaterialTheme.customColors.statusError else Color.Unspecified, + textColor = if (isBackupAvailable) MaterialTheme.customColors.statusError else MaterialTheme.customColors.fgPrimary, enabled = !isBackupLoading, bottomDivider = false, ) @@ -210,16 +205,34 @@ internal fun BackupOptions( } } -@Preview +@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO) @Composable -private fun PreviewBackup() { - BackupOptions( - isMnemonicAvailable = true, - isBackupAvailable = true, - isBackupLoading = false, - onShowPassphrase = { }, - onShowRawSeed = { }, - onExportJson = { }, - onBackupGoogle = {} - ) +private fun PreviewBackup01() { + SoraAppTheme { + BackupOptions( + isMnemonicAvailable = true, + isBackupAvailable = true, + isBackupLoading = false, + onShowPassphrase = { }, + onShowRawSeed = { }, + onExportJson = { }, + onBackupGoogle = {} + ) + } +} + +@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun PreviewBackup02() { + SoraAppTheme { + BackupOptions( + isMnemonicAvailable = true, + isBackupAvailable = true, + isBackupLoading = false, + onShowPassphrase = { }, + onShowRawSeed = { }, + onExportJson = { }, + onBackupGoogle = {} + ) + } } diff --git a/feature_multiaccount_impl/src/main/java/jp/co/soramitsu/feature_multiaccount_impl/presentation/export_account/account_details/AccountDetailsScreenBasic.kt b/feature_multiaccount_impl/src/main/java/jp/co/soramitsu/feature_multiaccount_impl/presentation/export_account/account_details/AccountDetailsScreenBasic.kt index 2be6db8b2..537711e52 100644 --- a/feature_multiaccount_impl/src/main/java/jp/co/soramitsu/feature_multiaccount_impl/presentation/export_account/account_details/AccountDetailsScreenBasic.kt +++ b/feature_multiaccount_impl/src/main/java/jp/co/soramitsu/feature_multiaccount_impl/presentation/export_account/account_details/AccountDetailsScreenBasic.kt @@ -32,6 +32,8 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.feature_multiaccount_impl.presentation.export_account.account_details +import android.content.res.Configuration +import androidx.compose.foundation.background import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth @@ -39,10 +41,12 @@ import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.tooling.preview.Preview import jp.co.soramitsu.common.R +import jp.co.soramitsu.common.presentation.compose.theme.SoraAppTheme import jp.co.soramitsu.common.util.ext.testTagAsId import jp.co.soramitsu.feature_multiaccount_impl.presentation.export_account.model.AccountDetailsScreenState import jp.co.soramitsu.ui_core.component.button.TonalButton @@ -93,29 +97,68 @@ internal fun AccountDetailsScreenBasic( ) } -@Preview(showBackground = true) +@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO) @Composable -private fun PreviewAccountDetailsScreenBasic() { - Column( - modifier = Modifier - .fillMaxWidth() - .wrapContentHeight() - ) { - AccountDetailsScreenBasic( - state = AccountDetailsScreenState( - accountNameState = InputTextState(value = TextFieldValue("bla"), label = "Name"), - isMnemonicAvailable = false, - isBackupLoading = false, - isBackupAvailable = false, - "cnVkoGs3rEMqLqY27c2nfVXJRGdzNJk2ns78DcqtppaSRe8qm", - ), - onValueChanged = {}, - onShowPassphrase = {}, - onShowRawSeed = {}, - onExportJson = {}, - onLogout = {}, - onAddressClick = {}, - onBackupClicked = {} - ) +private fun PreviewAccountDetailsScreenBasic01() { + SoraAppTheme { + Column( + modifier = Modifier + .background(Color.White) + .fillMaxWidth() + .wrapContentHeight() + ) { + AccountDetailsScreenBasic( + state = AccountDetailsScreenState( + accountNameState = InputTextState( + value = TextFieldValue("bla"), + label = "Name" + ), + isMnemonicAvailable = false, + isBackupLoading = false, + isBackupAvailable = false, + "cnVkoGs3rEMqLqY27c2nfVXJRGdzNJk2ns78DcqtppaSRe8qm", + ), + onValueChanged = {}, + onShowPassphrase = {}, + onShowRawSeed = {}, + onExportJson = {}, + onLogout = {}, + onAddressClick = {}, + onBackupClicked = {} + ) + } + } +} + +@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun PreviewAccountDetailsScreenBasic02() { + SoraAppTheme { + Column( + modifier = Modifier + .background(Color.White) + .fillMaxWidth() + .wrapContentHeight() + ) { + AccountDetailsScreenBasic( + state = AccountDetailsScreenState( + accountNameState = InputTextState( + value = TextFieldValue("bla"), + label = "Name" + ), + isMnemonicAvailable = false, + isBackupLoading = false, + isBackupAvailable = false, + "cnVkoGs3rEMqLqY27c2nfVXJRGdzNJk2ns78DcqtppaSRe8qm", + ), + onValueChanged = {}, + onShowPassphrase = {}, + onShowRawSeed = {}, + onExportJson = {}, + onLogout = {}, + onAddressClick = {}, + onBackupClicked = {} + ) + } } } diff --git a/feature_multiaccount_impl/src/main/java/jp/co/soramitsu/feature_multiaccount_impl/presentation/export_account/account_list/AccountListMenu.kt b/feature_multiaccount_impl/src/main/java/jp/co/soramitsu/feature_multiaccount_impl/presentation/export_account/account_list/AccountListMenu.kt index f77901eb5..9ebc361aa 100644 --- a/feature_multiaccount_impl/src/main/java/jp/co/soramitsu/feature_multiaccount_impl/presentation/export_account/account_list/AccountListMenu.kt +++ b/feature_multiaccount_impl/src/main/java/jp/co/soramitsu/feature_multiaccount_impl/presentation/export_account/account_list/AccountListMenu.kt @@ -33,7 +33,7 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.feature_multiaccount_impl.presentation.export_account.account_list import androidx.compose.foundation.background -import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.material.DropdownMenu import androidx.compose.material.DropdownMenuItem import androidx.compose.material.MaterialTheme @@ -41,10 +41,11 @@ import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.style.TextOverflow import jp.co.soramitsu.common.util.ext.testTagAsId import jp.co.soramitsu.feature_multiaccount_impl.R -import jp.co.soramitsu.ui_core.resources.Dimens import jp.co.soramitsu.ui_core.theme.customColors +import jp.co.soramitsu.ui_core.theme.customTypography @Composable internal fun AccountMenu( @@ -54,25 +55,37 @@ internal fun AccountMenu( address: String, expanded: Boolean, ) { - MaterialTheme(shapes = MaterialTheme.shapes.copy(medium = RoundedCornerShape(Dimens.x3))) { - DropdownMenu( - modifier = Modifier.background(MaterialTheme.customColors.bgSurface), - expanded = expanded, - onDismissRequest = onDismissMenu, + DropdownMenu( + modifier = Modifier.background(MaterialTheme.customColors.bgSurface), + expanded = expanded, + onDismissRequest = onDismissMenu, + ) { + DropdownMenuItem( + modifier = Modifier.testTagAsId("SelectAccountForBatchExport"), + onClick = { onSelectOptionsClicked(address) } ) { - DropdownMenuItem( - modifier = Modifier.testTagAsId("SelectAccountForBatchExport"), - onClick = { onSelectOptionsClicked(address) } - ) { - Text(stringResource(id = R.string.export_select_account)) - } + Text( + modifier = Modifier.wrapContentHeight(), + color = MaterialTheme.customColors.fgPrimary, + style = MaterialTheme.customTypography.textM, + text = stringResource(id = R.string.export_select_account), + maxLines = 1, + overflow = TextOverflow.Ellipsis, + ) + } - DropdownMenuItem( - modifier = Modifier.testTagAsId("OpenAccountOptions"), - onClick = { onAccountOptionsClicked(address) } - ) { - Text(stringResource(id = R.string.export_account_options)) - } + DropdownMenuItem( + modifier = Modifier.testTagAsId("OpenAccountOptions"), + onClick = { onAccountOptionsClicked(address) } + ) { + Text( + modifier = Modifier.wrapContentHeight(), + color = MaterialTheme.customColors.fgPrimary, + style = MaterialTheme.customTypography.textM, + text = stringResource(id = R.string.export_account_options), + maxLines = 1, + overflow = TextOverflow.Ellipsis, + ) } } } diff --git a/feature_multiaccount_impl/src/main/java/jp/co/soramitsu/feature_multiaccount_impl/presentation/export_account/account_list/AccountListScreen.kt b/feature_multiaccount_impl/src/main/java/jp/co/soramitsu/feature_multiaccount_impl/presentation/export_account/account_list/AccountListScreen.kt index a11df830d..5e789d5db 100644 --- a/feature_multiaccount_impl/src/main/java/jp/co/soramitsu/feature_multiaccount_impl/presentation/export_account/account_list/AccountListScreen.kt +++ b/feature_multiaccount_impl/src/main/java/jp/co/soramitsu/feature_multiaccount_impl/presentation/export_account/account_list/AccountListScreen.kt @@ -32,9 +32,11 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.feature_multiaccount_impl.presentation.export_account.account_list +import android.content.res.Configuration import android.graphics.drawable.Drawable import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.ScrollState +import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.layout.Arrangement @@ -56,9 +58,11 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp import jp.co.soramitsu.common.R import jp.co.soramitsu.common.account.SoraAccount import jp.co.soramitsu.common.presentation.compose.previewDrawable +import jp.co.soramitsu.common.presentation.compose.theme.SoraAppTheme import jp.co.soramitsu.common.util.ext.testTagAsId import jp.co.soramitsu.feature_multiaccount_impl.presentation.export_account.model.AccountListScreenState import jp.co.soramitsu.feature_multiaccount_impl.presentation.export_account.model.ExportAccountData @@ -190,38 +194,88 @@ private fun AccountListItem( } } -@Preview(showBackground = true, backgroundColor = 0xffffff) +@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO) @Composable -private fun PreviewList() { - Column { - AccountList( - state = AccountListScreenState( - isActionMode = false, - accountList = listOf( - ExportAccountData( - isSelected = false, - isSelectedAction = false, - icon = previewDrawable, - account = SoraAccount("cnFjl....sllkj", "name 1"), - ), - ExportAccountData( - isSelected = true, - isSelectedAction = false, - icon = previewDrawable, - account = SoraAccount("cnFjl....sllkj", "name 2"), - ), - ExportAccountData( - isSelected = false, - isSelectedAction = true, - icon = previewDrawable, - account = SoraAccount("cnFjl....sllkj", "name 3"), - ), - ) - ), - onAccountClicked = {}, - onAccountLongClicked = {}, - onSelectOptionsClicked = {}, - onAccountOptionsClicked = {}, - ) +private fun PreviewList01() { + SoraAppTheme { + Column( + modifier = Modifier + .background(MaterialTheme.customColors.bgSurface) + .fillMaxWidth() + .padding(12.dp) + ) { + AccountList( + state = AccountListScreenState( + isActionMode = false, + accountList = listOf( + ExportAccountData( + isSelected = false, + isSelectedAction = false, + icon = previewDrawable, + account = SoraAccount("cnFjl....sllkj", "name 1"), + ), + ExportAccountData( + isSelected = true, + isSelectedAction = false, + icon = previewDrawable, + account = SoraAccount("cnFjl....sllkj", "name 2"), + ), + ExportAccountData( + isSelected = false, + isSelectedAction = true, + icon = previewDrawable, + account = SoraAccount("cnFjl....sllkj", "name 3"), + ), + ) + ), + onAccountClicked = {}, + onAccountLongClicked = {}, + onSelectOptionsClicked = {}, + onAccountOptionsClicked = {}, + ) + } + } +} + +@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun PreviewList02() { + SoraAppTheme { + Column( + modifier = Modifier + .background(MaterialTheme.customColors.bgSurface) + .fillMaxWidth() + .padding(12.dp) + ) { + AccountList( + state = AccountListScreenState( + isActionMode = false, + accountList = listOf( + ExportAccountData( + isSelected = false, + isSelectedAction = false, + icon = previewDrawable, + account = SoraAccount("cnFjl....sllkj", "name 1"), + ), + ExportAccountData( + isSelected = true, + isSelectedAction = false, + icon = previewDrawable, + account = SoraAccount("cnFjl....sllkj", "name 2"), + ), + ExportAccountData( + isSelected = false, + isSelectedAction = true, + icon = previewDrawable, + account = SoraAccount("cnFjl....sllkj", "name 3"), + ), + ) + ), + onAccountClicked = {}, + onAccountLongClicked = {}, + onSelectOptionsClicked = {}, + onAccountOptionsClicked = {}, + ) + } } } diff --git a/feature_multiaccount_impl/src/main/java/jp/co/soramitsu/feature_multiaccount_impl/presentation/export_account/account_list/AccountWithIcon.kt b/feature_multiaccount_impl/src/main/java/jp/co/soramitsu/feature_multiaccount_impl/presentation/export_account/account_list/AccountWithIcon.kt index 0ef2b35b4..7dad7a6c1 100644 --- a/feature_multiaccount_impl/src/main/java/jp/co/soramitsu/feature_multiaccount_impl/presentation/export_account/account_list/AccountWithIcon.kt +++ b/feature_multiaccount_impl/src/main/java/jp/co/soramitsu/feature_multiaccount_impl/presentation/export_account/account_list/AccountWithIcon.kt @@ -49,7 +49,7 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp -import jp.co.soramitsu.common.presentation.compose.TokenIcon +import jp.co.soramitsu.common.presentation.compose.AccountIcon import jp.co.soramitsu.common.util.ext.truncateUserAddress import jp.co.soramitsu.ui_core.resources.Dimens import jp.co.soramitsu.ui_core.theme.customColors @@ -96,7 +96,7 @@ private fun AccountWithIcon( accountIcon: Drawable, ) { Row { - TokenIcon(uri = accountIcon, size = 40.dp, modifier = Modifier.padding(start = Dimens.x2)) + AccountIcon(drawable = accountIcon, size = 40.dp, modifier = Modifier.padding(start = Dimens.x2)) Column( modifier = Modifier diff --git a/feature_multiaccount_impl/src/main/java/jp/co/soramitsu/feature_multiaccount_impl/presentation/import_account_list/import_account_password/ImportAccountPasswordScreen.kt b/feature_multiaccount_impl/src/main/java/jp/co/soramitsu/feature_multiaccount_impl/presentation/import_account_list/import_account_password/ImportAccountPasswordScreen.kt index e141c3a8c..dc963a6c0 100644 --- a/feature_multiaccount_impl/src/main/java/jp/co/soramitsu/feature_multiaccount_impl/presentation/import_account_list/import_account_password/ImportAccountPasswordScreen.kt +++ b/feature_multiaccount_impl/src/main/java/jp/co/soramitsu/feature_multiaccount_impl/presentation/import_account_list/import_account_password/ImportAccountPasswordScreen.kt @@ -57,7 +57,7 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import jp.co.soramitsu.backup.domain.models.BackupAccountMeta import jp.co.soramitsu.common.R -import jp.co.soramitsu.common.presentation.compose.TokenIcon +import jp.co.soramitsu.common.presentation.compose.AccountIcon import jp.co.soramitsu.feature_multiaccount_impl.presentation.BackupAccountMetaWithIcon import jp.co.soramitsu.feature_multiaccount_impl.presentation.ImportAccountPasswordState import jp.co.soramitsu.ui_core.component.button.FilledButton @@ -159,8 +159,8 @@ fun AccountWithIcon( modifier = modifier, verticalAlignment = Alignment.CenterVertically ) { - TokenIcon( - uri = accountIcon ?: R.drawable.ic_token_default, + AccountIcon( + drawable = accountIcon, size = 40.dp, ) diff --git a/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/components/compose/SwapAmountSquare.kt b/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/components/compose/SwapAmountSquare.kt index de4b651a9..095eb30a7 100644 --- a/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/components/compose/SwapAmountSquare.kt +++ b/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/components/compose/SwapAmountSquare.kt @@ -32,7 +32,6 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.feature_polkaswap_impl.presentation.components.compose -import android.net.Uri import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row @@ -60,7 +59,7 @@ import jp.co.soramitsu.ui_core.theme.customTypography @Composable internal fun SwapAmountSquare( modifier: Modifier, - icon: Uri, + icon: String, amount: String, amountFiat: String, ) { diff --git a/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/components/compose/SwapMarketsScreen.kt b/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/components/compose/SwapMarketsScreen.kt index c8c2e3f5b..b80465174 100644 --- a/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/components/compose/SwapMarketsScreen.kt +++ b/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/components/compose/SwapMarketsScreen.kt @@ -117,6 +117,7 @@ private fun MarketScreenItem( var hintVisible by remember { mutableStateOf(false) } if (hintVisible) { AlertDialog( + backgroundColor = MaterialTheme.customColors.bgPage, title = { Text( text = stringResource(id = market.titleResource), diff --git a/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/components/compose/SwapSlippageScreen.kt b/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/components/compose/SwapSlippageScreen.kt index 65e8814f5..fc6a5a772 100644 --- a/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/components/compose/SwapSlippageScreen.kt +++ b/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/components/compose/SwapSlippageScreen.kt @@ -30,8 +30,9 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package jp.co.soramitsu.feature_polkaswap_impl.presentation.screens.swap +package jp.co.soramitsu.feature_polkaswap_impl.presentation.components.compose +import android.content.res.Configuration import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.background import androidx.compose.foundation.border @@ -47,6 +48,7 @@ import androidx.compose.material.MaterialTheme import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableDoubleStateOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue @@ -63,6 +65,7 @@ import java.math.BigDecimal import java.text.DecimalFormatSymbols import java.util.Locale import jp.co.soramitsu.common.R +import jp.co.soramitsu.common.presentation.compose.theme.SoraAppTheme import jp.co.soramitsu.ui_core.component.button.FilledButton import jp.co.soramitsu.ui_core.component.button.properties.Order import jp.co.soramitsu.ui_core.component.button.properties.Size @@ -84,7 +87,7 @@ internal fun SwapSlippageScreen( value: Double, onDone: (Double) -> Unit, ) { - var currentValueLocalStorage by remember { mutableStateOf(value) } + var currentValueLocalStorage by remember { mutableDoubleStateOf(value) } val desc = remember { mutableStateOf(null) } val frontrun = stringResource(id = R.string.polkaswap_slippage_frontrun) @@ -142,17 +145,20 @@ internal fun SwapSlippageScreen( .focusRequester(focusRequester) .onFocusChanged { focused.value = it.isFocused - }.border( + } + .border( border = BorderStroke( width = 1.dp, color = if (focused.value) MaterialTheme.customColors.fgPrimary else MaterialTheme.customColors.fgOutline ), shape = RoundedCornerShape(MaterialTheme.borderRadius.ml) - ).background( + ) + .background( color = MaterialTheme.customColors.bgSurface, shape = RoundedCornerShape(MaterialTheme.borderRadius.ml) - ).clip(RoundedCornerShape(MaterialTheme.borderRadius.ml)) + ) + .clip(RoundedCornerShape(MaterialTheme.borderRadius.ml)) .padding(vertical = Dimens.x1_2, horizontal = Dimens.x2) .defaultMinSize(minHeight = Dimens.InputHeight) .wrapContentHeight() @@ -160,7 +166,7 @@ internal fun SwapSlippageScreen( ) { BasicNumberInput( modifier = Modifier, - textStyle = MaterialTheme.customTypography.textM, + textStyle = MaterialTheme.customTypography.textM.copy(color = MaterialTheme.customColors.fgPrimary), initial = value.toBigDecimal(), // input value is used; no locally stored data!!! precision = 2, enabled = true, @@ -208,11 +214,24 @@ internal fun SwapSlippageScreen( } } -@Preview(showBackground = true) +@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_NO) +@Composable +private fun PreviewSwapSlippageScreen01() { + SoraAppTheme { + SwapSlippageScreen( + value = 0.5, + onDone = {}, + ) + } +} + +@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES) @Composable -private fun PreviewSwapSlippageScreen() { - SwapSlippageScreen( - value = 0.5, - onDone = {}, - ) +private fun PreviewSwapSlippageScreen02() { + SoraAppTheme { + SwapSlippageScreen( + value = 0.5, + onDone = {}, + ) + } } diff --git a/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/screens/liquidityadd/LiquidityAddFragment.kt b/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/screens/liquidityadd/LiquidityAddFragment.kt index 955594b49..414aea682 100644 --- a/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/screens/liquidityadd/LiquidityAddFragment.kt +++ b/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/screens/liquidityadd/LiquidityAddFragment.kt @@ -63,7 +63,7 @@ import jp.co.soramitsu.core_di.viewmodel.CustomViewModelFactory import jp.co.soramitsu.feature_assets_api.presentation.selectsearchtoken.SelectSearchTokenScreen import jp.co.soramitsu.feature_polkaswap_impl.presentation.components.compose.LiquidityAddConfirmScreen import jp.co.soramitsu.feature_polkaswap_impl.presentation.components.compose.LiquidityAddScreen -import jp.co.soramitsu.feature_polkaswap_impl.presentation.screens.swap.SwapSlippageScreen +import jp.co.soramitsu.feature_polkaswap_impl.presentation.components.compose.SwapSlippageScreen import jp.co.soramitsu.ui_core.theme.customColors import jp.co.soramitsu.ui_core.theme.customTypography import kotlinx.coroutines.ExperimentalCoroutinesApi diff --git a/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/screens/liquidityremove/LiquidityRemoveFragment.kt b/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/screens/liquidityremove/LiquidityRemoveFragment.kt index 1b3c5743b..29543ab1b 100644 --- a/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/screens/liquidityremove/LiquidityRemoveFragment.kt +++ b/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/screens/liquidityremove/LiquidityRemoveFragment.kt @@ -63,7 +63,7 @@ import jp.co.soramitsu.common.util.ext.getColorFromAttrs import jp.co.soramitsu.core_di.viewmodel.CustomViewModelFactory import jp.co.soramitsu.feature_polkaswap_impl.presentation.components.compose.LiquidityRemoveConfirmScreen import jp.co.soramitsu.feature_polkaswap_impl.presentation.components.compose.LiquidityRemoveScreen -import jp.co.soramitsu.feature_polkaswap_impl.presentation.screens.swap.SwapSlippageScreen +import jp.co.soramitsu.feature_polkaswap_impl.presentation.components.compose.SwapSlippageScreen import jp.co.soramitsu.ui_core.theme.customColors import jp.co.soramitsu.ui_core.theme.customTypography diff --git a/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/screens/swap/SwapFragment.kt b/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/screens/swap/SwapFragment.kt index 5f1ba4335..efd8dbbbe 100644 --- a/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/screens/swap/SwapFragment.kt +++ b/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/screens/swap/SwapFragment.kt @@ -34,7 +34,6 @@ package jp.co.soramitsu.feature_polkaswap_impl.presentation.screens.swap import android.os.Bundle import android.view.View -import androidx.compose.animation.ExperimentalAnimationApi import androidx.compose.foundation.ScrollState import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize @@ -66,6 +65,7 @@ import jp.co.soramitsu.feature_assets_api.presentation.selectsearchtoken.SelectS import jp.co.soramitsu.feature_polkaswap_impl.presentation.components.compose.SwapConfirmScreen import jp.co.soramitsu.feature_polkaswap_impl.presentation.components.compose.SwapMainScreen import jp.co.soramitsu.feature_polkaswap_impl.presentation.components.compose.SwapMarketsScreen +import jp.co.soramitsu.feature_polkaswap_impl.presentation.components.compose.SwapSlippageScreen import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.FlowPreview @@ -101,7 +101,6 @@ class SwapFragment : SoraBaseFragment() { override fun backgroundColor(): Int = R.attr.polkaswapBackground - @OptIn(ExperimentalAnimationApi::class) override fun NavGraphBuilder.content( scrollState: ScrollState, navController: NavHostController diff --git a/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/states/PoolDetailsState.kt b/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/states/PoolDetailsState.kt index a533a4675..f48c50527 100644 --- a/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/states/PoolDetailsState.kt +++ b/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/states/PoolDetailsState.kt @@ -32,12 +32,10 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.feature_polkaswap_impl.presentation.states -import android.net.Uri - internal data class PoolDetailsState( - val token1Icon: Uri, - val token2Icon: Uri, - val rewardsUri: Uri, + val token1Icon: String, + val token2Icon: String, + val rewardsUri: String, val rewardsTokenSymbol: String, val symbol1: String, val symbol2: String, @@ -52,7 +50,7 @@ internal data class PoolDetailsState( ) internal data class PoolDetailsDemeterState( - val rewardsUri: Uri, + val rewardsUri: String, val rewardsTokenSymbol: String, val percent: Float, ) diff --git a/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/states/PoolSettingsState.kt b/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/states/PoolSettingsState.kt index fd8b4032c..9ed4bd609 100644 --- a/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/states/PoolSettingsState.kt +++ b/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/states/PoolSettingsState.kt @@ -32,13 +32,12 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.feature_polkaswap_impl.presentation.states -import android.net.Uri import jp.co.soramitsu.common.util.StringPair data class PoolSettingsState( val id: StringPair, - val token1Icon: Uri, - val token2Icon: Uri, + val token1Icon: String, + val token2Icon: String, val tokenName: String, val tokenSymbol: String, val assetAmount: String, diff --git a/feature_polkaswap_impl/src/test/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/polkaswap/liquidity/add/AddLiquidityViewModelTest.kt b/feature_polkaswap_impl/src/test/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/polkaswap/liquidity/add/AddLiquidityViewModelTest.kt index 8e6311278..ae83e9535 100644 --- a/feature_polkaswap_impl/src/test/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/polkaswap/liquidity/add/AddLiquidityViewModelTest.kt +++ b/feature_polkaswap_impl/src/test/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/polkaswap/liquidity/add/AddLiquidityViewModelTest.kt @@ -117,8 +117,6 @@ class AddLiquidityViewModelTest { @Mock private lateinit var router: WalletRouter - private val mockedUri = Mockito.mock(Uri::class.java) - private lateinit var viewModel: LiquidityAddViewModel private fun setUpViewModel( @@ -143,14 +141,6 @@ class AddLiquidityViewModelTest { @Before fun setUp() = runTest { mockkObject(FirebaseWrapper) - mockkStatic(Uri::parse) - every { Uri.parse(any()) } returns mockedUri - mockkStatic(Token::iconUri) - every { TestTokens.xorToken.iconUri() } returns mockedUri - every { TestTokens.valToken.iconUri() } returns mockedUri - every { TestTokens.pswapToken.iconUri() } returns mockedUri - every { TestTokens.xstusdToken.iconUri() } returns mockedUri - every { TestTokens.xstToken.iconUri() } returns mockedUri given( assetsInteractor.isNotEnoughXorLeftAfterTransaction( networkFeeInXor = any(), diff --git a/feature_referral_impl/src/main/java/jp/co/soramitsu/feature_referral_impl/presentation/ReferralBondUnbondXor.kt b/feature_referral_impl/src/main/java/jp/co/soramitsu/feature_referral_impl/presentation/ReferralBondUnbondXor.kt index 57ea3851e..b9b6b67f9 100644 --- a/feature_referral_impl/src/main/java/jp/co/soramitsu/feature_referral_impl/presentation/ReferralBondUnbondXor.kt +++ b/feature_referral_impl/src/main/java/jp/co/soramitsu/feature_referral_impl/presentation/ReferralBondUnbondXor.kt @@ -32,6 +32,7 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.feature_referral_impl.presentation +import android.content.res.Configuration import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.clickable @@ -62,6 +63,7 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import jp.co.soramitsu.common.R import jp.co.soramitsu.common.presentation.compose.components.DetailsItemNetworkFee +import jp.co.soramitsu.common.presentation.compose.theme.SoraAppTheme import jp.co.soramitsu.common.view.WarningTextCard import jp.co.soramitsu.ui_core.component.button.FilledButton import jp.co.soramitsu.ui_core.component.button.LoaderWrapper @@ -297,6 +299,7 @@ fun InvitationsEnterField( maxLines = 1, keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number), colors = TextFieldDefaults.textFieldColors( + textColor = MaterialTheme.customColors.fgPrimary, cursorColor = MaterialTheme.customColors.fgPrimary, backgroundColor = Color.Transparent, focusedIndicatorColor = Color.Transparent, @@ -343,25 +346,53 @@ fun InvitationsEnterField( } @Composable -@Preview -fun PreviewReferralBondXor() { - ReferralBondXor( - common = ReferralCommonState( - activate = true, - progress = false, - referrer = "address", - referrerFee = "0.005 XOR", - extrinsicFee = "0.002 XOR", - extrinsicFeeFiat = "$12" - ), - state = ReferralBondState( - invitationsCount = 2, - invitationsAmount = "0.098 XOR", - balance = "123.56743 XOR" - ), - onBondInvitationsCountChange = {}, - onBondMinus = {}, - onBondPlus = {}, - onBondClick = {} - ) +@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO) +fun PreviewReferralBondXor01() { + SoraAppTheme { + ReferralBondXor( + common = ReferralCommonState( + activate = true, + progress = false, + referrer = "address", + referrerFee = "0.005 XOR", + extrinsicFee = "0.002 XOR", + extrinsicFeeFiat = "$12" + ), + state = ReferralBondState( + invitationsCount = 2, + invitationsAmount = "0.098 XOR", + balance = "123.56743 XOR" + ), + onBondInvitationsCountChange = {}, + onBondMinus = {}, + onBondPlus = {}, + onBondClick = {} + ) + } +} + +@Composable +@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) +fun PreviewReferralBondXor02() { + SoraAppTheme { + ReferralBondXor( + common = ReferralCommonState( + activate = true, + progress = false, + referrer = "address", + referrerFee = "0.005 XOR", + extrinsicFee = "0.002 XOR", + extrinsicFeeFiat = "$12" + ), + state = ReferralBondState( + invitationsCount = 2, + invitationsAmount = "0.098 XOR", + balance = "123.56743 XOR" + ), + onBondInvitationsCountChange = {}, + onBondMinus = {}, + onBondPlus = {}, + onBondClick = {} + ) + } } diff --git a/feature_referral_impl/src/main/java/jp/co/soramitsu/feature_referral_impl/presentation/ReferralFragment.kt b/feature_referral_impl/src/main/java/jp/co/soramitsu/feature_referral_impl/presentation/ReferralFragment.kt index 9c85f924c..d2999f526 100644 --- a/feature_referral_impl/src/main/java/jp/co/soramitsu/feature_referral_impl/presentation/ReferralFragment.kt +++ b/feature_referral_impl/src/main/java/jp/co/soramitsu/feature_referral_impl/presentation/ReferralFragment.kt @@ -34,6 +34,7 @@ package jp.co.soramitsu.feature_referral_impl.presentation import android.os.Bundle import android.view.View +import androidx.activity.compose.BackHandler import androidx.compose.animation.ExperimentalAnimationApi import androidx.compose.foundation.ScrollState import androidx.compose.foundation.layout.Box @@ -82,14 +83,14 @@ class ReferralFragment : SoraBaseFragment() { animatedComposable( route = ReferralFeatureRoutes.WELCOME_PROGRESS ) { - FooWrapper(scrollState) { + ReferralWrapper(scrollState) { WelcomeProgress() } } animatedComposable( route = ReferralFeatureRoutes.WELCOME_PAGE ) { - FooWrapper(scrollState) { + ReferralWrapper(scrollState) { ReferralWelcomePageScreen( state = viewModel.referralScreenState.collectAsStateWithLifecycle().value, onStartInviting = { @@ -107,7 +108,7 @@ class ReferralFragment : SoraBaseFragment() { animatedComposable( route = ReferralFeatureRoutes.REFERRAL_PROGRAM ) { - FooWrapper(scrollState) { + ReferralWrapper(scrollState) { ReferralProgramPage( state = viewModel.referralScreenState.collectAsStateWithLifecycle().value, onGetMoreInvitations = { @@ -133,7 +134,7 @@ class ReferralFragment : SoraBaseFragment() { animatedComposable( route = ReferralFeatureRoutes.BOND_XOR ) { - FooWrapper(scrollState) { + ReferralWrapper(scrollState) { val state = viewModel.referralScreenState.collectAsStateWithLifecycle().value ReferralBondXor( common = state.common, @@ -149,7 +150,7 @@ class ReferralFragment : SoraBaseFragment() { animatedComposable( route = ReferralFeatureRoutes.UNBOND_XOR ) { - FooWrapper(scrollState) { + ReferralWrapper(scrollState) { val state = viewModel.referralScreenState.collectAsStateWithLifecycle().value ReferralUnbondXor( common = state.common, @@ -165,7 +166,7 @@ class ReferralFragment : SoraBaseFragment() { animatedComposable( route = ReferralFeatureRoutes.REFERRER_INPUT ) { - FooWrapper(scrollState) { + ReferralWrapper(scrollState) { ReferrerInput( common = viewModel.referralScreenState.collectAsStateWithLifecycle().value.common, state = viewModel.referralScreenState.collectAsStateWithLifecycle().value.referrerInputState, @@ -180,7 +181,7 @@ class ReferralFragment : SoraBaseFragment() { animatedComposable( route = ReferralFeatureRoutes.REFERRER_FILLED ) { - FooWrapper(scrollState) { + ReferralWrapper(scrollState) { val state = viewModel.referralScreenState.collectAsStateWithLifecycle().value ReferrerFilled( state = state.common, @@ -203,7 +204,7 @@ class ReferralFragment : SoraBaseFragment() { } @Composable - private fun FooWrapper( + private fun ReferralWrapper( scrollState: ScrollState, content: @Composable BoxScope.() -> Unit ) { @@ -214,6 +215,9 @@ class ReferralFragment : SoraBaseFragment() { .verticalScroll(scrollState), contentAlignment = Alignment.TopCenter, ) { + BackHandler { + viewModel.onBackPressed() + } content() } } diff --git a/feature_referral_impl/src/main/java/jp/co/soramitsu/feature_referral_impl/presentation/ReferralViewModel.kt b/feature_referral_impl/src/main/java/jp/co/soramitsu/feature_referral_impl/presentation/ReferralViewModel.kt index 6828b9461..ff4066cf3 100644 --- a/feature_referral_impl/src/main/java/jp/co/soramitsu/feature_referral_impl/presentation/ReferralViewModel.kt +++ b/feature_referral_impl/src/main/java/jp/co/soramitsu/feature_referral_impl/presentation/ReferralViewModel.kt @@ -35,7 +35,6 @@ package jp.co.soramitsu.feature_referral_impl.presentation import androidx.compose.ui.text.input.TextFieldValue import androidx.lifecycle.LiveData import androidx.lifecycle.viewModelScope -import androidx.navigation.NavOptionsBuilder import dagger.hilt.android.lifecycle.HiltViewModel import java.math.BigDecimal import javax.inject.Inject @@ -116,10 +115,6 @@ class ReferralViewModel @Inject constructor( private var referrer: String? = null - private val singleTopTrue: NavOptionsBuilder.() -> Unit = { - launchSingleTop = true - } - override fun startScreen(): String = ReferralFeatureRoutes.WELCOME_PROGRESS init { @@ -190,8 +185,7 @@ class ReferralViewModel @Inject constructor( ) } if (currentDestination == ReferralFeatureRoutes.WELCOME_PROGRESS) { - _navEvent.value = - if (_referralScreenState.value.isInitialized()) REFERRAL_PROGRAM to singleTopTrue else WELCOME_PAGE to singleTopTrue + _navToStart.value = if (_referralScreenState.value.isInitialized()) REFERRAL_PROGRAM else WELCOME_PAGE } } .launchIn(viewModelScope) @@ -310,7 +304,7 @@ class ReferralViewModel @Inject constructor( _referralScreenState.value.copy(common = _referralScreenState.value.common.copy(progress = true)) val result = interactor.observeBond(calcInvitationsAmount(bondInvitationsCount)) assetsRouter.showTxDetails(result) - _navEvent.value = REFERRAL_PROGRAM to singleTopTrue + _navToStart.value = REFERRAL_PROGRAM } } } @@ -325,7 +319,7 @@ class ReferralViewModel @Inject constructor( ) assetsRouter.showTxDetails(result) - _navEvent.value = REFERRAL_PROGRAM to singleTopTrue + _navToStart.value = REFERRAL_PROGRAM } } } @@ -341,8 +335,8 @@ class ReferralViewModel @Inject constructor( val result = interactor.observeSetReferrer(referrerOk.second) assetsRouter.showTxDetails(result) - _navEvent.value = - if (_referralScreenState.value.isInitialized()) REFERRAL_PROGRAM to singleTopTrue else WELCOME_PAGE to singleTopTrue + _navToStart.value = + if (_referralScreenState.value.isInitialized()) REFERRAL_PROGRAM else WELCOME_PAGE } } } diff --git a/feature_referral_impl/src/test/java/jp/co/soramitsu/feature_referral_impl/data/ReferralRepositoryTest.kt b/feature_referral_impl/src/test/java/jp/co/soramitsu/feature_referral_impl/data/ReferralRepositoryTest.kt index e380ec6f7..41594590a 100644 --- a/feature_referral_impl/src/test/java/jp/co/soramitsu/feature_referral_impl/data/ReferralRepositoryTest.kt +++ b/feature_referral_impl/src/test/java/jp/co/soramitsu/feature_referral_impl/data/ReferralRepositoryTest.kt @@ -33,19 +33,13 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.feature_referral_impl.data import androidx.arch.core.executor.testing.InstantTaskExecutorRule -import androidx.room.withTransaction -import io.mockk.coEvery -import io.mockk.mockkStatic -import io.mockk.slot -import jp.co.soramitsu.common.R import jp.co.soramitsu.core_db.AppDatabase import jp.co.soramitsu.core_db.dao.ReferralsDao import jp.co.soramitsu.core_db.model.ReferralLocal -import jp.co.soramitsu.feature_referral_api.data.ReferralRepository import jp.co.soramitsu.feature_blockexplorer_api.data.BlockExplorerManager +import jp.co.soramitsu.feature_referral_api.data.ReferralRepository import jp.co.soramitsu.sora.substrate.runtime.RuntimeManager import jp.co.soramitsu.sora.substrate.substrate.ExtrinsicManager -import jp.co.soramitsu.sora.substrate.substrate.SubstrateApi import jp.co.soramitsu.sora.substrate.substrate.SubstrateCalls import jp.co.soramitsu.test_shared.MainCoroutineRule import jp.co.soramitsu.xnetworking.sorawallet.blockexplorerinfo.referral.ReferrerReward @@ -59,10 +53,11 @@ import org.junit.Rule import org.junit.Test import org.junit.rules.TestRule import org.junit.runner.RunWith -import org.mockito.BDDMockito.given import org.mockito.Mock import org.mockito.Mockito.verify import org.mockito.junit.MockitoJUnitRunner +import org.mockito.kotlin.doNothing +import org.mockito.kotlin.whenever @ExperimentalCoroutinesApi @RunWith(MockitoJUnitRunner::class) @@ -84,9 +79,6 @@ class ReferralRepositoryTest { @Mock private lateinit var blockExplorerManager: BlockExplorerManager - @Mock - private lateinit var substrateApi: SubstrateApi - @Mock private lateinit var runtimeManager: RuntimeManager @@ -114,8 +106,7 @@ class ReferralRepositoryTest { @Before fun setUp() = runTest { - given(db.referralsDao()).willReturn(referralsDao) - + whenever(db.referralsDao()).thenReturn(referralsDao) referralRepository = ReferralRepositoryImpl( db, extrinsicManager, @@ -128,13 +119,14 @@ class ReferralRepositoryTest { @Test fun `update referral rewards called`() = runTest { val address = "address" - given(blockExplorerManager.updateReferrerRewards(address)).willReturn(Unit) - - mockkStatic("androidx.room.RoomDatabaseKt") - val lambda = slot R>() - coEvery { db.withTransaction(capture(lambda)) } coAnswers { - lambda.captured.invoke() - } +// val captor = argumentCaptor R>() +// whenever(db.withTransaction(captor.capture())).thenReturn(captor.firstValue.invoke()) + +// mockkStatic("androidx.room.RoomDatabaseKt") +// val lambda = slot R>() +// coEvery { db.withTransaction(capture(lambda)) } coAnswers { +// lambda.captured.invoke() +// } referralRepository.updateReferralRewards(address) verify(blockExplorerManager).updateReferrerRewards(address) @@ -142,10 +134,8 @@ class ReferralRepositoryTest { @Test fun `get referral rewards`() = runTest { - given(referralsDao.getReferrals()).willReturn(flow { emit(REFERRER_LOCAL) }) - + whenever(referralsDao.getReferrals()).thenReturn(flow { emit(REFERRER_LOCAL) }) val result = referralRepository.getReferralRewards() - assertEquals(REFERRER_REWARDS, result.toList()[0]) } diff --git a/feature_referral_impl/src/test/java/jp/co/soramitsu/feature_referral_impl/presentation/ReferralViewModelTest.kt b/feature_referral_impl/src/test/java/jp/co/soramitsu/feature_referral_impl/presentation/ReferralViewModelTest.kt index c9292c05e..1e85cfbe9 100644 --- a/feature_referral_impl/src/test/java/jp/co/soramitsu/feature_referral_impl/presentation/ReferralViewModelTest.kt +++ b/feature_referral_impl/src/test/java/jp/co/soramitsu/feature_referral_impl/presentation/ReferralViewModelTest.kt @@ -203,8 +203,8 @@ class ReferralViewModelTest { advanceUntilIdle() val state = referralViewModel.referralScreenState.value assertNull(state.common.referrer) - var navEvent = referralViewModel.navEvent.getOrAwaitValue() - assertEquals(ReferralFeatureRoutes.WELCOME_PAGE, navEvent.first) + var navEvent = referralViewModel.navToStart.getOrAwaitValue() + assertEquals(ReferralFeatureRoutes.WELCOME_PAGE, navEvent) coEvery { interactor.isLinkOrAddressOk("") } returns (false to "") referralViewModel.openReferrerInput() advanceUntilIdle() @@ -219,8 +219,8 @@ class ReferralViewModelTest { every { assetsRouter.showTxDetails(any(), any()) } returns Unit referralViewModel.onActivateLinkClick() advanceUntilIdle() - navEvent = referralViewModel.navEvent.getOrAwaitValue() - assertEquals(ReferralFeatureRoutes.WELCOME_PAGE, navEvent.first) + navEvent = referralViewModel.navToStart.getOrAwaitValue() + assertEquals(ReferralFeatureRoutes.WELCOME_PAGE, navEvent) } @Test diff --git a/feature_select_node_impl/src/main/java/jp/co/soramitsu/feature_select_node_impl/presentation/details/NodeDetailsScreen.kt b/feature_select_node_impl/src/main/java/jp/co/soramitsu/feature_select_node_impl/presentation/details/NodeDetailsScreen.kt index 8b66227cd..4252853a2 100644 --- a/feature_select_node_impl/src/main/java/jp/co/soramitsu/feature_select_node_impl/presentation/details/NodeDetailsScreen.kt +++ b/feature_select_node_impl/src/main/java/jp/co/soramitsu/feature_select_node_impl/presentation/details/NodeDetailsScreen.kt @@ -47,7 +47,6 @@ import androidx.compose.runtime.remember import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester -import androidx.compose.ui.focus.FocusState import androidx.compose.ui.platform.LocalFocusManager import androidx.compose.ui.platform.LocalSoftwareKeyboardController import androidx.compose.ui.res.stringResource @@ -83,8 +82,6 @@ internal fun NodeDetailsScreen( onHowToRunNode = viewModel::onHowToRunNode, onNodeNameChanged = viewModel::onNameChanged, onNodeAddressChanged = viewModel::onAddressChanged, - onNodeNameFocused = viewModel::onNameFocusChanged, - onNodeAddressFocused = viewModel::onAddressFocusChanged ) if (state.loading) { @@ -101,8 +98,6 @@ private fun NodeDetailsScreenContent( onHowToRunNode: () -> Unit, onNodeNameChanged: (TextFieldValue) -> Unit, onNodeAddressChanged: (TextFieldValue) -> Unit, - onNodeNameFocused: (FocusState) -> Unit, - onNodeAddressFocused: (FocusState) -> Unit, ) { val focusRequester = remember { FocusRequester() } val keyboardController = LocalSoftwareKeyboardController.current @@ -133,7 +128,6 @@ private fun NodeDetailsScreenContent( } ), keyboardOptions = KeyboardOptions.Default.copy(imeAction = ImeAction.Done), - onFocusChanged = onNodeNameFocused, maxLines = 1, singleLine = true ) @@ -150,7 +144,6 @@ private fun NodeDetailsScreenContent( } ), keyboardOptions = KeyboardOptions.Default.copy(imeAction = ImeAction.Done), - onFocusChanged = onNodeAddressFocused, maxLines = 1, singleLine = true ) @@ -192,8 +185,6 @@ private fun PreviewNodeDetailsScreen() { onHowToRunNode = {}, onNodeNameChanged = {}, onNodeAddressChanged = {}, - onNodeAddressFocused = {}, - onNodeNameFocused = {} ) } } diff --git a/feature_select_node_impl/src/main/java/jp/co/soramitsu/feature_select_node_impl/presentation/details/NodeDetailsViewModel.kt b/feature_select_node_impl/src/main/java/jp/co/soramitsu/feature_select_node_impl/presentation/details/NodeDetailsViewModel.kt index 1a00b166c..3b23b683f 100644 --- a/feature_select_node_impl/src/main/java/jp/co/soramitsu/feature_select_node_impl/presentation/details/NodeDetailsViewModel.kt +++ b/feature_select_node_impl/src/main/java/jp/co/soramitsu/feature_select_node_impl/presentation/details/NodeDetailsViewModel.kt @@ -35,7 +35,6 @@ package jp.co.soramitsu.feature_select_node_impl.presentation.details import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue -import androidx.compose.ui.focus.FocusState import androidx.compose.ui.text.input.TextFieldValue import androidx.lifecycle.viewModelScope import dagger.assisted.Assisted @@ -213,22 +212,6 @@ internal class NodeDetailsViewModel @AssistedInject constructor( ) } - fun onNameFocusChanged(focusState: FocusState) { - state = state.copy( - nameState = state.nameState.copy( - focused = focusState.isFocused - ) - ) - } - - fun onAddressFocusChanged(focusState: FocusState) { - state = state.copy( - addressState = state.addressState.copy( - focused = focusState.isFocused - ) - ) - } - private fun subscribeAddressChanges() { address .debounce(800) diff --git a/feature_select_node_impl/src/test/java/jp/co/soramitsu/feature_select_node_impl/presentation/details/NodeDetailsViewModelTest.kt b/feature_select_node_impl/src/test/java/jp/co/soramitsu/feature_select_node_impl/presentation/details/NodeDetailsViewModelTest.kt index 4bd572d9c..d2a305174 100644 --- a/feature_select_node_impl/src/test/java/jp/co/soramitsu/feature_select_node_impl/presentation/details/NodeDetailsViewModelTest.kt +++ b/feature_select_node_impl/src/test/java/jp/co/soramitsu/feature_select_node_impl/presentation/details/NodeDetailsViewModelTest.kt @@ -43,7 +43,6 @@ import jp.co.soramitsu.feature_main_api.launcher.MainRouter import jp.co.soramitsu.feature_select_node_api.NodeManager import jp.co.soramitsu.feature_select_node_api.NodeManagerEvent import jp.co.soramitsu.feature_select_node_impl.TestData.CUSTOM_NODES -import jp.co.soramitsu.feature_select_node_impl.TestData.FOCUS_STATE import jp.co.soramitsu.feature_select_node_impl.TestData.NODE_DETAILS_ADDRESS import jp.co.soramitsu.feature_select_node_impl.TestData.NODE_DETAILS_NAME import jp.co.soramitsu.feature_select_node_impl.TestData.NODE_DETAIL_NODE @@ -245,24 +244,6 @@ class NodeDetailsViewModelTest { assertFalse(viewModel.state.submitButtonEnabled) } - @Test - fun `name input focused EXPECT update state`() { - addNodeViewModel() - - viewModel.onNameFocusChanged(FOCUS_STATE) - - assertEquals(FOCUS_STATE.isFocused, viewModel.state.nameState.focused) - } - - @Test - fun `address input focused EXPECT update state`() { - addNodeViewModel() - - viewModel.onAddressFocusChanged(FOCUS_STATE) - - assertEquals(FOCUS_STATE.isFocused, viewModel.state.addressState.focused) - } - @Test fun `onAddressChanged EXPECT submit button disabled`() { addNodeViewModel() diff --git a/feature_wallet_impl/build.gradle b/feature_wallet_impl/build.gradle index 7a7b445ac..fae60d8d5 100644 --- a/feature_wallet_impl/build.gradle +++ b/feature_wallet_impl/build.gradle @@ -30,9 +30,10 @@ android { // sourceCompatibility JavaVersion.VERSION_1_8 // targetCompatibility JavaVersion.VERSION_1_8 // } -// kotlinOptions { + kotlinOptions { // jvmTarget = JavaVersion.VERSION_1_8 -// } + freeCompilerArgs += ["-Xstring-concat=inline"] + } buildFeatures { viewBinding true diff --git a/feature_wallet_impl/src/main/java/jp/co/soramitsu/feature_wallet_impl/presentation/cardshub/BuyXorCard.kt b/feature_wallet_impl/src/main/java/jp/co/soramitsu/feature_wallet_impl/presentation/cardshub/BuyXorCard.kt index 8f9c6fe75..d168480ad 100644 --- a/feature_wallet_impl/src/main/java/jp/co/soramitsu/feature_wallet_impl/presentation/cardshub/BuyXorCard.kt +++ b/feature_wallet_impl/src/main/java/jp/co/soramitsu/feature_wallet_impl/presentation/cardshub/BuyXorCard.kt @@ -32,10 +32,12 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.feature_wallet_impl.presentation.cardshub +import android.content.res.Configuration import androidx.compose.runtime.Composable import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import jp.co.soramitsu.common.R +import jp.co.soramitsu.common.presentation.compose.theme.SoraAppTheme @Composable fun BuyXorCard( @@ -52,11 +54,24 @@ fun BuyXorCard( ) } -@Preview +@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO) @Composable -private fun PreviewBuyXorCard() { - BuyXorCard( - onCloseCard = {}, - onBuyXorClicked = {}, - ) +private fun PreviewBuyXorCard01() { + SoraAppTheme { + BuyXorCard( + onCloseCard = {}, + onBuyXorClicked = {}, + ) + } +} + +@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun PreviewBuyXorCard02() { + SoraAppTheme { + BuyXorCard( + onCloseCard = {}, + onBuyXorClicked = {}, + ) + } } diff --git a/feature_wallet_impl/src/main/java/jp/co/soramitsu/feature_wallet_impl/presentation/cardshub/SoraCard.kt b/feature_wallet_impl/src/main/java/jp/co/soramitsu/feature_wallet_impl/presentation/cardshub/SoraCard.kt index 27bafdec0..7e35ea1ec 100644 --- a/feature_wallet_impl/src/main/java/jp/co/soramitsu/feature_wallet_impl/presentation/cardshub/SoraCard.kt +++ b/feature_wallet_impl/src/main/java/jp/co/soramitsu/feature_wallet_impl/presentation/cardshub/SoraCard.kt @@ -32,6 +32,7 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.feature_wallet_impl.presentation.cardshub +import android.content.res.Configuration import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxWidth @@ -49,6 +50,7 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import jp.co.soramitsu.common.R import jp.co.soramitsu.common.presentation.compose.components.SoraCardImage +import jp.co.soramitsu.common.presentation.compose.theme.SoraAppTheme import jp.co.soramitsu.common.util.ext.testTagAsId import jp.co.soramitsu.common_wallet.presentation.compose.states.SoraCardState import jp.co.soramitsu.ui_core.component.button.BleachedButton @@ -79,10 +81,12 @@ fun SoraCard( CardStateButton( modifier = Modifier - .wrapContentWidth().run { + .wrapContentWidth() + .run { if (state.success.not()) padding(bottom = Dimens.x3) else padding(all = Dimens.x1) - }.run { + } + .run { if (state.success.not()) align(Alignment.BottomCenter) else align(Alignment.BottomEnd) }, @@ -156,12 +160,27 @@ private fun PreviewSoraCard1() { } @Composable -@Preview(locale = "he") +@Preview(locale = "he", uiMode = Configuration.UI_MODE_NIGHT_NO) private fun PreviewSoraCard2() { - SoraCard( - modifier = Modifier.fillMaxWidth(), - state = SoraCardState(kycStatus = "Pending", success = false, visible = true), - onCloseClicked = {}, - onCardStateClicked = {} - ) + SoraAppTheme { + SoraCard( + modifier = Modifier.fillMaxWidth(), + state = SoraCardState(kycStatus = "Pending", success = false, visible = true), + onCloseClicked = {}, + onCardStateClicked = {} + ) + } +} + +@Composable +@Preview(locale = "en", uiMode = Configuration.UI_MODE_NIGHT_NO) +private fun PreviewSoraCard3() { + SoraAppTheme { + SoraCard( + modifier = Modifier.fillMaxWidth(), + state = SoraCardState(kycStatus = null, success = false, visible = true), + onCloseClicked = {}, + onCardStateClicked = {} + ) + } } diff --git a/feature_wallet_impl/src/test/java/jp/co/soramitsu/feature_wallet_impl/data/repository/WalletRepositoryTest.kt b/feature_wallet_impl/src/test/java/jp/co/soramitsu/feature_wallet_impl/data/repository/WalletRepositoryTest.kt index 13f1b3528..2ec748382 100644 --- a/feature_wallet_impl/src/test/java/jp/co/soramitsu/feature_wallet_impl/data/repository/WalletRepositoryTest.kt +++ b/feature_wallet_impl/src/test/java/jp/co/soramitsu/feature_wallet_impl/data/repository/WalletRepositoryTest.kt @@ -36,6 +36,7 @@ import android.net.Uri import androidx.arch.core.executor.testing.InstantTaskExecutorRule import jp.co.soramitsu.common.domain.Asset import jp.co.soramitsu.common.domain.AssetBalance +import jp.co.soramitsu.common.domain.DEFAULT_ICON_URI import jp.co.soramitsu.common.domain.Token import jp.co.soramitsu.core_db.AppDatabase import jp.co.soramitsu.core_db.dao.GlobalCardsHubDao @@ -106,7 +107,7 @@ class WalletRepositoryTest { @Mock private lateinit var soraConfigManager: SoraConfigManager - private val mockedUri = mock(Uri::class.java) + private val mockedUri = DEFAULT_ICON_URI private lateinit var runtime: RuntimeSnapshot diff --git a/feature_wallet_impl/src/test/java/jp/co/soramitsu/feature_wallet_impl/presentation/wallet/CardsHubViewModelTest.kt b/feature_wallet_impl/src/test/java/jp/co/soramitsu/feature_wallet_impl/presentation/wallet/CardsHubViewModelTest.kt index bfa8e0d6b..37cf3813d 100644 --- a/feature_wallet_impl/src/test/java/jp/co/soramitsu/feature_wallet_impl/presentation/wallet/CardsHubViewModelTest.kt +++ b/feature_wallet_impl/src/test/java/jp/co/soramitsu/feature_wallet_impl/presentation/wallet/CardsHubViewModelTest.kt @@ -140,8 +140,6 @@ class CardsHubViewModelTest { @MockK private lateinit var connectionManager: ConnectionManager - private val mockedUri = mockk() - private lateinit var cardsHubViewModel: CardsHubViewModel private val account = SoraAccount("address", "name") @@ -149,16 +147,8 @@ class CardsHubViewModelTest { @OptIn(ExperimentalStdlibApi::class) @Before fun setUp() = runTest { - mockkStatic(Uri::parse) - every { Uri.parse(any()) } returns mockedUri - mockkStatic(Token::iconUri) mockkObject(BuildConfigWrapper) every { BuildConfigWrapper.getSoraCardBackEndUrl() }.returns("soracard backend") - every { TestTokens.xorToken.iconUri() } returns mockedUri - every { TestTokens.valToken.iconUri() } returns mockedUri - every { TestTokens.pswapToken.iconUri() } returns mockedUri - every { TestTokens.xstusdToken.iconUri() } returns mockedUri - every { TestTokens.xstToken.iconUri() } returns mockedUri every { connectionManager.isConnected } returns true mockkObject(OptionsProvider) every { OptionsProvider.header } returns "test android client" diff --git a/sorasubstrate/src/main/java/jp/co/soramitsu/sora/substrate/models/BlockResponse.kt b/sorasubstrate/src/main/java/jp/co/soramitsu/sora/substrate/models/BlockResponse.kt index e081c76d3..de3405fae 100644 --- a/sorasubstrate/src/main/java/jp/co/soramitsu/sora/substrate/models/BlockResponse.kt +++ b/sorasubstrate/src/main/java/jp/co/soramitsu/sora/substrate/models/BlockResponse.kt @@ -32,10 +32,8 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.sora.substrate.models -import androidx.annotation.Keep +import jp.co.soramitsu.common.util.ParseModel -@Keep -data class BlockResponse(val justification: Any?, val block: BlockEntry) +data class BlockResponse(val justification: Any?, val block: BlockEntry) : ParseModel() -@Keep -data class BlockEntry(val header: Any?, val extrinsics: List) +data class BlockEntry(val header: Any?, val extrinsics: List) : ParseModel() diff --git a/sorasubstrate/src/main/java/jp/co/soramitsu/sora/substrate/response/BalanceResponse.kt b/sorasubstrate/src/main/java/jp/co/soramitsu/sora/substrate/response/BalanceResponse.kt index 895049189..9be1fd864 100644 --- a/sorasubstrate/src/main/java/jp/co/soramitsu/sora/substrate/response/BalanceResponse.kt +++ b/sorasubstrate/src/main/java/jp/co/soramitsu/sora/substrate/response/BalanceResponse.kt @@ -32,7 +32,6 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.sora.substrate.response -import androidx.annotation.Keep +import jp.co.soramitsu.common.util.ParseModel -@Keep -data class BalanceResponse(val balance: String) +data class BalanceResponse(val balance: String) : ParseModel() diff --git a/sorasubstrate/src/main/java/jp/co/soramitsu/sora/substrate/response/ChainHeaderResponse.kt b/sorasubstrate/src/main/java/jp/co/soramitsu/sora/substrate/response/ChainHeaderResponse.kt index 246cf52d3..bd8416722 100644 --- a/sorasubstrate/src/main/java/jp/co/soramitsu/sora/substrate/response/ChainHeaderResponse.kt +++ b/sorasubstrate/src/main/java/jp/co/soramitsu/sora/substrate/response/ChainHeaderResponse.kt @@ -32,7 +32,6 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.sora.substrate.response -import androidx.annotation.Keep +import jp.co.soramitsu.common.util.ParseModel -@Keep -class ChainHeaderResponse(val parentHash: String, val number: String, val stateRoot: String, val extrinsicsRoot: String) +class ChainHeaderResponse(val parentHash: String, val number: String, val stateRoot: String, val extrinsicsRoot: String) : ParseModel() diff --git a/sorasubstrate/src/main/java/jp/co/soramitsu/sora/substrate/response/FeeResponse.kt b/sorasubstrate/src/main/java/jp/co/soramitsu/sora/substrate/response/FeeResponse.kt index 5f79a6477..510a398c9 100644 --- a/sorasubstrate/src/main/java/jp/co/soramitsu/sora/substrate/response/FeeResponse.kt +++ b/sorasubstrate/src/main/java/jp/co/soramitsu/sora/substrate/response/FeeResponse.kt @@ -32,11 +32,10 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.sora.substrate.response -import androidx.annotation.Keep import java.math.BigInteger +import jp.co.soramitsu.common.util.ParseModel -@Keep data class FeeResponse( val partialFee: BigInteger, val weight: Long -) +) : ParseModel() diff --git a/sorasubstrate/src/main/java/jp/co/soramitsu/sora/substrate/response/FeeResponse2.kt b/sorasubstrate/src/main/java/jp/co/soramitsu/sora/substrate/response/FeeResponse2.kt index 582f0f9ea..d9b454c4e 100644 --- a/sorasubstrate/src/main/java/jp/co/soramitsu/sora/substrate/response/FeeResponse2.kt +++ b/sorasubstrate/src/main/java/jp/co/soramitsu/sora/substrate/response/FeeResponse2.kt @@ -32,23 +32,21 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.sora.substrate.response -import androidx.annotation.Keep import java.math.BigInteger +import jp.co.soramitsu.common.util.ParseModel import jp.co.soramitsu.shared_utils.extensions.fromHex import jp.co.soramitsu.shared_utils.extensions.fromUnsignedBytes import jp.co.soramitsu.shared_utils.extensions.requireHexPrefix -@Keep class FeeResponse2( val inclusionFee: InclusionFee -) +) : ParseModel() -@Keep class InclusionFee( private val baseFee: String?, private val lenFee: String?, private val adjustedWeightFee: String? -) { +) : ParseModel() { val sum: BigInteger get() = BrokenSubstrateHex(baseFee).decodeBigInt() + BrokenSubstrateHex(lenFee).decodeBigInt() + BrokenSubstrateHex(adjustedWeightFee).decodeBigInt() } diff --git a/sorasubstrate/src/main/java/jp/co/soramitsu/sora/substrate/response/StateQueryResponse.kt b/sorasubstrate/src/main/java/jp/co/soramitsu/sora/substrate/response/StateQueryResponse.kt index 3d44bbac5..fa6becd40 100644 --- a/sorasubstrate/src/main/java/jp/co/soramitsu/sora/substrate/response/StateQueryResponse.kt +++ b/sorasubstrate/src/main/java/jp/co/soramitsu/sora/substrate/response/StateQueryResponse.kt @@ -32,13 +32,12 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.sora.substrate.response -import androidx.annotation.Keep +import jp.co.soramitsu.common.util.ParseModel -@Keep class StateQueryResponse( val block: String, private val changes: List> -) { +) : ParseModel() { fun changesAsMap(): Map { return changes.associate { it[0]!! to it[1] } } diff --git a/sorasubstrate/src/test/java/jp/co/soramitsu/sora/substrate/SubstrateApiTest.kt b/sorasubstrate/src/test/java/jp/co/soramitsu/sora/substrate/SubstrateApiTest.kt index c977c135d..698883279 100644 --- a/sorasubstrate/src/test/java/jp/co/soramitsu/sora/substrate/SubstrateApiTest.kt +++ b/sorasubstrate/src/test/java/jp/co/soramitsu/sora/substrate/SubstrateApiTest.kt @@ -32,49 +32,48 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.sora.substrate -import androidx.arch.core.executor.testing.InstantTaskExecutorRule -import io.mockk.MockKException -import io.mockk.coEvery -import io.mockk.impl.annotations.MockK -import io.mockk.junit4.MockKRule import jp.co.soramitsu.shared_utils.extensions.fromHex +import jp.co.soramitsu.shared_utils.runtime.RuntimeSnapshot import jp.co.soramitsu.shared_utils.wsrpc.SocketService import jp.co.soramitsu.sora.substrate.runtime.RuntimeManager import jp.co.soramitsu.sora.substrate.substrate.SubstrateApiImpl import jp.co.soramitsu.test_shared.RealRuntimeProvider -import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.runTest import org.junit.Assert.assertEquals -import org.junit.Rule +import org.junit.Before +import org.junit.Ignore import org.junit.Test -import org.junit.rules.TestRule +import org.junit.runner.RunWith +import org.mockito.junit.MockitoJUnitRunner +import org.mockito.kotlin.mock +import org.mockito.kotlin.whenever -@OptIn(ExperimentalCoroutinesApi::class) +@RunWith(MockitoJUnitRunner::class) class SubstrateApiTest { - @Rule - @JvmField - val rule: TestRule = InstantTaskExecutorRule() + private val socket: SocketService = mock() - @get:Rule - val mockkRule = MockKRule(this) - - @MockK - lateinit var socket: SocketService - - @MockK - lateinit var runtimeManager: RuntimeManager + private val runtimeManager: RuntimeManager = mock() private lateinit var api: SubstrateApiImpl + private lateinit var dev: RuntimeSnapshot + private lateinit var stage: RuntimeSnapshot private fun setUpApi() { api = SubstrateApiImpl(socket, runtimeManager) } - @Test(expected = MockKException::class) + @Before + fun before() { + dev = RealRuntimeProvider.buildRuntime(networkName = "sora2", suffix = "_dev") + stage = RealRuntimeProvider.buildRuntime(networkName = "sora2", suffix = "_soralution") + } + + @Test + @Ignore fun `dev env subscribe getPoolReserveAccount`() = runTest { - val n = RealRuntimeProvider.buildRuntime(networkName = "sora2", suffix = "_dev") - coEvery { runtimeManager.getRuntimeSnapshot() } returns n + //whenever(socket.executeAsync(request = any(), mapper = scale(PoolPropertiesResponse))).thenReturn() + whenever(runtimeManager.getRuntimeSnapshot()).thenReturn(dev) setUpApi() val baseTokenId = "0x0200000000000000000000000000000000000000000000000000000000000000" @@ -83,10 +82,10 @@ class SubstrateApiTest { assertEquals(byteArrayOf(12, 12, 14), t) } - @Test(expected = MockKException::class) + @Test + @Ignore fun `soralution env subscribe getPoolReserveAccount`() = runTest { - val n = RealRuntimeProvider.buildRuntime(networkName = "sora2", suffix = "_soralution") - coEvery { runtimeManager.getRuntimeSnapshot() } returns n + whenever(runtimeManager.getRuntimeSnapshot()).thenReturn(stage) setUpApi() val baseTokenId = "0x0200000000000000000000000000000000000000000000000000000000000000"