Skip to content

Commit

Permalink
only fetch active swap pools
Browse files Browse the repository at this point in the history
completely removed UpdateTokenContractRatesWorker
  • Loading branch information
Joey Harward committed May 17, 2021
1 parent bc1699e commit 51abe7e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 124 deletions.
23 changes: 12 additions & 11 deletions protonsdk/src/main/java/com/metallicus/protonsdk/Proton.kt
Original file line number Diff line number Diff line change
Expand Up @@ -965,18 +965,19 @@ class Proton private constructor(context: Context) {
val swapPoolJsonObject = it.asJsonObject

val swapPool = gson.fromJson(swapPoolJsonObject, SwapPool::class.java)

val pool1 = "${swapPool.getPool1Contract()}:${swapPool.getPool1Symbol()}"
val pool2 = "${swapPool.getPool2Contract()}:${swapPool.getPool2Symbol()}"

tokenCurrencyBalancesMap[pool1]?.let { tokenCurrencyBalance ->
swapPoolTokens.add(tokenCurrencyBalance)
if (swapPool.active == 1) {
val pool1 = "${swapPool.getPool1Contract()}:${swapPool.getPool1Symbol()}"
val pool2 = "${swapPool.getPool2Contract()}:${swapPool.getPool2Symbol()}"

tokenCurrencyBalancesMap[pool1]?.let { tokenCurrencyBalance ->
swapPoolTokens.add(tokenCurrencyBalance)
}
tokenCurrencyBalancesMap[pool2]?.let { tokenCurrencyBalance ->
swapPoolTokens.add(tokenCurrencyBalance)
}

swapPools.add(swapPool)
}
tokenCurrencyBalancesMap[pool2]?.let { tokenCurrencyBalance ->
swapPoolTokens.add(tokenCurrencyBalance)
}

swapPools.add(swapPool)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,6 @@ class WorkersModule {
.then(initTokenContracts)
.enqueue()
}

// start periodic worker to update exchange rates
/*val updateTokenContractRates = PeriodicWorkRequest.Builder(UpdateTokenContractRatesWorker::class.java, 15L, TimeUnit.MINUTES)
.setConstraints(constraints)
.setInitialDelay(1L, TimeUnit.MINUTES)
.build()
workManager.enqueueUniquePeriodicWork(UPDATE_RATES, ExistingPeriodicWorkPolicy.REPLACE, updateTokenContractRates)*/
}

fun onInitChainProvider(callback: (Boolean, Data?) -> Unit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ abstract class WorkerModule {
@WorkerKey(InitActiveAccountWorker::class)
abstract fun bindInitActiveAccountWorker(factory: InitActiveAccountWorker.Factory): ChildWorkerFactory

@Binds
@IntoMap
@WorkerKey(UpdateTokenContractRatesWorker::class)
abstract fun bindUpdateTokenContractRatesWorker(factory: UpdateTokenContractRatesWorker.Factory): ChildWorkerFactory

@Binds
abstract fun bindWorkerFactory(factory: ProtonWorkerFactory): WorkerFactory
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,14 @@ class ProtonWorkerFactory @Inject constructor(
workerParameters: WorkerParameters
): ListenableWorker? {
return try {
val factoryEntry =
workerFactory.entries.find { Class.forName(workerClassName).isAssignableFrom(it.key) }
val factoryEntry = workerFactory.entries.find { Class.forName(workerClassName).isAssignableFrom(it.key) }

if (factoryEntry != null) {
val factoryProvider = factoryEntry.value
factoryProvider.get().create(context, workerParameters)
} else { // fallback if no factory was found
val workerClass = Class.forName(workerClassName).asSubclass(ListenableWorker::class.java)
val constructor =
workerClass.getDeclaredConstructor(Context::class.java, WorkerParameters::class.java)
val constructor = workerClass.getDeclaredConstructor(Context::class.java, WorkerParameters::class.java)
constructor.newInstance(context, workerParameters)
}
} catch (e: ClassNotFoundException) {
Expand Down

This file was deleted.

0 comments on commit 51abe7e

Please sign in to comment.