Skip to content

Commit

Permalink
Merge branch 'master' into mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
dpad85 committed Jul 16, 2024
2 parents 78d4d68 + 22de914 commit 5ba07a8
Show file tree
Hide file tree
Showing 60 changed files with 1,122 additions and 441 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
object Versions {
const val lightningKmp = "1.7.1"
const val lightningKmp = "1.7.2"
const val secp256k1 = "0.14.0"
const val torMobile = "0.2.0"

Expand Down
4 changes: 2 additions & 2 deletions phoenix-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ android {
applicationId = "fr.acinq.phoenix.mainnet"
minSdk = 26
targetSdk = 34
versionCode = 84
versionName = "2.3.3"
versionCode = 85
versionName = gitCommitHash()
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
resourceConfigurations.addAll(listOf("en", "fr", "de", "es", "b+es+419", "cs", "pt-rBR", "sk", "vi"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ fun AppView(
// we keep a view model storing payments so that we don't have to fetch them every time
val paymentsViewModel = viewModel<PaymentsViewModel>(
factory = PaymentsViewModel.Factory(
connectionsFlow = business.connectionsManager.connections,
paymentsManager = business.paymentsManager,
contactsManager = business.contactsManager,
)
)
val noticesViewModel = viewModel<NoticesViewModel>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ package fr.acinq.phoenix.android
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import fr.acinq.lightning.db.IncomingPayment
import fr.acinq.lightning.db.LightningOutgoingPayment
import fr.acinq.lightning.payment.OfferPaymentMetadata
import fr.acinq.phoenix.data.ContactInfo
import fr.acinq.phoenix.data.WalletPaymentFetchOptions
import fr.acinq.phoenix.data.WalletPaymentId
import fr.acinq.phoenix.data.WalletPaymentInfo
import fr.acinq.phoenix.data.walletPaymentId
import fr.acinq.phoenix.db.WalletPaymentOrderRow
import fr.acinq.phoenix.managers.Connections
import fr.acinq.phoenix.managers.ContactsManager
import fr.acinq.phoenix.managers.PaymentsManager
import fr.acinq.phoenix.managers.PaymentsPageFetcher
import kotlinx.coroutines.CoroutineExceptionHandler
Expand All @@ -36,13 +41,14 @@ import org.slf4j.LoggerFactory

data class PaymentRowState(
val orderRow: WalletPaymentOrderRow,
val paymentInfo: WalletPaymentInfo?
val paymentInfo: WalletPaymentInfo?,
val contactInfo: ContactInfo?,
)

@OptIn(ExperimentalCoroutinesApi::class)
class PaymentsViewModel(
val connectionsFlow: StateFlow<Connections>,
private val paymentsManager: PaymentsManager,
private val contactsManager: ContactsManager,
) : ViewModel() {

companion object {
Expand Down Expand Up @@ -97,7 +103,7 @@ class PaymentsViewModel(

// collect changes on the payments page that we subscribed to
viewModelScope.launch(CoroutineExceptionHandler { _, e ->
log.error("failed to collect all payments page items: ", e)
log.error("error when collecting payments-page items: ", e)
}) {
paymentsPageFetcher.paymentsPage.collect { page ->
viewModelScope.launch(Dispatchers.Default) {
Expand All @@ -108,7 +114,7 @@ class PaymentsViewModel(
val existingData = paymentsFlow.value[paymentId]
// We look at the row to check if the payment has changed (the row contains timestamps)
if (existingData?.orderRow != newRow) {
paymentId to PaymentRowState(newRow, null)
paymentId to PaymentRowState(newRow, paymentInfo = null, contactInfo = null)
} else {
paymentId to existingData
}
Expand All @@ -122,8 +128,26 @@ class PaymentsViewModel(
fun fetchPaymentDetails(row: WalletPaymentOrderRow) {
viewModelScope.launch(Dispatchers.Main) {
val paymentInfo = paymentsManager.fetcher.getPayment(row, WalletPaymentFetchOptions.Descriptions)
val contactInfo = when (val payment = paymentInfo?.payment) {
is IncomingPayment -> {
val origin = payment.origin
if (origin is IncomingPayment.Origin.Offer) {
val metadata = origin.metadata
if (metadata is OfferPaymentMetadata.V1) {
contactsManager.getContactForPayerPubkey(metadata.payerKey)
} else null
} else null
}
is LightningOutgoingPayment -> {
val details = payment.details
if (details is LightningOutgoingPayment.Details.Blinded) {
contactsManager.getContactForOffer(details.paymentRequest.invoiceRequest.offer)
} else null
}
else -> null
}
if (paymentInfo != null) {
_paymentsFlow.value += (row.id.identifier to PaymentRowState(row, paymentInfo))
_paymentsFlow.value += (row.id.identifier to PaymentRowState(row, paymentInfo, contactInfo))
}
}
}
Expand All @@ -134,12 +158,12 @@ class PaymentsViewModel(
}

class Factory(
private val connectionsFlow: StateFlow<Connections>,
private val paymentsManager: PaymentsManager,
private val contactsManager: ContactsManager,
) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
@Suppress("UNCHECKED_CAST")
return PaymentsViewModel(connectionsFlow, paymentsManager) as T
return PaymentsViewModel(paymentsManager, contactsManager) as T
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@ package fr.acinq.phoenix.android.components
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.clipScrollableContainer
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.sizeIn
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
Expand All @@ -29,6 +25,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.PathEffect
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.layout.FirstBaseline
import androidx.compose.ui.layout.Placeable
Expand Down Expand Up @@ -141,7 +138,8 @@ fun AmountHeroInput(
),
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus(); keyboardController?.hide() }),
singleLine = true,
enabled = enabled
enabled = enabled,
cursorBrush = SolidColor(MaterialTheme.colors.primary.copy(alpha = 0.7f))
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fun BorderButton(
onClick = onClick,
shape = shape,
backgroundColor = backgroundColor,
border = BorderStroke(ButtonDefaults.OutlinedBorderSize, if (enabled) borderColor else borderColor.copy(alpha = 0.4f)),
border = BorderStroke(ButtonDefaults.OutlinedBorderSize, if (enabled) borderColor else borderColor.copy(alpha = 0.35f)),
textStyle = textStyle,
padding = padding,
maxLines = maxLines,
Expand Down Expand Up @@ -309,7 +309,7 @@ fun Button(
.padding(padding)
.alpha(
if (!enabled && enabledEffect) {
if (backgroundColor == Color.Unspecified) 0.3f else 0.8f
if (backgroundColor == Color.Unspecified) 0.3f else 0.65f
} else {
1f
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ fun TextInput(
onTextChange: (String) -> Unit,
textFieldColors: TextFieldColors = outlinedTextFieldColors(),
showResetButton: Boolean = true,
keyboardType: KeyboardType = KeyboardType.Text
) {
val charsCount by remember(text) { mutableStateOf(text.length) }
val focusManager = LocalFocusManager.current
Expand All @@ -81,7 +82,7 @@ fun TextInput(
singleLine = singleLine,
keyboardOptions = KeyboardOptions.Default.copy(
imeAction = ImeAction.Done,
keyboardType = KeyboardType.Text
keyboardType = keyboardType
),
label = null,
placeholder = placeholder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import androidx.compose.material.Text
import androidx.compose.material.ripple.rememberRipple
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.text.TextStyle
Expand Down Expand Up @@ -59,12 +58,11 @@ fun SwitchView(
internalChecked = !internalChecked
onCheckedChange(internalChecked)
}
.padding(vertical = 6.dp),
) {
Column(
modifier = Modifier
.weight(1f)
.padding(end = 16.dp)
.padding(top = 6.dp, bottom = 6.dp, end = 16.dp)
) {
Text(text = text, style = textStyle)
if (description != null) {
Expand All @@ -77,6 +75,7 @@ fun SwitchView(
onCheckedChange = null,
modifier = Modifier
.enableOrFade(enabled)
.offset(y = 4.dp)
.indication(
interactionSource = interactionSource,
indication = rememberRipple(bounded = false, color = if (isDarkTheme) gray300 else gray600, radius = 28.dp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,9 @@

package fr.acinq.phoenix.android.components.contact

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
Expand All @@ -36,7 +30,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import fr.acinq.lightning.wire.OfferTypes
import fr.acinq.phoenix.android.components.Clickable
import fr.acinq.phoenix.android.components.SplashClickableContent
import fr.acinq.phoenix.data.ContactInfo

Expand Down
Loading

0 comments on commit 5ba07a8

Please sign in to comment.