diff --git a/app/build.gradle b/app/build.gradle index a0755a7997..e6622b72da 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -128,9 +128,6 @@ dependencies { } implementation "com.github.gnosis.svalinn-kotlin:utils-ethereum:$versions.svalinn" implementation "com.github.gnosis.svalinn-kotlin:mnemonic-android:$versions.svalinn" - implementation ("com.github.gnosis.svalinn-kotlin:ticker:$versions.svalinn") { - exclude group: "com.squareup.retrofit2", module: "converter-moshi" - } implementation "com.github.gnosis.svalinn-kotlin:security:$versions.svalinn" implementation "com.github.gnosis.svalinn-kotlin:utils:$versions.svalinn" diff --git a/app/src/main/java/pm/gnosis/heimdall/data/remote/RelayServiceApi.kt b/app/src/main/java/pm/gnosis/heimdall/data/remote/RelayServiceApi.kt index e31e9319d2..2b2a33f9f8 100644 --- a/app/src/main/java/pm/gnosis/heimdall/data/remote/RelayServiceApi.kt +++ b/app/src/main/java/pm/gnosis/heimdall/data/remote/RelayServiceApi.kt @@ -11,11 +11,11 @@ interface RelayServiceApi { const val BASE_URL = "https://safe-relay.dev.gnosisdev.com/api/" } - @POST("v1/transactions/") - fun execute(@Body params: ExecuteParams): Single + @POST("v1/safes/{address}/transactions/") + fun execute(@Path("address") address: String, @Body params: ExecuteParams): Single - @POST("v1/transactions/estimate/") - fun estimate(@Body params: EstimateParams): Single + @POST("v1/safes/{address}/transactions/estimate/") + fun estimate(@Path("address") address: String, @Body params: EstimateParams): Single @POST("v1/safes/") fun safeCreation(@Body params: RelaySafeCreationParams): Single diff --git a/app/src/main/java/pm/gnosis/heimdall/data/remote/impls/LocalRelayServiceApi.kt b/app/src/main/java/pm/gnosis/heimdall/data/remote/impls/LocalRelayServiceApi.kt deleted file mode 100644 index bb3b93ecc8..0000000000 --- a/app/src/main/java/pm/gnosis/heimdall/data/remote/impls/LocalRelayServiceApi.kt +++ /dev/null @@ -1,128 +0,0 @@ -package pm.gnosis.heimdall.data.remote.impls - -import io.reactivex.Completable -import io.reactivex.Observable -import io.reactivex.Single -import pm.gnosis.ethereum.* -import pm.gnosis.heimdall.GnosisSafePersonalEdition -import pm.gnosis.heimdall.data.remote.RelayServiceApi -import pm.gnosis.heimdall.data.remote.models.* -import pm.gnosis.model.Solidity -import pm.gnosis.model.SolidityBase -import pm.gnosis.models.Transaction -import pm.gnosis.svalinn.accounts.base.repositories.AccountsRepository -import pm.gnosis.utils.* -import java.math.BigInteger - -class LocalRelayServiceApi( - private val accountsRepository: AccountsRepository, - private val ethereumRepository: EthereumRepository, - private val remoteService: RelayServiceApi -) : RelayServiceApi { - override fun execute(params: ExecuteParams): Single = - Single.fromCallable { - val signatureBytes = StringBuilder().apply { - params.signatures.forEach { - append(it.r.toString(16).padStart(64, '0').substring(0, 64)) - append(it.s.toString(16).padStart(64, '0').substring(0, 64)) - append(it.v.toString(16).padStart(2, '0')) - } - }.toString().hexStringToByteArray() - - val to = params.to.asEthereumAddress()!! - val value = Solidity.UInt256(params.value.decimalAsBigInteger()) - val data = Solidity.Bytes(params.data.hexStringToByteArrayOrNull() ?: ByteArray(0)) - val operation = Solidity.UInt8(params.operation.toBigInteger()) - val txGas = params.safeTxGas.decimalAsBigInteger() - val dataGas = params.dataGas.decimalAsBigInteger() - val gasPrice = params.gasPrice.decimalAsBigInteger() - val executionData = GnosisSafePersonalEdition.ExecTransactionAndPaySubmitter.encode( - to, value, data, operation, - Solidity.UInt256(txGas), Solidity.UInt256(dataGas), - Solidity.UInt256(gasPrice), Solidity.Address(BigInteger.ZERO), - Solidity.Bytes(signatureBytes) - ) - Transaction(params.safe.asEthereumAddress()!!, data = executionData) - } - .flatMap(::loadExecutionParams) - .flatMap(accountsRepository::signTransaction) - .flatMapObservable(ethereumRepository::sendRawTransaction) - .firstOrError() - .map(::RelayExecution) - - private fun loadExecutionParams(transaction: Transaction) = - accountsRepository.loadActiveAccount() - .flatMap { - ethereumRepository.request( - ExecutionInfoRequest( - EthGetTransactionCount(it.address, id = 0), - EthEstimateGas(it.address, transaction, id = 1) - ) - ) - .firstOrError() - .map { - val gasPrice = BigInteger("10000000000") - val gasLimit = it.estimate.result()!! * BigInteger.valueOf(2) - transaction.copy(nonce = it.nonce.result()!!, gas = gasLimit, gasPrice = gasPrice) - } - } - - override fun estimate(params: EstimateParams): Single { - return Observable.fromCallable { - val to = params.to.asEthereumAddress()!! - val value = Solidity.UInt256(params.value.decimalAsBigInteger()) - val data = Solidity.Bytes(params.data.hexStringToByteArrayOrNull() ?: ByteArray(0)) - val operation = Solidity.UInt8(params.operation.toBigInteger()) - val estimateData = GnosisSafePersonalEdition.RequiredTxGas.encode(to, value, data, operation) - Transaction(params.safe.asEthereumAddress()!!, data = estimateData) - }.flatMap { - ethereumRepository.request( - EthCall(transaction = it, id = 2, from = params.safe.asEthereumAddress()!!) - ) - } - .firstOrError() - .map { - val gasPrice = BigInteger("20000000000") - val txGas = it.result()!!.substring(138).hexAsBigInteger() + BigInteger.valueOf(10000) - val dataGas = calculateDataGas(params, txGas, gasPrice) + BigInteger.valueOf(32000) - RelayEstimate(txGas.asDecimalString(), dataGas.asDecimalString(), gasPrice.asDecimalString()) - } - } - - override fun safeCreation(params: RelaySafeCreationParams): Single = - remoteService.safeCreation(params) - - override fun notifySafeFunded(address: String): Completable = - remoteService.notifySafeFunded(address) - - override fun safeFundStatus(address: String): Single = - remoteService.safeFundStatus(address) - - private fun calculateDataGas(params: EstimateParams, txGas: BigInteger, gasPrice: BigInteger): BigInteger { - val signatureCosts = params.threshold * (68 + 2176 + 2176) - val to = params.to.asEthereumAddress()!! - val value = Solidity.UInt256(params.value.decimalAsBigInteger()) - val data = Solidity.Bytes(params.data.hexStringToByteArrayOrNull() ?: ByteArray(0)) - val operation = Solidity.UInt8(params.operation.toBigInteger()) - val payload = GnosisSafePersonalEdition.ExecTransactionAndPaySubmitter.encode( - to, value, data, operation, - Solidity.UInt256(txGas), Solidity.UInt256(BigInteger.ZERO), - Solidity.UInt256(gasPrice), Solidity.Address(BigInteger.ZERO), - Solidity.Bytes(byteArrayOf()) - ) - val dataGasEstimate = payload.chunked(2).fold(0L) { acc, part -> acc + dataGasValue(part) } + signatureCosts - return (dataGasEstimate + (if (dataGasEstimate > 65536) 128 else 64)).toBigInteger() - } - - private fun dataGasValue(hexValue: String) = - when (hexValue) { - "0x" -> 0L - "00" -> 4L - else -> 68L - } - - private class ExecutionInfoRequest( - val nonce: EthGetTransactionCount, - val estimate: EthEstimateGas - ) : BulkRequest(nonce, estimate) -} diff --git a/app/src/main/java/pm/gnosis/heimdall/data/remote/models/RelayServiceData.kt b/app/src/main/java/pm/gnosis/heimdall/data/remote/models/RelayServiceData.kt index 2d89c01bcf..f2963142bc 100644 --- a/app/src/main/java/pm/gnosis/heimdall/data/remote/models/RelayServiceData.kt +++ b/app/src/main/java/pm/gnosis/heimdall/data/remote/models/RelayServiceData.kt @@ -10,14 +10,12 @@ import java.math.BigInteger @JsonClass(generateAdapter = true) data class ExecuteParams( - @Json(name = "safe") - val safe: String, @Json(name = "to") val to: String, @Json(name = "value") val value: String, @Json(name = "data") - val data: String, + val data: String?, @Json(name = "operation") val operation: Int, @Json(name = "signatures") @@ -27,7 +25,9 @@ data class ExecuteParams( @Json(name = "dataGas") val dataGas: String, @Json(name = "gasPrice") - val gasPrice: String + val gasPrice: String, + @Json(name = "nonce") + val nonce: Long ) @JsonClass(generateAdapter = true) @@ -38,8 +38,6 @@ data class RelayExecution( @JsonClass(generateAdapter = true) data class EstimateParams( - @Json(name = "safe") - val safe: String, @Json(name = "to") val to: String, @Json(name = "value") diff --git a/app/src/main/java/pm/gnosis/heimdall/data/repositories/impls/DefaultTransactionExecutionRepository.kt b/app/src/main/java/pm/gnosis/heimdall/data/repositories/impls/DefaultTransactionExecutionRepository.kt index ce45ba4e19..ce1a673d5d 100644 --- a/app/src/main/java/pm/gnosis/heimdall/data/repositories/impls/DefaultTransactionExecutionRepository.kt +++ b/app/src/main/java/pm/gnosis/heimdall/data/repositories/impls/DefaultTransactionExecutionRepository.kt @@ -70,8 +70,8 @@ class DefaultTransactionExecutionRepository @Inject constructor( val initial = StringBuilder().append(ERC191_BYTE).append(ERC191_VERSION).append(safeAddress.asEthereumAddressString().removeHexPrefix()) return Sha3Utils.keccak( parts.fold( - initial, - { acc, part -> acc.append(part) }).toString().hexToByteArray() + initial + ) { acc, part -> acc.append(part) }.toString().hexToByteArray() ) } @@ -126,9 +126,9 @@ class DefaultTransactionExecutionRepository @Inject constructor( loadSafeState(safeAddress) .flatMap { info -> relayServiceApi.estimate( + safeAddress.asEthereumAddressChecksumString(), EstimateParams( - safeAddress.asEthereumAddressString(), - transaction.wrapped.address.asEthereumAddressString(), + transaction.wrapped.address.asEthereumAddressChecksumString(), transaction.wrapped.value?.value?.asDecimalString() ?: "0", transaction.wrapped.data ?: "0x", transaction.operation.toInt(), @@ -233,8 +233,8 @@ class DefaultTransactionExecutionRepository @Inject constructor( gasPrice: BigInteger ): Single = loadExecutionParams(safeAddress, transaction, signatures, senderIsOwner, txGas, dataGas, gasPrice) - .flatMap(relayServiceApi::execute) - .flatMap { handleSubmittedTransaction(safeAddress, transaction, it.transactionHash, txGas, dataGas, gasPrice) } + .flatMap { relayServiceApi.execute(safeAddress.asEthereumAddressChecksumString(), it) } + .flatMap { handleSubmittedTransaction(safeAddress, transaction, it.transactionHash.addHexPrefix(), txGas, dataGas, gasPrice) } private fun loadExecutionParams( safeAddress: Solidity.Address, @@ -265,15 +265,15 @@ class DefaultTransactionExecutionRepository @Inject constructor( val tx = innerTransaction.wrapped ExecuteParams( - safeAddress.asEthereumAddressChecksumString(), tx.address.asEthereumAddressChecksumString(), tx.value?.value?.asDecimalString() ?: "0", - tx.data ?: "0x", + tx.data, innerTransaction.operation.toInt(), serviceSignatures, txGas.asDecimalString(), dataGas.asDecimalString(), - gasPrice.asDecimalString() + gasPrice.asDecimalString(), + tx.nonce?.toLong() ?: 0 ) } @@ -314,7 +314,7 @@ class DefaultTransactionExecutionRepository @Inject constructor( .switchMap { status -> status.success?.let { Observable.just(it to (status.timestamp ?: 0)) - } ?: ethereumRepository.getTransactionReceipt(status.transactionId) + } ?: ethereumRepository.getTransactionReceipt(status.transactionId.addHexPrefix()) .flatMap { receipt -> ethereumRepository.getBlockByHash(receipt.blockHash) .map { receipt to (it.timestamp.toLong() * 1000) } diff --git a/app/src/main/java/pm/gnosis/heimdall/di/components/ApplicationComponent.kt b/app/src/main/java/pm/gnosis/heimdall/di/components/ApplicationComponent.kt index e7ededa862..f40036d2fc 100644 --- a/app/src/main/java/pm/gnosis/heimdall/di/components/ApplicationComponent.kt +++ b/app/src/main/java/pm/gnosis/heimdall/di/components/ApplicationComponent.kt @@ -24,7 +24,6 @@ import pm.gnosis.heimdall.ui.base.BaseActivity import pm.gnosis.svalinn.accounts.base.repositories.AccountsRepository import pm.gnosis.svalinn.common.utils.QrCodeGenerator import pm.gnosis.svalinn.security.EncryptionManager -import pm.gnosis.ticker.data.repositories.TickerRepository import javax.inject.Singleton @Singleton @@ -48,7 +47,6 @@ interface ApplicationComponent { fun accountsRepository(): AccountsRepository fun addressBookRepository(): AddressBookRepository fun safeRepository(): GnosisSafeRepository - fun tickerRepository(): TickerRepository fun tokenRepository(): TokenRepository fun transactionInfoRepository(): TransactionInfoRepository diff --git a/app/src/main/java/pm/gnosis/heimdall/di/modules/ApplicationModule.kt b/app/src/main/java/pm/gnosis/heimdall/di/modules/ApplicationModule.kt index 3c4ff4d020..1e239e87a1 100644 --- a/app/src/main/java/pm/gnosis/heimdall/di/modules/ApplicationModule.kt +++ b/app/src/main/java/pm/gnosis/heimdall/di/modules/ApplicationModule.kt @@ -25,7 +25,6 @@ import pm.gnosis.heimdall.data.remote.PushServiceApi import pm.gnosis.heimdall.data.remote.RelayServiceApi import pm.gnosis.heimdall.data.remote.TxExecutorApi import pm.gnosis.heimdall.data.remote.VerifiedTokensServiceApi -import pm.gnosis.heimdall.data.remote.impls.LocalRelayServiceApi import pm.gnosis.heimdall.di.ApplicationContext import pm.gnosis.mnemonic.Bip39 import pm.gnosis.mnemonic.Bip39Generator @@ -41,11 +40,6 @@ import pm.gnosis.svalinn.security.EncryptionManager import pm.gnosis.svalinn.security.FingerprintHelper import pm.gnosis.svalinn.security.impls.AesEncryptionManager import pm.gnosis.svalinn.security.impls.AndroidFingerprintHelper -import pm.gnosis.ticker.data.db.TickerDatabase -import pm.gnosis.ticker.data.remote.TickerAdapter -import pm.gnosis.ticker.data.remote.TickerApi -import pm.gnosis.ticker.data.repositories.TickerRepository -import pm.gnosis.ticker.data.repositories.impls.DefaultTickerRepository import retrofit2.Retrofit import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory import retrofit2.converter.moshi.MoshiConverterFactory @@ -93,92 +87,84 @@ class ApplicationModule(private val application: Application) { .add(HexNumberAdapter()) .add(DecimalNumberAdapter()) .add(DefaultNumberAdapter()) - .add(TickerAdapter()) .add(SolidityAddressAdapter()) .build() } @Provides @Singleton - fun providesEthereumJsonRpcApi(moshi: Moshi, @Named(INFURA_REST_CLIENT) client: OkHttpClient): RetrofitEthereumRpcApi { - val retrofit = Retrofit.Builder() + fun providesEthereumJsonRpcApi(moshi: Moshi, @Named(INFURA_REST_CLIENT) client: OkHttpClient): RetrofitEthereumRpcApi = + Retrofit.Builder() .client(client) .baseUrl(BuildConfig.BLOCKCHAIN_NET_URL) .addConverterFactory(MoshiConverterFactory.create(moshi)) .addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io())) .build() - return retrofit.create(RetrofitEthereumRpcApi::class.java) - } + .create(RetrofitEthereumRpcApi::class.java) @Provides @Singleton - fun providesTxExecutorApi(moshi: Moshi, client: OkHttpClient): TxExecutorApi { - val retrofit = Retrofit.Builder() + fun providesTxExecutorApi(moshi: Moshi, client: OkHttpClient): TxExecutorApi = + Retrofit.Builder() // Increase timeout since our server goes to sleeps .client(client.newBuilder().readTimeout(30, TimeUnit.SECONDS).build()) .baseUrl(TxExecutorApi.BASE_URL) .addConverterFactory(MoshiConverterFactory.create(moshi)) .addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io())) .build() - return retrofit.create(TxExecutorApi::class.java) - } + .create(TxExecutorApi::class.java) @Provides @Singleton - fun providesPushServiceApi(moshi: Moshi, client: OkHttpClient): PushServiceApi { - val retrofit = Retrofit.Builder() + fun providesPushServiceApi(moshi: Moshi, client: OkHttpClient): PushServiceApi = + Retrofit.Builder() .client(client) .baseUrl(PushServiceApi.BASE_URL) .addConverterFactory(MoshiConverterFactory.create(moshi)) .addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io())) .build() - return retrofit.create(PushServiceApi::class.java) - } + .create(PushServiceApi::class.java) @Provides @Singleton - fun providesRelayServiceApi( - accountsRepository: AccountsRepository, ethereumRepository: EthereumRepository, moshi: Moshi, client: OkHttpClient - ): RelayServiceApi { - val retrofit = Retrofit.Builder() + fun providesRelayServiceApi(moshi: Moshi, client: OkHttpClient): RelayServiceApi = + Retrofit.Builder() .client(client) .baseUrl(RelayServiceApi.BASE_URL) .addConverterFactory(MoshiConverterFactory.create(moshi)) .addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io())) .build() - return LocalRelayServiceApi(accountsRepository, ethereumRepository, retrofit.create(RelayServiceApi::class.java)) - } + .create(RelayServiceApi::class.java) @Provides @Singleton - fun providesVerifiedTokensServiceApi(moshi: Moshi, client: OkHttpClient): VerifiedTokensServiceApi { - val retrofit = Retrofit.Builder() + fun providesVerifiedTokensServiceApi(moshi: Moshi, client: OkHttpClient): VerifiedTokensServiceApi = + Retrofit.Builder() .client(client) .baseUrl(VerifiedTokensServiceApi.BASE_URL) .addConverterFactory(MoshiConverterFactory.create(moshi)) .addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io())) .build() - return retrofit.create(VerifiedTokensServiceApi::class.java) - } + .create(VerifiedTokensServiceApi::class.java) @Provides @Singleton @Named(INFURA_REST_CLIENT) - fun providesInfuraOkHttpClient(okHttpClient: OkHttpClient, @Named(InterceptorsModule.REST_CLIENT_INTERCEPTORS) interceptors: @JvmSuppressWildcards List): OkHttpClient { - return okHttpClient.newBuilder().apply { + fun providesInfuraOkHttpClient(okHttpClient: OkHttpClient, @Named(InterceptorsModule.REST_CLIENT_INTERCEPTORS) interceptors: @JvmSuppressWildcards List): OkHttpClient = + okHttpClient.newBuilder().apply { interceptors.forEach { addInterceptor(it) } }.build() - } @Provides @Singleton - fun providesOkHttpClient(): OkHttpClient = OkHttpClient.Builder().apply { - connectTimeout(10, TimeUnit.SECONDS) - readTimeout(10, TimeUnit.SECONDS) - writeTimeout(10, TimeUnit.SECONDS) - }.build() + fun providesOkHttpClient(): OkHttpClient = + OkHttpClient.Builder().apply { + connectTimeout(10, TimeUnit.SECONDS) + readTimeout(10, TimeUnit.SECONDS) + writeTimeout(10, TimeUnit.SECONDS) + }.build() @Provides @Singleton @@ -223,28 +209,6 @@ class ApplicationModule(private val application: Application) { @Provides fun providesWordListProvider(@ApplicationContext context: Context): WordListProvider = AndroidWordListProvider(context) - @Provides - @Singleton - fun providesTickerRepository(tickerApi: TickerApi, tickerDb: TickerDatabase): TickerRepository = - DefaultTickerRepository(tickerApi, tickerDb) - - @Provides - @Singleton - fun providesTickerApi(moshi: Moshi, client: OkHttpClient): TickerApi { - val retrofit = Retrofit.Builder() - .client(client) - .baseUrl(TickerApi.BASE_URL) - .addConverterFactory(MoshiConverterFactory.create(moshi)) - .addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io())) - .build() - return retrofit.create(TickerApi::class.java) - } - - @Provides - @Singleton - fun providesTickerDb(@ApplicationContext context: Context) = - Room.databaseBuilder(context, TickerDatabase::class.java, TickerDatabase.DB_NAME).build() - @Provides @Singleton fun providesQrCodeGenerator(): QrCodeGenerator = ZxingQrCodeGenerator() diff --git a/app/src/main/java/pm/gnosis/heimdall/ui/account/AccountActivity.kt b/app/src/main/java/pm/gnosis/heimdall/ui/account/AccountActivity.kt index bb0ecf68e4..647e70ccc3 100644 --- a/app/src/main/java/pm/gnosis/heimdall/ui/account/AccountActivity.kt +++ b/app/src/main/java/pm/gnosis/heimdall/ui/account/AccountActivity.kt @@ -23,13 +23,9 @@ import pm.gnosis.heimdall.utils.format import pm.gnosis.models.Wei import pm.gnosis.svalinn.accounts.base.models.Account import pm.gnosis.svalinn.common.utils.doOnNextForResult -import pm.gnosis.svalinn.common.utils.flatMapResult import pm.gnosis.svalinn.common.utils.subscribeForResult -import pm.gnosis.ticker.data.repositories.models.Currency import pm.gnosis.utils.asEthereumAddressString import pm.gnosis.utils.isValidEthereumAddress -import pm.gnosis.utils.stringWithNoTrailingZeroes -import java.math.BigDecimal import java.util.concurrent.TimeUnit import javax.inject.Inject @@ -87,20 +83,9 @@ class AccountActivity : ViewModelActivity() { .observeOn(AndroidSchedulers.mainThread()) // Update balance view .doOnNextForResult(onNext = ::onAccountBalance) - .flatMapResult(mapper = { viewModel.loadFiatConversion(it) }) - .observeOn(AndroidSchedulers.mainThread()) - // Update Fiat view - .doOnNextForResult(onNext = ::onFiat) .subscribeForResult(onError = ::handleError) } - private fun onFiat(currency: Pair) { - layout_account_fiat.text = getString( - R.string.fiat_approximation_parentheses, - currency.first.stringWithNoTrailingZeroes(), currency.second.getFiatSymbol() - ) - } - private fun accountBalance() = viewModel.getAccountBalance() .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe { onAccountBalanceLoading(true) } diff --git a/app/src/main/java/pm/gnosis/heimdall/ui/account/AccountContract.kt b/app/src/main/java/pm/gnosis/heimdall/ui/account/AccountContract.kt index 5065b8f2d6..dd5320aafd 100644 --- a/app/src/main/java/pm/gnosis/heimdall/ui/account/AccountContract.kt +++ b/app/src/main/java/pm/gnosis/heimdall/ui/account/AccountContract.kt @@ -7,12 +7,9 @@ import io.reactivex.Single import pm.gnosis.models.Wei import pm.gnosis.svalinn.accounts.base.models.Account import pm.gnosis.svalinn.common.utils.Result -import pm.gnosis.ticker.data.repositories.models.Currency -import java.math.BigDecimal abstract class AccountContract : ViewModel() { abstract fun getAccountBalance(): Observable> abstract fun getAccountAddress(): Observable> abstract fun getQrCode(contents: String): Single> - abstract fun loadFiatConversion(amount: Wei): Single>> } diff --git a/app/src/main/java/pm/gnosis/heimdall/ui/account/AccountViewModel.kt b/app/src/main/java/pm/gnosis/heimdall/ui/account/AccountViewModel.kt index a4615ab027..19e1c739d2 100644 --- a/app/src/main/java/pm/gnosis/heimdall/ui/account/AccountViewModel.kt +++ b/app/src/main/java/pm/gnosis/heimdall/ui/account/AccountViewModel.kt @@ -14,15 +14,13 @@ import pm.gnosis.svalinn.accounts.base.repositories.AccountsRepository import pm.gnosis.svalinn.common.utils.QrCodeGenerator import pm.gnosis.svalinn.common.utils.Result import pm.gnosis.svalinn.common.utils.mapToResult -import pm.gnosis.ticker.data.repositories.TickerRepository import javax.inject.Inject class AccountViewModel @Inject constructor( @ApplicationContext private val context: Context, private val accountsRepository: AccountsRepository, private val ethereumRepository: EthereumRepository, - private val qrCodeGenerator: QrCodeGenerator, - private val tickerRepository: TickerRepository + private val qrCodeGenerator: QrCodeGenerator ) : AccountContract() { private val errorHandler = SimpleLocalizedException.networkErrorHandlerBuilder(context) @@ -44,6 +42,4 @@ class AccountViewModel @Inject constructor( .onErrorResumeNext(Function { errorHandler.observable(it) }) .mapToResult() } - - override fun loadFiatConversion(amount: Wei) = tickerRepository.convertToFiat(amount).mapToResult() } diff --git a/app/src/main/res/layout/layout_account.xml b/app/src/main/res/layout/layout_account.xml index f0c617dd8b..9cabe04c1f 100644 --- a/app/src/main/res/layout/layout_account.xml +++ b/app/src/main/res/layout/layout_account.xml @@ -52,18 +52,6 @@ android:text="-" tools:text="12 ETH" /> - - >>() - val currency = Currency("", "", "", 0, 0, BigDecimal.ZERO, Currency.FiatSymbol.USD) - val fiatResult = BigDecimal.ZERO to currency - given(tickerRepositoryMock.convertToFiat(MockUtils.any(), MockUtils.any())).willReturn(Single.just(fiatResult)) - - viewModel.loadFiatConversion(amount).subscribe(testObserver) - - then(tickerRepositoryMock).should().convertToFiat(amount) - then(tickerRepositoryMock).shouldHaveNoMoreInteractions() - testObserver.assertResult(DataResult(fiatResult)) - } - - @Test - fun loadFiatConversionError() { - val amount = Wei(BigInteger.ZERO) - val testObserver = TestObserver.create>>() - val exception = IllegalArgumentException() - given(tickerRepositoryMock.convertToFiat(MockUtils.any(), MockUtils.any())).willReturn(Single.error(exception)) - - viewModel.loadFiatConversion(amount).subscribe(testObserver) - - then(tickerRepositoryMock).should().convertToFiat(amount) - then(tickerRepositoryMock).shouldHaveNoMoreInteractions() - testObserver.assertResult(ErrorResult(exception)) - } - private fun createObserver() = TestObserver.create>() companion object { diff --git a/buildsystem/dependencies.gradle b/buildsystem/dependencies.gradle index ff2e2a1f54..85404369e9 100644 --- a/buildsystem/dependencies.gradle +++ b/buildsystem/dependencies.gradle @@ -4,7 +4,7 @@ ext { android_tools : '3.1.3', fabric : '1.+', google_services : '3.3.0', - kotlin : '1.2.50', + kotlin : '1.2.51', jacoco : '0.7.9', // Runtime dependencies