damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit d0216bbce6438a55643e78f4650b5c940c332a5f
parent 4d2b79057d131b3ced2679036cfc9510e3ee6440
Author: William Casarin <jb55@jb55.com>
Date:   Tue,  9 May 2023 18:26:12 -0700

nwc: Add WalletModel

This model will be used for controlling the logic in the Wallet views

Diffstat:
Mdamus.xcodeproj/project.pbxproj | 4++++
Adamus/Models/WalletModel.swift | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 63 insertions(+), 0 deletions(-)

diff --git a/damus.xcodeproj/project.pbxproj b/damus.xcodeproj/project.pbxproj @@ -144,6 +144,7 @@ 4C7D09722A0AEF5E00943473 /* DamusGradient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C7D09712A0AEF5E00943473 /* DamusGradient.swift */; }; 4C7D09742A0AEF9000943473 /* AlbyGradient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C7D09732A0AEF9000943473 /* AlbyGradient.swift */; }; 4C7D09762A0AF19E00943473 /* FillAndStroke.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C7D09752A0AF19E00943473 /* FillAndStroke.swift */; }; + 4C7D09782A0B0CC900943473 /* WalletModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C7D09772A0B0CC900943473 /* WalletModel.swift */; }; 4C7FF7D52823313F009601DB /* Mentions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C7FF7D42823313F009601DB /* Mentions.swift */; }; 4C8682872814DE470026224F /* ProfileView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C8682862814DE470026224F /* ProfileView.swift */; }; 4C8D00C829DF791C0036AF10 /* CompatibleAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C8D00C729DF791C0036AF10 /* CompatibleAttribute.swift */; }; @@ -559,6 +560,7 @@ 4C7D09712A0AEF5E00943473 /* DamusGradient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DamusGradient.swift; sourceTree = "<group>"; }; 4C7D09732A0AEF9000943473 /* AlbyGradient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlbyGradient.swift; sourceTree = "<group>"; }; 4C7D09752A0AF19E00943473 /* FillAndStroke.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FillAndStroke.swift; sourceTree = "<group>"; }; + 4C7D09772A0B0CC900943473 /* WalletModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletModel.swift; sourceTree = "<group>"; }; 4C7FF7D42823313F009601DB /* Mentions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Mentions.swift; sourceTree = "<group>"; }; 4C8682862814DE470026224F /* ProfileView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileView.swift; sourceTree = "<group>"; }; 4C8D00C729DF791C0036AF10 /* CompatibleAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompatibleAttribute.swift; sourceTree = "<group>"; }; @@ -862,6 +864,7 @@ 4C54AA0629A540BA003E4487 /* NotificationsModel.swift */, 4CD348EE29C3659D00497EB2 /* ImageUploadModel.swift */, 3A48E7AF29DFBE9D006E787E /* MutedThreadsManager.swift */, + 4C7D09772A0B0CC900943473 /* WalletModel.swift */, ); path = Models; sourceTree = "<group>"; @@ -1687,6 +1690,7 @@ 9609F058296E220800069BF3 /* BannerImageView.swift in Sources */, 4C363A94282704FA006E126D /* Post.swift in Sources */, 4C216F32286E388800040376 /* DMChatView.swift in Sources */, + 4C7D09782A0B0CC900943473 /* WalletModel.swift in Sources */, 4C7D09662A0AE62100943473 /* AlbyButton.swift in Sources */, 4CAAD8AD298851D000060CEA /* AccountDeletion.swift in Sources */, 4CFF8F6329CC9AD7008DB934 /* ImageContextMenuModifier.swift in Sources */, diff --git a/damus/Models/WalletModel.swift b/damus/Models/WalletModel.swift @@ -0,0 +1,59 @@ +// +// WalletModel.swift +// damus +// +// Created by William Casarin on 2023-05-09. +// + +import Foundation + +enum WalletConnectState { + case new(WalletConnectURL) + case existing(WalletConnectURL) + case none +} + +class WalletModel: ObservableObject { + let settings: UserSettingsStore? + private(set) var previous_state: WalletConnectState + @Published private(set) var connect_state: WalletConnectState + + init() { + self.connect_state = .none + self.previous_state = .none + self.settings = nil + } + + init(settings: UserSettingsStore) { + self.settings = settings + if let str = settings.nostr_wallet_connect, + let nwc = WalletConnectURL(str: str) { + self.previous_state = .existing(nwc) + self.connect_state = .existing(nwc) + } else { + self.previous_state = .none + self.connect_state = .none + } + } + + func cancel() { + self.connect_state = previous_state + self.objectWillChange.send() + } + + func disconnect() { + self.settings?.nostr_wallet_connect = nil + self.connect_state = .none + self.previous_state = .none + } + + func new(_ nwc: WalletConnectURL) { + self.connect_state = .new(nwc) + } + + func connect(_ nwc: WalletConnectURL) { + self.settings?.nostr_wallet_connect = nwc.to_url().absoluteString + self.connect_state = .existing(nwc) + self.previous_state = .existing(nwc) + } +}