diff --git a/app/src/main/java/io/kthulu/sdk/MainActivity.kt b/app/src/main/java/io/kthulu/sdk/MainActivity.kt index 7c2d428..2f1a44a 100644 --- a/app/src/main/java/io/kthulu/sdk/MainActivity.kt +++ b/app/src/main/java/io/kthulu/sdk/MainActivity.kt @@ -29,12 +29,8 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) - // Setting the context - MyContext.setAppContext(this) - launch { withContext(Dispatchers.IO) { - } } } diff --git a/app/src/main/java/io/kthulu/sdk/account.kt b/app/src/main/java/io/kthulu/sdk/account.kt index c820be6..82968b6 100644 --- a/app/src/main/java/io/kthulu/sdk/account.kt +++ b/app/src/main/java/io/kthulu/sdk/account.kt @@ -28,7 +28,7 @@ suspend fun createAccountsAsync( // save data arrya var saveMainNet = JSONArray() var jsonData = JSONObject() - val resultArray = JSONArray() + var resultArray = JSONArray() var resultData = JSONObject() resultData.put("result", "FAIL") resultData.put("value", resultArray) @@ -79,6 +79,7 @@ suspend fun createAccountsAsync( resultData } catch(e: Exception){ + resultArray = JSONArray() jsonData.put("error", e.message) resultArray.put(jsonData) resultData.put("result", "FAIL") @@ -123,7 +124,7 @@ suspend fun restoreAccountAsync( var saveMainNet = JSONArray() var jsonData = JSONObject() // return array & object - val resultArray = JSONArray() + var resultArray = JSONArray() var resultData = JSONObject() resultData.put("result", "FAIL") resultData.put("value", resultArray) @@ -190,6 +191,7 @@ suspend fun restoreAccountAsync( resultData } catch(e: Exception){ + resultArray = JSONArray() jsonData.put("error", e.message) resultArray.put(jsonData) resultData.put("result", "FAIL") @@ -199,7 +201,7 @@ suspend fun restoreAccountAsync( } suspend fun getAccountInfoAsync(account: String): JSONObject = withContext(Dispatchers.IO) { - val resultArray = JSONArray() + var resultArray = JSONArray() var jsonData = JSONObject() val resultData = JSONObject().apply { put("result", "FAIL") @@ -234,6 +236,7 @@ suspend fun getAccountInfoAsync(account: String): JSONObject = withContext(Dispa put("value", resultArray) } } catch(e: Exception){ + resultArray = JSONArray() jsonData.put("error", e.message) resultArray.put(jsonData) resultData.put("result", "FAIL") @@ -252,7 +255,7 @@ suspend fun getBalanceAsync( networkSettings(network) val jsonData = JSONObject() // return array & object - val resultArray = JSONArray() + var resultArray = JSONArray() val resultData = JSONObject().apply { put("result", "FAIL") put("value", resultArray) @@ -293,6 +296,7 @@ suspend fun getBalanceAsync( resultData.put("value", resultArray) } } catch (e: Exception) { + resultArray = JSONArray() jsonData.put("error", e.message) resultArray.put(jsonData) resultData.put("result", "FAIL") @@ -307,7 +311,7 @@ suspend fun getTokenInfoAsync( networkSettings(network) val jsonData = JSONObject() // return array & object - val resultArray = JSONArray() + var resultArray = JSONArray() val resultData = JSONObject().apply { put("result", "FAIL") put("value", resultArray) @@ -387,6 +391,7 @@ suspend fun getTokenInfoAsync( resultData.put("result", "OK") resultData.put("value", resultArray) } catch (e: Exception) { + resultArray = JSONArray() jsonData.put("error", e.message) resultArray.put(jsonData) resultData.put("result", "FAIL") @@ -402,7 +407,7 @@ suspend fun getTokenHistoryAsync( limit: Int? = 1000, page_number: Int? = 1 ) : JSONObject = withContext(Dispatchers.IO) { - val resultArray = JSONArray() + var resultArray = JSONArray() var jsonData = JSONObject() val resultData = JSONObject().apply { put("result", "FAIL") @@ -474,6 +479,7 @@ suspend fun getTokenHistoryAsync( dbConnector.disconnect() resultData } catch (e: Exception) { + resultArray = JSONArray() jsonData.put("error", e.message) resultArray.put(jsonData) resultData.put("result", "FAIL") @@ -486,7 +492,7 @@ suspend fun getTokenHistoryAsync( suspend fun getUsersAsync( owner: String ) : JSONObject = withContext(Dispatchers.IO) { - val resultArray = JSONArray() + var resultArray = JSONArray() var jsonData = JSONObject() val resultData = JSONObject().apply { put("result", "FAIL") @@ -528,6 +534,7 @@ suspend fun getUsersAsync( dbConnector.disconnect() resultData } catch (e: Exception) { + resultArray = JSONArray() jsonData.put("error", e.message) resultArray.put(jsonData) resultData.put("result", "FAIL") @@ -541,7 +548,7 @@ suspend fun getTokenListAsync( sort: String? = "DESC", limit: Int? = 1000, page_number: Int? = 1): JSONObject = withContext(Dispatchers.IO) { - val resultArray = JSONArray() + var resultArray = JSONArray() var jsonData = JSONObject() val resultData = JSONObject().apply { put("result", "FAIL") @@ -613,6 +620,7 @@ suspend fun getTokenListAsync( dbConnector.disconnect() resultData } catch (e: Exception) { + resultArray = JSONArray() jsonData.put("error", e.message) resultArray.put(jsonData) resultData.put("result", "FAIL") diff --git a/app/src/main/java/io/kthulu/sdk/transaction.kt b/app/src/main/java/io/kthulu/sdk/transaction.kt index f8dafb3..1627da5 100644 --- a/app/src/main/java/io/kthulu/sdk/transaction.kt +++ b/app/src/main/java/io/kthulu/sdk/transaction.kt @@ -45,7 +45,7 @@ suspend fun sendTransactionAsync( val jsonData = JSONObject() // return array & object - val resultArray = JSONArray() + var resultArray = JSONArray() var resultData = JSONObject() resultData.put("result", "FAIL") resultData.put("value", resultArray) @@ -185,12 +185,14 @@ suspend fun sendTransactionAsync( resultData.put("result", "OK") resultData.put("value", resultArray) } else { + resultArray = JSONArray() jsonData.put("error", "insufficient funds") resultArray.put(jsonData) resultData.put("result", "FAIL") resultData.put("value", resultArray) } } catch (e: Exception) { + resultArray = JSONArray() jsonData.put("error", e.message) resultArray.put(jsonData) resultData.put("result", "FAIL") @@ -210,7 +212,7 @@ suspend fun sendTokenTransactionAsync( val jsonData = JSONObject() // return array & object - val resultArray = JSONArray() + var resultArray = JSONArray() var resultData = JSONObject() resultData.put("result", "FAIL") resultData.put("value", resultArray) @@ -370,12 +372,14 @@ suspend fun sendTokenTransactionAsync( resultData.put("result", "OK") resultData.put("value", resultArray) } else { + resultArray = JSONArray() jsonData.put("error", "insufficient funds") resultArray.put(jsonData) resultData.put("result", "FAIL") resultData.put("value", resultArray) } } catch (e: Exception) { + resultArray = JSONArray() jsonData.put("error", e.message) resultArray.put(jsonData) resultData.put("result", "FAIL") @@ -394,7 +398,7 @@ suspend fun deployErc20Async( val jsonData = JSONObject() // return array & object - val resultArray = JSONArray() + var resultArray = JSONArray() var resultData = JSONObject() resultData.put("result", "FAIL") @@ -512,6 +516,7 @@ suspend fun deployErc20Async( .getString("gas") } catch (e: Exception){ + resultArray = JSONArray() jsonData.put("error", e.message) resultArray.put(jsonData) resultData.put("result", "FAIL") @@ -552,12 +557,14 @@ suspend fun deployErc20Async( resultData.put("result", "OK") resultData.put("value", resultArray) } else { + resultArray = JSONArray() jsonData.put("error", "insufficient funds") resultArray.put(jsonData) resultData.put("result", "FAIL") resultData.put("value", resultArray) } } catch (e: Exception) { + resultArray = JSONArray() jsonData.put("error", e.message) resultArray.put(jsonData) resultData.put("result", "FAIL") @@ -576,7 +583,7 @@ suspend fun bridgeCoinAsync( val jsonData = JSONObject() // return array & object - val resultArray = JSONArray() + var resultArray = JSONArray() var resultData = JSONObject() resultData.put("result", "FAIL") @@ -714,12 +721,14 @@ suspend fun bridgeCoinAsync( resultData.put("result", "OK") resultData.put("value", resultArray) } else { + resultArray = JSONArray() jsonData.put("error", "insufficient funds") resultArray.put(jsonData) resultData.put("result", "FAIL") resultData.put("value", resultArray) } } catch (e: Exception) { + resultArray = JSONArray() jsonData.put("error", e.message) resultArray.put(jsonData) resultData.put("result", "FAIL") @@ -738,7 +747,7 @@ suspend fun bridgeTokenAsync( val jsonData = JSONObject() // return array & object - val resultArray = JSONArray() + var resultArray = JSONArray() var resultData = JSONObject() resultData.put("result", "FAIL") @@ -952,12 +961,14 @@ suspend fun bridgeTokenAsync( resultData.put("result", "OK") resultData.put("value", resultArray) } else { + resultArray = JSONArray() jsonData.put("error", "insufficient funds") resultArray.put(jsonData) resultData.put("result", "FAIL") resultData.put("value", resultArray) } } catch (e: Exception) { + resultArray = JSONArray() jsonData.put("error", e.message) resultArray.put(jsonData) resultData.put("result", "FAIL") @@ -976,7 +987,7 @@ suspend fun tokenSwapAppoveAsync( val jsonData = JSONObject() // return array & object - val resultArray = JSONArray() + var resultArray = JSONArray() var resultData = JSONObject() resultData.put("result", "FAIL") resultData.put("value", resultArray) @@ -1094,6 +1105,7 @@ suspend fun tokenSwapAppoveAsync( resultData.put("result", "OK") resultData.put("value", resultArray) } else { + resultArray = JSONArray() jsonData.put("error", "insufficient funds") resultArray.put(jsonData) resultData.put("result", "FAIL") @@ -1101,12 +1113,14 @@ suspend fun tokenSwapAppoveAsync( } } else { + resultArray = JSONArray() jsonData.put("error", "pair not found") resultArray.put(jsonData) resultData.put("result", "FAIL") resultData.put("value", resultArray) } } catch (e: Exception) { + resultArray = JSONArray() jsonData.put("error", e.message) resultArray.put(jsonData) resultData.put("result", "FAIL") @@ -1126,7 +1140,7 @@ suspend fun coinForTokenswapAsync( val jsonData = JSONObject() // return array & object - val resultArray = JSONArray() + var resultArray = JSONArray() var resultData = JSONObject() resultData.put("result", "FAIL") resultData.put("value", resultArray) @@ -1247,6 +1261,7 @@ suspend fun coinForTokenswapAsync( } } else { + resultArray = JSONArray() jsonData.put("error", "pair not found") resultArray.put(jsonData) resultData.put("result", "FAIL") @@ -1254,6 +1269,7 @@ suspend fun coinForTokenswapAsync( return@withContext resultData } } catch (e: Exception) { + resultArray = JSONArray() jsonData.put("error", e.message) resultArray.put(jsonData) resultData.put("result", "FAIL") @@ -1274,7 +1290,7 @@ suspend fun tokenForTokenswapAsync( val jsonData = JSONObject() // return array & object - val resultArray = JSONArray() + var resultArray = JSONArray() var resultData = JSONObject() resultData.put("result", "FAIL") resultData.put("value", resultArray) @@ -1404,6 +1420,7 @@ suspend fun tokenForTokenswapAsync( resultData.put("result", "OK") resultData.put("value", resultArray) } else { + resultArray = JSONArray() jsonData.put("error", "insufficient funds") resultArray.put(jsonData) resultData.put("result", "FAIL") @@ -1411,12 +1428,14 @@ suspend fun tokenForTokenswapAsync( } } else { + resultArray = JSONArray() jsonData.put("error", "pair not found") resultArray.put(jsonData) resultData.put("result", "FAIL") resultData.put("value", resultArray) } } catch (e: Exception) { + resultArray = JSONArray() jsonData.put("error", e.message) resultArray.put(jsonData) resultData.put("result", "FAIL") @@ -1436,7 +1455,7 @@ suspend fun tokenForCoinswapAsync( val jsonData = JSONObject() // return array & object - val resultArray = JSONArray() + var resultArray = JSONArray() var resultData = JSONObject() resultData.put("result", "FAIL") resultData.put("value", resultArray) @@ -1574,6 +1593,7 @@ suspend fun tokenForCoinswapAsync( resultData.put("result", "OK") resultData.put("value", resultArray) } else { + resultArray = JSONArray() jsonData.put("error", "insufficient funds") resultArray.put(jsonData) resultData.put("result", "FAIL") @@ -1581,12 +1601,14 @@ suspend fun tokenForCoinswapAsync( } } else { + resultArray = JSONArray() jsonData.put("error", "pair not found") resultArray.put(jsonData) resultData.put("result", "FAIL") resultData.put("value", resultArray) } } catch (e: Exception) { + resultArray = JSONArray() jsonData.put("error", e.message) resultArray.put(jsonData) resultData.put("result", "FAIL")