Skip to content

Commit

Permalink
Update 1inch API, clear service subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
omurovch committed Oct 20, 2023
1 parent f35dedf commit e3156eb
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 14 deletions.
4 changes: 3 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ android {
resValue "string", "solscanApiKey", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjcmVhdGVkQXQiOjE2Nzk0NjQyMTQ4NDAsImVtYWlsIjoiaHJ6c3lzdGVtczEwMUBnbWFpbC5jb20iLCJhY3Rpb24iOiJ0b2tlbi1hcGkiLCJpYXQiOjE2Nzk0NjQyMTR9.BRM7J9RbDpHgd2oMAus00XfWOxTJgV2Tn2_chXZOdtk"
resValue "string", "trongridApiKey", "33374494-8060-447e-8367-90c5efd4ed95"
resValue "string", "udnApiKey", "r2phzgatt_zt9-hd_wyvdjrdsrimnxgokm7knyag1malzgcz"
resValue "string", "oneInchApiKey", "ElyK7s22HR0JD78CEXVPnpZA8UyuUwIl"
}

appcenterdebug {
Expand Down Expand Up @@ -133,6 +134,7 @@ android {
resValue "string", "solscanApiKey", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjcmVhdGVkQXQiOjE2Nzk0NjQxMTQ0ODUsImVtYWlsIjoiaHNkYW84ODg4QGdtYWlsLmNvbSIsImFjdGlvbiI6InRva2VuLWFwaSIsImlhdCI6MTY3OTQ2NDExNH0.91DUjjjYu86f1ZMMJ5cyJxIKTTw_srhI-vNgYaTCPUU"
resValue "string", "trongridApiKey", "8f5ae2c8-8012-42a8-b0ca-ffc2741f6a29"
resValue "string", "udnApiKey", "r2phzgatt_zt9-hd_wyvdjrdsrimnxgokm7knyag1malzgcz"
resValue "string", "oneInchApiKey", "ElyK7s22HR0JD78CEXVPnpZA8UyuUwIl"
}

appcenterrelease {
Expand Down Expand Up @@ -269,7 +271,7 @@ dependencies {

// Wallet kits
implementation 'com.github.horizontalsystems:bitcoin-kit-android:8e990e3'
implementation 'com.github.horizontalsystems:ethereum-kit-android:ddf4404'
implementation 'com.github.horizontalsystems:ethereum-kit-android:fe96dfa'
implementation 'com.github.horizontalsystems:blockchain-fee-rate-kit-android:1d3bd49'
implementation 'com.github.horizontalsystems:binance-chain-kit-android:7e4d7c0'
implementation 'com.github.horizontalsystems:market-kit-android:0059cac'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ class AppConfigProvider(localStorage: ILocalStorage) {
Translator.getString(R.string.udnApiKey)
}

val oneInchApiKey by lazy {
Translator.getString(R.string.oneInchApiKey)
}

val fiatDecimal: Int = 2
val feeRateAdjustForCurrencies: List<String> = listOf("USD", "EUR")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ interface IEvmFeeService {
val transactionStatus: DataState<Transaction>
val transactionStatusObservable: Observable<DataState<Transaction>>

fun clear()
fun reset()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class EvmFeeService(
gasPriceService.setRecommended()
}

fun onCleared() {
override fun clear() {
disposable.clear()
gasPriceInfoDisposable?.dispose()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class SendEvmSettingsService(
nonceService.start()
}

fun clear() {
feeService.clear()
}

private fun sync() {
val feeState = feeService.transactionStatus
val nonceState = nonceService.state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ interface ISendEvmTransactionService {
suspend fun start()
fun send(logger: AppLogger)
fun methodName(input: ByteArray): String?
fun clear()
}

class SendEvmTransactionService(
Expand Down Expand Up @@ -138,6 +139,7 @@ class SendEvmTransactionService(

override fun clear() {
disposable.clear()
settingsService.clear()
}

private fun syncTxDataState(transaction: SendEvmSettingsService.Transaction? = null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class SendEvmTransactionViewModel(

override fun onCleared() {
disposable.clear()
service.clear()
}

@Synchronized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class SwapMainViewModel(
private var tokenToState = toTokenService.state

private val evmKit: EthereumKit by lazy { App.evmBlockchainManager.getEvmKitManager(dex.blockchainType).evmKitWrapper?.evmKit!! }
private val oneIncKitHelper by lazy { OneInchKitHelper(evmKit) }
private val oneIncKitHelper by lazy { OneInchKitHelper(evmKit, App.appConfigProvider.oneInchApiKey) }
private val uniswapKit by lazy { UniswapKit.getInstance(evmKit) }
private val uniswapV3Kit by lazy { UniswapV3Kit.getInstance(evmKit, DexType.Uniswap) }
private val pancakeSwapV3Kit by lazy { UniswapV3Kit.getInstance(evmKit, DexType.PancakeSwap) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import io.horizontalsystems.bankwallet.modules.send.evm.settings.SendEvmNonceSer
import io.horizontalsystems.bankwallet.modules.send.evm.settings.SendEvmNonceViewModel
import io.horizontalsystems.bankwallet.modules.send.evm.settings.SendEvmSettingsService
import io.horizontalsystems.bankwallet.modules.sendevmtransaction.SendEvmTransactionViewModel
import io.horizontalsystems.bankwallet.modules.swap.SwapViewItemHelper
import io.horizontalsystems.bankwallet.modules.swap.SwapMainModule.OneInchSwapParameters
import io.horizontalsystems.bankwallet.modules.swap.SwapViewItemHelper
import io.horizontalsystems.bankwallet.modules.swap.oneinch.OneInchKitHelper
import io.horizontalsystems.ethereumkit.core.LegacyGasPriceProvider
import io.horizontalsystems.ethereumkit.core.eip1559.Eip1559GasPriceProvider
Expand All @@ -25,7 +25,7 @@ object OneInchConfirmationModule {
class Factory(val blockchainType: BlockchainType, private val oneInchSwapParameters: OneInchSwapParameters) : ViewModelProvider.Factory {

private val evmKitWrapper by lazy { App.evmBlockchainManager.getEvmKitManager(blockchainType).evmKitWrapper!! }
private val oneInchKitHelper by lazy { OneInchKitHelper(evmKitWrapper.evmKit) }
private val oneInchKitHelper by lazy { OneInchKitHelper(evmKitWrapper.evmKit, App.appConfigProvider.oneInchApiKey) }
private val token by lazy { App.evmBlockchainManager.getBaseToken(blockchainType)!! }
private val gasPriceService: IEvmGasPriceService by lazy {
val evmKit = evmKitWrapper.evmKit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,27 @@ class OneInchFeeService(
override val transactionStatusObservable: Observable<DataState<Transaction>> = transactionStatusSubject

init {
sync(gasPriceService.state)
gasPriceService.stateObservable
.subscribeIO {
sync(it)
}
.let { disposable.add(it) }
val gasPriceServiceState = gasPriceService.state
sync(gasPriceServiceState)
if (gasPriceServiceState.dataOrNull == null) {
gasPriceService.stateObservable
.subscribeIO {
sync(it)
}
.let { disposable.add(it) }
}
}

override fun reset() {
gasPriceService.setRecommended()
}

override fun clear() {
disposable.clear()
gasPriceInfoDisposable?.dispose()
retryDisposable?.dispose()
}

private fun sync(gasPriceServiceState: DataState<GasPriceInfo>) {
when (gasPriceServiceState) {
is DataState.Error -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import io.horizontalsystems.bankwallet.modules.send.evm.SendEvmData
import io.horizontalsystems.bankwallet.modules.send.evm.settings.SendEvmSettingsService
import io.horizontalsystems.bankwallet.modules.sendevmtransaction.ISendEvmTransactionService
import io.horizontalsystems.bankwallet.modules.sendevmtransaction.SendEvmTransactionService
import io.horizontalsystems.bankwallet.modules.swap.SwapViewItemHelper
import io.horizontalsystems.bankwallet.modules.swap.SwapMainModule.OneInchSwapParameters
import io.horizontalsystems.bankwallet.modules.swap.SwapViewItemHelper
import io.horizontalsystems.ethereumkit.models.Address
import io.reactivex.BackpressureStrategy
import io.reactivex.Flowable
Expand Down Expand Up @@ -153,5 +153,6 @@ class OneInchSendEvmTransactionService(

override fun clear() {
disposable.clear()
settingsService.clear()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import io.reactivex.Single
import java.math.BigDecimal

class OneInchKitHelper(
evmKit: EthereumKit
evmKit: EthereumKit,
apiKey: String
) {
private val oneInchKit = OneInchKit.getInstance(evmKit)
private val oneInchKit = OneInchKit.getInstance(evmKit, apiKey)

// TODO take evmCoinAddress from oneInchKit
private val evmCoinAddress = Address("0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee")
Expand Down

0 comments on commit e3156eb

Please sign in to comment.