Skip to content

Commit 56fbe17

Browse files
dpad85robbiehanson
andauthored
Add logic to show or hide the manual liquidity button (#757)
The wallet-context resource now contains a boolean to enable or disable manual liquidity. If disabled, the request liquidity button is hidden in the UI. Also fixed a few issues with the `PhoenixGlobal` jobs. --------- Co-authored-by: Robbie Hanson <[email protected]>
1 parent 5f9824f commit 56fbe17

File tree

13 files changed

+118
-40
lines changed

13 files changed

+118
-40
lines changed

phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/PhoenixApplication.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ class PhoenixApplication : Application() {
4141

4242
override fun onCreate() {
4343
super.onCreate()
44+
Logging.setupLogger(applicationContext)
4445

4546
phoenixGlobal = PhoenixGlobal(PlatformContext(applicationContext))
4647
globalPrefs = GlobalPrefs(applicationContext.globalPrefs)
4748
BusinessManager.initialize(applicationContext)
4849

49-
Logging.setupLogger(applicationContext)
5050
log.info("creating app")
5151
SystemNotificationHelper.registerNotificationChannels(applicationContext)
5252
}

phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/home/HomeView.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ fun HomeView(
219219
val balance by business.balanceManager.balance.collectAsState()
220220
val notices = noticesViewModel.notices
221221
val notifications by business.notificationsManager.notifications.collectAsState(emptyList())
222+
val walletContext by application.phoenixGlobal.walletContextManager.walletContext.collectAsState()
222223

223224
Column(modifier = Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
224225
MotionLayout(
@@ -238,7 +239,7 @@ fun HomeView(
238239
onTorClick = onTorClick,
239240
isFCMUnavailable = fcmTokenFlow.value == null || !isFCMAvailable,
240241
isPowerSaverMode = isPowerSaverModeOn,
241-
showRequestLiquidity = channels.canRequestLiquidity(),
242+
showRequestLiquidity = walletContext?.isManualLiquidityEnabled == true && channels.canRequestLiquidity(),
242243
onRequestLiquidityClick = onRequestLiquidityClick,
243244
)
244245
HomeBalance(

phoenix-android/src/main/kotlin/fr/acinq/phoenix/android/settings/SettingsMenuView.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import fr.acinq.phoenix.android.Notice
4747
import fr.acinq.phoenix.android.R
4848
import fr.acinq.phoenix.android.UserWallet
4949
import fr.acinq.phoenix.android.WalletId
50+
import fr.acinq.phoenix.android.application
5051
import fr.acinq.phoenix.android.components.ProgressView
5152
import fr.acinq.phoenix.android.components.buttons.FilledButton
5253
import fr.acinq.phoenix.android.components.buttons.MenuButton
@@ -110,7 +111,8 @@ fun SettingsView(
110111
Card {
111112
MenuButton(text = stringResource(R.string.settings_liquidity_policy), icon = R.drawable.ic_wand, onClick = { nc.navigate(Screen.BusinessNavGraph.LiquidityPolicy.route) })
112113
val channelsState = business.peerManager.channelsFlow.collectAsState()
113-
if (channelsState.value?.canRequestLiquidity() == true) {
114+
val walletContext by application.phoenixGlobal.walletContextManager.walletContext.collectAsState()
115+
if (channelsState.value?.canRequestLiquidity() == true && walletContext?.isManualLiquidityEnabled == true) {
114116
MenuButton(text = stringResource(R.string.settings_add_liquidity), icon = R.drawable.ic_bucket, onClick = { nc.navigate(Screen.BusinessNavGraph.LiquidityRequest.route) })
115117
}
116118
}

phoenix-ios/phoenix-ios.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@
345345
DCA7263D2C80BC0800600716 /* SyncBackupManager+Contacts.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCA7263C2C80BC0800600716 /* SyncBackupManager+Contacts.swift */; };
346346
DCA849E02813311D000FADE1 /* aes256Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCA849DF2813311D000FADE1 /* aes256Tests.swift */; };
347347
DCA849E2281333EB000FADE1 /* currencyFormattingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCA849E1281333EB000FADE1 /* currencyFormattingTests.swift */; };
348+
DCAB8C332E9EA89A0075462A /* Array+IsNotEmpty.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCAB8C322E9EA8950075462A /* Array+IsNotEmpty.swift */; };
348349
DCAC5B7027726FC80077BB98 /* DeepLink.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCAC5B6F27726FC80077BB98 /* DeepLink.swift */; };
349350
DCACF6F02566D0A60009B01E /* Data+Hexadecimal.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCACF6EF2566D0A60009B01E /* Data+Hexadecimal.swift */; };
350351
DCACF6FA2566D0BA0009B01E /* KeyStoreError.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCACF6F52566D0BA0009B01E /* KeyStoreError.swift */; };
@@ -806,6 +807,7 @@
806807
DCA7263C2C80BC0800600716 /* SyncBackupManager+Contacts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SyncBackupManager+Contacts.swift"; sourceTree = "<group>"; };
807808
DCA849DF2813311D000FADE1 /* aes256Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = aes256Tests.swift; sourceTree = "<group>"; };
808809
DCA849E1281333EB000FADE1 /* currencyFormattingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = currencyFormattingTests.swift; sourceTree = "<group>"; };
810+
DCAB8C322E9EA8950075462A /* Array+IsNotEmpty.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Array+IsNotEmpty.swift"; sourceTree = "<group>"; };
809811
DCAC5B6F27726FC80077BB98 /* DeepLink.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeepLink.swift; sourceTree = "<group>"; };
810812
DCACF6EF2566D0A60009B01E /* Data+Hexadecimal.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Data+Hexadecimal.swift"; sourceTree = "<group>"; };
811813
DCACF6F52566D0BA0009B01E /* KeyStoreError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyStoreError.swift; sourceTree = "<group>"; };
@@ -1611,6 +1613,7 @@
16111613
DCACF6EE2566D0A60009B01E /* extensions */ = {
16121614
isa = PBXGroup;
16131615
children = (
1616+
DCAB8C322E9EA8950075462A /* Array+IsNotEmpty.swift */,
16141617
DC5895C92E551A4E00CBCCF9 /* AnyAsyncSequence.swift */,
16151618
DC2CE3AE29AFEB0500BA0B00 /* Bundle+Icon.swift */,
16161619
DCEE3E532931446A00EB4DFF /* Collections+AsInt.swift */,
@@ -2197,6 +2200,7 @@
21972200
DC1844032A2690BB004D9578 /* MinerFeeSheet.swift in Sources */,
21982201
DC39A2662A12C04D00F59E39 /* LiquidityPolicyHelp.swift in Sources */,
21992202
DC49FE9B2AC49CB500D8D2E2 /* KotlinExtensions+Lightning.swift in Sources */,
2203+
DCAB8C332E9EA89A0075462A /* Array+IsNotEmpty.swift in Sources */,
22002204
DCACF6FA2566D0BA0009B01E /* KeyStoreError.swift in Sources */,
22012205
DC0E31BB26EFDED4002071C6 /* VSlider.swift in Sources */,
22022206
DC370A892B7FBD7C0093C56F /* BtcAddrOptionsSheet.swift in Sources */,

phoenix-ios/phoenix-ios/Localizable.xcstrings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24519,6 +24519,9 @@
2451924519
},
2452024520
"Liquidity" : {
2452124521

24522+
},
24523+
"Liquidity not currently available, try again later" : {
24524+
2452224525
},
2452324526
"Liquidity requested" : {
2452424527
"localizations" : {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Foundation
2+
3+
extension Array {
4+
5+
/// Why does this not already exist
6+
var isNotEmpty: Bool {
7+
return !self.isEmpty
8+
}
9+
}

phoenix-ios/phoenix-ios/views/configuration/fees/liquidity management/LiquidityAdsView.swift

Lines changed: 55 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ struct LiquidityAdsView: View {
2929
@State var isEstimating: Bool = false
3030
@State var isPurchasing: Bool = false
3131
@State var isPurchased: Bool = false
32-
@State var channelsNotAvailable: Bool = false
3332
@State var iUnderstand: Bool = false
3433

34+
@State var channelsNotAvailable: Bool = false
35+
@State var liquidityNotAvailable: Bool = false
36+
3537
@State var showHelpSheet = false
3638

3739
@State var popoverPresent_minerFee = false
@@ -63,12 +65,18 @@ struct LiquidityAdsView: View {
6365
@ViewBuilder
6466
var body: some View {
6567

68+
main()
69+
.navigationTitle("Add Liquidity")
70+
.navigationBarTitleDisplayMode(.inline)
71+
}
72+
73+
@ViewBuilder
74+
func main() -> some View {
75+
6676
VStack(alignment: HorizontalAlignment.center, spacing: 0) {
6777
header()
6878
content()
6979
}
70-
.navigationTitle("Add Liquidity")
71-
.navigationBarTitleDisplayMode(.inline)
7280
.toolbar {
7381
ToolbarItem(placement: .navigationBarTrailing) {
7482
Button {
@@ -81,6 +89,24 @@ struct LiquidityAdsView: View {
8189
.sheet(isPresented: $showHelpSheet) {
8290
LiquidityAdsHelp(isShowing: $showHelpSheet)
8391
}
92+
.task {
93+
for await newValue in Biz.business.peerManager.channelsArraySequence() {
94+
channelsChanged(newValue)
95+
}
96+
}
97+
.task {
98+
for await context in BizGlobal.walletContextManager.walletContextSequence() {
99+
walletContextChanged(context)
100+
}
101+
}
102+
.task {
103+
for await newValue in Biz.business.balanceManager.balanceSequence() {
104+
balanceChanged(newValue)
105+
}
106+
}
107+
.task {
108+
await fetchMempoolRecommendedFees()
109+
}
84110
}
85111

86112
@ViewBuilder
@@ -133,19 +159,6 @@ struct LiquidityAdsView: View {
133159
}
134160
.listStyle(.insetGrouped)
135161
.listBackgroundColor(.primaryBackground)
136-
.task {
137-
for await newValue in Biz.business.peerManager.channelsArraySequence() {
138-
channelsChanged(newValue)
139-
}
140-
}
141-
.task {
142-
for await newValue in Biz.business.balanceManager.balanceSequence() {
143-
balanceChanged(newValue)
144-
}
145-
}
146-
.task {
147-
await fetchMempoolRecommendedFees()
148-
}
149162
}
150163

151164
@ViewBuilder
@@ -271,10 +284,17 @@ struct LiquidityAdsView: View {
271284
}
272285
}
273286
.font(.headline)
274-
.disabled(isEstimating)
287+
.disabled(isEstimating || channelsNotAvailable || liquidityNotAvailable)
275288

276289
if channelsNotAvailable {
277290
Text("Channels are not available, try again later")
291+
.multilineTextAlignment(.center)
292+
.font(.callout)
293+
.foregroundColor(.appNegative)
294+
295+
} else if liquidityNotAvailable {
296+
Text("Liquidity not currently available, try again later")
297+
.multilineTextAlignment(.center)
278298
.font(.callout)
279299
.foregroundColor(.appNegative)
280300
}
@@ -753,20 +773,28 @@ struct LiquidityAdsView: View {
753773
// MARK: Notifications
754774
// --------------------------------------------------
755775

756-
func channelsChanged(_ newValue: [LocalChannelInfo]) {
757-
log.trace("channelsChanged()")
776+
func channelsChanged(_ newChannels: [LocalChannelInfo]) {
777+
log.trace(#function)
758778

759-
channels = newValue
779+
channels = newChannels
780+
if channelsNotAvailable {
781+
if channels.filter({ !$0.isTerminated }).isNotEmpty {
782+
// Channels may now be available; Flip flag so user can try again.
783+
channelsNotAvailable = false
784+
}
785+
}
760786
}
761787

762-
func balanceChanged(_ balance: Lightning_kmpMilliSatoshi?) {
763-
log.trace("balanceDidChange()")
788+
func walletContextChanged(_ context: WalletContext) {
789+
log.trace(#function)
764790

765-
if let balance = balance {
766-
balanceMsat = balance.msat
767-
} else {
768-
balanceMsat = nil
769-
}
791+
liquidityNotAvailable = (context.isManualLiquidityEnabled == false)
792+
}
793+
794+
func balanceChanged(_ newBalance: Lightning_kmpMilliSatoshi?) {
795+
log.trace(#function)
796+
797+
balanceMsat = newBalance?.msat
770798
}
771799

772800
// --------------------------------------------------

phoenix-ios/phoenix-ios/views/main/HomeView.swift

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct HomeView : MVIView {
3838
@State var finalWallet = Biz.business.peerManager.finalWalletValue()
3939

4040
@State var channels: [LocalChannelInfo] = []
41+
@State var walletContext: WalletContext? = nil
4142

4243
let incomingSwapScaleFactor_BIG: CGFloat = 1.2
4344
@State var incomingSwapScaleFactor: CGFloat = 1.0
@@ -149,6 +150,11 @@ struct HomeView : MVIView {
149150
channelsChanged(newChannels)
150151
}
151152
}
153+
.task {
154+
for await context in BizGlobal.walletContextManager.walletContextSequence() {
155+
walletContextChanged(context)
156+
}
157+
}
152158
.task {
153159
for await notifications in Biz.business.notificationsManager.notificationsSequence() {
154160
bizNotificationsChanged(notifications)
@@ -759,7 +765,7 @@ struct HomeView : MVIView {
759765
return false
760766
}
761767

762-
return true
768+
return walletContext?.isManualLiquidityEnabled ?? false
763769
}
764770

765771
// --------------------------------------------------
@@ -871,7 +877,7 @@ struct HomeView : MVIView {
871877
}
872878

873879
func swapInWalletChanged(_ newWallet: Lightning_kmpWalletState.WalletWithConfirmations) {
874-
log.trace("swapInWalletChanged()")
880+
log.trace(#function)
875881

876882
let oldBalance = swapInWallet.totalBalance.sat
877883
let newBalance = newWallet.totalBalance.sat
@@ -886,17 +892,23 @@ struct HomeView : MVIView {
886892
}
887893

888894
func finalWalletChanged(_ newValue: Lightning_kmpWalletState.WalletWithConfirmations) {
889-
log.trace("finalWalletChanged()")
895+
log.trace(#function)
890896

891897
finalWallet = newValue
892898
}
893899

894900
func channelsChanged(_ channels: [LocalChannelInfo]) {
895-
log.trace("channelsChanged()")
901+
log.trace(#function)
896902

897903
self.channels = channels
898904
}
899905

906+
func walletContextChanged(_ context: WalletContext) {
907+
log.trace(#function)
908+
909+
self.walletContext = context
910+
}
911+
900912
func bizNotificationsChanged(_ list: [PhoenixShared.NotificationsManager.NotificationItem]) {
901913
log.trace("bizNotificationsChanges()")
902914

phoenix-shared/src/commonMain/kotlin/fr.acinq.phoenix/PhoenixBusiness.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ import kotlin.time.Duration.Companion.seconds
4141
class PhoenixBusiness(
4242
val phoenixGlobal: PhoenixGlobal,
4343
) {
44-
// this logger factory will be used throughout the project (including dependencies like lightning-kmp) to
45-
// create new [Logger] instances, and output logs to platform dependent writers.
46-
val loggerFactory = LoggerFactory(PhoenixLoggerConfig(phoenixGlobal.ctx))
44+
val loggerFactory = phoenixGlobal.loggerFactory
4745
private val logger = loggerFactory.newLogger(this::class)
4846

4947
private val tcpSocketBuilder = TcpSocket.Builder()

phoenix-shared/src/commonMain/kotlin/fr.acinq.phoenix/PhoenixGlobal.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,27 @@ import fr.acinq.phoenix.utils.logger.PhoenixLoggerConfig
3131

3232
class PhoenixGlobal(val ctx: PlatformContext) {
3333

34+
// this logger factory will be used throughout the project (including dependencies like lightning-kmp) to
35+
// create new [Logger] instances, and output logs to platform dependent writers.
3436
val loggerFactory = LoggerFactory(PhoenixLoggerConfig(ctx))
3537
private val logger = loggerFactory.newLogger(this::class)
3638

3739
val appDb by lazy { SqliteAppDb(createAppDbDriver(ctx)) }
38-
val networkMonitor by lazy { NetworkMonitor(loggerFactory, ctx) }
40+
val networkMonitor = NetworkMonitor(loggerFactory, ctx)
3941
val currencyManager by lazy { CurrencyManager(loggerFactory, appDb) }
4042
val feerateManager by lazy { FeerateManager(loggerFactory) }
41-
val walletContextManager by lazy { WalletContextManager(loggerFactory) }
43+
val walletContextManager = WalletContextManager(loggerFactory)
4244

4345
init {
4446
logger.info { "init PhoenixGlobal..." }
47+
feerateManager.startMonitoringFeerate()
48+
walletContextManager.startJobs()
4549
}
4650

4751
/** Called by [AppConnectionsDaemon] when internet is available. */
4852
internal fun enableNetworkAccess() {
4953
feerateManager.startMonitoringFeerate()
50-
walletContextManager.stopJobs()
54+
walletContextManager.startJobs()
5155
currencyManager.enableNetworkAccess()
5256
}
5357

0 commit comments

Comments
 (0)