Skip to content

Commit

Permalink
Auto Shielding
Browse files Browse the repository at this point in the history
  • Loading branch information
nighthawk24 committed Jul 11, 2021
1 parent d887472 commit 860163e
Show file tree
Hide file tree
Showing 90 changed files with 4,624 additions and 982 deletions.
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
Change Log
==========

Version 1.0.20
------------------------------------
- New: Added workflow for automatically shielding funds.
- New: Automatically recover from more network failure states.
- New: Link to play store from the build number.
- New: Hide available/total toggle when there are no pending funds.
- New: Easter Egg to access the testnet faucets.
- New: Updated checkpoints for mainnet and testnet.
- New: Address tabs with t-address support [Credit @herou].
- New: Balance details screen [Credit @herou].
- New: Better balance information around unmined transactions.
- New: Add toggle to show available vs. total funds.
- New: Auto-shielding via balance details screen.
- Fix: Expand tappable area for showing the balance details.
- Fix: Off by one error when calculating confirmations.
- Fix: Do not show time in transaction details for pending transactions.
- Fix: Repaired QR scanning on older devices (below API 24).
- Fix: Several of the most frequent crashes reported in bugsnag.
- Fix: Corrected over-sized icon in history.
- Fix: History no longer displays negative balance during initial sync.
- Fix: Errors that prevented sync from working in some situations.
- Fix: Improved support for smaller screens and older devices.
- Update ECC & Android dependencies.

Version 1.0.19 *(2021-05-13)*
------------------------------------
- Hotfix: Remove un-used flags during wallet creation.
Expand Down
18 changes: 7 additions & 11 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import com.nighthawkapps.wallet.android.Deps

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

