Skip to content
This repository was archived by the owner on Oct 20, 2025. It is now read-only.

Commit 8c5ffb8

Browse files
committed
Allow only specific wallets in the modal screen
1 parent d52bc5b commit 8c5ffb8

File tree

5 files changed

+489
-13
lines changed

5 files changed

+489
-13
lines changed

app/src/main/java/exchange/dydx/carteraExample/WalletProvidersConfigUtil.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package exchange.dydx.carteraexample
22

3+
import exchange.dydx.cartera.WalletConnectModalConfig
34
import exchange.dydx.cartera.WalletConnectV1Config
45
import exchange.dydx.cartera.WalletConnectV2Config
56
import exchange.dydx.cartera.WalletProvidersConfig
@@ -29,9 +30,10 @@ object WalletProvidersConfigUtil {
2930
)
3031

3132
return WalletProvidersConfig(
32-
walletConnectV1Config,
33-
walletConnectV2Config,
34-
walletSegueConfig,
33+
walletConnectV1 = walletConnectV1Config,
34+
walletConnectV2 = walletConnectV2Config,
35+
walletConnectModal = WalletConnectModalConfig.default,
36+
walletSegue = walletSegueConfig,
3537
)
3638
}
3739
}

cartera/src/main/java/exchange/dydx/cartera/CarteraConfig.kt

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,24 @@ class CarteraConfig(
7070
if (walletProvidersConfig.walletConnectV2 != null) {
7171
registration[WalletConnectionType.WalletConnectV2] = RegistrationConfig(
7272
provider = WalletConnectV2Provider(
73-
walletProvidersConfig.walletConnectV2,
74-
application,
73+
walletConnectV2Config = walletProvidersConfig.walletConnectV2,
74+
application = application,
7575
),
7676
)
7777

7878
registration[WalletConnectionType.WalletConnectModal] = RegistrationConfig(
7979
provider = WalletConnectModalProvider(
8080
application = application,
81+
config = walletProvidersConfig.walletConnectModal,
8182
),
8283
)
8384
}
8485
if (walletProvidersConfig.walletSegue != null) {
8586
registration[WalletConnectionType.WalletSegue] = RegistrationConfig(
8687
provider = WalletSegueProvider(
87-
walletProvidersConfig.walletSegue,
88-
application,
89-
launcher,
88+
walletSegueConfig = walletProvidersConfig.walletSegue,
89+
application = application,
90+
launcher = launcher,
9091
),
9192
)
9293
}
@@ -106,6 +107,7 @@ class CarteraConfig(
106107
registration[WalletConnectionType.WalletConnectModal] = RegistrationConfig(
107108
provider = WalletConnectModalProvider(
108109
application = application,
110+
config = walletProvidersConfig.walletConnectModal,
109111
),
110112
)
111113
}
@@ -164,6 +166,7 @@ class CarteraConfig(
164166
data class WalletProvidersConfig(
165167
val walletConnectV1: WalletConnectV1Config? = null,
166168
val walletConnectV2: WalletConnectV2Config? = null,
169+
val walletConnectModal: WalletConnectModalConfig? = null,
167170
val walletSegue: WalletSegueConfig? = null
168171
)
169172

@@ -184,6 +187,34 @@ data class WalletConnectV2Config(
184187
val iconUrls: List<String>
185188
)
186189

190+
data class WalletConnectModalConfig(
191+
val walletIds: List<String>?
192+
) {
193+
companion object {
194+
val default: WalletConnectModalConfig = WalletConnectModalConfig(
195+
walletIds = listOf(
196+
"c57ca95b47569778a828d19178114f4db188b89b763c899ba0be274e97267d96", // Metamask
197+
"4622a2b2d6af1c9844944291e5e7351a6aa24cd7b23099efac1b2fd875da31a0", // Trust
198+
"971e689d0a5be527bac79629b4ee9b925e82208e5168b733496a09c0faed0709", // OKX
199+
"c03dfee351b6fcc421b4494ea33b9d4b92a984f87aa76d1663bb28705e95034a", // Uniswap
200+
"1ae92b26df02f0abca6304df07debccd18262fdf5fe82daa81593582dac9a369", // Rainbow
201+
"ecc4036f814562b41a5268adc86270fba1365471402006302e70169465b7ac18", // Zerion
202+
"c286eebc742a537cd1d6818363e9dc53b21759a1e8e5d9b263d0c03ec7703576", // 1inch
203+
"ef333840daf915aafdc4a004525502d6d49d77bd9c65e0642dbaefb3c2893bef", // imToken
204+
"38f5d18bd8522c244bdd70cb4a68e0e718865155811c043f052fb9f1c51de662", // Bitget
205+
"0b415a746fb9ee99cce155c2ceca0c6f6061b1dbca2d722b3ba16381d0562150", // Safepal
206+
"15c8b91ade1a4e58f3ce4e7a0dd7f42b47db0c8df7e0d84f63eb39bcb96c4e0f", // Bybit
207+
"19177a98252e07ddfc9af2083ba8e07ef627cb6103467ffebb3f8f4205fd7927", // Ledger Live
208+
"344d0e58b139eb1b6da0c29ea71d52a8eace8b57897c6098cb9b46012665c193", // Timeless X
209+
"225affb176778569276e484e1b92637ad061b01e13a048b35a9d280c3b58970f", // Safe
210+
"f2436c67184f158d1beda5df53298ee84abfc367581e4505134b5bcf5f46697d", // Crypto.com
211+
"18450873727504ae9315a084fa7624b5297d2fe5880f0982979c17345a138277", // Kraken
212+
"541d5dcd4ede02f3afaf75bf8e3e4c4f1fb09edb5fa6c4377ebf31c2785d9adf" // Ronin
213+
)
214+
)
215+
}
216+
}
217+
187218
data class WalletSegueConfig(
188219
val callbackUrl: String
189220
)

cartera/src/main/java/exchange/dydx/cartera/walletprovider/providers/WalletConnectModalProvider.kt

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ import android.content.ActivityNotFoundException
55
import android.content.Intent
66
import android.net.Uri
77
import androidx.navigation.NavHostController
8+
import com.google.gson.Gson
9+
import com.google.gson.reflect.TypeToken
810
import com.walletconnect.android.CoreClient
911
import com.walletconnect.wcmodal.client.Modal
1012
import com.walletconnect.wcmodal.client.WalletConnectModal
1113
import com.walletconnect.wcmodal.ui.openWalletConnectModal
1214
import exchange.dydx.cartera.CarteraErrorCode
15+
import exchange.dydx.cartera.R
16+
import exchange.dydx.cartera.WalletConnectModalConfig
1317
import exchange.dydx.cartera.entities.Wallet
1418
import exchange.dydx.cartera.entities.toJsonRequest
1519
import exchange.dydx.cartera.tag
@@ -34,9 +38,11 @@ import kotlinx.coroutines.CoroutineScope
3438
import kotlinx.coroutines.Dispatchers
3539
import kotlinx.coroutines.launch
3640
import timber.log.Timber
41+
import java.lang.reflect.Type
3742

3843
class WalletConnectModalProvider(
39-
private val application: Application
44+
private val application: Application,
45+
private val config: WalletConnectModalConfig?,
4046
) : WalletOperationProviderProtocol, WalletConnectModal.ModalDelegate {
4147

4248
private var _walletStatus = WalletStatusImp()
@@ -65,8 +71,23 @@ class WalletConnectModalProvider(
6571
var nav: NavHostController? = null
6672

6773
init {
74+
val jsonData = application.getResources().openRawResource(R.raw.wc_modal_ids)
75+
.bufferedReader().use { it.readText() }
76+
val gson = Gson()
77+
val idListType: Type = object : TypeToken<List<String>?>() {}.type
78+
val wc_modal_ids: List<String>? = gson.fromJson(jsonData, idListType)
79+
val excludedIds = wc_modal_ids?.toMutableList() ?: mutableListOf()
80+
for (id in config?.walletIds ?: emptyList()) {
81+
if (excludedIds.contains(id)) {
82+
excludedIds.remove(id)
83+
}
84+
}
6885
WalletConnectModal.initialize(
69-
init = Modal.Params.Init(CoreClient),
86+
init = Modal.Params.Init(
87+
core = CoreClient,
88+
recommendedWalletsIds = config?.walletIds ?: emptyList(),
89+
excludedWalletIds = excludedIds,
90+
),
7091
onSuccess = {
7192
// Callback will be called if initialization is successful
7293
Timber.tag(tag(this)).d("WalletConnectModal initialized.")
@@ -306,9 +327,9 @@ class WalletConnectModalProvider(
306327
completion(
307328
null,
308329
WalletError(
309-
CarteraErrorCode.CONNECTION_FAILED,
310-
"WalletConnectModal.request error",
311-
error.throwable.stackTraceToString(),
330+
code = CarteraErrorCode.CONNECTION_FAILED,
331+
title = "WalletConnectModal.request error",
332+
message = error.throwable.stackTraceToString(),
312333
),
313334
)
314335
},

0 commit comments

Comments
 (0)