Skip to content

Commit

Permalink
Merge pull request #764 from juanky201271/dev_improving_performance
Browse files Browse the repository at this point in the history
Improving performance
  • Loading branch information
juanky201271 authored Jan 16, 2025
2 parents 886ab5d + 3aa8a62 commit 0e1c1cf
Show file tree
Hide file tree
Showing 4 changed files with 526 additions and 363 deletions.
187 changes: 134 additions & 53 deletions android/app/src/main/java/org/ZingoLabs/Zingo/RPCModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.bridge.Promise

//import android.util.Log
import java.io.File
import java.io.FileNotFoundException
import java.io.IOException
import kotlin.concurrent.thread
import org.ZingoLabs.Zingo.Constants.*

import kotlinx.coroutines.*

class RPCModule internal constructor(private val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
override fun getName(): String {
Expand Down Expand Up @@ -425,105 +424,187 @@ class RPCModule internal constructor(private val reactContext: ReactApplicationC

@ReactMethod
fun execute(cmd: String, args: String, promise: Promise) {
thread {
uniffi.zingo.initLogging()
CoroutineScope(Dispatchers.IO).launch {
try {
uniffi.zingo.initLogging()

// Log.i("execute", "Executing $cmd with $args")
val resp = uniffi.zingo.executeCommand(cmd, args)
// Log.i("execute", "Response to $cmd : $resp")
val resp = uniffi.zingo.executeCommand(cmd, args)

// And save it if it was a sync
if (cmd == "sync" && !resp.lowercase().startsWith(ErrorPrefix.value)) {
saveWalletFile()
}
if (cmd == "sync" && !resp.lowercase().startsWith(ErrorPrefix.value)) {
saveWalletFile()
}

promise.resolve(resp)
withContext(Dispatchers.Main) {
promise.resolve(resp)
}
} catch (e: Exception) {
val errorMessage = "Error: executing command '$cmd': ${e.localizedMessage}"
Log.e("MAIN", errorMessage, e)

withContext(Dispatchers.Main) {
promise.resolve(errorMessage)
}
}
}
}

@ReactMethod
fun doSave(promise: Promise) {
thread {
promise.resolve(saveWalletFile())
CoroutineScope(Dispatchers.IO).launch {
try {
val result = saveWalletFile()

withContext(Dispatchers.Main) {
promise.resolve(result)
}
} catch (e: Exception) {
val errorMessage = "Error: saving wallet: ${e.localizedMessage}"
Log.e("MAIN", errorMessage, e)

withContext(Dispatchers.Main) {
promise.resolve(errorMessage)
}
}
}
}

@ReactMethod
fun doSaveBackup(promise: Promise) {
thread {
promise.resolve(saveWalletBackupFile())
CoroutineScope(Dispatchers.IO).launch {
try {
val result = saveWalletBackupFile()

withContext(Dispatchers.Main) {
promise.resolve(result)
}
} catch (e: Exception) {
val errorMessage = "Error: saving wallet backup: ${e.localizedMessage}"
Log.e("MAIN", errorMessage, e)

withContext(Dispatchers.Main) {
promise.resolve(errorMessage)
}
}
}
}

@ReactMethod
fun getLatestBlock(server: String, promise: Promise) {
thread {
uniffi.zingo.initLogging()

// Initialize Light Client
val resp = uniffi.zingo.getLatestBlockServer(server)
promise.resolve(resp)
}
CoroutineScope(Dispatchers.IO).launch {
try {
uniffi.zingo.initLogging()
val resp = uniffi.zingo.getLatestBlockServer(server)

withContext(Dispatchers.Main) {
promise.resolve(resp)
}
} catch (e: Exception) {
val errorMessage = "Error: getting latest block: ${e.localizedMessage}"
Log.e("MAIN", errorMessage, e)
withContext(Dispatchers.Main) {
promise.resolve(errorMessage)
}
}
}
}

@ReactMethod
fun getDonationAddress(promise: Promise) {
thread {
uniffi.zingo.initLogging()

// Initialize Light Client
val resp = uniffi.zingo.getDeveloperDonationAddress()
CoroutineScope(Dispatchers.IO).launch {
try {
uniffi.zingo.initLogging()
val resp = uniffi.zingo.getDeveloperDonationAddress()

promise.resolve(resp)
withContext(Dispatchers.Main) {
promise.resolve(resp)
}
} catch (e: Exception) {
val errorMessage = "Error: getting donation address: ${e.localizedMessage}"
Log.e("MAIN", errorMessage, e)
withContext(Dispatchers.Main) {
promise.resolve(errorMessage)
}
}
}
}

@ReactMethod
fun getZenniesDonationAddress(promise: Promise) {
thread {
uniffi.zingo.initLogging()

// Initialize Light Client
val resp = uniffi.zingo.getZenniesForZingoDonationAddress()
CoroutineScope(Dispatchers.IO).launch {
try {
uniffi.zingo.initLogging()
val resp = uniffi.zingo.getZenniesForZingoDonationAddress()

promise.resolve(resp)
withContext(Dispatchers.Main) {
promise.resolve(resp)
}
} catch (e: Exception) {
val errorMessage = "Error: getting Zennies donation address: ${e.localizedMessage}"
Log.e("MAIN", errorMessage, e)
withContext(Dispatchers.Main) {
promise.resolve(errorMessage)
}
}
}
}

@ReactMethod
fun getValueTransfersList(promise: Promise) {
thread {
uniffi.zingo.initLogging()
CoroutineScope(Dispatchers.IO).launch {
try {
uniffi.zingo.initLogging()
val resp = uniffi.zingo.getValueTransfers()

// Initialize Light Client
val resp = uniffi.zingo.getValueTransfers()

promise.resolve(resp)
withContext(Dispatchers.Main) {
promise.resolve(resp)
}
} catch (e: Exception) {
val errorMessage = "Error: getting value transfers list: ${e.localizedMessage}"
Log.e("MAIN", errorMessage, e)
withContext(Dispatchers.Main) {
promise.resolve(errorMessage)
}
}
}
}

@ReactMethod
fun getTransactionSummariesList(promise: Promise) {
thread {
uniffi.zingo.initLogging()

// Initialize Light Client
val resp = uniffi.zingo.getTransactionSummaries()
CoroutineScope(Dispatchers.IO).launch {
try {
uniffi.zingo.initLogging()
val resp = uniffi.zingo.getTransactionSummaries()

promise.resolve(resp)
withContext(Dispatchers.Main) {
promise.resolve(resp)
}
} catch (e: Exception) {
val errorMessage = "Error: getting transaction summaries list: ${e.localizedMessage}"
Log.e("MAIN", errorMessage, e)
withContext(Dispatchers.Main) {
promise.resolve(errorMessage)
}
}
}
}

@ReactMethod
fun setCryptoDefaultProvider(promise: Promise) {
thread {
uniffi.zingo.initLogging()

// Initialize Light Client
val resp = uniffi.zingo.setCryptoDefaultProviderToRing()
CoroutineScope(Dispatchers.IO).launch {
try {
uniffi.zingo.initLogging()
val resp = uniffi.zingo.setCryptoDefaultProviderToRing()

promise.resolve(resp)
withContext(Dispatchers.Main) {
promise.resolve(resp)
}
} catch (e: Exception) {
val errorMessage = "Error: setting crypto default provider: ${e.localizedMessage}"
Log.e("MAIN", errorMessage, e)
withContext(Dispatchers.Main) {
promise.resolve(errorMessage)
}
}
}
}

Expand Down
Loading

0 comments on commit 0e1c1cf

Please sign in to comment.