From e5897ba06ee985d1ed6421275a00562acc5cb3fd Mon Sep 17 00:00:00 2001 From: Rui Date: Wed, 24 Jan 2024 17:33:03 -0800 Subject: [PATCH 1/2] Update the testnet to Sepolia --- .../dydx/carteraExample/WalletList.kt | 2 +- .../carteraExample/WalletListViewModel.kt | 19 ++++++++++--------- .../exchange/dydx/cartera/CarteraConstants.kt | 6 ++++++ .../exchange/dydx/cartera/CarteraProvider.kt | 2 +- .../walletprovider/WalletProviderProtocols.kt | 2 +- .../cartera/walletprovider/WalletStatus.kt | 2 +- .../providers/WalletConnectV2Provider.kt | 6 +++--- .../providers/WalletSegueProvider.kt | 7 ++++--- 8 files changed, 27 insertions(+), 19 deletions(-) create mode 100644 cartera/src/main/java/exchange/dydx/cartera/CarteraConstants.kt diff --git a/app/src/main/java/exchange/dydx/carteraExample/WalletList.kt b/app/src/main/java/exchange/dydx/carteraExample/WalletList.kt index c888270..1361455 100644 --- a/app/src/main/java/exchange/dydx/carteraExample/WalletList.kt +++ b/app/src/main/java/exchange/dydx/carteraExample/WalletList.kt @@ -210,7 +210,7 @@ object WalletList { .fillMaxWidth(), ) { Text( - "Goerli Testnet:", + "Testnet:", modifier = Modifier .padding(16.dp) .weight(1f, false), diff --git a/app/src/main/java/exchange/dydx/carteraExample/WalletListViewModel.kt b/app/src/main/java/exchange/dydx/carteraExample/WalletListViewModel.kt index 4fcc45d..27d2c80 100644 --- a/app/src/main/java/exchange/dydx/carteraExample/WalletListViewModel.kt +++ b/app/src/main/java/exchange/dydx/carteraExample/WalletListViewModel.kt @@ -8,6 +8,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import exchange.dydx.cartera.CarteraConfig +import exchange.dydx.cartera.CarteraConstants import exchange.dydx.cartera.CarteraProvider import exchange.dydx.cartera.entities.Wallet import exchange.dydx.cartera.tag @@ -39,7 +40,7 @@ class WalletListViewModel( viewState.value = WalletList.WalletListState( wallets = CarteraConfig.shared?.wallets ?: listOf(), walletAction = { action: WalletList.WalletAction, wallet: Wallet?, useTestnet: Boolean -> - val chainId: Int = if (useTestnet) 5 else 1 + val chainId: String = if (useTestnet) CarteraConstants.testnetChainId else "1" when (action) { WalletList.WalletAction.Connect -> { testConnect(wallet, chainId) @@ -59,7 +60,7 @@ class WalletListViewModel( } }, debugQRCodeAction = { action: WalletList.QrCodeAction, useTestnet: Boolean -> - val chainId: Int = if (useTestnet) 5 else 1 + val chainId: String = if (useTestnet) CarteraConstants.testnetChainId else "1" when (action) { WalletList.QrCodeAction.V1 -> { // TODO: testQRCodeV1() @@ -74,7 +75,7 @@ class WalletListViewModel( } } - private fun testQRCodeV2(chainId: Int) { + private fun testQRCodeV2(chainId: String) { viewState.value.showingQrCodeState = true viewState.value.showBottomSheet = false viewState.value.selectedWallet = null @@ -89,7 +90,7 @@ class WalletListViewModel( } } - private fun testConnect(wallet: Wallet?, chainId: Int) { + private fun testConnect(wallet: Wallet?, chainId: String) { val request = WalletRequest(wallet = wallet, address = null, chainId = chainId, context = context) provider.connect(request) { info, error -> if (error != null) { @@ -100,7 +101,7 @@ class WalletListViewModel( } } - private fun testSignMessage(wallet: Wallet?, chainId: Int) { + private fun testSignMessage(wallet: Wallet?, chainId: String) { val request = WalletRequest(wallet = wallet, address = null, chainId = chainId, context = context) provider.signMessage( request = request, @@ -118,9 +119,9 @@ class WalletListViewModel( ) } - private fun testSignTypedData(wallet: Wallet?, chainId: Int) { - val dydxSign = EIP712DomainTypedDataProvider(name = "dYdX", chainId = chainId) - dydxSign.message = message(action = "Sample Action", chainId = chainId) + private fun testSignTypedData(wallet: Wallet?, chainId: String) { + val dydxSign = EIP712DomainTypedDataProvider(name = "dYdX", chainId = chainId.toInt()) + dydxSign.message = message(action = "Sample Action", chainId = chainId.toInt()) val request = WalletRequest(wallet = wallet, address = null, chainId = chainId, context = context) provider.sign( @@ -139,7 +140,7 @@ class WalletListViewModel( ) } - private fun testSendTransaction(wallet: Wallet?, chainId: Int) { + private fun testSendTransaction(wallet: Wallet?, chainId: String) { val request = WalletRequest(wallet = wallet, address = null, chainId = chainId, context = context) provider.connect(request) { info, error -> if (error != null) { diff --git a/cartera/src/main/java/exchange/dydx/cartera/CarteraConstants.kt b/cartera/src/main/java/exchange/dydx/cartera/CarteraConstants.kt new file mode 100644 index 0000000..526349d --- /dev/null +++ b/cartera/src/main/java/exchange/dydx/cartera/CarteraConstants.kt @@ -0,0 +1,6 @@ +package exchange.dydx.cartera + + object CarteraConstants { + const val testnetChainId = "11155111" + const val testnetName = "Sepolia" +} \ No newline at end of file diff --git a/cartera/src/main/java/exchange/dydx/cartera/CarteraProvider.kt b/cartera/src/main/java/exchange/dydx/cartera/CarteraProvider.kt index 1e19d9f..2b81be0 100644 --- a/cartera/src/main/java/exchange/dydx/cartera/CarteraProvider.kt +++ b/cartera/src/main/java/exchange/dydx/cartera/CarteraProvider.kt @@ -22,7 +22,7 @@ class CarteraProvider(private val context: Context) : WalletOperationProviderPro private val debugQrCodeProvider = CarteraConfig.shared?.getProvider(WalletConnectionType.WalletConnectV2) - fun startDebugLink(chainId: Int, completion: WalletConnectCompletion) { + fun startDebugLink(chainId: String, completion: WalletConnectCompletion) { updateCurrentHandler(WalletRequest(null, null, chainId, context)) currentRequestHandler?.connect(WalletRequest(null, null, chainId, context), completion) } diff --git a/cartera/src/main/java/exchange/dydx/cartera/walletprovider/WalletProviderProtocols.kt b/cartera/src/main/java/exchange/dydx/cartera/walletprovider/WalletProviderProtocols.kt index b110fd6..586b180 100644 --- a/cartera/src/main/java/exchange/dydx/cartera/walletprovider/WalletProviderProtocols.kt +++ b/cartera/src/main/java/exchange/dydx/cartera/walletprovider/WalletProviderProtocols.kt @@ -8,7 +8,7 @@ import java.math.BigInteger data class WalletRequest( val wallet: Wallet? = null, val address: String? = null, - val chainId: Int? = null, + val chainId: String? = null, val context: Context ) diff --git a/cartera/src/main/java/exchange/dydx/cartera/walletprovider/WalletStatus.kt b/cartera/src/main/java/exchange/dydx/cartera/walletprovider/WalletStatus.kt index abd2fe2..72fef52 100644 --- a/cartera/src/main/java/exchange/dydx/cartera/walletprovider/WalletStatus.kt +++ b/cartera/src/main/java/exchange/dydx/cartera/walletprovider/WalletStatus.kt @@ -4,7 +4,7 @@ import exchange.dydx.cartera.entities.Wallet data class WalletInfo( val address: String? = null, - val chainId: Int? = null, + val chainId: String? = null, val wallet: Wallet? = null, val peerName: String? = null, val peerImageUrl: String? = null diff --git a/cartera/src/main/java/exchange/dydx/cartera/walletprovider/providers/WalletConnectV2Provider.kt b/cartera/src/main/java/exchange/dydx/cartera/walletprovider/providers/WalletConnectV2Provider.kt index 18a2eb7..4651de2 100644 --- a/cartera/src/main/java/exchange/dydx/cartera/walletprovider/providers/WalletConnectV2Provider.kt +++ b/cartera/src/main/java/exchange/dydx/cartera/walletprovider/providers/WalletConnectV2Provider.kt @@ -73,7 +73,7 @@ class WalletConnectV2Provider( CoroutineScope(Dispatchers.Main).launch { if (requestingWallet?.chainId != null && approvedSession.chainId() != null && - requestingWallet?.chainId != approvedSession.chainId() + requestingWallet?.chainId != approvedSession.chainId().toString() ) { for (connectCompletion in connectCompletions) { connectCompletion.invoke( @@ -507,7 +507,7 @@ class WalletConnectV2Provider( private fun fromPairing(pairing: Core.Model.Pairing, wallet: Wallet): WalletInfo { return WalletInfo( address = "address", - chainId = 0, + chainId = "0", wallet = wallet, peerName = pairing.peerAppMetaData?.name, peerImageUrl = pairing.peerAppMetaData?.icons?.firstOrNull(), @@ -517,7 +517,7 @@ class WalletConnectV2Provider( private fun fromApprovedSession(session: Sign.Model.ApprovedSession, wallet: Wallet?): WalletInfo { return WalletInfo( address = session.account(), - chainId = session.chainId(), + chainId = session.chainId().toString(), wallet = wallet, peerName = session.metaData?.name, peerImageUrl = session.metaData?.icons?.firstOrNull(), diff --git a/cartera/src/main/java/exchange/dydx/cartera/walletprovider/providers/WalletSegueProvider.kt b/cartera/src/main/java/exchange/dydx/cartera/walletprovider/providers/WalletSegueProvider.kt index a84f6d4..1134208 100644 --- a/cartera/src/main/java/exchange/dydx/cartera/walletprovider/providers/WalletSegueProvider.kt +++ b/cartera/src/main/java/exchange/dydx/cartera/walletprovider/providers/WalletSegueProvider.kt @@ -11,6 +11,7 @@ import com.coinbase.android.nativesdk.message.request.Action import com.coinbase.android.nativesdk.message.request.RequestContent import com.coinbase.android.nativesdk.message.request.Web3JsonRPC import com.coinbase.android.nativesdk.message.response.ActionResult +import exchange.dydx.cartera.CarteraConstants import exchange.dydx.cartera.CarteraErrorCode import exchange.dydx.cartera.WalletSegueConfig import exchange.dydx.cartera.tag @@ -78,12 +79,12 @@ class WalletSegueProvider( ) { result: Result>, account: Account? -> result.onSuccess { actionResults: List -> if (account != null) { - if (expected.chainId != null && account.networkId.toInt() != expected.chainId) { + if (expected.chainId != null && account.networkId.toString() != expected.chainId) { val errorTitle = "Network Mismatch" - val errorMessage = if (expected.chainId == 1) { + val errorMessage = if (expected.chainId == "1") { "Set your wallet network to 'Ethereum Mainnet'." } else { - "Set your wallet network to 'Goerli Test Network'." + "Set your wallet network to '${CarteraConstants.testnetName} Test Network'." } completion( null, From 4388a02015f55d2dea328dc14b51f8a3485610b2 Mon Sep 17 00:00:00 2001 From: Rui Date: Wed, 24 Jan 2024 17:58:42 -0800 Subject: [PATCH 2/2] Lint --- .../java/exchange/dydx/carteraExample/WalletListViewModel.kt | 2 +- .../src/main/java/exchange/dydx/cartera/CarteraConstants.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/exchange/dydx/carteraExample/WalletListViewModel.kt b/app/src/main/java/exchange/dydx/carteraExample/WalletListViewModel.kt index 27d2c80..24f18cb 100644 --- a/app/src/main/java/exchange/dydx/carteraExample/WalletListViewModel.kt +++ b/app/src/main/java/exchange/dydx/carteraExample/WalletListViewModel.kt @@ -120,7 +120,7 @@ class WalletListViewModel( } private fun testSignTypedData(wallet: Wallet?, chainId: String) { - val dydxSign = EIP712DomainTypedDataProvider(name = "dYdX", chainId = chainId.toInt()) + val dydxSign = EIP712DomainTypedDataProvider(name = "dYdX", chainId = chainId.toInt()) dydxSign.message = message(action = "Sample Action", chainId = chainId.toInt()) val request = WalletRequest(wallet = wallet, address = null, chainId = chainId, context = context) diff --git a/cartera/src/main/java/exchange/dydx/cartera/CarteraConstants.kt b/cartera/src/main/java/exchange/dydx/cartera/CarteraConstants.kt index 526349d..8274cd0 100644 --- a/cartera/src/main/java/exchange/dydx/cartera/CarteraConstants.kt +++ b/cartera/src/main/java/exchange/dydx/cartera/CarteraConstants.kt @@ -1,6 +1,6 @@ package exchange.dydx.cartera - object CarteraConstants { +object CarteraConstants { const val testnetChainId = "11155111" const val testnetName = "Sepolia" -} \ No newline at end of file +}