Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TRCL-3471 Update the testnet to Sepolia #16

Merged
merged 2 commits into from
Jan 27, 2024
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 @@ -210,7 +210,7 @@ object WalletList {
.fillMaxWidth(),
) {
Text(
"Goerli Testnet:",
"Testnet:",
modifier = Modifier
.padding(16.dp)
.weight(1f, false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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,
Expand All @@ -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(
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package exchange.dydx.cartera

object CarteraConstants {
const val testnetChainId = "11155111"
const val testnetName = "Sepolia"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(),
Expand All @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -78,12 +79,12 @@ class WalletSegueProvider(
) { result: Result<List<ActionResult>>, account: Account? ->
result.onSuccess { actionResults: List<ActionResult> ->
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,
Expand Down
Loading