archivesBaseName = 'nighthawk-android-wallet'
group = 'com.nighthawkapps.wallet.android'
version = Deps.versionName
android {
ndkVersion "21.1.6352462"
compileSdkVersion Deps.compileSdkVersion
Expand Down Expand Up @@ -52,19 +53,19 @@ android {
release {
minifyEnabled false
shrinkResources false
useProguard false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.placeholder
}
debug {
minifyEnabled false
shrinkResources false
useProguard false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

compileOptions {
// enable support for new language APIs but also fix the issue with zxing on API < 24
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Expand All @@ -86,13 +87,8 @@ android {
}

apply from: "$rootDir/ktlint.gradle"

afterEvaluate {
if (project.tasks.getByName("preBuild")) {
preBuild.dependsOn('ktlintFormat')
preBuild.dependsOn('ktlint')
}
}
preBuild.dependsOn('ktlintFormat')
preBuild.dependsOn('ktlint')

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
Expand Down Expand Up @@ -122,13 +118,13 @@ dependencies {
implementation Deps.AndroidX.CameraX.LIFECYCLE
implementation Deps.AndroidX.CameraX.View.EXT
implementation Deps.AndroidX.CameraX.View.VIEW
implementation Deps.AndroidX.Lifecycle.LIFECYCLE_EXTENSIONS
implementation Deps.AndroidX.Lifecycle.LIFECYCLE_RUNTIME_KTX
implementation Deps.AndroidX.Navigation.FRAGMENT_KTX
implementation Deps.AndroidX.Navigation.UI_KTX
implementation Deps.AndroidX.Room.ROOM_KTX
kapt Deps.AndroidX.Room.ROOM_COMPILER
implementation Deps.AndroidX.SECURITY
coreLibraryDesugaring Deps.AndroidX.DESUGAR_JDK

// Google
implementation Deps.Google.GUAVA
Expand Down
Binary file modified app/src/main/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.nighthawkapps.wallet.android
import android.app.Application
import androidx.camera.camera2.Camera2Config
import androidx.camera.core.CameraXConfig
import cash.z.ecc.android.sdk.ext.ZcashSdk
import cash.z.ecc.android.sdk.type.ZcashNetwork
import com.nighthawkapps.wallet.android.di.component.AppComponent
import com.nighthawkapps.wallet.android.di.component.DaggerAppComponent
Expand All @@ -14,6 +15,9 @@ class NighthawkWalletApp : Application(), CameraXConfig.Provider {
*/
lateinit var defaultNetwork: ZcashNetwork

/** The amount of transparent funds that need to accumulate before autoshielding is triggered */
val autoshieldThreshold: Long = ZcashSdk.ZATOSHI_PER_ZEC // 1 ZEC

override fun onCreate() {
instance = this
super.onCreate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import dagger.Provides
@Module(includes = [ViewModelsSynchronizerModule::class])
class SynchronizerModule {

private var synchronizer: Synchronizer? = null

@Provides
@SynchronizerScope
fun provideSynchronizer(initializer: Initializer): Synchronizer {
return Synchronizer(initializer)
return synchronizer ?: Synchronizer(initializer).also { synchronizer = it }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import com.nighthawkapps.wallet.android.di.annotation.SynchronizerScope
import com.nighthawkapps.wallet.android.di.annotation.ViewModelKey
import com.nighthawkapps.wallet.android.di.viewmodel.ViewModelFactory
import com.nighthawkapps.wallet.android.ext.Const
import com.nighthawkapps.wallet.android.ui.detail.WalletDetailViewModel
import com.nighthawkapps.wallet.android.ui.history.HistoryViewModel
import com.nighthawkapps.wallet.android.ui.home.BalanceDetailViewModel
import com.nighthawkapps.wallet.android.ui.home.HomeViewModel
import com.nighthawkapps.wallet.android.ui.profile.ProfileViewModel
import com.nighthawkapps.wallet.android.ui.receive.ReceiveViewModel
import com.nighthawkapps.wallet.android.ui.scan.ScanViewModel
import com.nighthawkapps.wallet.android.ui.send.AutoShieldViewModel
import com.nighthawkapps.wallet.android.ui.send.SendViewModel
import com.nighthawkapps.wallet.android.ui.setup.SettingsViewModel
import dagger.Binds
Expand Down Expand Up @@ -39,8 +41,8 @@ abstract class ViewModelsSynchronizerModule {
@SynchronizerScope
@Binds
@IntoMap
@ViewModelKey(WalletDetailViewModel::class)
abstract fun bindWalletDetailViewModel(implementation: WalletDetailViewModel): ViewModel
@ViewModelKey(HistoryViewModel::class)
abstract fun bindHistoryViewModel(implementation: HistoryViewModel): ViewModel

@SynchronizerScope
@Binds
Expand All @@ -66,6 +68,18 @@ abstract class ViewModelsSynchronizerModule {
@ViewModelKey(SettingsViewModel::class)
abstract fun bindSettingsViewModel(implementation: SettingsViewModel): ViewModel

@SynchronizerScope
@Binds
@IntoMap
@ViewModelKey(BalanceDetailViewModel::class)
abstract fun bindBalanceDetailViewModel(implementation: BalanceDetailViewModel): ViewModel

@SynchronizerScope
@Binds
@IntoMap
@ViewModelKey(AutoShieldViewModel::class)
abstract fun bindAutoShieldViewModel(implementation: AutoShieldViewModel): ViewModel

/**
* Factory for view models that are not created until the Synchronizer exists. Only VMs that
* require the Synchronizer should wait until it is created. In other words, these are the VMs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ object Const {
* Default values to use application-wide. Ideally, this set of values should remain very short.
*/
object Default {

const val FIRST_USE_VIEW_TX = "const.pref.first_use_view_tx"

object Server {
const val HOST = BuildConfig.DEFAULT_SERVER_URL
const val PORT = 9067
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ fun Context.showScanFailure(error: Throwable?, onCancel: () -> Unit = {}, onDism
}

fun Context.showCriticalMessage(@StringRes titleResId: Int, @StringRes messageResId: Int, onDismiss: () -> Unit = {}): Dialog {
return showCriticalError(getString(titleResId), getString(messageResId), onDismiss)
return showCriticalMessage(titleResId.toAppString(), messageResId.toAppString(), onDismiss)
}

fun Context.showCriticalError(title: String, message: String, onDismiss: () -> Unit = {}): Dialog {
fun Context.showCriticalMessage(title: String, message: String, onDismiss: () -> Unit = {}): Dialog {
return MaterialAlertDialogBuilder(this)
.setTitle(title)
.setMessage(message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,35 @@ import android.content.Context
import android.os.Build
import androidx.fragment.app.Fragment
import cash.z.ecc.android.sdk.ext.twig
import cash.z.ecc.android.sdk.type.WalletBalance
import java.util.Locale
import kotlin.math.roundToInt

/**
* Distribute a string into evenly-sized chunks and then execute a function with each chunk.
*
* @param chunks the number of chunks to create
* @param block a function to be applied to each zero-indexed chunk.
*/
fun <T> String.distribute(chunks: Int, block: (Int, String) -> T) {
val charsPerChunk = length / chunks.toFloat()
val wholeCharsPerChunk = charsPerChunk.toInt()
val chunksWithExtra = ((charsPerChunk - wholeCharsPerChunk) * chunks).roundToInt()
repeat(chunks) { i ->
val part = if (i < chunksWithExtra) {
substring(i * (wholeCharsPerChunk + 1), (i + 1) * (wholeCharsPerChunk + 1))
} else {
substring(i * wholeCharsPerChunk + chunksWithExtra, (i + 1) * wholeCharsPerChunk + chunksWithExtra)
}
block(i, part)
}
}

fun Boolean.asString(ifTrue: String = "", ifFalse: String = "") = if (this) ifTrue else ifFalse

inline val WalletBalance.pending: Long
get() = (this.totalZatoshi - this.availableZatoshi).coerceAtLeast(0)

inline fun <R> tryWithWarning(message: String = "", block: () -> R): R? {
return try {
block()
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/nighthawkapps/wallet/android/ext/Int.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ internal inline fun @receiver:StringRes Int.toAppString(lowercase: Boolean = fal
}
}

/**
* Grab a formatted string from the application resources
*/
internal inline fun @receiver:StringRes Int.toAppStringFormatted(vararg formatArgs: Any): String {
return NighthawkWalletApp.instance.getString(this, *formatArgs)
}

/**
* Grab an integer from the application resources
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package com.nighthawkapps.wallet.android.ext

import android.text.Spanned
import android.text.style.ForegroundColorSpan
import androidx.annotation.ColorRes
import androidx.core.text.toSpannable

fun CharSequence.toColoredSpan(colorResId: Int, coloredPortion: String): CharSequence {
fun CharSequence.toColoredSpan(@ColorRes colorResId: Int, coloredPortion: String): CharSequence {
return toSpannable().apply {
val start = this@toColoredSpan.indexOf(coloredPortion)
setSpan(
Expand All @@ -15,3 +16,10 @@ fun CharSequence.toColoredSpan(colorResId: Int, coloredPortion: String): CharSeq
)
}
}

fun CharSequence.toSplitColorSpan(@ColorRes startColorResId: Int, @ColorRes endColorResId: Int, startColorLength: Int): CharSequence {
return toSpannable().apply {
setSpan(ForegroundColorSpan(startColorResId.toAppColor()), 0, startColorLength - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
setSpan(ForegroundColorSpan(endColorResId.toAppColor()), startColorLength, this@toSplitColorSpan.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
}
}
Loading

0 comments on commit 860163e

Please sign in to comment.