Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
202 changes: 80 additions & 122 deletions LDKNodeMonday/View/Home/BitcoinView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ struct BitcoinView: View {
@State private var isCopied = false
@State private var showCheckmark = false
@State private var showingBitcoinViewErrorAlert = false
@State private var showReceiveViewWithOption: ReceiveOption?
@State private var showToast = false
@State private var showingNodeIDView = false
@State private var displayBalanceType = DisplayBalanceType.userDefaults
@State private var isReceiveSheetPresented = false
@State private var isSendSheetManualPresented = false
@State private var isSendSheetCameraPresented = false
@StateObject var viewModel: BitcoinViewModel
@StateObject private var eventService = EventService()
@Binding var sendNavigationPath: NavigationPath
Expand All @@ -28,9 +30,6 @@ struct BitcoinView: View {
BalanceHeader(displayBalanceType: $displayBalanceType, viewModel: viewModel)
.padding(.vertical, 40)

TransactionButtons(viewModel: viewModel)
.padding(.horizontal, 40)

PaymentsListView(
payments: $viewModel.payments,
displayBalanceType: $displayBalanceType,
Expand Down Expand Up @@ -59,13 +58,46 @@ struct BitcoinView: View {
}
}
}

ToolbarItemGroup(placement: .bottomBar) {
Button {
isSendSheetManualPresented = true
} label: {
Image(systemName: "arrow.up")
}
.disabled(viewModel.unifiedBalance == 0)

Spacer()

Button {
isSendSheetCameraPresented = true
} label: {
Label("Scan QR", systemImage: "qrcode.viewfinder")
.labelStyle(.iconOnly)
}
.disabled(viewModel.unifiedBalance == 0)

Spacer()

Button {
isReceiveSheetPresented = true
} label: {
Image(systemName: "arrow.down")
}
.sensoryFeedback(.increase, trigger: isReceiveSheetPresented)
}
}
.dynamicTypeSize(...DynamicTypeSize.accessibility2) // Sets max dynamic size for all Text
.onAppear { viewModel.update() }
.onChange(
of: eventService.lastEvent,
{ _, _ in
showToast = eventService.lastEvent != nil
withAnimation {
isReceiveSheetPresented = false
isSendSheetManualPresented = false
isSendSheetCameraPresented = false
}
}
)
.onReceive(viewModel.$bitcoinViewError) { errorMessage in
Expand Down Expand Up @@ -100,12 +132,51 @@ struct BitcoinView: View {
.padding(.horizontal, 40)
}
.sheet(
item: $showReceiveViewWithOption,
onDismiss: { viewModel.update() }
) { receiveOption in
ReceiveView(
viewModel: .init(lightningClient: viewModel.lightningClient)
isPresented: $isSendSheetManualPresented,
onDismiss: {
Task {
viewModel.update()
}
}
) {
SendView(
viewModel: SendViewModel.init(
lightningClient: viewModel.lightningClient,
sendViewState: .manualEntry,
price: viewModel.price,
balances: viewModel.balances
)
)
.presentationDetents([.large])
}
.sheet(
isPresented: $isSendSheetCameraPresented,
onDismiss: {
Task {
viewModel.update()
}
}
) {
SendView(
viewModel: SendViewModel.init(
lightningClient: viewModel.lightningClient,
sendViewState: .scanAddress,
price: viewModel.price,
balances: viewModel.balances
)
)
.presentationDetents([.large])
}
.sheet(
isPresented: $isReceiveSheetPresented,
onDismiss: {
Task {
viewModel.update()
}
}
) {
ReceiveView(viewModel: .init(lightningClient: viewModel.lightningClient))
.presentationDetents([.large])
}
}

Expand Down Expand Up @@ -197,119 +268,6 @@ struct BalanceHeader: View {
}
}

struct TransactionButtons: View {
@ObservedObject var viewModel: BitcoinViewModel
@State private var isReceiveSheetPresented = false
@State private var isSendSheetManualPresented = false
@State private var isSendSheetCameraPresented = false
@StateObject private var eventService = EventService()

var body: some View {
HStack(alignment: .center) {

// Send button
Button {
isSendSheetManualPresented = true
} label: {
Text("Send")
}.buttonStyle(
BitcoinFilled(
width: 120,
tintColor: .accent,
isCapsule: true
)
).disabled(viewModel.unifiedBalance == 0)

Spacer()

// Scan QR button
Button {
isSendSheetCameraPresented = true
} label: {
Label("Scan QR", systemImage: "qrcode.viewfinder")
.font(.title)
.frame(height: 60, alignment: .center)
.labelStyle(.iconOnly)
.foregroundColor(.accentColor)
.padding()
}.disabled(viewModel.unifiedBalance == 0)

Spacer()

// Receive button
Button("Receive") {
isReceiveSheetPresented = true
}
.sensoryFeedback(.increase, trigger: isReceiveSheetPresented)
.buttonStyle(
BitcoinFilled(
width: 120,
tintColor: .accent,
isCapsule: true
)
)
.sheet(
isPresented: $isSendSheetManualPresented,
onDismiss: {
Task {
viewModel.update()
}
}
) {
SendView(
viewModel: SendViewModel.init(
lightningClient: viewModel.lightningClient,
sendViewState: .manualEntry,
price: viewModel.price,
balances: viewModel.balances
)
)
.presentationDetents([.large])
}
.sheet(
isPresented: $isSendSheetCameraPresented,
onDismiss: {
Task {
viewModel.update()
}
}
) {
SendView(
viewModel: SendViewModel.init(
lightningClient: viewModel.lightningClient,
sendViewState: .scanAddress,
price: viewModel.price,
balances: viewModel.balances
)
)
.presentationDetents([.large])
}
.sheet(
isPresented: $isReceiveSheetPresented,
onDismiss: {
Task {
viewModel.update()
}
}
) {
ReceiveView(viewModel: .init(lightningClient: viewModel.lightningClient))
.presentationDetents([.large])
}

}.onChange(
of: eventService.lastEvent,
{ _, _ in
withAnimation {
isReceiveSheetPresented = false
isSendSheetManualPresented = false
isSendSheetCameraPresented = false
}
}
)
}

}

public enum DisplayBalanceType: String {
case fiatSats
case fiatBtc
Expand Down