diff --git a/app/src/main/java/im/status/keycard/connect/data/Constants.kt b/app/src/main/java/im/status/keycard/connect/data/Constants.kt index 5d0afd0..9b12e97 100644 --- a/app/src/main/java/im/status/keycard/connect/data/Constants.kt +++ b/app/src/main/java/im/status/keycard/connect/data/Constants.kt @@ -39,15 +39,16 @@ const val SETTINGS_BIP32_PATH = "bip32Path" const val INFURA_API_KEY = "27efcb33f94e4bd0866d1aadf8e1a12d" const val RPC_ENDPOINT_TEMPLATE = "https://%s.infura.io/v3/${INFURA_API_KEY}" - +const val XDAI_ENDPOINT = "https://rpc.xdaichain.com" const val CHAIN_ID_MAINNET = 1L const val CHAIN_ID_ROPSTEN = 3L const val CHAIN_ID_RINKEBY = 4L const val CHAIN_ID_GOERLI = 5L const val CHAIN_ID_KOVAN = 42L +const val CHAIN_ID_XDAI = 100L val CHAIN_ID_TO_SHORTNAME = mapOf(CHAIN_ID_MAINNET to "mainnet", CHAIN_ID_ROPSTEN to "ropsten", CHAIN_ID_RINKEBY to "rinkeby", CHAIN_ID_GOERLI to "goerli", CHAIN_ID_KOVAN to "kovan") -val CHAIN_IDS = listOf(CHAIN_ID_MAINNET, CHAIN_ID_ROPSTEN, CHAIN_ID_RINKEBY, CHAIN_ID_GOERLI, CHAIN_ID_KOVAN) +val CHAIN_IDS = listOf(CHAIN_ID_MAINNET, CHAIN_ID_XDAI, CHAIN_ID_ROPSTEN, CHAIN_ID_RINKEBY, CHAIN_ID_GOERLI, CHAIN_ID_KOVAN) const val DEFAULT_CHAIN_ID = CHAIN_ID_MAINNET const val DEFAULT_BIP32_PATH = "m/44'/60'/0'/0/0" \ No newline at end of file diff --git a/app/src/main/java/im/status/keycard/connect/data/SettingsManager.kt b/app/src/main/java/im/status/keycard/connect/data/SettingsManager.kt index 7a08ba0..cf2d2d1 100644 --- a/app/src/main/java/im/status/keycard/connect/data/SettingsManager.kt +++ b/app/src/main/java/im/status/keycard/connect/data/SettingsManager.kt @@ -14,8 +14,11 @@ class SettingsManager(context: Context) { sharedPreferences = EncryptedSharedPreferences.create(context,"settings", masterKey, EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV, EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM) } - val rpcEndpoint - get() = String.format(RPC_ENDPOINT_TEMPLATE, CHAIN_ID_TO_SHORTNAME.getValue(sharedPreferences.getLong(SETTINGS_CHAIN_ID, DEFAULT_CHAIN_ID))) + val rpcEndpoint : String + get() { + val chainID = sharedPreferences.getLong(SETTINGS_CHAIN_ID, DEFAULT_CHAIN_ID) + return if (chainID == CHAIN_ID_XDAI) XDAI_ENDPOINT else String.format(RPC_ENDPOINT_TEMPLATE, CHAIN_ID_TO_SHORTNAME.getValue(chainID)) + } var chainID get() = sharedPreferences.getLong(SETTINGS_CHAIN_ID, DEFAULT_CHAIN_ID) diff --git a/app/src/main/java/im/status/keycard/connect/net/WalletConnect.kt b/app/src/main/java/im/status/keycard/connect/net/WalletConnect.kt index 3677f70..fd1922d 100644 --- a/app/src/main/java/im/status/keycard/connect/net/WalletConnect.kt +++ b/app/src/main/java/im/status/keycard/connect/net/WalletConnect.kt @@ -50,12 +50,14 @@ class WalletConnect(var sessionStatusListener : Session.Callback, var bip32Path: private val sessionStore = FileWCSessionStore(File(Registry.mainActivity.filesDir, "wcSessions.json").apply { createNewFile() }, moshi) private var session: WCSession? = null private var requestId: Long = 0 + private var currentAccount: String? = null private var uiAction: (Intent?) -> Unit = this::nop private var signAction: (RecoverableSignature) -> Unit = this::nop override fun onStatus(status: Session.Status) { if (status == Session.Status.Closed) { session = null + currentAccount = null } } @@ -235,8 +237,8 @@ class WalletConnect(var sessionStatusListener : Session.Callback, var bip32Path: override fun onResponse(keyPair: BIP32KeyPair) { scope.launch(Dispatchers.IO) { - val addr = keyPair.toEthereumAddress().toHexString() - session?.approve(listOf(addr), chainID) + currentAccount = keyPair.toEthereumAddress().toHexString() + session?.approve(listOf(currentAccount!!), chainID) } } diff --git a/app/src/main/res/values/networks.xml b/app/src/main/res/values/networks.xml index ed65521..ea7d784 100644 --- a/app/src/main/res/values/networks.xml +++ b/app/src/main/res/values/networks.xml @@ -2,6 +2,7 @@ Ethereum Mainnet + xDAI Network Ropsten PoW Testnet Rinkeby PoA Testnet Görli PoA Testnet