commit 631220fdcb278a985217e19683b939df96a3addb
parent 5aa0d6c3e14f3e00ae1b9469704ac2c34354e1d5
Author: William Casarin <jb55@jb55.com>
Date: Sun, 14 May 2023 20:50:27 -0700
ui: add support damus ui in WalletView
This appears after you've connected your wallet
Diffstat:
7 files changed, 137 insertions(+), 12 deletions(-)
diff --git a/damus/ContentView.swift b/damus/ContentView.swift
@@ -147,7 +147,7 @@ struct ContentView: View {
func MainContent(damus: DamusState) -> some View {
VStack {
- NavigationLink(destination: WalletView(model: damus_state!.wallet), isActive: $wallet_open) {
+ NavigationLink(destination: WalletView(damus_state: damus, model: damus_state!.wallet), isActive: $wallet_open) {
EmptyView()
}
NavigationLink(destination: MaybeProfileView, isActive: $profile_open) {
diff --git a/damus/Models/DamusState.swift b/damus/Models/DamusState.swift
@@ -48,5 +48,5 @@ struct DamusState {
}
static var empty: DamusState {
- return DamusState.init(pool: RelayPool(), keypair: Keypair(pubkey: "", privkey: ""), likes: EventCounter(our_pubkey: ""), boosts: EventCounter(our_pubkey: ""), contacts: Contacts(our_pubkey: ""), profiles: Profiles(), dms: DirectMessagesModel(our_pubkey: ""), previews: PreviewCache(), zaps: Zaps(our_pubkey: ""), lnurls: LNUrls(), settings: UserSettingsStore(), relay_filters: RelayFilters(our_pubkey: ""), relay_metadata: RelayMetadatas(), drafts: Drafts(), events: EventCache(), bookmarks: BookmarksManager(pubkey: ""), postbox: PostBox(pool: RelayPool()), bootstrap_relays: [], replies: ReplyCounter(our_pubkey: ""), muted_threads: MutedThreadsManager(keypair: Keypair(pubkey: "", privkey: nil)), wallet: WalletModel()) }
+ return DamusState.init(pool: RelayPool(), keypair: Keypair(pubkey: "", privkey: ""), likes: EventCounter(our_pubkey: ""), boosts: EventCounter(our_pubkey: ""), contacts: Contacts(our_pubkey: ""), profiles: Profiles(), dms: DirectMessagesModel(our_pubkey: ""), previews: PreviewCache(), zaps: Zaps(our_pubkey: ""), lnurls: LNUrls(), settings: UserSettingsStore(), relay_filters: RelayFilters(our_pubkey: ""), relay_metadata: RelayMetadatas(), drafts: Drafts(), events: EventCache(), bookmarks: BookmarksManager(pubkey: ""), postbox: PostBox(pool: RelayPool()), bootstrap_relays: [], replies: ReplyCounter(our_pubkey: ""), muted_threads: MutedThreadsManager(keypair: Keypair(pubkey: "", privkey: nil)), wallet: WalletModel(settings: UserSettingsStore())) }
}
diff --git a/damus/Models/Mentions.swift b/damus/Models/Mentions.swift
@@ -246,7 +246,7 @@ func format_msats_abbrev(_ msats: Int64) -> String {
formatter.positiveSuffix = "m"
formatter.positivePrefix = ""
formatter.minimumFractionDigits = 0
- formatter.maximumFractionDigits = 3
+ formatter.maximumFractionDigits = 2
formatter.roundingMode = .down
formatter.roundingIncrement = 0.1
formatter.multiplier = 1
diff --git a/damus/Models/WalletModel.swift b/damus/Models/WalletModel.swift
@@ -14,14 +14,15 @@ enum WalletConnectState {
}
class WalletModel: ObservableObject {
- let settings: UserSettingsStore?
+ var settings: UserSettingsStore
private(set) var previous_state: WalletConnectState
+
@Published private(set) var connect_state: WalletConnectState
- init() {
- self.connect_state = .none
+ init(state: WalletConnectState, settings: UserSettingsStore) {
+ self.connect_state = state
self.previous_state = .none
- self.settings = nil
+ self.settings = settings
}
init(settings: UserSettingsStore) {
@@ -42,7 +43,7 @@ class WalletModel: ObservableObject {
}
func disconnect() {
- self.settings?.nostr_wallet_connect = nil
+ self.settings.nostr_wallet_connect = nil
self.connect_state = .none
self.previous_state = .none
}
@@ -52,7 +53,7 @@ class WalletModel: ObservableObject {
}
func connect(_ nwc: WalletConnectURL) {
- self.settings?.nostr_wallet_connect = nwc.to_url().absoluteString
+ self.settings.nostr_wallet_connect = nwc.to_url().absoluteString
notify(.attached_wallet, nwc)
self.connect_state = .existing(nwc)
self.previous_state = .existing(nwc)
diff --git a/damus/Views/SideMenuView.swift b/damus/Views/SideMenuView.swift
@@ -48,7 +48,7 @@ struct SideMenuView: View {
navLabel(title: NSLocalizedString("Profile", comment: "Sidebar menu label for Profile view."), systemImage: "person")
}
- NavigationLink(destination: WalletView(model: damus_state.wallet)) {
+ NavigationLink(destination: WalletView(damus_state: damus_state, model: damus_state.wallet)) {
HStack {
Image("wallet")
.tint(DamusColors.adaptableBlack)
diff --git a/damus/Views/Wallet/ConnectWalletView.swift b/damus/Views/Wallet/ConnectWalletView.swift
@@ -99,6 +99,6 @@ struct ConnectWalletView: View {
struct ConnectWalletView_Previews: PreviewProvider {
static var previews: some View {
- ConnectWalletView(model: WalletModel())
+ ConnectWalletView(model: WalletModel(settings: UserSettingsStore()))
}
}
diff --git a/damus/Views/Wallet/WalletView.swift b/damus/Views/Wallet/WalletView.swift
@@ -8,10 +8,22 @@
import SwiftUI
struct WalletView: View {
+ let damus_state: DamusState
@ObservedObject var model: WalletModel
+ @ObservedObject var settings: UserSettingsStore
+
+ init(damus_state: DamusState, model: WalletModel? = nil) {
+ self.damus_state = damus_state
+ self._model = ObservedObject(wrappedValue: model ?? damus_state.wallet)
+ self._settings = ObservedObject(wrappedValue: damus_state.settings)
+ }
func MainWalletView(nwc: WalletConnectURL) -> some View {
VStack {
+ SupportDamus
+
+ Spacer()
+
Text("\(nwc.relay.id)")
if let lud16 = nwc.lud16 {
@@ -21,10 +33,119 @@ struct WalletView: View {
BigButton("Disconnect Wallet") {
self.model.disconnect()
}
+
}
+ .navigationTitle("Wallet")
+ .navigationBarTitleDisplayMode(.large)
.padding()
}
+ func donation_binding() -> Binding<Double> {
+ return Binding(get: {
+ return Double(model.settings.donation_percent)
+ }, set: { v in
+ model.settings.donation_percent = Int(v)
+ })
+ }
+
+ static let min_donation: Double = 0.0
+ static let max_donation: Double = 100.0
+
+ var percent: Double {
+ Double(model.settings.donation_percent) / 100.0
+ }
+
+ var tip_msats: String {
+ let msats = Int64(percent * Double(model.settings.default_zap_amount * 1000))
+ let s = format_msats_abbrev(msats)
+ return s.split(separator: ".").first.map({ x in String(x) }) ?? s
+ }
+
+ var SupportDamus: some View {
+ ZStack(alignment: .topLeading) {
+ RoundedRectangle(cornerRadius: 20)
+ .fill(DamusGradient.gradient.opacity(0.5))
+
+ VStack(alignment: .leading, spacing: 20) {
+ HStack {
+ Image("logo-nobg")
+ .resizable()
+ .frame(width: 50, height: 50)
+ Text("Support Damus")
+ .font(.title.bold())
+ .foregroundColor(.white)
+ }
+
+ Text("Help build the future of decentralized communication on the web.")
+ .fixedSize(horizontal: false, vertical: true)
+ .foregroundColor(.white)
+
+ Text("An additional percentage of each zap will be sent to support Damus development ")
+ .fixedSize(horizontal: false, vertical: true)
+ .foregroundColor(.white)
+
+ let binding = donation_binding()
+
+ HStack {
+ Slider(value: binding,
+ in: WalletView.min_donation...WalletView.max_donation,
+ label: { })
+ Text("\(Int(binding.wrappedValue))%")
+ .font(.title.bold())
+ .foregroundColor(.white)
+ }
+
+ HStack{
+ Spacer()
+
+ VStack {
+ HStack {
+ Text("\(Image("zap.fill")) \(format_msats_abbrev(Int64(model.settings.default_zap_amount) * 1000))")
+ .font(.title)
+ .foregroundColor(percent == 0 ? .gray : .yellow)
+ .frame(width: 100)
+ }
+
+ Text("Zap")
+ .foregroundColor(.white)
+ }
+ Spacer()
+
+ Text("+")
+ .font(.title)
+ .foregroundColor(.white)
+ Spacer()
+
+ VStack {
+ HStack {
+ Text("\(Image("zap.fill")) \(tip_msats)")
+ .font(.title)
+ .foregroundColor(percent == 0 ? .gray : Color.yellow)
+ .frame(width: 100)
+ }
+ Text("Donation")
+ .foregroundColor(.white)
+ }
+ Spacer()
+ }
+
+ EventProfile(damus_state: damus_state, pubkey: damus_state.pubkey, profile: damus_state.profiles.lookup(id: damus_state.pubkey), size: .small)
+
+ /*
+ Slider(value: donation_binding(),
+ in: WalletView.min...WalletView.max,
+ step: 1,
+ minimumValueLabel: { Text("\(WalletView.min)") },
+ maximumValueLabel: { Text("\(WalletView.max)") },
+ label: { Text("label") }
+ )
+ */
+ }
+ .padding(25)
+ }
+ .frame(height: 370)
+ }
+
var body: some View {
switch model.connect_state {
case .new:
@@ -37,8 +158,11 @@ struct WalletView: View {
}
}
+let test_wallet_connect_url = WalletConnectURL(pubkey: "pk", relay: .init("wss://relay.damus.io")!, keypair: test_damus_state().keypair.to_full()!, lud16: "jb55@sendsats.com")
+
struct WalletView_Previews: PreviewProvider {
+ static let tds = test_damus_state()
static var previews: some View {
- WalletView(model: WalletModel())
+ WalletView(damus_state: tds, model: WalletModel(state: .existing(test_wallet_connect_url), settings: tds.settings))
}
}