@@ -18,8 +18,10 @@ package fr.acinq.phoenix.android.home
18
18
19
19
import androidx.compose.foundation.clickable
20
20
import androidx.compose.foundation.layout.Column
21
+ import androidx.compose.foundation.layout.PaddingValues
21
22
import androidx.compose.foundation.layout.Row
22
23
import androidx.compose.foundation.layout.Spacer
24
+ import androidx.compose.foundation.layout.fillMaxWidth
23
25
import androidx.compose.foundation.layout.height
24
26
import androidx.compose.foundation.layout.padding
25
27
import androidx.compose.foundation.layout.size
@@ -30,24 +32,27 @@ import androidx.compose.material.Surface
30
32
import androidx.compose.material.Text
31
33
import androidx.compose.runtime.Composable
32
34
import androidx.compose.runtime.collectAsState
35
+ import androidx.compose.runtime.getValue
33
36
import androidx.compose.ui.Alignment
34
37
import androidx.compose.ui.Modifier
35
38
import androidx.compose.ui.res.stringResource
36
39
import androidx.compose.ui.semantics.Role
37
40
import androidx.compose.ui.unit.dp
38
- import androidx.compose.ui.unit.sp
39
41
import fr.acinq.lightning.utils.Connection
40
42
import fr.acinq.phoenix.android.R
43
+ import fr.acinq.phoenix.android.components.Card
41
44
import fr.acinq.phoenix.android.components.Dialog
42
45
import fr.acinq.phoenix.android.components.HSeparator
43
46
import fr.acinq.phoenix.android.components.TextWithIcon
44
47
import fr.acinq.phoenix.android.userPrefs
45
48
import fr.acinq.phoenix.android.utils.extensions.isBadCertificate
46
49
import fr.acinq.phoenix.android.utils.monoTypo
50
+ import fr.acinq.phoenix.android.utils.mutedBgColor
47
51
import fr.acinq.phoenix.android.utils.negativeColor
48
52
import fr.acinq.phoenix.android.utils.orange
49
53
import fr.acinq.phoenix.android.utils.positiveColor
50
54
import fr.acinq.phoenix.managers.Connections
55
+ import fr.acinq.phoenix.utils.extensions.isOnion
51
56
52
57
53
58
@Composable
@@ -66,52 +71,45 @@ fun ConnectionDialog(
66
71
modifier = Modifier .padding(top = 16 .dp, start = 24 .dp, end = 24 .dp)
67
72
)
68
73
} else {
69
- if (connections.electrum != Connection .ESTABLISHED || connections.peer != Connection .ESTABLISHED ) {
74
+ val hasConnectionIssues = connections.electrum != Connection .ESTABLISHED || connections.peer != Connection .ESTABLISHED
75
+ if (hasConnectionIssues) {
70
76
Text (text = stringResource(id = R .string.conndialog_summary_not_ok), Modifier .padding(horizontal = 24 .dp))
71
77
}
72
- Spacer (modifier = Modifier .height(24 .dp))
78
+ Spacer (modifier = Modifier .height(16 .dp))
73
79
HSeparator ()
74
-
75
- val isTorEnabled = userPrefs.getIsTorEnabled.collectAsState(initial = null ).value
76
- if (isTorEnabled != null && isTorEnabled) {
77
- ConnectionDialogLine (label = stringResource(id = R .string.conndialog_tor), connection = connections.tor, onClick = onTorClick)
78
- HSeparator ()
79
- }
80
-
81
80
ConnectionDialogLine (label = stringResource(id = R .string.conndialog_electrum), connection = connections.electrum, onClick = onElectrumClick) {
82
81
when (val connection = connections.electrum) {
83
82
Connection .ESTABLISHING -> {
84
83
Text (text = stringResource(R .string.conndialog_connecting), style = monoTypo)
85
84
}
86
85
Connection .ESTABLISHED -> {
87
- Column {
88
- Text (text = stringResource(R .string.conndialog_connected), style = monoTypo)
89
- if (electrumBlockheight < 795_000 ) { // FIXME use a dynamic blockheight
90
- TextWithIcon (
91
- text = stringResource(id = R .string.conndialog_connected_electrum_behind, electrumBlockheight),
92
- textStyle = MaterialTheme .typography.body1.copy(fontSize = 14 .sp),
93
- icon = R .drawable.ic_alert_triangle,
94
- iconTint = negativeColor
95
- )
96
- }
97
- }
86
+ Text (text = stringResource(R .string.conndialog_connected), style = monoTypo)
98
87
}
99
88
else -> {
100
- Text (
101
- text = if (connection is Connection . CLOSED && connection.isBadCertificate() ) {
102
- stringResource(R .string.conndialog_closed_bad_cert )
103
- } else {
104
- stringResource(R .string.conndialog_closed )
105
- },
106
- style = monoTypo
107
- )
89
+ val customElectrumServer by userPrefs.getElectrumServer.collectAsState(initial = null )
90
+ if (customElectrumServer?.isOnion == false ) {
91
+ TextWithIcon (text = stringResource(R .string.conndialog_electrum_not_onion), textStyle = monoTypo, icon = R .drawable.ic_alert_triangle, iconTint = negativeColor )
92
+ } else if (connection is Connection . CLOSED && connection.isBadCertificate()) {
93
+ TextWithIcon (text = stringResource(R .string.conndialog_closed_bad_cert), textStyle = monoTypo, icon = R .drawable.ic_alert_triangle, iconTint = negativeColor )
94
+ } else {
95
+ Text (text = stringResource( R .string.conndialog_closed), style = monoTypo)
96
+ }
108
97
}
109
98
}
110
99
}
111
100
HSeparator ()
112
101
ConnectionDialogLine (label = stringResource(id = R .string.conndialog_lightning), connection = connections.peer)
113
102
HSeparator ()
114
103
Spacer (Modifier .height(16 .dp))
104
+
105
+ val isTorEnabled = userPrefs.getIsTorEnabled.collectAsState(initial = null ).value
106
+ if (hasConnectionIssues && isTorEnabled == true ) {
107
+ Card (backgroundColor = mutedBgColor, modifier = Modifier .fillMaxWidth(), internalPadding = PaddingValues (horizontal = 16 .dp, vertical = 12 .dp), onClick = onTorClick) {
108
+ TextWithIcon (text = stringResource(id = R .string.conndialog_tor_disclaimer_title), icon = R .drawable.ic_tor_shield, textStyle = MaterialTheme .typography.body2)
109
+ Spacer (modifier = Modifier .height(4 .dp))
110
+ Text (text = stringResource(id = R .string.conndialog_tor_disclaimer_body))
111
+ }
112
+ }
115
113
}
116
114
}
117
115
}
@@ -147,7 +145,7 @@ private fun ConnectionDialogLine(
147
145
.then(
148
146
if (onClick != null ) Modifier .clickable(role = Role .Button , onClickLabel = stringResource(id = R .string.conndialog_accessibility_desc, label), onClick = onClick) else Modifier
149
147
)
150
- .padding(vertical = 12 .dp, horizontal = 24 .dp),
148
+ .padding(vertical = 16 .dp, horizontal = 24 .dp),
151
149
verticalAlignment = Alignment .CenterVertically
152
150
) {
153
151
Surface (
@@ -161,6 +159,7 @@ private fun ConnectionDialogLine(
161
159
) {}
162
160
Spacer (modifier = Modifier .width(16 .dp))
163
161
Text (text = label, modifier = Modifier .weight(1.0f ))
162
+ Spacer (modifier = Modifier .width(24 .dp))
164
163
content()
165
164
}
166
165
}
0 commit comments