Compare commits

...

11 Commits

Author SHA1 Message Date
William Casarin
8097cfdfb8 Include donation_amount on profile 2023-05-15 09:59:51 -07:00
William Casarin
af912b1a0e v1.5-1 2023-05-15 09:59:22 -07:00
William Casarin
51cd34c9c2 c: move parse_digit to remove warning 2023-05-15 09:59:10 -07:00
William Casarin
a6745af519 Implement damus zap split donations using NWC 2023-05-15 09:41:26 -07:00
William Casarin
631220fdcb ui: add support damus ui in WalletView
This appears after you've connected your wallet
2023-05-14 22:24:12 -07:00
William Casarin
5aa0d6c3e1 settings: add donation_percent to settings
This will be used in damus donations splits
2023-05-14 22:24:12 -07:00
f9982e992a Migrate away from sticky deprecated non-pubkey-scoped settings
Changelog-Fixed: Migrate away from sticky deprecated non-pubkey-scoped settings
Closes: #1124
2023-05-14 21:08:56 -07:00
transifex-integration[bot]
0eaebb80f1 Apply translations
in:

- nl
- de
- cs
- hu_HU
- sv_SE
- ar
- fa
- pl_PL
- ja

Closes: #1122
2023-05-14 21:06:20 -07:00
6f23b69f2c Export strings for translation 2023-05-14 20:54:13 -07:00
William Casarin
ec50c75062 ui: expose raw LinearGradient in DamusGradient
This will be used in background-fill applications
2023-05-14 20:47:53 -07:00
William Casarin
0293b61d7a Rename 'Connect to Alby' to 'Attach Alby Wallet' 2023-05-14 14:07:04 -07:00
39 changed files with 337 additions and 77 deletions

View File

