Skip to content

Commit

Permalink
Merge pull request #326 from horizontalsystems/release-0.3.0
Browse files Browse the repository at this point in the history
Release 0.3.0
  • Loading branch information
omurovch authored May 9, 2019
2 parents affdbed + bd3d0d7 commit e80fdaa
Show file tree
Hide file tree
Showing 375 changed files with 12,174 additions and 8,884 deletions.
11 changes: 8 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
minSdkVersion 23
targetSdkVersion 27
versionCode 1
versionName "1.0"
versionName "0.3.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -32,12 +32,15 @@ dependencies {
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:27.1.1'

implementation 'io.reactivex.rxjava2:rxjava:2.2.0'
implementation 'io.reactivex.rxjava2:rxjava:2.2.2'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'

// ViewModel and LiveData
implementation "android.arch.lifecycle:extensions:1.1.1"
kapt "android.arch.lifecycle:compiler:1.1.1"
annotationProcessor "android.arch.lifecycle:compiler:1.1.1"

// For debug
implementation 'com.facebook.stetho:stetho:1.5.1'

//LeakCanary
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.2'
Expand All @@ -48,4 +51,6 @@ dependencies {
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

implementation project(':bitcoinkit')
implementation project(':dashkit')
implementation project(':bitcoincashkit')
}
12 changes: 11 additions & 1 deletion app/src/main/java/io/horizontalsystems/bitcoinkit/demo/App.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.horizontalsystems.bitcoinkit.demo

import android.app.Application
import com.facebook.stetho.Stetho
import com.squareup.leakcanary.LeakCanary
import io.horizontalsystems.bitcoinkit.BitcoinKit

