ui: add support damus ui in WalletView
This appears after you've connected your wallet
This commit is contained in:
@@ -147,7 +147,7 @@ struct ContentView: View {
|
|||||||
|
|
||||||
func MainContent(damus: DamusState) -> some View {
|
func MainContent(damus: DamusState) -> some View {
|
||||||
VStack {
|
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()
|
EmptyView()
|
||||||
}
|
}
|
||||||
NavigationLink(destination: MaybeProfileView, isActive: $profile_open) {
|
NavigationLink(destination: MaybeProfileView, isActive: $profile_open) {
|
||||||
|
|||||||
@@ -48,5 +48,5 @@ struct DamusState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static var empty: 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())) }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -246,7 +246,7 @@ func format_msats_abbrev(_ msats: Int64) -> String {
|
|||||||
formatter.positiveSuffix = "m"
|
formatter.positiveSuffix = "m"
|
||||||
formatter.positivePrefix = ""
|
formatter.positivePrefix = ""
|
||||||
formatter.minimumFractionDigits = 0
|
formatter.minimumFractionDigits = 0
|
||||||
formatter.maximumFractionDigits = 3
|
formatter.maximumFractionDigits = 2
|
||||||
formatter.roundingMode = .down
|
formatter.roundingMode = .down
|
||||||
formatter.roundingIncrement = 0.1
|
formatter.roundingIncrement = 0.1
|
||||||
formatter.multiplier = 1
|
formatter.multiplier = 1
|
||||||
|
|||||||
@@ -14,14 +14,15 @@ enum WalletConnectState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class WalletModel: ObservableObject {
|
class WalletModel: ObservableObject {
|
||||||
let settings: UserSettingsStore?
|
var settings: UserSettingsStore
|
||||||
private(set) var previous_state: WalletConnectState
|
private(set) var previous_state: WalletConnectState
|
||||||
|
|
||||||
@Published private(set) var connect_state: WalletConnectState
|
@Published private(set) var connect_state: WalletConnectState
|
||||||
|
|
||||||
init() {
|
init(state: WalletConnectState, settings: UserSettingsStore) {
|
||||||
self.connect_state = .none
|
self.connect_state = state
|
||||||
self.previous_state = .none
|
self.previous_state = .none
|
||||||
self.settings = nil
|
self.settings = settings
|
||||||
}
|
}
|
||||||
|
|
||||||
init(settings: UserSettingsStore) {
|
init(settings: UserSettingsStore) {
|
||||||
@@ -42,7 +43,7 @@ class WalletModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func disconnect() {
|
func disconnect() {
|
||||||
self.settings?.nostr_wallet_connect = nil
|
self.settings.nostr_wallet_connect = nil
|
||||||
self.connect_state = .none
|
self.connect_state = .none
|
||||||
self.previous_state = .none
|
self.previous_state = .none
|
||||||
}
|
}
|
||||||
@@ -52,7 +53,7 @@ class WalletModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func connect(_ nwc: WalletConnectURL) {
|
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)
|
notify(.attached_wallet, nwc)
|
||||||
self.connect_state = .existing(nwc)
|
self.connect_state = .existing(nwc)
|
||||||
self.previous_state = .existing(nwc)
|
self.previous_state = .existing(nwc)
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ struct SideMenuView: View {
|
|||||||
navLabel(title: NSLocalizedString("Profile", comment: "Sidebar menu label for Profile view."), systemImage: "person")
|
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 {
|
HStack {
|
||||||
Image("wallet")
|
Image("wallet")
|
||||||
.tint(DamusColors.adaptableBlack)
|
.tint(DamusColors.adaptableBlack)
|
||||||
|
|||||||
@@ -99,6 +99,6 @@ struct ConnectWalletView: View {
|
|||||||
|
|
||||||
struct ConnectWalletView_Previews: PreviewProvider {
|
struct ConnectWalletView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
ConnectWalletView(model: WalletModel())
|
ConnectWalletView(model: WalletModel(settings: UserSettingsStore()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,10 +8,22 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct WalletView: View {
|
struct WalletView: View {
|
||||||
|
let damus_state: DamusState
|
||||||
@ObservedObject var model: WalletModel
|
@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 {
|
func MainWalletView(nwc: WalletConnectURL) -> some View {
|
||||||
VStack {
|
VStack {
|
||||||
|
SupportDamus
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
Text("\(nwc.relay.id)")
|
Text("\(nwc.relay.id)")
|
||||||
|
|
||||||
if let lud16 = nwc.lud16 {
|
if let lud16 = nwc.lud16 {
|
||||||
@@ -21,10 +33,119 @@ struct WalletView: View {
|
|||||||
BigButton("Disconnect Wallet") {
|
BigButton("Disconnect Wallet") {
|
||||||
self.model.disconnect()
|
self.model.disconnect()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
.navigationTitle("Wallet")
|
||||||
|
.navigationBarTitleDisplayMode(.large)
|
||||||
.padding()
|
.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 {
|
var body: some View {
|
||||||
switch model.connect_state {
|
switch model.connect_state {
|
||||||
case .new:
|
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 {
|
struct WalletView_Previews: PreviewProvider {
|
||||||
|
static let tds = test_damus_state()
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
WalletView(model: WalletModel())
|
WalletView(damus_state: tds, model: WalletModel(state: .existing(test_wallet_connect_url), settings: tds.settings))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user