@@ -110,21 +110,6 @@ static inline int peek_char(struct cursor *cur, int ind) {
return *(cur->p + ind);
}
static int parse_digit(struct cursor *cur, int *digit) {
int c;
if ((c = peek_char(cur, 0)) == -1)
return 0;
c -= '0';
if (c >= 0 && c <= 9) {
*digit = c;
cur->p++;
return 1;
}
return 0;
}
static inline int pull_byte(struct cursor *cur, u8 *byte) {
if (cur->p >= cur->end)

View File

@@ -12,6 +12,22 @@
#include <stdlib.h>
#include <string.h>
static int parse_digit(struct cursor *cur, int *digit) {
int c;
if ((c = peek_char(cur, 0)) == -1)
return 0;
c -= '0';
if (c >= 0 && c <= 9) {
*digit = c;
cur->p++;
return 1;
}
return 0;
}
static int parse_mention_index(struct cursor *cur, struct block *block) {
int d1, d2, d3, ind;
const u8 *start = cur->p;

View File

@@ -26,7 +26,7 @@ bool hex_decode(const char *str, size_t slen, void *buf, size_t bufsize);
/**
* hex_encode - Create a nul-terminated hex string
* @buf: the buffer to read the data from
* @bufsize: the length of @buf
* @bufsize: the length of buf
* @dest: the string to fill
* @destsize: the max size of the string
*

View File

@@ -2128,7 +2128,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = damus/damus.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 24;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"damus/Preview Content\"";
DEVELOPMENT_TEAM = XK7H4JAB3D;
ENABLE_PREVIEWS = YES;
@@ -2175,7 +2175,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = damus/damus.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 24;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"damus/Preview Content\"";
DEVELOPMENT_TEAM = XK7H4JAB3D;
ENABLE_PREVIEWS = YES;

View File

@@ -14,9 +14,13 @@ fileprivate let damus_grad = [damus_grad_c1, damus_grad_c2, damus_grad_c3]
struct DamusGradient: View {
var body: some View {
LinearGradient(colors: damus_grad, startPoint: .bottomLeading, endPoint: .topTrailing)
DamusGradient.gradient
.edgesIgnoringSafeArea([.top,.bottom])
}
static var gradient: LinearGradient {
LinearGradient(colors: damus_grad, startPoint: .bottomLeading, endPoint: .topTrailing)
}
}
struct DamusGradient_Previews: PreviewProvider {

View File

@@ -208,8 +208,7 @@ func send_zap(damus_state: DamusState, event: NostrEvent, lnurl: String, is_cust
return
}
let zap_amount = amount_sats ?? damus_state.settings.default_zap_amount
let amount_msat = Int64(zap_amount) * 1000
let amount_msat = Int64(amount_sats ?? damus_state.settings.default_zap_amount) * 1000
let pending_zap_state = initial_pending_zap_state(settings: damus_state.settings)
let pending_zap = PendingZap(amount_msat: amount_msat, target: target, request: mzapreq, type: zap_type, state: pending_zap_state)
let zapreq = mzapreq.potentially_anon_outer_request.ev
@@ -239,7 +238,7 @@ func send_zap(damus_state: DamusState, event: NostrEvent, lnurl: String, is_cust
damus_state.lnurls.endpoints[target.pubkey] = payreq
}
guard let inv = await fetch_zap_invoice(payreq, zapreq: zapreq, sats: zap_amount, zap_type: zap_type, comment: comment) else {
guard let inv = await fetch_zap_invoice(payreq, zapreq: zapreq, msats: amount_msat, zap_type: zap_type, comment: comment) else {
DispatchQueue.main.async {
remove_zap(reqid: reqid, zapcache: damus_state.zaps, evcache: damus_state.events)
let typ = ZappingEventType.failed(.fetching_invoice)
@@ -259,9 +258,16 @@ func send_zap(damus_state: DamusState, event: NostrEvent, lnurl: String, is_cust
return
}
guard let nwc_req = nwc_pay(url: nwc_state.url, pool: damus_state.pool, post: damus_state.postbox, invoice: inv),
case .nwc(let pzap_state) = pending_zap_state
else {
let nwc_req = nwc_pay(url: nwc_state.url, pool: damus_state.pool, post: damus_state.postbox, invoice: inv, on_flush: .once({ pe in
// send donation zap when the pending zap is flushed, this allows user to cancel and not send a donation
Task.init { @MainActor in
await send_donation_zap(pool: damus_state.pool, postbox: damus_state.postbox, nwc: nwc_state.url, percent: damus_state.settings.donation_percent, base_msats: amount_msat)
}
}))
guard let nwc_req, case .nwc(let pzap_state) = pending_zap_state else {
return
}

View File

@@ -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) {

View File

@@ -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())) }
}

View File

@@ -154,10 +154,14 @@ class HomeModel: ObservableObject {
}
if resp.response.error == nil {
nwc_success(zapcache: self.damus_state.zaps, evcache: self.damus_state.events, resp: resp)
}
guard let err = resp.response.error else {
nwc_success(state: self.damus_state, resp: resp)
return
}
print("nwc error: \(err)")
nwc_error(zapcache: self.damus_state.zaps, evcache: self.damus_state.events, resp: resp)
}
}

View File

@@ -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

View File

@@ -19,8 +19,11 @@ let fallback_zap_amount = 1000
if let loaded = UserDefaults.standard.object(forKey: self.key) as? T {
self.value = loaded
} else if let loaded = UserDefaults.standard.object(forKey: key) as? T {
// try to load from deprecated non-pubkey-keyed setting
// If pubkey-scoped setting does not exist but the deprecated non-pubkey-scoped setting does,
// migrate the deprecated setting into the pubkey-scoped one and delete the deprecated one.
self.value = loaded
UserDefaults.standard.set(loaded, forKey: self.key)
UserDefaults.standard.removeObject(forKey: key)
} else {
self.value = default_value
}
@@ -48,8 +51,11 @@ let fallback_zap_amount = 1000
if let loaded = UserDefaults.standard.string(forKey: self.key), let val = T.init(from: loaded) {
self.value = val
} else if let loaded = UserDefaults.standard.string(forKey: key), let val = T.init(from: loaded) {
// try to load from deprecated non-pubkey-keyed setting
// If pubkey-scoped setting does not exist but the deprecated non-pubkey-scoped setting does,
// migrate the deprecated setting into the pubkey-scoped one and delete the deprecated one.
self.value = val
UserDefaults.standard.set(val.to_string(), forKey: self.key)
UserDefaults.standard.removeObject(forKey: key)
} else {
self.value = default_value
}
@@ -137,6 +143,9 @@ class UserSettingsStore: ObservableObject {
@Setting(key: "disable_animation", default_value: UIAccessibility.isReduceMotionEnabled)
var disable_animation: Bool
@Setting(key: "donation_percent", default_value: 0)
var donation_percent: Int
// Helper for inverse of disable_animation.
// disable_animation was introduced as a setting first, but it's more natural for the settings UI to show the inverse.

View File

@@ -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)

View File

@@ -10,7 +10,7 @@ import Foundation
class Profile: Codable {
var value: [String: AnyCodable]
init (name: String?, display_name: String?, about: String?, picture: String?, banner: String?, website: String?, lud06: String?, lud16: String?, nip05: String?) {
init (name: String?, display_name: String?, about: String?, picture: String?, banner: String?, website: String?, lud06: String?, lud16: String?, nip05: String?, damus_donation: Int?) {
self.value = [:]
self.name = name
self.display_name = display_name
@@ -21,12 +21,17 @@ class Profile: Codable {
self.lud06 = lud06
self.lud16 = lud16
self.nip05 = nip05
self.damus_donation = damus_donation
}
private func str(_ str: String) -> String? {
return get_val(str)
}
private func int(_ key: String) -> Int? {
return get_val(key)
}
private func get_val<T>(_ v: String) -> T? {
guard let val = self.value[v] else{
return nil
@@ -52,6 +57,10 @@ class Profile: Codable {
set_val(key, val)
}
private func set_int(_ key: String, _ val: Int?) {
set_val(key, val)
}
var reactions: Bool? {
get { return get_val("reactions"); }
set(s) { set_val("reactions", s) }
@@ -77,6 +86,11 @@ class Profile: Codable {
set(s) { set_str("about", s) }
}
var damus_donation: Int? {
get { return int("damus_donation"); }
set(s) { set_int("damus_donation", s) }
}
var picture: String? {
get { return str("picture"); }
set(s) { set_str("picture", s) }
@@ -180,7 +194,7 @@ class Profile: Codable {
}
func make_test_profile() -> Profile {
return Profile(name: "jb55", display_name: "Will", about: "Its a me", picture: "https://cdn.jb55.com/img/red-me.jpg", banner: "https://pbs.twimg.com/profile_banners/9918032/1531711830/600x200", website: "jb55.com", lud06: "jb55@jb55.com", lud16: nil, nip05: "jb55@jb55.com")
return Profile(name: "jb55", display_name: "Will", about: "Its a me", picture: "https://cdn.jb55.com/img/red-me.jpg", banner: "https://pbs.twimg.com/profile_banners/9918032/1531711830/600x200", website: "jb55.com", lud06: "jb55@jb55.com", lud16: nil, nip05: "jb55@jb55.com", damus_donation: 1)
}
func make_ln_url(_ str: String?) -> URL? {

View File

@@ -601,7 +601,7 @@ enum MakeZapRequest {
var private_inner_request: ZapRequest {
switch self {
case .priv(let _, let pzr):
case .priv(_, let pzr):
return pzr.req
case .normal(let zr):
return zr

View File

@@ -14,6 +14,7 @@ func insert_uniq_sorted_zap(zaps: inout [Zapping], new_zap: Zapping, cmp: (Zappi
if new_zap.request.id == zap.request.id {
// replace pending
if !new_zap.is_pending && zap.is_pending {
print("nwc: replacing pending with real zap \(new_zap.request.id)")
zaps[i] = new_zap
return true
}

View File

@@ -22,16 +22,25 @@ class Relayer {
}
}
enum OnFlush {
case once((PostedEvent) -> Void)
case all((PostedEvent) -> Void)
}
class PostedEvent {
let event: NostrEvent
let skip_ephemeral: Bool
var remaining: [Relayer]
let flush_after: Date?
var flushed_once: Bool
let on_flush: OnFlush?
init(event: NostrEvent, remaining: [String], skip_ephemeral: Bool, flush_after: Date? = nil) {
init(event: NostrEvent, remaining: [String], skip_ephemeral: Bool, flush_after: Date?, on_flush: OnFlush?) {
self.event = event
self.skip_ephemeral = skip_ephemeral
self.flush_after = flush_after
self.on_flush = on_flush
self.flushed_once = false
self.remaining = remaining.map {
Relayer(relay: $0, attempts: 0, retry_after: 2.0)
}
@@ -109,6 +118,19 @@ class PostBox {
guard let ev = self.events[event_id] else {
return false
}
if let on_flush = ev.on_flush {
switch on_flush {
case .once(let cb):
if !ev.flushed_once {
ev.flushed_once = true
cb(ev)
}
case .all(let cb):
cb(ev)
}
}
let prev_count = ev.remaining.count
ev.remaining = ev.remaining.filter { $0.relay != relay_id }
let after_count = ev.remaining.count
@@ -132,7 +154,7 @@ class PostBox {
}
}
func send(_ event: NostrEvent, to: [String]? = nil, skip_ephemeral: Bool = true, delay: TimeInterval? = nil) {
func send(_ event: NostrEvent, to: [String]? = nil, skip_ephemeral: Bool = true, delay: TimeInterval? = nil, on_flush: OnFlush? = nil) {
// Don't add event if we already have it
if events[event.id] != nil {
return
@@ -140,7 +162,7 @@ class PostBox {
let remaining = to ?? pool.our_descriptors.map { $0.url.id }
let after = delay.map { d in Date.now.addingTimeInterval(d) }
let posted_ev = PostedEvent(event: event, remaining: remaining, skip_ephemeral: skip_ephemeral, flush_after: after)
let posted_ev = PostedEvent(event: event, remaining: remaining, skip_ephemeral: skip_ephemeral, flush_after: after, on_flush: on_flush)
events[event.id] = posted_ev

View File

@@ -182,7 +182,8 @@ func subscribe_to_nwc(url: WalletConnectURL, pool: RelayPool) {
pool.send(.subscribe(sub), to: [url.relay.id])
}
func nwc_pay(url: WalletConnectURL, pool: RelayPool, post: PostBox, invoice: String) -> NostrEvent? {
@discardableResult
func nwc_pay(url: WalletConnectURL, pool: RelayPool, post: PostBox, invoice: String, delay: TimeInterval? = 5.0, on_flush: OnFlush? = nil) -> NostrEvent? {
let req = make_wallet_pay_invoice_request(invoice: invoice)
guard let ev = make_wallet_connect_request(req: req, to_pk: url.pubkey, keypair: url.keypair) else {
return nil
@@ -190,14 +191,14 @@ func nwc_pay(url: WalletConnectURL, pool: RelayPool, post: PostBox, invoice: Str
try? pool.add_relay(.nwc(url: url.relay))
subscribe_to_nwc(url: url, pool: pool)
post.send(ev, to: [url.relay.id], skip_ephemeral: false, delay: 5.0)
post.send(ev, to: [url.relay.id], skip_ephemeral: false, delay: delay, on_flush: on_flush)
return ev
}
func nwc_success(zapcache: Zaps, evcache: EventCache, resp: FullWalletResponse) {
func nwc_success(state: DamusState, resp: FullWalletResponse) {
// find the pending zap and mark it as pending-confirmed
for kv in zapcache.our_zaps {
for kv in state.zaps.our_zaps {
let zaps = kv.value
for zap in zaps {
@@ -211,14 +212,29 @@ func nwc_success(zapcache: Zaps, evcache: EventCache, resp: FullWalletResponse)
if nwc_state.update_state(state: .confirmed) {
// notify the zaps model of an update so it can mark them as paid
evcache.get_cache_data(pzap.target.id).zaps_model.objectWillChange.send()
state.events.get_cache_data(pzap.target.id).zaps_model.objectWillChange.send()
print("NWC success confirmed")
}
return
}
}
}
func send_donation_zap(pool: RelayPool, postbox: PostBox, nwc: WalletConnectURL, percent: Int, base_msats: Int64) async {
let percent_f = Double(percent) / 100.0
let donations_msats = Int64(percent_f * Double(base_msats))
let payreq = LNUrlPayRequest(allowsNostr: true, commentAllowed: nil, nostrPubkey: "", callback: "https://sendsats.lol/@damus")
guard let invoice = await fetch_zap_invoice(payreq, zapreq: nil, msats: donations_msats, zap_type: .non_zap, comment: nil) else {
// we failed... oh well. no donation for us.
print("damus-donation failed to fetch invoice")
return
}
nwc_pay(url: nwc, pool: pool, post: postbox, invoice: invoice, delay: nil)
}
func nwc_error(zapcache: Zaps, evcache: EventCache, resp: FullWalletResponse) {
// find a pending zap with the nwc request id associated with this response and remove it
for kv in zapcache.our_zaps {

View File

@@ -440,15 +440,14 @@ func fetch_static_payreq(_ lnurl: String) async -> LNUrlPayRequest? {
return endpoint
}
func fetch_zap_invoice(_ payreq: LNUrlPayRequest, zapreq: NostrEvent, sats: Int, zap_type: ZapType, comment: String?) async -> String? {
func fetch_zap_invoice(_ payreq: LNUrlPayRequest, zapreq: NostrEvent?, msats: Int64, zap_type: ZapType, comment: String?) async -> String? {
guard var base_url = payreq.callback.flatMap({ URLComponents(string: $0) }) else {
return nil
}
let zappable = payreq.allowsNostr ?? false
let amount: Int64 = Int64(sats) * 1000
var query = [URLQueryItem(name: "amount", value: "\(amount)")]
var query = [URLQueryItem(name: "amount", value: "\(msats)")]
if zappable && zap_type != .non_zap, let json = encode_json(zapreq) {
print("zapreq json: \(json)")
@@ -489,7 +488,7 @@ func fetch_zap_invoice(_ payreq: LNUrlPayRequest, zapreq: NostrEvent, sats: Int,
// make sure it's the correct amount
guard let bolt11 = decode_bolt11(result.pr),
.specific(amount) == bolt11.amount
.specific(msats) == bolt11.amount
else {
return nil
}

View File

@@ -22,7 +22,7 @@ class Zaps {
self.event_counts = [:]
self.event_totals = [:]
}
func remove_zap(reqid: String) -> Zapping? {
var res: Zapping? = nil
for kv in our_zaps {

View File

@@ -23,7 +23,7 @@ struct AlbyButton: View {
HStack {
Image("alby")
Text("Connect to Alby")
Text("Attach Alby Wallet", comment: "Button to attach an Alby Wallet, a service that provides a Lightning wallet for zapping sats. Alby is the name of the service and should not be translated.")
}
.offset(x: -25)
.frame(minWidth: 300, maxWidth: .infinity, minHeight: 50, maxHeight: 50, alignment: .center)

View File

@@ -177,7 +177,7 @@ func get_profile_url(picture: String?, pubkey: String, profiles: Profiles) -> UR
func make_preview_profiles(_ pubkey: String) -> Profiles {
let profiles = Profiles()
let picture = "http://cdn.jb55.com/img/red-me.jpg"
let profile = Profile(name: "jb55", display_name: "William Casarin", about: "It's me", picture: picture, banner: "", website: "https://jb55.com", lud06: nil, lud16: nil, nip05: "jb55.com")
let profile = Profile(name: "jb55", display_name: "William Casarin", about: "It's me", picture: picture, banner: "", website: "https://jb55.com", lud06: nil, lud16: nil, nip05: "jb55.com", damus_donation: nil)
let ts_profile = TimestampedProfile(profile: profile, timestamp: 0, event: test_event)
profiles.add(id: pubkey, profile: ts_profile)
return profiles

View File

@@ -497,7 +497,7 @@ func test_damus_state() -> DamusState {
let pubkey = "3efdaebb1d8923ebd99c9e7ace3b4194ab45512e2be79c1b7d68d9243e0d2681"
let damus = DamusState.empty
let prof = Profile(name: "damus", display_name: "damus", about: "iOS app!", picture: "https://damus.io/img/logo.png", banner: "", website: "https://damus.io", lud06: nil, lud16: "jb55@sendsats.lol", nip05: "damus.io")
let prof = Profile(name: "damus", display_name: "damus", about: "iOS app!", picture: "https://damus.io/img/logo.png", banner: "", website: "https://damus.io", lud06: nil, lud16: "jb55@sendsats.lol", nip05: "damus.io", damus_donation: nil)
let tsprof = TimestampedProfile(profile: prof, timestamp: 0, event: test_event)
damus.profiles.add(id: pubkey, profile: tsprof)
return damus

View File

@@ -224,5 +224,5 @@ struct SaveKeysView_Previews: PreviewProvider {
}
func create_account_to_metadata(_ model: CreateAccountModel) -> Profile {
return Profile(name: model.nick_name, display_name: model.real_name, about: model.about, picture: model.profile_image, banner: nil, website: nil, lud06: nil, lud16: nil, nip05: nil)
return Profile(name: model.nick_name, display_name: model.real_name, about: model.about, picture: model.profile_image, banner: nil, website: nil, lud06: nil, lud16: nil, nip05: nil, damus_donation: nil)
}

View File

@@ -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)

View File

@@ -99,6 +99,6 @@ struct ConnectWalletView: View {
struct ConnectWalletView_Previews: PreviewProvider {
static var previews: some View {
ConnectWalletView(model: WalletModel())
ConnectWalletView(model: WalletModel(settings: UserSettingsStore()))
}
}

View File

@@ -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("💜")
.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:
@@ -33,12 +154,27 @@ struct WalletView: View {
ConnectWalletView(model: model)
case .existing(let nwc):
MainWalletView(nwc: nwc)
.onDisappear {
guard let keypair = damus_state.keypair.to_full(),
let profile = damus_state.profiles.lookup(id: damus_state.pubkey),
profile.damus_donation != settings.donation_percent
else {
return
}
profile.damus_donation = settings.donation_percent
let meta = make_metadata_event(keypair: keypair, metadata: profile)
damus_state.postbox.send(meta)
}
}
}
}
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))
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -291,6 +291,11 @@ Sentence composed of 2 variables to describe how many people are following a use
<target>Connect To Relay</target>
<note>Label for section for adding a relay server.</note>
</trans-unit>
<trans-unit id="Connect to Alby" xml:space="preserve">
<source>Connect to Alby</source>
<target>Connect to Alby</target>
<note>Button to connect to Alby, a service that provides a Lightning wallet for zapping sats. Alby is the name of the service and should not be translated.</note>
</trans-unit>
<trans-unit id="Connected Relays" xml:space="preserve">
<source>Connected Relays</source>
<target>Connected Relays</target>
@@ -471,11 +476,6 @@ Sentence composed of 2 variables to describe how many people are following a use
<target>Disconnect From Relay</target>
<note>Button to disconnect from the relay.</note>
</trans-unit>
<trans-unit id="Dismiss" xml:space="preserve">
<source>Dismiss</source>
<target>Dismiss</target>
<note>Button to dismiss a text field alert.</note>
</trans-unit>
<trans-unit id="Display Name" xml:space="preserve">
<source>Display Name</source>
<target>Display Name</target>
@@ -995,8 +995,7 @@ Button text to indicate that the zap type is a private zap.</note>
<trans-unit id="Relay" xml:space="preserve">
<source>Relay</source>
<target>Relay</target>
<note>Label to display relay address.
Text field for relay server. Used for testing purposes.</note>
<note>Label to display relay address.</note>
</trans-unit>
<trans-unit id="Relays" xml:space="preserve">
<source>Relays</source>
@@ -1067,11 +1066,6 @@ Button text to indicate that the zap type is a private zap.</note>
<target>Repost</target>
<note>Button to repost a note</note>
</trans-unit>
<trans-unit id="Repost Note" xml:space="preserve">
<source>Repost Note</source>
<target>Repost Note</target>
<note>Title text to indicate that the buttons below are meant to be used to repost a note to others.</note>
</trans-unit>
<trans-unit id="Reposted" xml:space="preserve">
<source>Reposted</source>
<target>Reposted</target>
@@ -1358,6 +1352,11 @@ Button text to indicate that the zap type is a private zap.</note>
<target>Universe 🛸</target>
<note>Toolbar label for the universal view where posts from all connected relay servers appear.</note>
</trans-unit>
<trans-unit id="Unmute" xml:space="preserve">
<source>Unmute</source>
<target>Unmute</target>
<note>Button to unmute a profile.</note>
</trans-unit>
<trans-unit id="Unmute conversation" xml:space="preserve">
<source>Unmute conversation</source>
<target>Unmute conversation</target>

Binary file not shown.

Binary file not shown.

View File

@@ -15,7 +15,7 @@
<key>one</key>
<string>... %d یادداشت دیگر ...</string>
<key>other</key>
<string>... %d یادداشت‌های دیگر ...</string>
<string>... %d نوت های دیگر ...</string>
</dict>
</dict>
<key>followers_count</key>
@@ -63,7 +63,7 @@
<key>one</key>
<string>%2$@ و %1$d نفر دیگر به یک مطلب که شما در آن تگ شده‌اید بازخورد داده‌اند</string>
<key>other</key>
<string>%2$@ و %1$d نفر دیگر به یک مطلب که شما در آن تگ شده‌اید بازخورد داده‌اند</string>
<string>%2$@ و %1$d نفر دیگر به یک نوت که شما در آن تگ شده‌اید بازخورد داده‌اند</string>
</dict>
</dict>
<key>reacted_your_post_3</key>
@@ -79,7 +79,7 @@
<key>one</key>
<string>%2$@ و %1$d نفر دیگر به مطلب شما بازخورد داده‌اند</string>
<key>other</key>
<string>%2$@ و %1$d نفر دیگر به مطلب شما بازخورد داده‌اند</string>
<string>%2$@ و %1$d نفر دیگر به نوت شما بازخورد داده‌اند</string>
</dict>
</dict>
<key>reacted_your_profile_3</key>
@@ -95,7 +95,7 @@
<key>one</key>
<string>%2$@ و %1$d نفر دیگر به نمایه‌ی شما بازخورد داده‌اند</string>
<key>other</key>
<string>%2$@ و %1$d نفر دیگر به نمایه‌ی شما بازخورد داده‌اند</string>
<string>%2$@ و %1$d نفر دیگر به پروفایل شما بازخورد داده‌اند</string>
</dict>
</dict>
<key>reactions_count</key>
@@ -210,6 +210,22 @@
<string>بازنشرها</string>
</dict>
</dict>
<key>sats</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@SATS@</string>
<key>SATS</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>one</key>
<string>ساتوشی</string>
<key>other</key>
<string>ساتوشی</string>
</dict>
</dict>
<key>sats_count</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
@@ -226,6 +242,38 @@
<string>%2$@ ساتوشی</string>
</dict>
</dict>
<key>zap_notification_no_message</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%1$#@NOTIFICATION@</string>
<key>NOTIFICATION</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>@</string>
<key>one</key>
<string>%2$@ ساتوشی از %3$@ دریافت کردید</string>
<key>other</key>
<string>%2$@ ساتوشی از %3$@ دریافت کردید</string>
</dict>
</dict>
<key>zap_notification_with_message</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%1$#@NOTIFICATION@</string>
<key>NOTIFICATION</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>@</string>
<key>one</key>
<string>%2$@ ساتوشی از %3$@ دریافت کردید: "%4$@"</string>
<key>other</key>
<string>%2$@ ساتوشی از %3$@ دریافت کردید: "%4$@"</string>
</dict>
</dict>
<key>zapped_tagged_in_3</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
@@ -287,7 +335,7 @@
<key>one</key>
<string>Zap</string>
<key>other</key>
<string>Zaps</string>
<string>زپ</string>
</dict>
</dict>
</dict>

Binary file not shown.

Binary file not shown.