Repository: horizontalsystems/unstoppable-wallet-android
Issue: Issue with sending BTC in dollars 

Sending in dollars sends 0 coins to the recipient.

Need to check in all coin types.

Changed files:
app/src/main/java/io/horizontalsystems/bankwallet/modules/send/SendInteractor.kt
app/src/test/java/io/horizontalsystems/bankwallet/modules/send/SendInteractorTest.kt

diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/send/SendInteractor.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/send/SendInteractor.kt
index 7b6f2ac11..2a220c462 100644
--- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/send/SendInteractor.kt
+++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/send/SendInteractor.kt
@@ -173,25 +173,17 @@ class SendInteractor(private val currencyManager: ICurrencyManager,
             return
         }
 
-        var computedAmount: BigDecimal? = null
-
-        if (userInput.inputType == SendModule.InputType.COIN) {
-            computedAmount = userInput.amount
-        } else {
-            val rateValue = rate?.value
-            if (rateValue != null) {
-                computedAmount = userInput.amount / rateValue
-            }
+        val computedAmount = when(userInput.inputType) {
+            SendModule.InputType.COIN -> userInput.amount
+            SendModule.InputType.CURRENCY -> convertedAmountForInputType(SendModule.InputType.CURRENCY, userInput.amount)
         }
 
-        val amount = computedAmount
-
-        if (amount == null) {
+        if (computedAmount == null || computedAmount.compareTo(BigDecimal.ZERO) == 0) {
             delegate?.didFailToSend(SendError.NoAmount())
             return
         }
 
-        wallet.adapter.send(address, amount) { error ->
+        wallet.adapter.send(address, computedAmount) { error ->
             when (error) {
                 null -> delegate?.didSend()
                 else -> delegate?.didFailToSend(error)
diff --git a/app/src/test/java/io/horizontalsystems/bankwallet/modules/send/SendInteractorTest.kt b/app/src/test/java/io/horizontalsystems/bankwallet/modules/send/SendInteractorTest.kt
index 48e577f4e..d4fc5c585 100644
--- a/app/src/test/java/io/horizontalsystems/bankwallet/modules/send/SendInteractorTest.kt
+++ b/app/src/test/java/io/horizontalsystems/bankwallet/modules/send/SendInteractorTest.kt
@@ -1,9 +1,6 @@
 package io.horizontalsystems.bankwallet.modules.send
 
-import com.nhaarman.mockito_kotlin.any
-import com.nhaarman.mockito_kotlin.argThat
-import com.nhaarman.mockito_kotlin.verify
-import com.nhaarman.mockito_kotlin.whenever
+import com.nhaarman.mockito_kotlin.*
 import io.horizontalsystems.bankwallet.core.*
 import io.horizontalsystems.bankwallet.entities.*
 import io.horizontalsystems.bankwallet.modules.RxBaseTest
@@ -29,7 +26,7 @@ class SendInteractorTest {
 
     private val currency = Currency("USD", symbol = "\\u0024")
     private val coin = CoinCode()
-    private val rate = Rate(coin, currency.code, BigDecimal("0.1"), System.currentTimeMillis(), true)
+    private val rate = mock(Rate::class.java)
     private val userInput = mock(SendModule.UserInput::class.java)
     private val balance = BigDecimal(123)
     private val zero = BigDecimal.ZERO
@@ -43,6 +40,8 @@ class SendInteractorTest {
     fun setup() {
         RxBaseTest.setup()
 
+        whenever(userInput.inputType).thenReturn(SendModule.InputType.COIN)
+        whenever(rate.value).thenReturn(BigDecimal("0.1"))
         whenever(wallet.coinCode).thenReturn(coin)
         whenever(wallet.adapter).thenReturn(adapter)
         whenever(currencyManager.baseCurrency).thenReturn(currency)
@@ -88,6 +87,23 @@ class SendInteractorTest {
         verify(rateStorage).latestRateObservable(coin, currency.code)
     }
 
+    @Test
+    fun send_inCurrency() {
+        interactor.retrieveRate() // set rate
+
+        whenever(rate.value).thenReturn(BigDecimal(1024))
+        whenever(userInput.inputType).thenReturn(SendModule.InputType.CURRENCY)
+        whenever(userInput.address).thenReturn("abc")
+        whenever(userInput.amount).thenReturn(one)
+        whenever(adapter.decimal).thenReturn(8)
+
+        interactor.send(userInput)
+
+        val expectedAmountToSend = BigDecimal.valueOf(0.00097656) // 0.0009765625
+
+        verify(adapter).send(eq("abc"), eq(expectedAmountToSend), any())
+    }
+
     @Test
     fun send() {
         interactor.retrieveRate() // set rate