Skip to content

Commit 1f450bd

Browse files
committed
Merge branch 'master' into mainnet
2 parents b28924f + 3959b12 commit 1f450bd

File tree

6 files changed

+45
-29
lines changed

6 files changed

+45
-29
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ dependencies {
132132

133133
// eclair core
134134
def libsecp256k1_version = "1.3"
135-
def eclair_version = "0.3.5-android-phoenix"
135+
def eclair_version = "0.3.6-android-phoenix-RC1"
136136
implementation "fr.acinq.bitcoin:secp256k1-jni:$libsecp256k1_version"
137137
implementation("fr.acinq.eclair:eclair-core_2.11:$eclair_version") {
138138
exclude group: 'fr.acinq.bitcoin', module: 'secp256k1-jni'

app/src/main/java/fr/acinq/phoenix/MainActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class MainActivity : AppCompatActivity() {
9797
handleNetworkAlert()
9898
})
9999
appKit.navigationEvent.observe(this, Observer {
100+
log.info("navigation event @ $it")
100101
when (it) {
101102
is PayToOpenRequestEvent -> {
102103
val action = ReceiveWithOpenDialogFragmentDirections.globalActionAnyToReceiveWithOpen(

app/src/main/java/fr/acinq/phoenix/receive/ReceiveWithOpenDialogFragment.kt

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ package fr.acinq.phoenix.receive
1818

1919
import android.content.DialogInterface
2020
import android.os.Bundle
21-
import android.os.CountDownTimer
2221
import android.text.Html
2322
import android.view.LayoutInflater
2423
import android.view.View
2524
import android.view.ViewGroup
2625
import androidx.activity.addCallback
2726
import androidx.fragment.app.DialogFragment
2827
import androidx.lifecycle.MutableLiveData
28+
import androidx.lifecycle.Observer
2929
import androidx.lifecycle.ViewModel
3030
import androidx.lifecycle.ViewModelProvider
3131
import androidx.navigation.fragment.navArgs
@@ -38,6 +38,8 @@ import fr.acinq.phoenix.databinding.FragmentReceiveWithOpenBinding
3838
import fr.acinq.phoenix.utils.Converter
3939
import org.slf4j.Logger
4040
import org.slf4j.LoggerFactory
41+
import java.util.*
42+
import kotlin.math.max
4143

4244

4345
open class ReceiveWithOpenDialogFragment : DialogFragment() {
@@ -64,6 +66,14 @@ open class ReceiveWithOpenDialogFragment : DialogFragment() {
6466
model = ViewModelProvider(this).get(ReceiveWithOpenViewModel::class.java)
6567
mBinding.model = model
6668

69+
model.timeToExpiry.observe(viewLifecycleOwner, Observer {
70+
mBinding.acceptButton.setText(getString(R.string.receive_with_open_accept, max(it / 1000, 0).toString()))
71+
if (it <= 0) {
72+
log.info("pay to open with payment_hash=${args.paymentHash} has expired and is declined")
73+
appKit.rejectPayToOpen(ByteVector32.fromValidHex(args.paymentHash))
74+
}
75+
})
76+
6777
activity?.onBackPressedDispatcher?.addCallback(this) {
6878
log.debug("back pressed disabled here")
6979
}
@@ -72,18 +82,6 @@ open class ReceiveWithOpenDialogFragment : DialogFragment() {
7282

7383
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
7484
super.onViewCreated(view, savedInstanceState)
75-
object : CountDownTimer(30000, 1000) {
76-
override fun onTick(millisUntilFinished: Long) {
77-
mBinding.acceptButton.setText(getString(R.string.receive_with_open_accept, millisUntilFinished / 1000))
78-
}
79-
80-
override fun onFinish() {
81-
log.info("pay to open with payment_hash=${args.paymentHash} has expired and is declined")
82-
model.hasExpired.value = true
83-
appKit.rejectPayToOpen(ByteVector32.fromValidHex(args.paymentHash))
84-
}
85-
}.start()
86-
8785
context?.let {
8886
mBinding.amountValue.text = Converter.printAmountPretty(MilliSatoshi(args.amountMsat), it, withUnit = true)
8987
mBinding.amountFiat.text = Converter.html(getString(R.string.utils_converted_amount, Converter.printFiatPretty(it, MilliSatoshi(args.amountMsat), withUnit = true)))
@@ -117,15 +115,32 @@ open class ReceiveWithOpenDialogFragment : DialogFragment() {
117115
appKit.rejectPayToOpen(ByteVector32.fromValidHex(args.paymentHash))
118116
super.onCancel(dialog)
119117
}
120-
121-
override fun onDismiss(dialog: DialogInterface) {
122-
super.onDismiss(dialog)
123-
}
124118
}
125119

126120
class ReceiveWithOpenViewModel : ViewModel() {
127-
private val log = LoggerFactory.getLogger(ReceiveWithOpenViewModel::class.java)
121+
companion object {
122+
private const val DEFAULT_TIMEOUT_MILLIS = 30000
123+
}
128124

125+
private val log = LoggerFactory.getLogger(ReceiveWithOpenViewModel::class.java)
126+
private val timer: Timer = Timer()
129127
val showHelp = MutableLiveData(false)
130-
val hasExpired = MutableLiveData(false)
128+
129+
// FIXME: this value should be initialized using an absolute / server defined timestamp in the PayToOpenRequest (not implemented yet).
130+
val timeToExpiry = MutableLiveData(DEFAULT_TIMEOUT_MILLIS)
131+
132+
init {
133+
timer.schedule(object : TimerTask() {
134+
override fun run() {
135+
timeToExpiry.value?.let {
136+
timeToExpiry.postValue(max(0, it - 1000))
137+
}
138+
}
139+
}, 0, 1000)
140+
}
141+
142+
override fun onCleared() {
143+
super.onCleared()
144+
timer.cancel()
145+
}
131146
}

app/src/main/java/fr/acinq/phoenix/utils/Logging.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ object Logging {
5757
lc.getLogger("io.netty").level = if (BuildConfig.DEBUG) Level.INFO else Level.WARN
5858

5959
val root = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME) as Logger
60-
root.level = Level.DEBUG
60+
root.level = if (BuildConfig.DEBUG) Level.DEBUG else Level.INFO
6161
root.addAppender(logcatAppender)
6262
root.addAppender(localFileAppender)
6363
}

app/src/main/res/layout/fragment_receive_with_open.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
android:layout_marginEnd="@dimen/space_lg"
154154
android:text="@string/receive_with_open_cost"
155155
android:textAlignment="center"
156-
android:visibility="@{!model.hasExpired}"
156+
android:visibility="@{model.timeToExpiry &gt; 0}"
157157
app:layout_constrainedWidth="true"
158158
app:layout_constraintEnd_toEndOf="parent"
159159
app:layout_constraintStart_toStartOf="parent"
@@ -175,7 +175,7 @@
175175
android:padding="@dimen/space_sm"
176176
android:text="@string/receive_with_open_expired"
177177
android:textAlignment="center"
178-
android:visibility="@{model.hasExpired}"
178+
android:visibility="@{model.timeToExpiry &lt;= 0}"
179179
app:layout_constrainedWidth="true"
180180
app:layout_constraintEnd_toEndOf="parent"
181181
app:layout_constraintStart_toStartOf="parent"
@@ -186,7 +186,7 @@
186186
android:layout_width="match_parent"
187187
android:layout_height="wrap_content"
188188
android:background="@drawable/button_bg_square"
189-
android:visibility="@{!model.hasExpired}"
189+
android:visibility="@{model.timeToExpiry &gt; 0}"
190190
app:icon="@drawable/ic_check_circle"
191191
app:icon_tint="?attr/positiveColor"
192192
app:layout_constraintTop_toBottomOf="@id/expired"
@@ -205,7 +205,7 @@
205205
android:layout_height="wrap_content"
206206
android:background="@drawable/button_bg_square"
207207
android:textAlignment="center"
208-
android:visibility="@{model.hasExpired}"
208+
android:visibility="@{model.timeToExpiry &lt;= 0}"
209209
app:icon="@drawable/ic_cross_circle"
210210
app:layout_constraintTop_toBottomOf="@id/decline_separator"
211211
app:text="@string/btn_close" />
@@ -215,7 +215,7 @@
215215
android:layout_width="match_parent"
216216
android:layout_height="wrap_content"
217217
android:background="@drawable/button_bg_square"
218-
android:visibility="@{!model.hasExpired}"
218+
android:visibility="@{model.timeToExpiry &gt; 0}"
219219
app:icon="@drawable/ic_cross_circle"
220220
app:layout_constraintTop_toBottomOf="@id/decline_separator"
221221
app:text="@string/receive_with_open_decline" />

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@
129129
<string name="receive_with_open_help">In order to receive payments on Lightning, you need to have a channel with enough inbound liquidity.\n\nIf you don\'t have one, Phoenix will automatically create a channel on-the-fly as needed. The setup fee covers the cost of creating the channel and allocating liquidity to it.</string>
130130
<string name="receive_with_open_amount_label">You have a pending incoming payment of</string>
131131
<string name="receive_with_open_cost"><![CDATA[Accepting this payment requires a setup fee of <b>%1$s</b> (%2$s).]]></string>
132-
<string name="receive_with_open_accept">Accept (expires in %1$ds)</string>
132+
<string name="receive_with_open_accept">Accept (expires in %1$ss)</string>
133133
<string name="receive_with_open_decline">Decline</string>
134-
<string name="receive_with_open_expired">Request has expired!</string>
134+
<string name="receive_with_open_expired">This payment has expired!</string>
135135

136136
<!-- //////////////// send //////////////// -->
137137

@@ -307,7 +307,7 @@
307307
<string name="inappnotif_mnemonics_never_seen">Thanks for using Phoenix. Have you made a backup of your wallet?</string>
308308
<string name="inappnotif_mnemonics_never_seen_action">Backup my wallet</string>
309309
<string name="inappnotif_background_worker_cannot_run">Phoenix needs to be able to run in background from time to time. Make sure your device does not aggressively kill this app for battery savings.</string>
310-
<string name="inappnotif_upgrade">A new version of the wallet is available.</string>
310+
<string name="inappnotif_upgrade">An update for this app is available.</string>
311311
<string name="inappnotif_upgrade_critical">A critical update is available. The wallet may malfunction if not updated.</string>
312312

313313
<!-- //////////////// display seed //////////////// -->

0 commit comments

Comments
 (0)