-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from WalletConnect/develop
Beta 100 Release
- Loading branch information
Showing
261 changed files
with
7,933 additions
and
5,057 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,3 +88,6 @@ lint/tmp/ | |
|
||
# Android Profiling | ||
*.hprof | ||
|
||
# Project ID | ||
/samples_common/src/main/res/values/project_id.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.walletconnect.dapp"> | ||
|
||
<application | ||
android:name=".DappSampleApplication" | ||
android:allowBackup="true" | ||
android:icon="@drawable/ic_walletconnect_circle_blue" | ||
android:label="@string/app_name" | ||
android:roundIcon="@drawable/ic_walletconnect_circle_blue" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.WalletConnect"> | ||
|
||
<activity | ||
android:name="com.walletconnect.dapp.ui.host.DappSampleActivity" | ||
android:exported="true" | ||
android:screenOrientation="portrait"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
</manifest> |
45 changes: 45 additions & 0 deletions
45
dapp/src/main/kotlin/com/walletconnect/dapp/DappSampleApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.walletconnect.dapp | ||
|
||
import android.app.Application | ||
import com.walletconnect.sample_common.R | ||
import com.walletconnect.sample_common.WALLET_CONNECT_PROD_RELAY_URL | ||
import com.walletconnect.walletconnectv2.client.WalletConnect | ||
import com.walletconnect.walletconnectv2.client.WalletConnectClient | ||
|
||
class DappSampleApplication: Application() { | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
|
||
// This is strictly for sample purposes | ||
val projectId = resources.getString(R.string.project_id) | ||
|
||
// Sample of how to use parts of a URI to initialize the WalletConnect SDK | ||
// val initParts = WalletConnect.Params.Init( | ||
// application = this, | ||
// useTls = true, | ||
// hostName = WALLET_CONNECT_PROD_RELAY_URL, | ||
// projectId = projectId, //TODO: register at https://walletconnect.com/register to get a project ID | ||
// metadata = WalletConnect.Model.AppMetaData( | ||
// name = "Kotlin Dapp", | ||
// description = "Dapp description", | ||
// url = "example.dapp", | ||
// icons = listOf("https://gblobscdn.gitbook.com/spaces%2F-LJJeCjcLrr53DcT1Ml7%2Favatar.png?alt=media") | ||
// ) | ||
// ) | ||
|
||
// Sample of how to use a URI to initialize the WalletConnect SDK | ||
val initString = WalletConnect.Params.Init( | ||
application = this, | ||
relayServerUrl = "wss://$WALLET_CONNECT_PROD_RELAY_URL?projectId=$projectId", //TODO: register at https://walletconnect.com/register to get a project ID | ||
metadata = WalletConnect.Model.AppMetaData( | ||
name = "Kotlin Dapp", | ||
description = "Dapp description", | ||
url = "example.dapp", | ||
icons = listOf("https://gblobscdn.gitbook.com/spaces%2F-LJJeCjcLrr53DcT1Ml7%2Favatar.png?alt=media") | ||
) | ||
) | ||
|
||
WalletConnectClient.initialize(initString) | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
dapp/src/main/kotlin/com/walletconnect/dapp/domain/DappDelegate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.walletconnect.dapp.domain | ||
|
||
import com.walletconnect.walletconnectv2.client.WalletConnect | ||
import com.walletconnect.walletconnectv2.client.WalletConnectClient | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.SupervisorJob | ||
import kotlinx.coroutines.flow.MutableSharedFlow | ||
import kotlinx.coroutines.flow.SharedFlow | ||
import kotlinx.coroutines.flow.asSharedFlow | ||
import kotlinx.coroutines.launch | ||
|
||
object DappDelegate : WalletConnectClient.DappDelegate { | ||
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO) | ||
private val _wcEventModels: MutableSharedFlow<WalletConnect.Model?> = MutableSharedFlow() | ||
val wcEventModels: SharedFlow<WalletConnect.Model?> = _wcEventModels.asSharedFlow() | ||
|
||
var selectedSessionTopic: String? = null | ||
private set | ||
|
||
init { | ||
WalletConnectClient.setDappDelegate(this) | ||
} | ||
|
||
override fun onSessionApproved(approvedSession: WalletConnect.Model.ApprovedSession) { | ||
selectedSessionTopic = approvedSession.topic | ||
|
||
scope.launch { | ||
_wcEventModels.emit(approvedSession) | ||
} | ||
} | ||
|
||
override fun onSessionRejected(rejectedSession: WalletConnect.Model.RejectedSession) { | ||
scope.launch { | ||
_wcEventModels.emit(rejectedSession) | ||
} | ||
} | ||
|
||
override fun onSessionUpdateAccounts(updatedSessionAccounts: WalletConnect.Model.UpdatedSessionAccounts) { | ||
scope.launch { | ||
_wcEventModels.emit(updatedSessionAccounts) | ||
} | ||
} | ||
|
||
override fun onSessionUpdateMethods(updatedSessionMethods: WalletConnect.Model.UpdatedSessionMethods) { | ||
scope.launch { | ||
_wcEventModels.emit(updatedSessionMethods) | ||
} | ||
} | ||
|
||
override fun onSessionUpdateEvents(updatedSessionEvents: WalletConnect.Model.UpdatedSessionEvents) { | ||
scope.launch { | ||
_wcEventModels.emit(updatedSessionEvents) | ||
} | ||
} | ||
|
||
override fun onSessionDelete(deletedSession: WalletConnect.Model.DeletedSession) { | ||
deselectAccountDetails() | ||
|
||
scope.launch { | ||
_wcEventModels.emit(deletedSession) | ||
} | ||
} | ||
|
||
override fun onUpdateSessionExpiry(session: WalletConnect.Model.Session) { | ||
scope.launch { | ||
_wcEventModels.emit(session) | ||
} | ||
} | ||
|
||
override fun onSessionRequestResponse(response: WalletConnect.Model.SessionRequestResponse) { | ||
scope.launch { | ||
_wcEventModels.emit(response) | ||
} | ||
} | ||
|
||
fun deselectAccountDetails() { | ||
selectedSessionTopic = null | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
dapp/src/main/kotlin/com/walletconnect/dapp/ui/SampleDappEvents.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.walletconnect.dapp.ui | ||
|
||
sealed class SampleDappEvents { | ||
|
||
object SessionApproved : SampleDappEvents() | ||
|
||
object SessionRejected : SampleDappEvents() | ||
|
||
data class PingSuccess(val topic: String) : SampleDappEvents() | ||
|
||
object PingError : SampleDappEvents() | ||
|
||
object Disconnect : SampleDappEvents() | ||
|
||
data class RequestSuccess(val result: String) : SampleDappEvents() | ||
|
||
data class RequestPeerError(val errorMsg: String) : SampleDappEvents() | ||
|
||
data class RequestError(val exceptionMsg: String) : SampleDappEvents() | ||
|
||
object NoAction : SampleDappEvents() | ||
} |
79 changes: 79 additions & 0 deletions
79
dapp/src/main/kotlin/com/walletconnect/dapp/ui/connect/ConnectViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.walletconnect.dapp.ui.connect | ||
|
||
import android.util.Log | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.walletconnect.dapp.domain.DappDelegate | ||
import com.walletconnect.dapp.ui.SampleDappEvents | ||
import com.walletconnect.dapp.ui.connect.chain_select.ChainSelectionUI | ||
import com.walletconnect.sample_common.EthTestChains | ||
import com.walletconnect.sample_common.tag | ||
import com.walletconnect.walletconnectv2.client.WalletConnect | ||
import com.walletconnect.walletconnectv2.client.WalletConnectClient | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.channels.Channel | ||
import kotlinx.coroutines.flow.launchIn | ||
import kotlinx.coroutines.flow.map | ||
import kotlinx.coroutines.flow.onEach | ||
import kotlinx.coroutines.flow.receiveAsFlow | ||
import kotlinx.coroutines.launch | ||
|
||
class ConnectViewModel : ViewModel() { | ||
private val _listOfChainUI: MutableList<ChainSelectionUI> = mutableListOf() | ||
get() { | ||
return if (field.isEmpty()) { | ||
EthTestChains.values().mapTo(field) { | ||
ChainSelectionUI(it.chainName, it.parentChain, it.chainId, it.icon, it.methods) | ||
} | ||
} else { | ||
field | ||
} | ||
} | ||
val listOfChainUI: List<ChainSelectionUI> = _listOfChainUI | ||
|
||
private val navigationChannel = Channel<SampleDappEvents>(Channel.BUFFERED) | ||
val navigation = navigationChannel.receiveAsFlow() | ||
|
||
init { | ||
DappDelegate.wcEventModels.map { walletEvent: WalletConnect.Model? -> | ||
when (walletEvent) { | ||
is WalletConnect.Model.ApprovedSession -> SampleDappEvents.SessionApproved | ||
is WalletConnect.Model.RejectedSession -> SampleDappEvents.SessionRejected | ||
else -> SampleDappEvents.NoAction | ||
} | ||
}.onEach { event -> | ||
navigationChannel.trySend(event) | ||
}.launchIn(viewModelScope) | ||
} | ||
|
||
fun updateSelectedChainUI(position: Int, isChecked: Boolean) { | ||
_listOfChainUI[position].isSelected = isChecked | ||
} | ||
|
||
fun connectToWallet(pairingTopicPosition: Int = -1, onProposedSequence: (WalletConnect.Model.ProposedSequence) -> Unit = {}) { | ||
var pairingTopic: String? = null | ||
|
||
if (pairingTopicPosition > -1) { | ||
pairingTopic = WalletConnectClient.getListOfSettledPairings()[pairingTopicPosition].topic | ||
} | ||
|
||
val selectedChains: List<ChainSelectionUI> = listOfChainUI.filter { it.isSelected } | ||
val chains = selectedChains.map { "${it.parentChain}:${it.chainId}" } | ||
val methods = selectedChains.flatMap { it.methods }.distinct() | ||
|
||
val connectParams = WalletConnect.Params.Connect( | ||
chains = chains, | ||
methods = methods, | ||
events = listOf(), | ||
pairingTopic = pairingTopic) | ||
|
||
WalletConnectClient.connect(connectParams, | ||
onProposedSequence = { proposedSequence -> | ||
viewModelScope.launch(Dispatchers.Main) { | ||
onProposedSequence(proposedSequence) | ||
} | ||
|
||
}, | ||
onFailure = { error -> Log.e(tag(this@ConnectViewModel), error.error.stackTraceToString()) }) | ||
} | ||
} |
Oops, something went wrong.