Skip to content

Commit

Permalink
fix: show amount for bolt12
Browse files Browse the repository at this point in the history
  • Loading branch information
reez committed Aug 27, 2024
1 parent 4ae5fb1 commit 4acb7f1
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 212 deletions.
18 changes: 9 additions & 9 deletions LDKNodeMonday.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
AE060C382C051B59006724F1 /* LDKNode in Frameworks */ = {isa = PBXBuildFile; productRef = AE060C372C051B59006724F1 /* LDKNode */; };
AE0BD4AC2B598C3F00B9901E /* UInt32+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE0BD4AB2B598C3F00B9901E /* UInt32+Extensions.swift */; };
AE17E8DA29A402E30058C9C9 /* LDKNodeMondayApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE17E8D929A402E30058C9C9 /* LDKNodeMondayApp.swift */; };
AE17E8DC29A402E30058C9C9 /* AddressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE17E8DB29A402E30058C9C9 /* AddressView.swift */; };
AE17E8DE29A402E40058C9C9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = AE17E8DD29A402E40058C9C9 /* Assets.xcassets */; };
AE17E8E129A402E40058C9C9 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = AE17E8E029A402E40058C9C9 /* Preview Assets.xcassets */; };
AE17E90D29A42D430058C9C9 /* LightningNodeService.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE17E90C29A42D430058C9C9 /* LightningNodeService.swift */; };
Expand All @@ -39,7 +38,6 @@
AE49E84C2A24F96F002623E8 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE49E84B2A24F96F002623E8 /* Constants.swift */; };
AE49E8522A253618002623E8 /* StartViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE49E8512A253618002623E8 /* StartViewModel.swift */; };
AE49E8542A253647002623E8 /* BitcoinViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE49E8532A253647002623E8 /* BitcoinViewModel.swift */; };
AE49E8562A253674002623E8 /* AddressViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE49E8552A253674002623E8 /* AddressViewModel.swift */; };
AE49E8582A2536B4002623E8 /* ChannelsListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE49E8572A2536B4002623E8 /* ChannelsListViewModel.swift */; };
AE49E85A2A2536D4002623E8 /* ChannelAddViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE49E8592A2536D4002623E8 /* ChannelAddViewModel.swift */; };
AE49E85C2A2536FB002623E8 /* ChannelDetailViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE49E85B2A2536FB002623E8 /* ChannelDetailViewModel.swift */; };
Expand Down Expand Up @@ -108,7 +106,6 @@
AE0BD4AB2B598C3F00B9901E /* UInt32+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UInt32+Extensions.swift"; sourceTree = "<group>"; };
AE17E8D629A402E30058C9C9 /* LDKNodeMonday.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LDKNodeMonday.app; sourceTree = BUILT_PRODUCTS_DIR; };
AE17E8D929A402E30058C9C9 /* LDKNodeMondayApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LDKNodeMondayApp.swift; sourceTree = "<group>"; };
AE17E8DB29A402E30058C9C9 /* AddressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddressView.swift; sourceTree = "<group>"; };
AE17E8DD29A402E40058C9C9 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
AE17E8E029A402E40058C9C9 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
AE17E90C29A42D430058C9C9 /* LightningNodeService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LightningNodeService.swift; sourceTree = "<group>"; };
Expand All @@ -121,7 +118,6 @@
AE49E84B2A24F96F002623E8 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
AE49E8512A253618002623E8 /* StartViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StartViewModel.swift; sourceTree = "<group>"; };
AE49E8532A253647002623E8 /* BitcoinViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BitcoinViewModel.swift; sourceTree = "<group>"; };
AE49E8552A253674002623E8 /* AddressViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddressViewModel.swift; sourceTree = "<group>"; };
AE49E8572A2536B4002623E8 /* ChannelsListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChannelsListViewModel.swift; sourceTree = "<group>"; };
AE49E8592A2536D4002623E8 /* ChannelAddViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChannelAddViewModel.swift; sourceTree = "<group>"; };
AE49E85B2A2536FB002623E8 /* ChannelDetailViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChannelDetailViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -246,6 +242,14 @@
path = LightningNodesService;
sourceTree = "<group>";
};
AE43F27A2C7E529C00406326 /* Send */ = {
isa = PBXGroup;
children = (
AE551D482B8ECEB00034B61E /* AmountViewModel.swift */,
);
path = Send;
sourceTree = "<group>";
};
AE49E86D2A253A9A002623E8 /* Channel */ = {
isa = PBXGroup;
children = (
Expand All @@ -271,7 +275,6 @@
children = (
AE80C2012C4AB38D006E7193 /* BIP21ViewModel.swift */,
AE028A292B96328600B336E7 /* JITInvoiceViewModel.swift */,
AE49E8552A253674002623E8 /* AddressViewModel.swift */,
);
path = Receive;
sourceTree = "<group>";
Expand Down Expand Up @@ -305,8 +308,8 @@
AE00550F2B479F1100100797 /* OnboardingViewModel.swift */,
AE49E8512A253618002623E8 /* StartViewModel.swift */,
AE49E8532A253647002623E8 /* BitcoinViewModel.swift */,
AE551D482B8ECEB00034B61E /* AmountViewModel.swift */,
AE551D452B8ECE180034B61E /* Payments */,
AE43F27A2C7E529C00406326 /* Send */,
AE49E8722A253AD5002623E8 /* Receive */,
);
path = Home;
Expand Down Expand Up @@ -363,7 +366,6 @@
AEBFD8B52B8BABC00024E3F7 /* ReceiveView.swift */,
AE80C1FF2C4AB360006E7193 /* BIP21View.swift */,
AEA057EC2B912FEA00DB1096 /* JITInvoiceView.swift */,
AE17E8DB29A402E30058C9C9 /* AddressView.swift */,
);
path = Receive;
sourceTree = "<group>";
Expand Down Expand Up @@ -604,7 +606,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
AE49E8562A253674002623E8 /* AddressViewModel.swift in Sources */,
AE7096352B5C205F0038BE56 /* PriceServiceError.swift in Sources */,
AE186B8E2A1540B700338463 /* StartView.swift in Sources */,
AEDF47F32B3FBAB900145D64 /* Notification+Extensions.swift in Sources */,
Expand Down Expand Up @@ -634,7 +635,6 @@
AEDF76022B5C6863002DDEE1 /* Optional+Extensions.swift in Sources */,
AE7096382B5C208A0038BE56 /* Price.swift in Sources */,
AE49E86C2A253A32002623E8 /* NodeIDViewModel.swift in Sources */,
AE17E8DC29A402E30058C9C9 /* AddressView.swift in Sources */,
AEBAA48D2A01A93B0042EA82 /* PeerView.swift in Sources */,
AE028A242B96316B00B336E7 /* ReceiveOption.swift in Sources */,
AEDF76062B5C68A0002DDEE1 /* ChannelDetailsFormatted.swift in Sources */,
Expand Down
19 changes: 11 additions & 8 deletions LDKNodeMonday/Extensions/String+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ extension String {
}

