Skip to content

Commit

Permalink
Increment to version 4.0.17
Browse files Browse the repository at this point in the history
  • Loading branch information
angelix committed Nov 3, 2023
1 parent 7e93072 commit e8be575
Show file tree
Hide file tree
Showing 23 changed files with 166 additions and 67 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [4.0.17] - 2023-10-30

### Changed
- Bump GDK to version 0.68.4
- Bump Breez to version 0.2.7

### Added
- Add icons to menu items
- Display an error message when personal electrum server is unreachable

### Fixed
- Fix scan of color inverted QR codes
- Fix NPE crash related to session handling
- Fix fetching remote config when Tor is enabled

## [4.0.15] - 2023-10-11

### Changed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package com.blockstream.common.extensions

import com.blockstream.common.CountlyBase
import com.blockstream.common.data.AppInfo
import kotlinx.coroutines.CoroutineExceptionHandler
import org.koin.mp.KoinPlatformTools


// Log and handle the exception. Prevent unhanded exception crash
fun logException(
countly: CountlyBase
): CoroutineExceptionHandler {
return CoroutineExceptionHandler { _, exception ->
// if (isDevelopmentOrDebug) {
if (KoinPlatformTools.defaultContext().get().get<AppInfo>().isDevelopmentOrDebug) {
exception.printStackTrace()
// }
}

countly.recordException(exception)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ class GdkSession constructor(
if(isConnected) {
isConnected = false

scope.launch(context = Dispatchers.IO) {
scope.launch(context = Dispatchers.IO + logException(countly)) {
disconnect()

// Destroy session if it's ephemeral
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import kotlinx.serialization.json.JsonElement
abstract class GreenJson<T> {
open fun encodeDefaultsValues() = true

open fun explicitNulls() = true

open fun keepJsonElement() = false

@Transient
Expand All @@ -19,6 +21,7 @@ abstract class GreenJson<T> {
protected val json by lazy {
Json {
encodeDefaults = encodeDefaultsValues()
explicitNulls = explicitNulls()
ignoreUnknownKeys = true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import kotlinx.serialization.Serializable
data class ValidateAddresseesParams private constructor(
@SerialName("addressees") val addressees: List<Addressee>,
) : GreenJson<ValidateAddresseesParams>() {
override fun explicitNulls(): Boolean = false

override fun kSerializer() = serializer()

companion object{
companion object {
fun create(network: Network, address: String): ValidateAddresseesParams {
return ValidateAddresseesParams(
addressees = listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import com.blockstream.common.gdk.data.Network
import com.blockstream.common.gdk.data.TorEvent
import com.blockstream.common.gdk.device.DeviceInterface
import com.blockstream.common.lightning.LightningManager
import com.blockstream.common.utils.ConsumableEvent
import com.blockstream.common.utils.Loggable
import com.blockstream.common.utils.Timer
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.IO
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asSharedFlow
Expand Down Expand Up @@ -86,7 +86,7 @@ class SessionManager constructor(

private var timeoutTimers = mutableListOf<Timer>()

var pendingUri = MutableStateFlow<ConsumableEvent<String>?>(null)
val pendingUri: Channel<String?> = Channel(capacity = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST)

private val _connectionChangeEvent = MutableSharedFlow<Unit>(replay = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST).also {
// Set initial value
Expand Down
2 changes: 1 addition & 1 deletion gms/src/main/java/com/blockstream/gms/ZendeskSdkImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ZendeskSdkImpl constructor(context: Context, clientId: String) : ZendeskSd
request.description = message.takeIf { it.isNotBlank() } ?: "{No Message}"
request.customFields = listOfNotNull(
appVersion?.let { CustomField( 900009625166, it) }, // App Version
CustomField( 21409433258649, errorReport.error), // Logs
CustomField( 21409433258649L, errorReport.error), // Logs
errorReport.supportId?.let { CustomField(23833728377881L, it) }, // Support ID
errorReport.zendeskHardwareWallet?.let { CustomField(900006375926L, it) }, // Hardware Wallet
errorReport.zendeskSecurityPolicy?.let { CustomField(6167739898649L, it) } // Policy
Expand Down
4 changes: 2 additions & 2 deletions green/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ android {
defaultConfig {
minSdk = libs.versions.androidMinSdk.get().toInt()
targetSdk = libs.versions.androidTargetSdk.get().toInt()
versionCode = 415
versionName = "4.0.15"
versionCode = 417
versionName = "4.0.17"

setProperty("archivesBaseName", "BlockstreamGreen-v$versionName")
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.blockstream.green.devices

import android.content.Context
import android.os.Build
import com.blockstream.HardwareQATester
import com.blockstream.JadeHWWallet
import com.blockstream.common.CountlyBase
Expand Down Expand Up @@ -61,6 +62,9 @@ class DeviceConnectionManager constructor(
)
}

var needsAndroid14BleUpdate:Boolean = false
private set

fun connectDevice(context: Context, device: Device) {
scope.launch(context = Dispatchers.IO) {
try {
Expand Down Expand Up @@ -160,8 +164,11 @@ class DeviceConnectionManager constructor(

val jadeWallet = JadeHWWallet(gdk, jade, jadeDevice, verInfo, qaTester)

onHWalletCreated(device, jadeWallet, jadeWallet.isUninitialized)
if (version.isLessThan(JadeVersion("1.0.25")) && device.isBle && Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
needsAndroid14BleUpdate = true
}

onHWalletCreated(device, jadeWallet, jadeWallet.isUninitialized)
} catch (e: Exception) {
closeJadeAndFail(device, jade)
}
Expand Down
4 changes: 2 additions & 2 deletions green/src/main/java/com/blockstream/green/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -416,15 +416,15 @@ class MainActivity : AppActivity() {
// Handle Uri (BIP-21 or lightning)
intent?.data?.let {

sessionManager.pendingUri.value = ConsumableEvent(it.toString())
sessionManager.pendingUri.trySend(it.toString())

if(navController.currentDestination?.id == R.id.homeFragment) {
Snackbar.make(
binding.root,
R.string.id_you_have_clicked_a_payment_uri,
Snackbar.LENGTH_LONG
).setAction(R.string.id_cancel) {
sessionManager.pendingUri.value = null
sessionManager.pendingUri.trySend(null)
}.show()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.lifecycle.MutableLiveData
import com.blockstream.HwWalletLogin
import com.blockstream.JadeHWWallet
import com.blockstream.common.data.GreenWallet
import com.blockstream.common.extensions.logException
import com.blockstream.common.gdk.GdkSession
import com.blockstream.common.gdk.data.Network
import com.blockstream.common.gdk.device.DeviceBrand
Expand All @@ -20,6 +21,8 @@ import com.greenaddress.greenbits.wallets.FirmwareFileData
import com.greenaddress.greenbits.wallets.FirmwareUpgradeRequest
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import mu.KLogging

Expand Down Expand Up @@ -170,7 +173,10 @@ abstract class AbstractDeviceViewModel constructor(
if(!proceedToLogin) {

if(sessionManager.getConnectedHardwareWalletSessions().none { it.device?.id == device?.id }){
device?.disconnect()
// Disconnect without blocking the UI
applicationScope.launch(context = Dispatchers.IO + logException(countly)) {
device?.disconnect()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ class DeviceInfoFragment : AbstractDeviceFragment<DeviceInfoFragmentBinding>(
}
.show()
}
} else if (sideEffect is SideEffects.OpenDialog) {
MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.id_new_jade_firmware_required )
.setCancelable(false)
.setMessage(R.string.id_please_upgrade_your_jade_firmware_to)
.setPositiveButton(R.string.id_ok) { _, _ ->
popBackStack()
}
.setNeutralButton(R.string.id_read_more) { _, _ ->
popBackStack()
openBrowser(Urls.HELP_JADE_USB_UPGRADE)
}.show()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ class DeviceInfoViewModel constructor(
}

if(device.gdkHardwareWallet == null){
unlockDevice(context)
connectDevice(context)
}
}

private fun unlockDevice(context: Context) {
private fun connectDevice(context: Context) {
onProgressAndroid.value = true
navigationLock.value = true
deviceConnectionManager.connectDevice(context, device)
Expand Down Expand Up @@ -171,6 +171,11 @@ class DeviceInfoViewModel constructor(
}

override fun onDeviceReady(device: Device, isJadeUninitialized: Boolean?) {

if (deviceConnectionManager.needsAndroid14BleUpdate) {
postSideEffect(SideEffects.OpenDialog(0))
}

onProgressAndroid.postValue(false)
navigationLock.postValue(false)
deviceIsConnected.postValue(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ class DeviceScanFragment : AbstractDeviceFragment<DeviceScanFragmentBinding>(
navigate(findNavController(), navDirections.actionId, navDirections.arguments, isLogout = true)
}
}
} else if (sideEffect is SideEffects.OpenDialog) {
MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.id_new_jade_firmware_required )
.setCancelable(false)
.setMessage(R.string.id_please_upgrade_your_jade_firmware_to)
.setPositiveButton(R.string.id_ok) { _, _ ->
popBackStack()
}
.setNeutralButton(R.string.id_read_more) { _, _ ->
popBackStack()
openBrowser(Urls.HELP_JADE_USB_UPGRADE)
}.show()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ class DeviceScanViewModel constructor(

override fun onDeviceReady(device: Device, isJadeUninitialized: Boolean?) {

if (deviceConnectionManager.needsAndroid14BleUpdate) {
postSideEffect(SideEffects.OpenDialog(0))
return
}

doUserAction({
val gdkHardwareWallet = device.gdkHardwareWallet ?: throw Exception("Not HWWallet initiated")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import com.blockstream.common.gdk.GdkSession
import com.blockstream.green.R
import com.blockstream.green.data.Countly
import com.blockstream.green.databinding.ListItemWalletBalanceBinding
import com.blockstream.green.extensions.setOnClickListener
import com.blockstream.green.gdk.getAssetDrawableOrNull
import com.blockstream.green.gdk.getAssetIcon
import com.blockstream.green.utils.toAmountLook
Expand All @@ -39,9 +38,7 @@ data class WalletBalanceListItem constructor(val session: GdkSession, val countl
override val type: Int
get() = R.id.fastadapter_wallet_balance_item_id

var isFiat = false

private var denomination: Denomination = Denomination.default(session)
var denomination: Denomination = Denomination.default(session)

private suspend fun balanceInBtc() = session.starsOrNull ?: session.walletTotalBalance.value.toAmountLook(
session = session,
Expand All @@ -64,8 +61,22 @@ data class WalletBalanceListItem constructor(val session: GdkSession, val countl

override fun createScope(): CoroutineScope = session.createScope(Dispatchers.Main)

fun reset() {
denomination = Denomination.default(session)
fun reset(denomination: Denomination) {
this.denomination = denomination
}

suspend fun updateBalanceView(binding: ListItemWalletBalanceBinding) {
val balance = session.walletTotalBalance.value

if (balance != -1L) {
if (denomination.isFiat) {
binding.balanceTextView.text = withContext(context = Dispatchers.IO) { balanceInFiat() }
binding.fiatTextView.text = withContext(context = Dispatchers.IO) { balanceInBtc() }
} else {
binding.balanceTextView.text = withContext(context = Dispatchers.IO) { balanceInBtc() }
binding.fiatTextView.text = withContext(context = Dispatchers.IO) { balanceInFiat() }
}
}
}

override fun bindView(binding: ListItemWalletBalanceBinding, payloads: List<Any>) {
Expand All @@ -78,42 +89,9 @@ data class WalletBalanceListItem constructor(val session: GdkSession, val countl
binding.hideAmounts = session.hideAmounts

scope.launch {
if (balance != -1L) {
binding.balanceTextView.text = withContext(context = Dispatchers.IO) { balanceInBtc() }
binding.fiatTextView.text = withContext(context = Dispatchers.IO) { balanceInFiat() }
}
}

listOf(binding.balanceTextView, binding.fiatTextView).setOnClickListener {
val walletDenomination = Denomination.default(session)

denomination = (when (denomination) {
is Denomination.FIAT -> {
walletDenomination
}
// Disable BTC
// denomination == walletDenomination && denomination != Denomination.BTC -> {
// Denomination.BTC
// }
else -> {
Denomination.fiat(session)
}
}) ?: Denomination.BTC

scope.launch {
if (denomination.isFiat) {
binding.balanceTextView.text = withContext(context = Dispatchers.IO) { balanceInFiat() }
binding.fiatTextView.text = withContext(context = Dispatchers.IO) { balanceInBtc() }
} else {
binding.balanceTextView.text = withContext(context = Dispatchers.IO) { balanceInBtc() }
binding.fiatTextView.text = withContext(context = Dispatchers.IO) { balanceInFiat() }
}
}

countly.balanceConvert(session)
updateBalanceView(binding)
}


// Clear all icons
binding.assetsIcons.removeAllViews()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ interface OverviewInterface {
} else {
if (isQr) {
appFragment.snackbar(R.string.id_could_not_recognized_qr_code)
} else {
appFragment.snackbar(R.string.id_could_not_recognized_the_uri)
}
}
}
Expand Down
Loading

0 comments on commit e8be575

Please sign in to comment.