Skip to content

Commit

Permalink
Merge pull request #1079 from soramitsu/staging
Browse files Browse the repository at this point in the history
staging
  • Loading branch information
PankraSerg authored Jan 15, 2024
2 parents 9ec4002 + c9129c3 commit 6732e4c
Show file tree
Hide file tree
Showing 328 changed files with 8,913 additions and 2,557 deletions.
15 changes: 11 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ android {
}

compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
sourceCompatibility 11
targetCompatibility 11
}

kotlinOptions {
freeCompilerArgs = ["-Xallow-result-return-type"]

jvmTarget = '1.8'
jvmTarget = '11'
}
composeOptions {
kotlinCompilerExtensionVersion composeCompilerVersion
Expand Down Expand Up @@ -173,6 +173,9 @@ dependencies {
implementation project(':feature-soracard-api')
implementation project(':feature-soracard-impl')

implementation project(':feature-walletconnect-api')
implementation project(':feature-walletconnect-impl')

implementation kotlinDep

implementation androidDep
Expand All @@ -193,7 +196,7 @@ dependencies {

implementation lifeCycleKtxDep

implementation retrofitDep
// implementation retrofitDep
implementation gsonConvertedDep

implementation gifDep
Expand All @@ -219,6 +222,10 @@ dependencies {

implementation soraUiCoreDep

implementation(platform(libs.walletconnectBomDep))
implementation(libs.walletconnectCoreDep)
implementation(libs.walletconnectWeb3WalletDep)

androidTestImplementation androidTestRunnerDep
androidTestImplementation androidTestRulesDep
androidTestImplementation androidJunitDep
Expand Down
39 changes: 39 additions & 0 deletions app/src/main/java/jp/co/soramitsu/app/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ package jp.co.soramitsu.app
import android.app.Application
import android.content.Context
import android.content.res.Configuration
import com.walletconnect.android.Core
import com.walletconnect.android.CoreClient
import com.walletconnect.android.relay.ConnectionType
import com.walletconnect.web3.wallet.client.Wallet
import com.walletconnect.web3.wallet.client.Web3Wallet
import dagger.hilt.android.HiltAndroidApp
import jp.co.soramitsu.common.data.network.OptionsProvider
import jp.co.soramitsu.common.resources.ContextManager
Expand Down Expand Up @@ -31,5 +36,39 @@ open class App : Application() {
OptionsProvider.CURRENT_VERSION_CODE = BuildConfig.VERSION_CODE
OptionsProvider.CURRENT_VERSION_NAME = BuildConfig.VERSION_NAME
OptionsProvider.CURRENT_BUILD_TYPE = BuildConfig.BUILD_TYPE

setupWalletConnect()
}

private fun setupWalletConnect() {
val connectionType = ConnectionType.AUTOMATIC // ConnectionType.AUTOMATIC or ConnectionType.MANUAL
val projectId = jp.co.soramitsu.common.BuildConfig.WALLET_CONNECT_PROJECT_ID // Project ID at https://cloud.walletconnect.com/
val relayUrl = "relay.walletconnect.com"
val serverUrl = "wss://$relayUrl?projectId=${projectId}"

val appMetaData = Core.Model.AppMetaData(
name = "Fearless wallet",
description = "Defi wallet",
url = "https://fearlesswallet.io",
icons = listOf("https://raw.githubusercontent.com/soramitsu/shared-features-utils/master/icons/FW%20icon%20128.png"),
redirect = "fearless-wallet-wc://request"
)

CoreClient.initialize(
relayServerUrl = serverUrl,
connectionType = connectionType,
application = this,
metaData = appMetaData,
onError = {
it.throwable.printStackTrace()
}
)

val initParams = Wallet.Params.Init(core = CoreClient)

Web3Wallet.initialize(initParams) { error ->
// Error will be thrown if there's an issue during initialization
error.throwable.printStackTrace()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package jp.co.soramitsu.app.di.app

import co.jp.soramitsu.walletconnect.domain.WalletConnectRouter
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand Down Expand Up @@ -59,4 +60,8 @@ class NavigationModule {
@Singleton
@Provides
fun provideSoraCardRouter(navigator: Navigator): SoraCardRouter = navigator

@Singleton
@Provides
fun provideWalletConnectRouter(navigator: Navigator): WalletConnectRouter = navigator
}
143 changes: 125 additions & 18 deletions app/src/main/java/jp/co/soramitsu/app/root/navigation/Navigator.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package jp.co.soramitsu.app.root.navigation

import android.annotation.SuppressLint
import android.graphics.drawable.Drawable
import android.os.Bundle
import androidx.annotation.IdRes
Expand All @@ -11,6 +12,9 @@ import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavController
import androidx.navigation.NavDeepLinkRequest
import androidx.navigation.NavOptions
import co.jp.soramitsu.walletconnect.domain.WalletConnectRouter
import co.jp.soramitsu.walletconnect.model.ChainChooseResult
import co.jp.soramitsu.walletconnect.model.ChainChooseState
import it.airgap.beaconsdk.blockchain.substrate.data.SubstrateSignerPayload
import java.math.BigDecimal
import jp.co.soramitsu.account.api.domain.model.ImportMode
Expand All @@ -21,7 +25,6 @@ import jp.co.soramitsu.account.impl.domain.account.details.AccountInChain
import jp.co.soramitsu.account.impl.presentation.AccountRouter
import jp.co.soramitsu.account.impl.presentation.account.create.CreateAccountDialog
import jp.co.soramitsu.account.impl.presentation.account.details.AccountDetailsDialog
import jp.co.soramitsu.account.impl.presentation.account.export.WalletExportFragment
import jp.co.soramitsu.account.impl.presentation.account.exportaccounts.AccountsForExportFragment
import jp.co.soramitsu.account.impl.presentation.account.rename.RenameAccountDialog
import jp.co.soramitsu.account.impl.presentation.backup_wallet.BackupWalletDialog
Expand Down Expand Up @@ -124,6 +127,7 @@ import jp.co.soramitsu.wallet.impl.domain.model.QrContentCBDC
import jp.co.soramitsu.wallet.impl.presentation.AssetPayload
import jp.co.soramitsu.wallet.impl.presentation.WalletRouter
import jp.co.soramitsu.wallet.impl.presentation.addressbook.CreateContactFragment
import jp.co.soramitsu.wallet.impl.presentation.balance.assetDetails.AssetDetailsFragment
import jp.co.soramitsu.wallet.impl.presentation.balance.assetselector.AssetSelectFragment
import jp.co.soramitsu.wallet.impl.presentation.balance.chainselector.ChainSelectFragment
import jp.co.soramitsu.wallet.impl.presentation.balance.detail.BalanceDetailFragment
Expand Down Expand Up @@ -152,11 +156,18 @@ import jp.co.soramitsu.wallet.impl.presentation.transaction.detail.reward.Reward
import jp.co.soramitsu.wallet.impl.presentation.transaction.detail.reward.RewardDetailsPayload
import jp.co.soramitsu.wallet.impl.presentation.transaction.detail.swap.SwapDetailFragment
import jp.co.soramitsu.wallet.impl.presentation.transaction.detail.transfer.TransferDetailFragment
import jp.co.soramitsu.walletconnect.impl.presentation.sessionproposal.SessionProposalFragment
import jp.co.soramitsu.walletconnect.impl.presentation.chainschooser.ChainChooseFragment
import jp.co.soramitsu.walletconnect.impl.presentation.connectioninfo.ConnectionInfoFragment
import jp.co.soramitsu.walletconnect.impl.presentation.requestpreview.RequestPreviewFragment
import jp.co.soramitsu.walletconnect.impl.presentation.sessionrequest.SessionRequestFragment
import jp.co.soramitsu.walletconnect.impl.presentation.transactionrawdata.RawDataFragment
import kotlin.coroutines.coroutineContext
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.filterNotNull
Expand All @@ -183,7 +194,8 @@ class Navigator :
CrowdloanRouter,
PolkaswapRouter,
SuccessRouter,
SoraCardRouter {
SoraCardRouter,
WalletConnectRouter {

private var navController: NavController? = null
private var activity: AppCompatActivity? = null
Expand Down Expand Up @@ -725,6 +737,22 @@ class Navigator :
navController?.navigate(R.id.sendSetupFragment, bundle)
}

override fun openWalletConnectSessionProposal(pairingTopic: String?) {
if (navController?.currentDestination?.id == R.id.sessionProposalFragment) return

val bundle = SessionProposalFragment.getBundle(pairingTopic)

navController?.navigate(R.id.sessionProposalFragment, bundle)
}

override fun openWalletConnectSessionRequest(sessionRequestTopic: String) {
if (navController?.currentDestination?.id == R.id.sessionRequestFragment) return

val bundle = SessionRequestFragment.getBundle(sessionRequestTopic)

navController?.navigate(R.id.sessionRequestFragment, bundle)
}

override fun openLockedAmountSend(assetPayload: AssetPayload?, initialSendToAddress: String?, currencyId: String?, amount: BigDecimal?) {
val bundle = SendSetupFragment.getBundle(assetPayload, initialSendToAddress, currencyId, amount, true)

Expand Down Expand Up @@ -791,32 +819,78 @@ class Navigator :
assetId: String,
chainId: ChainId?,
chooserMode: Boolean,
isSelectAsset: Boolean
isSelectAsset: Boolean,
showAllChains: Boolean
) {
val bundle = ChainSelectFragment.getBundle(
assetId = assetId,
chainId = chainId,
chooserMode = chooserMode,
isSelectAsset = isSelectAsset
isSelectAsset = isSelectAsset,
showAllChains = showAllChains
)
navController?.navigate(R.id.chainSelectFragment, bundle)
}

override fun openConnectionsScreen() {
navController?.navigate(R.id.connectionsFragment)
}

override fun openSelectMultipleChains(
items: List<String>,
selected: List<String>,
isViewMode: Boolean
) {
val bundle = ChainChooseFragment.getBundle(
state = ChainChooseState(items, selected, isViewMode)
)
navController?.navigate(R.id.chainChooseFragment, bundle)
}

override fun openSelectMultipleChainsForResult(
items: List<String>,
selected: List<String>
): Flow<ChainChooseResult> {
val bundle = ChainChooseFragment.getBundle(state = ChainChooseState(items, selected))
return openWithResult(
destinationId = R.id.chainChooseFragment,
bundle = bundle,
resultKey = ChainChooseFragment.RESULT
)
}

override fun openConnectionDetails(topic: String) {
val bundle = ConnectionInfoFragment.getBundle(topic)
navController?.navigate(R.id.connectionInfoFragment, bundle)
}

override fun openRequestPreview(topic: String) {
val bundle = RequestPreviewFragment.getBundle(topic)
navController?.navigate(R.id.requestPreviewFragment, bundle)
}

override fun openRawData(payload: String) {
val bundle = RawDataFragment.getBundle(payload)
navController?.navigate(R.id.rawDataFragment, bundle)
}

override fun openSelectChain(
selectedChainId: ChainId?,
filterChainIds: List<ChainId>?,
chooserMode: Boolean,
currencyId: String?,
showAllChains: Boolean,
isSelectAsset: Boolean
isSelectAsset: Boolean,
isFilteringEnabled: Boolean
) {
val bundle = ChainSelectFragment.getBundle(
selectedChainId,
filterChainIds,
chooserMode,
currencyId,
showAllChains,
isSelectAsset
isSelectAsset,
isFilteringEnabled
)
navController?.navigate(R.id.chainSelectFragment, bundle)
}
Expand Down Expand Up @@ -893,7 +967,7 @@ class Navigator :
navController?.navigate(R.id.confirmCrossChainSendFragment, bundle)
}

override fun openOperationSuccess(operationHash: String?, chainId: ChainId) {
override fun openOperationSuccess(operationHash: String?, chainId: ChainId?) {
openOperationSuccess(operationHash, chainId, null)
}

Expand Down Expand Up @@ -930,16 +1004,29 @@ class Navigator :
navController?.navigate(R.id.polkaswapDisclaimerFragment, bundle)
}

override fun openOperationSuccess(
operationHash: String?,
chainId: ChainId,
customMessage: String?
) {
override fun openOperationSuccess(operationHash: String?, chainId: ChainId?, customMessage: String?) {
val bundle = SuccessFragment.getBundle(operationHash, chainId, customMessage)

navController?.navigate(R.id.successSheetFragment, bundle)
}

@SuppressLint("RestrictedApi")
override fun openOperationSuccessAndPopUpToNearestRelatedScreen(operationHash: String?, chainId: ChainId?, customMessage: String?) {
val bundle = SuccessFragment.getBundle(operationHash, chainId, customMessage)

val latestAvailableWalletConnectRelatedDestinationId =
navController?.currentBackStack?.replayCache?.firstOrNull()?.last {
it.destination.id == R.id.connectionsFragment ||
it.destination.id == R.id.mainFragment
}?.destination?.id ?: R.id.mainFragment

val navOptions = NavOptions.Builder()
.setPopUpTo(latestAvailableWalletConnectRelatedDestinationId, false)
.build()

navController?.navigate(R.id.successSheetFragment, bundle, navOptions)
}

override fun finishSendFlow() {
navController?.popBackStack()
navController?.popBackStack()
Expand Down Expand Up @@ -1015,12 +1102,6 @@ class Navigator :
navController?.navigate(R.id.backupWalletDialog, extras)
}

override fun openExportWallet(metaAccountId: Long) {
val extras = WalletExportFragment.getBundle(metaAccountId)

navController?.navigate(R.id.action_open_walletExportFragment, extras)
}

override fun openRenameWallet(metaAccountId: Long) {
val extras = RenameAccountDialog.getBundle(metaAccountId)

Expand All @@ -1037,12 +1118,38 @@ class Navigator :
navController?.navigate(R.id.action_nodesFragment_to_nodeDetailsFragment, NodeDetailsFragment.getBundle(payload))
}

override fun trackReturnToAssetDetailsFromChainSelector(): Flow<Unit>? {
return navController?.currentBackStackEntryFlow?.filter {
it.destination.id == R.id.assetDetailFragment
}?.distinctUntilChanged()?.map { /* DO NOTHING */ }
}

override fun openAssetDetails(assetPayload: AssetPayload) {
val bundle = BalanceDetailFragment.getBundle(assetPayload)

navController?.navigate(R.id.action_mainFragment_to_balanceDetailFragment, bundle)
}

override fun openAssetDetailsAndPopUpToBalancesList(assetPayload: AssetPayload) {
val bundle = BalanceDetailFragment.getBundle(assetPayload)

val navOptions = NavOptions.Builder()
.setPopUpTo(R.id.mainFragment, false)
.build()

navController?.navigate(R.id.action_mainFragment_to_balanceDetailFragment, bundle, navOptions)
}

override fun openAssetIntermediateDetails(assetId: String) {
val bundle = AssetDetailsFragment.getBundle(assetId)

navController?.navigate(R.id.action_mainFragment_to_assetDetailFragment, bundle)
}

override fun openAssetIntermediateDetailsSort() {
navController?.navigate(R.id.assetDetailSortFragment)
}

override fun openAddressHistory(chainId: ChainId) {
val bundle = AddressHistoryFragment.getBundle(chainId)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ interface RootRouter {
fun openPincodeCheck()

fun openNavGraph()
fun openWalletConnectSessionProposal(pairingTopic: String?)
fun openWalletConnectSessionRequest(sessionRequestTopic: String)
}
Loading

0 comments on commit 6732e4c

Please sign in to comment.