if let offer = bolt12Offer {
return processLightningAddress(offer)
return processLightningAddress(offer, amount: amount)
}
if let invoice = bolt11Invoice {
return processLightningAddress(invoice)
return processLightningAddress(invoice, amount: amount)
}
return (bitcoinAddress, amount, .isBitcoin)
}
Expand All @@ -171,9 +171,9 @@ extension String {
return processBIP21(self, spendableBalance: spendableBalance)
} else if self.lowercased().starts(with: "lightning:") {
let invoice = String(self.dropFirst(10)) // Remove "lightning:" prefix
return processLightningAddress(invoice)
return processLightningAddress(invoice, amount: "0")
} else if self.lowercased().starts(with: "lnbc") || self.lowercased().starts(with: "lntb") {
return processLightningAddress(self)
return processLightningAddress(self, amount: "0")
} else if self.isBitcoinAddress {
return processBitcoinAddress(spendableBalance)
} else if self.starts(with: "lnurl") {
Expand All @@ -195,14 +195,17 @@ extension String {
}
}

private func processLightningAddress(_ address: String) -> (String, String, Payment) {
private func processLightningAddress(_ address: String, amount: String) -> (
String, String, Payment
) {
let sanitizedAddress = address.replacingOccurrences(of: "lightning:", with: "")

if sanitizedAddress.lowercased().starts(with: "lno") {
return (sanitizedAddress, "0", .isLightning)
} else {
let amount = sanitizedAddress.bolt11amount() ?? "0"
// Use the amount passed from the BIP21 parsing logic
return (sanitizedAddress, amount, .isLightning)
} else {
let bolt11Amount = sanitizedAddress.bolt11amount() ?? amount
return (sanitizedAddress, bolt11Amount, .isLightning)
}
}

Expand Down
2 changes: 1 addition & 1 deletion LDKNodeMonday/Model/ReceiveOption.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
enum ReceiveOption: String, CaseIterable, Identifiable {
var id: Self { self }

case bolt11JIT = "Bolt11 JIT"
case bolt11JIT = "BOLT11 JIT"
case bip21 = "BIP21"
}

Expand Down
46 changes: 0 additions & 46 deletions LDKNodeMonday/View Model/Home/Receive/AddressViewModel.swift

This file was deleted.

6 changes: 3 additions & 3 deletions LDKNodeMonday/View/Home/BitcoinView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct BitcoinView: View {
@State private var isCopied = false
@State private var showCheckmark = false
@State private var showingBitcoinViewErrorAlert = false
@State private var isAddressSheetPresented = false
@State private var isReceiveSheetPresented = false
@State private var isSendSheetPresented = false
@State private var isPaymentsPresented = false
@State private var showToast = false
Expand Down Expand Up @@ -183,7 +183,7 @@ struct BitcoinView: View {
.padding(.horizontal)

Button {
isAddressSheetPresented = true
isReceiveSheetPresented = true
} label: {
HStack {
Image(systemName: "arrow.down")
Expand Down Expand Up @@ -293,7 +293,7 @@ struct BitcoinView: View {
.font(.caption2)
}
.sheet(
isPresented: $isAddressSheetPresented,
isPresented: $isReceiveSheetPresented,
onDismiss: {
Task {
await viewModel.getTotalOnchainBalanceSats()
Expand Down
111 changes: 0 additions & 111 deletions LDKNodeMonday/View/Home/Receive/AddressView.swift

This file was deleted.

4 changes: 2 additions & 2 deletions LDKNodeMonday/View/Home/Receive/BIP21View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ struct BIP21View: View {
HStack(alignment: .center) {

VStack(alignment: .leading, spacing: 5.0) {
Text("Bolt 11")
Text("BOLT 11")
.bold()
if let components = parseUnifiedQR(viewModel.unified) {
Text(components.bolt11)
Expand Down Expand Up @@ -225,7 +225,7 @@ struct BIP21View: View {
HStack(alignment: .center) {

VStack(alignment: .leading, spacing: 5.0) {
Text("Bolt 12")
Text("BOLT12")
.bold()
if let components = parseUnifiedQR(viewModel.unified) {
Text(components.bolt12)
Expand Down
Loading

0 comments on commit 4acb7f1

Please sign in to comment.