Expand All @@ -9,14 +10,23 @@ class App : Application() {
override fun onCreate() {
super.onCreate()

// Enable debug bridge
Stetho.initializeWithDefaults(this);

if (LeakCanary.isInAnalyzerProcess(this)) {
// This process is dedicated to LeakCanary for heap analysis.
// You should not init your app in this process.
return
}

LeakCanary.install(this)

BitcoinKit.init(this)
instance = this
}

companion object {
lateinit var instance: App
private set
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import io.horizontalsystems.bitcoinkit.BitcoinKit
import io.horizontalsystems.bitcoincore.BitcoinCore

class BalanceFragment : Fragment() {

Expand All @@ -29,7 +29,7 @@ class BalanceFragment : Fragment() {
viewModel = ViewModelProviders.of(it).get(MainViewModel::class.java)

viewModel.balance.observe(this, Observer { balance ->
balanceValue.text = when(balance) {
balanceValue.text = when (balance) {
null -> ""
else -> NumberFormatHelper.cryptoAmountFormat.format(balance / 100_000_000.0)
}
Expand All @@ -39,15 +39,15 @@ class BalanceFragment : Fragment() {
lastBlockValue.text = (it ?: 0).toString()
})

viewModel.state.observe(this, Observer {
when (it) {
is BitcoinKit.KitState.Synced -> {
viewModel.state.observe(this, Observer { state ->
when (state) {
is BitcoinCore.KitState.Synced -> {
stateValue.text = "synced"
}
is BitcoinKit.KitState.Syncing -> {
stateValue.text = "syncing ${it.progress}"
is BitcoinCore.KitState.Syncing -> {
stateValue.text = "syncing ${"%.3f".format(state.progress)}"
}
is BitcoinKit.KitState.NotSynced -> {
is BitcoinCore.KitState.NotSynced -> {
stateValue.text = "not synced"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package io.horizontalsystems.bitcoinkit.demo

import android.arch.lifecycle.MutableLiveData
import android.arch.lifecycle.ViewModel
import io.horizontalsystems.bitcoincore.BitcoinCore.KitState
import io.horizontalsystems.bitcoincore.models.BlockInfo
import io.horizontalsystems.bitcoincore.models.FeePriority
import io.horizontalsystems.bitcoincore.models.TransactionInfo
import io.horizontalsystems.bitcoinkit.BitcoinKit
import io.horizontalsystems.bitcoinkit.BitcoinKit.KitState
import io.horizontalsystems.bitcoinkit.models.BlockInfo
import io.horizontalsystems.bitcoinkit.models.FeePriority
import io.horizontalsystems.bitcoinkit.models.TransactionInfo
import io.reactivex.disposables.CompositeDisposable

class MainViewModel : ViewModel(), BitcoinKit.Listener {
Expand All @@ -20,7 +20,7 @@ class MainViewModel : ViewModel(), BitcoinKit.Listener {
val lastBlockHeight = MutableLiveData<Int>()
val state = MutableLiveData<KitState>()
val status = MutableLiveData<State>()
val networkName: String
lateinit var networkName: String
var feePriority: FeePriority = FeePriority.Medium
private val disposables = CompositeDisposable()

Expand All @@ -30,16 +30,23 @@ class MainViewModel : ViewModel(), BitcoinKit.Listener {
status.value = (if (value) State.STARTED else State.STOPPED)
}

private var bitcoinKit: BitcoinKit
private lateinit var bitcoinKit: BitcoinKit

private val walletId = "MyWallet"
private val networkType = BitcoinKit.NetworkType.MainNet

init {
val words = listOf("used", "ugly", "meat", "glad", "balance", "divorce", "inner", "artwork", "hire", "invest", "already", "piano")
val networkType = BitcoinKit.NetworkType.TestNet
init()
}

private fun init() {
val words = "used ugly meat glad balance divorce inner artwork hire invest already piano".split(" ")

bitcoinKit = BitcoinKit(App.instance, words, walletId, networkType)

bitcoinKit = BitcoinKit(words, networkType)
bitcoinKit.listener = this

networkName = networkType.name
networkName = bitcoinKit.networkName
balance.value = bitcoinKit.balance

bitcoinKit.transactions().subscribe { txList: List<TransactionInfo> ->
Expand All @@ -62,7 +69,10 @@ class MainViewModel : ViewModel(), BitcoinKit.Listener {
}

fun clear() {
bitcoinKit.clear()
bitcoinKit.stop()
BitcoinKit.clear(App.instance, networkType, walletId)

init()
}

fun receiveAddress(): String {
Expand All @@ -86,7 +96,7 @@ class MainViewModel : ViewModel(), BitcoinKit.Listener {
//
// BitcoinKit Listener implementations
//
override fun onTransactionsUpdate(bitcoinKit: BitcoinKit, inserted: List<TransactionInfo>, updated: List<TransactionInfo>) {
override fun onTransactionsUpdate(inserted: List<TransactionInfo>, updated: List<TransactionInfo>) {
bitcoinKit.transactions().subscribe { txList: List<TransactionInfo> ->
transactions.postValue(txList.sortedByDescending { it.blockHeight })
}.let {
Expand All @@ -97,15 +107,15 @@ class MainViewModel : ViewModel(), BitcoinKit.Listener {
override fun onTransactionsDelete(hashes: List<String>) {
}

override fun onBalanceUpdate(bitcoinKit: BitcoinKit, balance: Long) {
override fun onBalanceUpdate(balance: Long) {
this.balance.postValue(balance)
}

override fun onLastBlockInfoUpdate(bitcoinKit: BitcoinKit, blockInfo: BlockInfo) {
override fun onLastBlockInfoUpdate(blockInfo: BlockInfo) {
this.lastBlockHeight.postValue(blockInfo.height)
}

override fun onKitStateUpdate(bitcoinKit: BitcoinKit, state: KitState) {
override fun onKitStateUpdate(state: KitState) {
this.state.postValue(state)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.*
import io.horizontalsystems.bitcoinkit.managers.UnspentOutputSelector
import io.horizontalsystems.bitcoinkit.models.FeePriority
import io.horizontalsystems.bitcoincore.managers.UnspentOutputSelectorError
import io.horizontalsystems.bitcoincore.models.FeePriority

class SendReceiveFragment : Fragment() {

Expand Down Expand Up @@ -63,7 +63,7 @@ class SendReceiveFragment : Fragment() {
val customFeePriority = view.findViewById<EditText>(R.id.customFeePriority)
customFeePriority.addTextChangedListener(object: TextWatcher {
override fun afterTextChanged(s: Editable) {
val feePriority = s.toString().toDoubleOrNull()
val feePriority = s.toString().toIntOrNull()
feePriority?.let {
viewModel.feePriority = FeePriority.Custom(it)
updateFee()
Expand Down Expand Up @@ -99,8 +99,8 @@ class SendReceiveFragment : Fragment() {
message = "Transaction sent"
} catch (e: Exception) {
message = when (e) {
is UnspentOutputSelector.Error.InsufficientUnspentOutputs,
is UnspentOutputSelector.Error.EmptyUnspentOutputs -> "Insufficient balance"
is UnspentOutputSelectorError.InsufficientUnspentOutputs,
is UnspentOutputSelectorError.EmptyUnspentOutputs -> "Insufficient balance"
else -> e.message ?: "Failed to send transaction"
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.horizontalsystems.bitcoinkit.demo

import android.annotation.SuppressLint
import android.arch.lifecycle.Observer
import android.arch.lifecycle.ViewModelProviders
import android.graphics.Color
Expand All @@ -11,7 +12,8 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import io.horizontalsystems.bitcoinkit.models.TransactionInfo
import io.horizontalsystems.bitcoincore.models.TransactionAddress
import io.horizontalsystems.bitcoincore.models.TransactionInfo
import java.text.DateFormat
import java.util.*

Expand Down Expand Up @@ -67,20 +69,38 @@ class TransactionsAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
class ViewHolderTransaction(val containerView: View) : RecyclerView.ViewHolder(containerView) {
private val summary = containerView.findViewById<TextView>(R.id.summary)!!

@SuppressLint("SetTextI18n")
fun bind(transactionInfo: TransactionInfo, index: Int) {
containerView.setBackgroundColor(if (index % 2 == 0) Color.parseColor("#dddddd") else Color.TRANSPARENT)

val timeInMillis = transactionInfo.timestamp.times(1000)

val date = DateFormat.getInstance().format(Date(timeInMillis))
val amount = NumberFormatHelper.cryptoAmountFormat.format(transactionInfo.amount / 100_000_000.0)

summary.text = "#$index" +
"\nFrom: ${transactionInfo.from.first().address}" +
"\nTo: ${transactionInfo.to.first().address}" +
"\nAmount: ${NumberFormatHelper.cryptoAmountFormat.format(transactionInfo.amount / 100_000_000.0)}" +
val text = "#$index" +
"\nFrom: ${mapAddresses(transactionInfo.from)}" +
"\nTo: ${mapAddresses(transactionInfo.to)}" +
"\nAmount: $amount" +
"\nTx hash: ${transactionInfo.transactionHash}" +
"\nTx index: ${transactionInfo.transactionIndex}" +
"\nBlock: ${transactionInfo.blockHeight}" +
"\nTimestamp: ${transactionInfo.timestamp}" +
"\nDate: $date"
summary.text = text
summary.setOnClickListener {
println(transactionInfo)
println(text)
}
}

private fun mapAddresses(list: List<TransactionAddress>): String {
return list.joinToString("\n ") {
if (it.mine) {
"${it.address} (mine)"
} else {
it.address
}
}
}
}
1 change: 1 addition & 0 deletions bitcoincashkit/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
73 changes: 73 additions & 0 deletions bitcoincashkit/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

android {
compileSdkVersion 28

defaultConfig {
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "0.3.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
test.java.srcDirs += 'src/test/kotlin'
}

kotlinOptions { jvmTarget = '1.8' }
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation 'com.android.support:support-annotations:28.0.0'

// Room
implementation "android.arch.persistence.room:runtime:1.1.1"
implementation "android.arch.persistence.room:rxjava2:1.1.1"
kapt "android.arch.persistence.room:compiler:1.1.1"

api project(':bitcoincore')

// HDWallet Kit
implementation 'com.github.horizontalsystems:hd-wallet-kit-android:a3666d8'


// Test helpers
testImplementation 'junit:junit:4.12'
testImplementation 'org.junit.jupiter:junit-jupiter:5.4.1'
testImplementation 'org.mockito:mockito-core:2.23.0'
testImplementation 'com.nhaarman:mockito-kotlin-kt1.1:1.6.0'
testImplementation 'org.powermock:powermock-api-mockito2:2.0.0-beta.5'
testImplementation 'org.powermock:powermock-module-junit4:2.0.0-beta.5'

// Spek
testImplementation "org.spekframework.spek2:spek-dsl-jvm:2.0.3"
testRuntimeOnly "org.spekframework.spek2:spek-runner-junit5:2.0.3"
testRuntimeOnly "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"

// Android Instrumentation Test
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.linkedin.dexmaker:dexmaker-mockito-inline:2.19.1'
androidTestImplementation 'com.nhaarman:mockito-kotlin-kt1.1:1.6.0'
}

repositories {
mavenCentral()
}
21 changes: 21 additions & 0 deletions bitcoincashkit/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
2 changes: 2 additions & 0 deletions bitcoincashkit/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.horizontalsystems.bitcoincashkit" />
Loading

0 comments on commit e80fdaa

Please sign in to comment.