Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ internal class JsonRpcInteractor(
val jsonResponseDO = response.toJsonRpcResponse()
val responseJson = serializer.serialize(jsonResponseDO) ?: return onFailure(IllegalStateException("JsonRpcInteractor: Unknown result params"))
val encryptedResponse = chaChaPolyCodec.encrypt(topic, responseJson, envelopeType, participants)

relay.publish(topic.value, encryptedResponse, params.toRelay()) { result ->
result.fold(
onSuccess = {
Expand Down Expand Up @@ -301,7 +300,6 @@ internal class JsonRpcInteractor(
handleError("ManSub: ${e.stackTraceToString()}")
String.Empty
}

Pair(message, topic)
}.collect { (decryptedMessage, topic) ->
if (decryptedMessage.isNotEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ val accounts: List<Pair<Chains, String>> = listOf(
Chains.POLYGON_MATIC to ACCOUNTS_1_EIP155_ADDRESS,
Chains.ETHEREUM_KOVAN to ACCOUNTS_1_EIP155_ADDRESS,
Chains.POLYGON_MUMBAI to ACCOUNTS_1_EIP155_ADDRESS,
Chains.COSMOS to "cosmos1w605a5ejjlhp04eahjqxhjhmg8mj6nqhp8v6xc"
Chains.COSMOS to "cosmos1w605a5ejjlhp04eahjqxhjhmg8mj6nqhp8v6xc",
Chains.BNB to ACCOUNTS_1_EIP155_ADDRESS
)

val PRIVATE_KEY_1: ByteArray = "e05c1a7f048a164ab400e38764708a401c773fa83181b923fc8b2724f46c0c6c".hexToBytes()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ import androidx.core.app.ActivityCompat
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.ContextCompat
import androidx.core.view.WindowCompat
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import com.google.accompanist.navigation.material.BottomSheetNavigator
import com.google.accompanist.navigation.material.ExperimentalMaterialNavigationApi
import com.google.accompanist.systemuicontroller.SystemUiController
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import com.walletconnect.web3.wallet.sample.R
import com.walletconnect.web3.wallet.ui.routes.Route
import com.walletconnect.web3.wallet.ui.routes.composable_routes.connections.ConnectionsViewModel
Expand Down Expand Up @@ -54,24 +57,51 @@ class Web3WalletActivity : ComponentActivity() {
super.onCreate(savedInstanceState)
val web3walletViewModel: Web3WalletViewModel = Web3WalletViewModel()
val connectionsViewModel: ConnectionsViewModel = ConnectionsViewModel()
handleWeb3WalletEvents(web3walletViewModel, connectionsViewModel)
handlePushEvents(web3walletViewModel)
handleCoreEvents(connectionsViewModel)
askNotificationPermission()
createNotificationChannel()
setContent(web3walletViewModel, connectionsViewModel)
}

web3walletViewModel.walletEvents
private fun setContent(
web3walletViewModel: Web3WalletViewModel,
connectionsViewModel: ConnectionsViewModel
) {
setContent {
val sheetState = rememberModalBottomSheetState(initialValue = ModalBottomSheetValue.Hidden, skipHalfExpanded = true)
val bottomSheetNavigator = BottomSheetNavigator(sheetState)
val navController = rememberNavController(bottomSheetNavigator)
this.navController = navController

val sharedPref = getPreferences(MODE_PRIVATE)
val getStartedVisited = sharedPref.getBoolean("get_started_visited", false)
Web3WalletTheme {
Web3WalletNavGraph(
bottomSheetNavigator = bottomSheetNavigator, navController = navController,
getStartedVisited = getStartedVisited, web3walletViewModel = web3walletViewModel, connectionsViewModel = connectionsViewModel
)
}
}
}

private fun handleCoreEvents(connectionsViewModel: ConnectionsViewModel) {
connectionsViewModel.coreEvents
.flowWithLifecycle(lifecycle, Lifecycle.State.STARTED)
.onEach { event ->
when (event) {
is SignEvent.SessionProposal -> navController.navigate(Route.SessionProposal.path)
is SignEvent.SessionRequest -> navController.navigate(Route.SessionRequest.path)
is SignEvent.Disconnect -> {
is CoreEvent.Disconnect -> {
connectionsViewModel.refreshConnections()
navController.navigate(Route.Connections.path)
}
is AuthEvent.OnRequest -> navController.navigate(Route.AuthRequest.path)

else -> Unit
}
}
.launchIn(lifecycleScope)
}

private fun handlePushEvents(web3walletViewModel: Web3WalletViewModel) {
web3walletViewModel.pushEvents
.flowWithLifecycle(lifecycle)
.onEach { event ->
Expand Down Expand Up @@ -121,39 +151,28 @@ class Web3WalletActivity : ComponentActivity() {
}
.flowOn(Dispatchers.IO)
.launchIn(lifecycleScope)
}

connectionsViewModel.coreEvents
private fun handleWeb3WalletEvents(
web3walletViewModel: Web3WalletViewModel,
connectionsViewModel: ConnectionsViewModel
) {
web3walletViewModel.walletEvents
.flowWithLifecycle(lifecycle, Lifecycle.State.STARTED)
.onEach { event ->
when (event) {
is CoreEvent.Disconnect -> {
is SignEvent.SessionProposal -> navController.navigate(Route.SessionProposal.path)
is SignEvent.SessionRequest -> navController.navigate(Route.SessionRequest.path)
is SignEvent.Disconnect -> {
connectionsViewModel.refreshConnections()
navController.navigate(Route.Connections.path)
}
is AuthEvent.OnRequest -> navController.navigate(Route.AuthRequest.path)

else -> Unit
}
}
.launchIn(lifecycleScope)

askNotificationPermission()
createNotificationChannel()

setContent {
val sheetState = rememberModalBottomSheetState(initialValue = ModalBottomSheetValue.Hidden, skipHalfExpanded = true)
val bottomSheetNavigator = BottomSheetNavigator(sheetState)
val navController = rememberNavController(bottomSheetNavigator)
this.navController = navController

val sharedPref = getPreferences(Context.MODE_PRIVATE)
val getStartedVisited = sharedPref.getBoolean("get_started_visited", false)
Web3WalletTheme {
// Note (Szymon): Due to lack of capacity I didn't implement remembering if user already seen GetStarted route.
Web3WalletNavGraph(
bottomSheetNavigator = bottomSheetNavigator, navController = navController,
getStartedVisited = getStartedVisited, web3walletViewModel = web3walletViewModel, connectionsViewModel = connectionsViewModel
)
}
}
}

override fun onNewIntent(intent: Intent?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp


@Composable
fun SemiTransparentDialog(content: @Composable () -> Unit) {
val backgroundColor = themedColor(Color(0xFF242425).copy(alpha = .95f), Color(0xFFF2F2F7).copy(alpha = .95f))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

package com.walletconnect.web3.wallet.ui.routes.composable_routes.connection_details

import android.util.Log
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
Expand Down Expand Up @@ -34,17 +33,15 @@ import com.google.accompanist.pager.rememberPagerState
import com.google.firebase.crashlytics.ktx.crashlytics
import com.google.firebase.ktx.Firebase
import com.skydoves.landscapist.glide.GlideImage
import com.walletconnect.web3.wallet.client.Wallet
import com.walletconnect.web3.wallet.client.Web3Wallet
import com.walletconnect.web3.wallet.domain.accounts
import com.walletconnect.web3.wallet.sample.R
import com.walletconnect.web3.wallet.ui.common.*
import com.walletconnect.web3.wallet.ui.routes.composable_routes.connections.ConnectionType
import com.walletconnect.web3.wallet.ui.routes.composable_routes.connections.ConnectionUI
import com.walletconnect.web3.wallet.ui.routes.composable_routes.connections.ConnectionsViewModel
import com.walletconnect.web3.wallet.ui.common.themedColor
import com.walletconnect.web3.wallet.ui.routes.showSnackbar
import com.walletconnect.web3.wallet.client.Wallet
import com.walletconnect.web3.wallet.client.Web3Wallet
import com.walletconnect.web3.wallet.sample.R


@Composable
fun ConnectionDetailsRoute(navController: NavController, connectionId: Int?, connectionsViewModel: ConnectionsViewModel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.*

class ConnectionsViewModel : ViewModel() {

private var _refreshFlow: MutableSharedFlow<Unit> = MutableSharedFlow(replay = 0, extraBufferCapacity = 1, BufferOverflow.DROP_OLDEST)
private var refreshFlow: SharedFlow<Unit> = _refreshFlow.asSharedFlow()
private val signConnectionsFlow = merge(WCDelegate.walletEvents, refreshFlow).map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
Expand All @@ -24,8 +25,10 @@ import com.walletconnect.web3.wallet.client.Wallet
import com.walletconnect.web3.wallet.ui.common.*
import com.walletconnect.web3.wallet.ui.common.peer.Peer
import com.walletconnect.web3.wallet.ui.routes.Route
import com.walletconnect.web3.wallet.ui.routes.showSnackbar
import com.walletconnect.web3.wallet.ui.theme.Web3WalletTheme
import com.walletconnect.web3.wallet.ui.utils.CompletePreviews
import kotlinx.coroutines.launch

@CompletePreviews
@Composable
Expand All @@ -38,6 +41,7 @@ fun SessionProposalRoutePreview() {
@Composable
fun SessionProposalRoute(navController: NavHostController, sessionProposalViewModel: SessionProposalViewModel = viewModel()) {
val sessionProposalUI = sessionProposalViewModel.sessionProposal ?: throw Exception("Missing session proposal")
val composableScope = rememberCoroutineScope()
SemiTransparentDialog {
Spacer(modifier = Modifier.height(24.dp))
Peer(peerUI = sessionProposalUI.peerUI, "would like to connect")
Expand All @@ -50,8 +54,15 @@ fun SessionProposalRoute(navController: NavHostController, sessionProposalViewMo
sessionProposalViewModel.reject()
navController.popBackStack(route = Route.Connections.path, inclusive = false)
}, onAllow = {
sessionProposalViewModel.approve()
navController.popBackStack(route = Route.Connections.path, inclusive = false)
composableScope.launch {
try {
sessionProposalViewModel.approve()
navController.popBackStack(route = Route.Connections.path, inclusive = false)
} catch (e: Exception) {
navController.popBackStack(route = Route.Connections.path, inclusive = false)
navController.showSnackbar(e.message ?: "Session approval error: Please check if all Namespaces are supported")
}
}
})
Spacer(modifier = Modifier.height(16.dp))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data class SessionProposalUI(
val namespaces: Map<String, Wallet.Model.Namespace.Proposal>,
)

private val extensiveSessionProposalUI = SessionProposalUI(
val sessionProposalUI = SessionProposalUI(
peerUI = PeerUI(
peerIcon = "https://raw.githubusercontent.com/WalletConnect/walletconnect-assets/master/Icon/Gradient/Icon.png",
peerName = "Kotlin.Responder",
Expand All @@ -17,8 +17,8 @@ private val extensiveSessionProposalUI = SessionProposalUI(
),
namespaces = mapOf(
"eip155" to Wallet.Model.Namespace.Proposal(
chains = listOf("eip155:1", "eip155:137"),
methods = listOf("accountsChanged", "personalSign",),
chains = listOf("eip155:1", "eip155:137", "eip155:56"),
methods = listOf("accountsChanged", "personalSign"),
events = listOf("someEvent1", "someEvent2"),
),
"cosmos" to Wallet.Model.Namespace.Proposal(
Expand All @@ -27,23 +27,4 @@ private val extensiveSessionProposalUI = SessionProposalUI(
events = listOf("someEvent1", "someEvent2"),
)
)
)

private val minimalSessionProposalUI = SessionProposalUI(
peerUI = PeerUI(
peerIcon = "https://raw.githubusercontent.com/WalletConnect/walletconnect-assets/master/Icon/Gradient/Icon.png",
peerName = "Kotlin.Responder",
peerUri = "kotlin.responder.app",
peerDescription = ""
),
namespaces = mapOf(
"eip155" to Wallet.Model.Namespace.Proposal(
chains = listOf("eip155:1"),
methods = listOf("accountsChanged", "personalSign"),
events = listOf("someEvent1", "someEvent2"),
),
)
)

val sessionProposalUI = extensiveSessionProposalUI

)
Loading