mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-26 08:55:56 +01:00
REF: Widget views are now reusable
This commit is contained in:
parent
6f24f284f0
commit
e17b13692d
7 changed files with 173 additions and 157 deletions
|
@ -21,6 +21,12 @@
|
|||
47A71B37E7A47E7CADA091A1 /* libPods-MarketWidgetExtension.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 41BD3AC9FD81723B68A63C12 /* libPods-MarketWidgetExtension.a */; };
|
||||
5875B7B2D85DC56E00F292FF /* libPods-WalletInformationWidgetExtension.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0CC8A6C610EAE90F810EADCC /* libPods-WalletInformationWidgetExtension.a */; };
|
||||
590C62D2ED8BF487C33945B0 /* libPods-WalletInformationAndMarketWidgetExtension.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 98455D960744E4E5DD50BA87 /* libPods-WalletInformationAndMarketWidgetExtension.a */; };
|
||||
6D641F18255226DA003792DF /* MarketView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D641F17255226DA003792DF /* MarketView.swift */; };
|
||||
6D641F19255226DA003792DF /* MarketView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D641F17255226DA003792DF /* MarketView.swift */; };
|
||||
6D641F1A255226DA003792DF /* MarketView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D641F17255226DA003792DF /* MarketView.swift */; };
|
||||
6D641F2325525054003792DF /* WalletInformationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D641F2225525053003792DF /* WalletInformationView.swift */; };
|
||||
6D641F2425525054003792DF /* WalletInformationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D641F2225525053003792DF /* WalletInformationView.swift */; };
|
||||
6D641F2525525054003792DF /* WalletInformationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D641F2225525053003792DF /* WalletInformationView.swift */; };
|
||||
6D9A2E03254BA347007B5B82 /* WidgetKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D333B3A252FE1A3004D72DF /* WidgetKit.framework */; };
|
||||
6D9A2E04254BA347007B5B82 /* SwiftUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D333B3C252FE1A3004D72DF /* SwiftUI.framework */; };
|
||||
6D9A2E07254BA347007B5B82 /* WalletInformationAndMarketWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D9A2E06254BA347007B5B82 /* WalletInformationAndMarketWidget.swift */; };
|
||||
|
@ -254,6 +260,8 @@
|
|||
6D294A9E24D512800039E22B /* xh */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = xh; path = xh.lproj/MainInterface.strings; sourceTree = "<group>"; };
|
||||
6D333B3A252FE1A3004D72DF /* WidgetKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WidgetKit.framework; path = System/Library/Frameworks/WidgetKit.framework; sourceTree = SDKROOT; };
|
||||
6D333B3C252FE1A3004D72DF /* SwiftUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SwiftUI.framework; path = System/Library/Frameworks/SwiftUI.framework; sourceTree = SDKROOT; };
|
||||
6D641F17255226DA003792DF /* MarketView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarketView.swift; sourceTree = "<group>"; };
|
||||
6D641F2225525053003792DF /* WalletInformationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletInformationView.swift; sourceTree = "<group>"; };
|
||||
6D9A2DB2254B69B6007B5B82 /* MarketWidgetExtension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = MarketWidgetExtension.entitlements; sourceTree = "<group>"; };
|
||||
6D9A2E02254BA347007B5B82 /* WalletInformationAndMarketWidgetExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = WalletInformationAndMarketWidgetExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
6D9A2E06254BA347007B5B82 /* WalletInformationAndMarketWidget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletInformationAndMarketWidget.swift; sourceTree = "<group>"; };
|
||||
|
@ -544,6 +552,7 @@
|
|||
6DEB4BC1254FB98300E9F9AA /* Shared */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
6DEB4DD82552260200E9F9AA /* Views */,
|
||||
6D9A2E6A254BAB1B007B5B82 /* WidgetAPI.swift */,
|
||||
6D9A2E6B254BAB1B007B5B82 /* WidgetDataStore.swift */,
|
||||
6DA7047D254E24D5005FE5E2 /* UserDefaultsGroup.swift */,
|
||||
|
@ -554,6 +563,15 @@
|
|||
path = Shared;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
6DEB4DD82552260200E9F9AA /* Views */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
6D641F17255226DA003792DF /* MarketView.swift */,
|
||||
6D641F2225525053003792DF /* WalletInformationView.swift */,
|
||||
);
|
||||
path = Views;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
83CBB9F61A601CBA00E9B192 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
|
@ -1145,12 +1163,14 @@
|
|||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
6D641F2325525054003792DF /* WalletInformationView.swift in Sources */,
|
||||
6D9A2E6D254BAB1B007B5B82 /* WidgetAPI.swift in Sources */,
|
||||
6DEB4C3B254FBF4800E9F9AA /* Colors.swift in Sources */,
|
||||
6D9A2E6F254BAB1B007B5B82 /* WidgetDataStore.swift in Sources */,
|
||||
6DA7047E254E24D5005FE5E2 /* UserDefaultsGroup.swift in Sources */,
|
||||
6D9A2E07254BA347007B5B82 /* WalletInformationAndMarketWidget.swift in Sources */,
|
||||
6DEB4BFB254FBA0E00E9F9AA /* Models.swift in Sources */,
|
||||
6D641F18255226DA003792DF /* MarketView.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -1158,12 +1178,14 @@
|
|||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
6D641F2425525054003792DF /* WalletInformationView.swift in Sources */,
|
||||
6DEB4AB2254FB59C00E9F9AA /* WalletInformationWidget.swift in Sources */,
|
||||
6DEB4C3C254FBF4800E9F9AA /* Colors.swift in Sources */,
|
||||
6DEB4BDA254FB98E00E9F9AA /* WidgetAPI.swift in Sources */,
|
||||
6DEB4BDB254FB98E00E9F9AA /* UserDefaultsGroup.swift in Sources */,
|
||||
6DEB4BD9254FB98E00E9F9AA /* WidgetDataStore.swift in Sources */,
|
||||
6DEB4BFC254FBA0E00E9F9AA /* Models.swift in Sources */,
|
||||
6D641F19255226DA003792DF /* MarketView.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -1171,12 +1193,14 @@
|
|||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
6D641F2525525054003792DF /* WalletInformationView.swift in Sources */,
|
||||
6DEB4B2B254FB80300E9F9AA /* MarketWidget.swift in Sources */,
|
||||
6DEB4C3D254FBF4800E9F9AA /* Colors.swift in Sources */,
|
||||
6DEB4BD7254FB98D00E9F9AA /* WidgetAPI.swift in Sources */,
|
||||
6DEB4BD8254FB98D00E9F9AA /* UserDefaultsGroup.swift in Sources */,
|
||||
6DEB4BD6254FB98D00E9F9AA /* WidgetDataStore.swift in Sources */,
|
||||
6DEB4BFD254FBA0E00E9F9AA /* Models.swift in Sources */,
|
||||
6D641F1A255226DA003792DF /* MarketView.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
@ -27,7 +27,7 @@ struct Provider: TimelineProvider {
|
|||
func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
|
||||
var entries: [SimpleEntry] = []
|
||||
let userPreferredCurrency = WidgetAPI.getUserPreferredCurrency();
|
||||
|
||||
|
||||
let marketDataEntry = MarketData(nextBlock: "...", sats: "...", price: "...", rate: 0)
|
||||
let allwalletsBalance = WalletData(balance: UserDefaultsGroup.getAllWalletsBalance(), latestTransactionTime: UserDefaultsGroup.getAllWalletsLatestTransactionTime())
|
||||
WidgetAPI.fetchPrice(currency: userPreferredCurrency, completion: { (result, error) in
|
||||
|
@ -53,54 +53,13 @@ struct SimpleEntry: TimelineEntry {
|
|||
|
||||
struct WalletInformationWidgetEntryView : View {
|
||||
var entry: Provider.Entry
|
||||
var formattedBalance: String {
|
||||
let numberFormatter = NumberFormatter()
|
||||
numberFormatter.locale = Locale(identifier: WidgetAPI.getUserPreferredCurrencyLocale())
|
||||
numberFormatter.numberStyle = .currency
|
||||
numberFormatter.numberStyle = .currency
|
||||
let amount = numberFormatter.string(from: NSNumber(value: ((entry.allWalletsBalance.balance / 100000000) * entry.marketData.rate))) ?? ""
|
||||
return amount
|
||||
}
|
||||
var formattedLatestTransactionTime: String {
|
||||
if entry.allWalletsBalance.latestTransactionTime == 0 {
|
||||
return "never"
|
||||
}
|
||||
let forDate = Date(timeIntervalSince1970: (TimeInterval(entry.allWalletsBalance.latestTransactionTime) / 1000))
|
||||
let dateFormatter = RelativeDateTimeFormatter()
|
||||
dateFormatter.locale = Locale(identifier: Locale.current.identifier)
|
||||
dateFormatter.dateTimeStyle = .numeric
|
||||
return dateFormatter.localizedString(for: forDate, relativeTo: Date())
|
||||
}
|
||||
|
||||
var WalletBalance: some View {
|
||||
VStack(alignment: .leading, spacing:nil , content: {
|
||||
HStack(alignment: .top, content: {
|
||||
VStack(alignment: .leading, spacing: nil, content: {
|
||||
VStack(alignment: .leading, spacing: /*@START_MENU_TOKEN@*/nil/*@END_MENU_TOKEN@*/, content: {
|
||||
Text(entry.allWalletsBalance.formattedBalanceBTC).lineLimit(1).minimumScaleFactor(0.01).font(Font.system(size: 15, weight: .medium, design: .default)).foregroundColor(.textColorLightGray)
|
||||
Text(formattedBalance).lineLimit(1).foregroundColor(.textColor).font(Font.system(size:28, weight: .bold, design: .default)).minimumScaleFactor(0.01)
|
||||
|
||||
})
|
||||
})
|
||||
Spacer()
|
||||
})
|
||||
Spacer()
|
||||
|
||||
HStack(alignment: .top, content: {
|
||||
|
||||
VStack(alignment: .leading, spacing: nil, content: {
|
||||
Text("Latest transaction").font(Font.system(size: 11, weight: .regular, design: .default)).foregroundColor(.textColorLightGray)
|
||||
Text(formattedLatestTransactionTime).lineLimit(1).foregroundColor(.textColor).font(Font.system(size:13, weight: .regular, design: .default)).minimumScaleFactor(0.01)
|
||||
|
||||
})
|
||||
Spacer()
|
||||
|
||||
})}).padding()
|
||||
WalletInformationView(allWalletsBalance: entry.allWalletsBalance, marketData: entry.marketData)
|
||||
}
|
||||
|
||||
|
||||
var body: some View {
|
||||
WalletBalance.background(Color.widgetBackground)
|
||||
WalletBalance.padding().background(Color.widgetBackground)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,36 +52,7 @@ struct MarketWidgetEntryView : View {
|
|||
var entry: Provider.Entry
|
||||
|
||||
var MarketStack: some View {
|
||||
VStack(alignment: .leading, spacing:23 , content: {
|
||||
VStack(alignment: .leading, spacing: /*@START_MENU_TOKEN@*/nil/*@END_MENU_TOKEN@*/, content: {
|
||||
Text("Market").font(.headline).foregroundColor(.textColor).bold()
|
||||
Spacer()
|
||||
HStack(alignment: .center, spacing: 0, content: {
|
||||
Text("Next Block").bold().lineLimit(1).font(Font.system(size:11, weight: .medium, design: .default)).foregroundColor(.textColor)
|
||||
Spacer()
|
||||
Text(entry.marketData.formattedNextBlock).padding(EdgeInsets(top: 2, leading: 4, bottom: 2, trailing: 4)).lineLimit(1).foregroundColor(.widgetBackground).font(Font.system(size:11, weight: .semibold, design: .default)).background(Color(red: 0.29, green: 0.86, blue: 0.73)).overlay(
|
||||
RoundedRectangle(cornerRadius: 4.0)
|
||||
.stroke(Color.containerGreen, lineWidth: 4.0))
|
||||
})
|
||||
|
||||
Spacer()
|
||||
HStack(alignment: .center, spacing: 0, content: {
|
||||
Text("Sats/Dollar").bold().lineLimit(1).font(Font.system(size:11, weight: .medium, design: .default)).foregroundColor(.textColor)
|
||||
Spacer()
|
||||
Text(entry.marketData.sats == "..." ? "..." : entry.marketData.sats).padding(EdgeInsets(top: 2, leading: 4, bottom: 2, trailing: 4)).lineLimit(1).foregroundColor(.widgetBackground).font(Font.system(size:11, weight: .semibold, design: .default)).background(Color(red: 0.97, green: 0.21, blue: 0.38)).overlay(
|
||||
RoundedRectangle(cornerRadius: 4.0)
|
||||
.stroke(Color.containerRed, lineWidth: 4.0))
|
||||
})
|
||||
Spacer()
|
||||
HStack(alignment: .center, spacing: 0, content: {
|
||||
Text("Price").bold().lineLimit(1).font(Font.system(size:11, weight: . medium, design: .default)).foregroundColor(.textColor)
|
||||
Spacer()
|
||||
Text(entry.marketData.price == "..." ? "..." : entry.marketData.price).padding(EdgeInsets(top: 2, leading: 4, bottom: 2, trailing: 4)).lineLimit(1).foregroundColor(.widgetBackground).font(Font.system(size:11, weight: .semibold, design: .default)).background(Color(red: 0.29, green: 0.86, blue: 0.73)).overlay(
|
||||
RoundedRectangle(cornerRadius:4.0)
|
||||
.stroke(Color.containerGreen, lineWidth: 4.0))
|
||||
})
|
||||
}).padding(EdgeInsets(top: 18, leading: 11, bottom: 18, trailing: 11))
|
||||
})
|
||||
MarketView(marketData: entry.marketData).padding(EdgeInsets(top: 18, leading: 11, bottom: 18, trailing: 11))
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
// Copyright © 2020 BlueWallet. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
struct MarketData {
|
||||
var nextBlock: String
|
||||
var sats: String
|
||||
|
@ -27,3 +29,4 @@ struct WalletData {
|
|||
|
||||
|
||||
let emptyMarketData = MarketData(nextBlock: "...", sats: "...", price: "...", rate: 0)
|
||||
let emptyWalletData = WalletData(balance: 0, latestTransactionTime: Int(Date().timeIntervalSince1970))
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
//
|
||||
// MarketView.swift
|
||||
// BlueWallet
|
||||
//
|
||||
// Created by Marcos Rodriguez on 11/3/20.
|
||||
// Copyright © 2020 BlueWallet. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import WidgetKit
|
||||
|
||||
struct MarketView: View {
|
||||
|
||||
var marketData: MarketData = emptyMarketData
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing:23 , content: {
|
||||
VStack(alignment: .leading, spacing: /*@START_MENU_TOKEN@*/nil/*@END_MENU_TOKEN@*/, content: {
|
||||
Text("Market").font(.headline).foregroundColor(.textColor).bold()
|
||||
Spacer()
|
||||
HStack(alignment: .center, spacing: 0, content: {
|
||||
Text("Next Block").bold().lineLimit(1).font(Font.system(size:11, weight: .medium, design: .default)).foregroundColor(.textColor)
|
||||
Spacer()
|
||||
Text(marketData.formattedNextBlock).padding(EdgeInsets(top: 2, leading: 4, bottom: 2, trailing: 4)).lineLimit(1).minimumScaleFactor(0.1).foregroundColor(.widgetBackground).font(Font.system(size:11, weight: .semibold, design: .default)).background(Color(red: 0.29, green: 0.86, blue: 0.73)).overlay(
|
||||
RoundedRectangle(cornerRadius: 4.0)
|
||||
.stroke(Color.containerGreen, lineWidth: 4.0))
|
||||
})
|
||||
|
||||
Spacer()
|
||||
HStack(alignment: .center, spacing: 0, content: {
|
||||
Text("Sats/Dollar").bold().lineLimit(1).font(Font.system(size:11, weight: .medium, design: .default)).foregroundColor(.textColor)
|
||||
Spacer()
|
||||
Text(marketData.sats == "..." ? "..." : marketData.sats).padding(EdgeInsets(top: 2, leading: 4, bottom: 2, trailing: 4)).lineLimit(1).minimumScaleFactor(0.1).foregroundColor(.widgetBackground).font(Font.system(size:11, weight: .semibold, design: .default)).background(Color(red: 0.97, green: 0.21, blue: 0.38)).overlay(
|
||||
RoundedRectangle(cornerRadius: 4.0)
|
||||
.stroke(Color.containerRed, lineWidth: 4.0))
|
||||
})
|
||||
Spacer()
|
||||
HStack(alignment: .center, spacing: 0, content: {
|
||||
Text("Price").bold().lineLimit(1).font(Font.system(size:11, weight: . medium, design: .default)).foregroundColor(.textColor)
|
||||
Spacer()
|
||||
Text(marketData.price == "..." ? "..." : marketData.price).padding(EdgeInsets(top: 2, leading: 4, bottom: 2, trailing: 4)).lineLimit(1).minimumScaleFactor(0.1).foregroundColor(.widgetBackground).font(Font.system(size:11, weight: .semibold, design: .default)).background(Color(red: 0.29, green: 0.86, blue: 0.73)).overlay(
|
||||
RoundedRectangle(cornerRadius:4.0)
|
||||
.stroke(Color.containerGreen, lineWidth: 4.0))
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct MarketView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
MarketView(marketData: MarketData(nextBlock: "26", sats: "9 134", price: "$10,000", rate: 0))
|
||||
.previewContext(WidgetPreviewContext(family: .systemSmall))
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
//
|
||||
// WalletInformationView.swift
|
||||
// BlueWallet
|
||||
//
|
||||
// Created by Marcos Rodriguez on 11/3/20.
|
||||
// Copyright © 2020 BlueWallet. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import WidgetKit
|
||||
|
||||
struct WalletInformationView: View {
|
||||
|
||||
var allWalletsBalance: WalletData = emptyWalletData
|
||||
var marketData: MarketData = emptyMarketData
|
||||
|
||||
var formattedBalance: String {
|
||||
let numberFormatter = NumberFormatter()
|
||||
numberFormatter.locale = Locale(identifier: WidgetAPI.getUserPreferredCurrencyLocale())
|
||||
numberFormatter.numberStyle = .currency
|
||||
numberFormatter.numberStyle = .currency
|
||||
let amount = numberFormatter.string(from: NSNumber(value: ((allWalletsBalance.balance / 100000000) * marketData.rate))) ?? ""
|
||||
return amount
|
||||
}
|
||||
var formattedLatestTransactionTime: String {
|
||||
if allWalletsBalance.latestTransactionTime == 0 {
|
||||
return "never"
|
||||
}
|
||||
let forDate = Date(timeIntervalSince1970: (TimeInterval(allWalletsBalance.latestTransactionTime) / 1000))
|
||||
let dateFormatter = RelativeDateTimeFormatter()
|
||||
dateFormatter.locale = Locale(identifier: Locale.current.identifier)
|
||||
dateFormatter.dateTimeStyle = .numeric
|
||||
return dateFormatter.localizedString(for: forDate, relativeTo: Date())
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing:nil , content: {
|
||||
Text(allWalletsBalance.formattedBalanceBTC).font(Font.system(size: 15, weight: .medium, design: .default)).foregroundColor(.textColorLightGray).lineLimit(1).minimumScaleFactor(0.01)
|
||||
|
||||
|
||||
Text(formattedBalance).lineLimit(1).foregroundColor(.textColor).font(Font.system(size:28, weight: .bold, design: .default)).minimumScaleFactor(0.01)
|
||||
Spacer()
|
||||
|
||||
Text("Latest transaction").font(Font.system(size: 11, weight: .regular, design: .default)).foregroundColor(.textColorLightGray)
|
||||
Text(formattedLatestTransactionTime).lineLimit(1).foregroundColor(.textColor).font(Font.system(size:13, weight: .regular, design: .default)).minimumScaleFactor(0.01)
|
||||
|
||||
}).frame(minWidth: 0,
|
||||
maxWidth: .infinity,
|
||||
minHeight: 0,
|
||||
maxHeight: .infinity,
|
||||
alignment: .topLeading)
|
||||
}
|
||||
}
|
||||
|
||||
struct WalletInformationView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
WalletInformationView(allWalletsBalance: WalletData(balance: 10000, latestTransactionTime: 1568804029000), marketData: MarketData(nextBlock: "26", sats: "9 134", price: "$10,000", rate: Double(13000)))
|
||||
.previewContext(WidgetPreviewContext(family: .systemSmall))
|
||||
}
|
||||
}
|
|
@ -53,107 +53,49 @@ struct SimpleEntry: TimelineEntry {
|
|||
struct WalletInformationAndMarketWidgetEntryView : View {
|
||||
@Environment(\.widgetFamily) var family
|
||||
var entry: Provider.Entry
|
||||
var formattedBalance: String {
|
||||
let numberFormatter = NumberFormatter()
|
||||
numberFormatter.locale = Locale(identifier: WidgetAPI.getUserPreferredCurrencyLocale())
|
||||
numberFormatter.numberStyle = .currency
|
||||
numberFormatter.numberStyle = .currency
|
||||
let amount = numberFormatter.string(from: NSNumber(value: ((entry.allWalletsBalance.balance / 100000000) * entry.marketData.rate))) ?? ""
|
||||
return amount
|
||||
}
|
||||
var formattedLatestTransactionTime: String {
|
||||
if entry.allWalletsBalance.latestTransactionTime == 0 {
|
||||
return "never"
|
||||
}
|
||||
let forDate = Date(timeIntervalSince1970: (TimeInterval(entry.allWalletsBalance.latestTransactionTime) / 1000))
|
||||
let dateFormatter = RelativeDateTimeFormatter()
|
||||
dateFormatter.locale = Locale(identifier: Locale.current.identifier)
|
||||
dateFormatter.dateTimeStyle = .numeric
|
||||
return dateFormatter.localizedString(for: forDate, relativeTo: Date())
|
||||
}
|
||||
|
||||
|
||||
var WalletBalance: some View {
|
||||
VStack(alignment: .leading, spacing:nil , content: {
|
||||
VStack(alignment: .leading, spacing: /*@START_MENU_TOKEN@*/nil/*@END_MENU_TOKEN@*/, content: {
|
||||
Text(entry.allWalletsBalance.formattedBalanceBTC).font(Font.system(size: 15, weight: .medium, design: .default)).foregroundColor(.textColorLightGray).lineLimit(1).minimumScaleFactor(0.01)
|
||||
Text(formattedBalance).lineLimit(1).foregroundColor(.textColor).font(Font.system(size:28, weight: .bold, design: .default)).minimumScaleFactor(0.01)
|
||||
})
|
||||
Spacer()
|
||||
VStack(content: {
|
||||
VStack(alignment: .leading, spacing: /*@START_MENU_TOKEN@*/nil/*@END_MENU_TOKEN@*/, content: {
|
||||
Text("Latest transaction").font(Font.system(size: 11, weight: .regular, design: .default)).foregroundColor(.textColorLightGray)
|
||||
Text(formattedLatestTransactionTime).lineLimit(1).foregroundColor(.textColor).font(Font.system(size:13, weight: .regular, design: .default)).minimumScaleFactor(0.01)
|
||||
})
|
||||
})
|
||||
}).background(Color.widgetBackground)
|
||||
WalletInformationView(allWalletsBalance: entry.allWalletsBalance, marketData: entry.marketData).background(Color.widgetBackground)
|
||||
}
|
||||
|
||||
var MarketStack: some View {
|
||||
VStack(alignment: .leading, spacing:23 , content: {
|
||||
VStack(alignment: .leading, spacing: /*@START_MENU_TOKEN@*/nil/*@END_MENU_TOKEN@*/, content: {
|
||||
Text("Market").font(.headline).foregroundColor(.textColor).bold()
|
||||
Spacer()
|
||||
HStack(alignment: .center, spacing: 0, content: {
|
||||
Text("Next Block").bold().lineLimit(1).font(Font.system(size:11, weight: .medium, design: .default)).foregroundColor(.textColor)
|
||||
Spacer()
|
||||
Text(entry.marketData.formattedNextBlock).padding(EdgeInsets(top: 2, leading: 4, bottom: 2, trailing: 4)).lineLimit(1).foregroundColor(.widgetBackground).font(Font.system(size:11, weight: .semibold, design: .default)).background(Color(red: 0.29, green: 0.86, blue: 0.73)).overlay(
|
||||
RoundedRectangle(cornerRadius: 4.0)
|
||||
.stroke(Color.containerGreen, lineWidth: 4.0))
|
||||
})
|
||||
|
||||
Spacer()
|
||||
HStack(alignment: .center, spacing: 0, content: {
|
||||
Text("Sats/Dollar").bold().lineLimit(1).font(Font.system(size:11, weight: .medium, design: .default)).foregroundColor(.textColor)
|
||||
Spacer()
|
||||
Text(entry.marketData.sats == "..." ? "..." : entry.marketData.sats).padding(EdgeInsets(top: 2, leading: 4, bottom: 2, trailing: 4)).lineLimit(1).foregroundColor(.widgetBackground).font(Font.system(size:11, weight: .semibold, design: .default)).background(Color(red: 0.97, green: 0.21, blue: 0.38)).overlay(
|
||||
RoundedRectangle(cornerRadius: 4.0)
|
||||
.stroke(Color.containerRed, lineWidth: 4.0))
|
||||
})
|
||||
Spacer()
|
||||
HStack(alignment: .center, spacing: 0, content: {
|
||||
Text("Price").bold().lineLimit(1).font(Font.system(size:11, weight: . medium, design: .default)).foregroundColor(.textColor)
|
||||
Spacer()
|
||||
Text(entry.marketData.price == "..." ? "..." : entry.marketData.price).padding(EdgeInsets(top: 2, leading: 4, bottom: 2, trailing: 4)).lineLimit(1).foregroundColor(.widgetBackground).font(Font.system(size:11, weight: .semibold, design: .default)).background(Color(red: 0.29, green: 0.86, blue: 0.73)).overlay(
|
||||
RoundedRectangle(cornerRadius:4.0)
|
||||
.stroke(Color.containerGreen, lineWidth: 4.0))
|
||||
})
|
||||
}).padding(EdgeInsets(top: 18, leading: 11, bottom: 18, trailing: 11))
|
||||
})
|
||||
MarketView(marketData: entry.marketData)
|
||||
}
|
||||
|
||||
var SendReceiveButtons: some View {
|
||||
VStack(alignment: .center, spacing: nil, content: {
|
||||
Spacer()
|
||||
HStack(alignment: .center, spacing: nil, content: {
|
||||
Spacer()
|
||||
HStack( content: {
|
||||
Link("receive", destination: URL(string: "bluewallet://widget?action=openReceive")!).frame(minWidth: 144, maxWidth: /*@START_MENU_TOKEN@*/.infinity/*@END_MENU_TOKEN@*/, minHeight: 32, maxHeight: 32, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/).padding(EdgeInsets(top: 2, leading: 4, bottom: 2, trailing: 4)).lineLimit(1).foregroundColor(.textColor).font(Font.system(size:11, weight: .semibold, design: .default)).background(Color.widgetBackground).overlay(
|
||||
RoundedRectangle(cornerRadius: 4.0)
|
||||
.stroke(Color.widgetBackground, lineWidth: 4.0))
|
||||
})
|
||||
Spacer()
|
||||
Link("send", destination: URL(string: "bluewallet://widget?action=openSend")!).frame(minWidth: 144, maxWidth: /*@START_MENU_TOKEN@*/.infinity/*@END_MENU_TOKEN@*/, minHeight: 32, maxHeight: 32, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/).padding(EdgeInsets(top: 2, leading: 4, bottom: 2, trailing: 4)).lineLimit(1).foregroundColor(.textColor).font(Font.system(size:11, weight: .semibold, design: .default)).background(Color.widgetBackground).overlay(
|
||||
HStack(alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/, spacing: 16, content: {
|
||||
Link("receive", destination: URL(string: "bluewallet://widget?action=openReceive")!).frame(minWidth: 144, maxWidth: /*@START_MENU_TOKEN@*/.infinity/*@END_MENU_TOKEN@*/, minHeight: 32, maxHeight: 32, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/).lineLimit(1).foregroundColor(.textColor).font(Font.system(size:11, weight: .semibold, design: .default)).background(Color.widgetBackground).overlay(
|
||||
RoundedRectangle(cornerRadius: 4.0)
|
||||
.stroke(Color.widgetBackground, lineWidth: 4.0))
|
||||
Spacer()
|
||||
})
|
||||
Spacer()
|
||||
})
|
||||
Link("send", destination: URL(string: "bluewallet://widget?action=openSend")!).frame(minWidth: 144, maxWidth: /*@START_MENU_TOKEN@*/.infinity/*@END_MENU_TOKEN@*/, minHeight: 32, maxHeight: 32, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/).lineLimit(1).foregroundColor(.textColor).font(Font.system(size:11, weight: .semibold, design: .default)).background(Color.widgetBackground).overlay(
|
||||
RoundedRectangle(cornerRadius: 4.0)
|
||||
.stroke(Color.widgetBackground, lineWidth: 4.0))
|
||||
}).padding(.horizontal, /*@START_MENU_TOKEN@*/10/*@END_MENU_TOKEN@*/)
|
||||
}).padding(.vertical, /*@START_MENU_TOKEN@*/10/*@END_MENU_TOKEN@*/)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
if family == .systemLarge {
|
||||
VStack(alignment: .leading, spacing: nil, content: {
|
||||
WalletBalance.padding()
|
||||
MarketStack.background(Color(.lightGray).opacity(0.77))
|
||||
SendReceiveButtons.background(Color(.lightGray).opacity(0.77))
|
||||
}).background(Color.widgetBackground)
|
||||
HStack(alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/, spacing: /*@START_MENU_TOKEN@*/nil/*@END_MENU_TOKEN@*/, content: {
|
||||
VStack(alignment: .leading, spacing: nil, content: {
|
||||
HStack(content: {
|
||||
WalletBalance.padding()
|
||||
}).background(Color.widgetBackground)
|
||||
HStack(content: {
|
||||
MarketStack }).padding()
|
||||
SendReceiveButtons }).background(Color(.lightGray).opacity(0.77))
|
||||
|
||||
})
|
||||
|
||||
} else {
|
||||
HStack(content: {
|
||||
WalletBalance.padding().background(Color.widgetBackground)
|
||||
MarketStack
|
||||
}).background(Color(.lightGray).opacity(0.77))
|
||||
WalletBalance.padding()
|
||||
HStack(content: {
|
||||
MarketStack.padding()
|
||||
}).background(Color(.lightGray).opacity(0.77))
|
||||
}).background(Color.widgetBackground)
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue