Skip to content

Commit 72cba38

Browse files
committed
fix widget update wallet
1 parent 4c8a566 commit 72cba38

File tree

7 files changed

+43
-35
lines changed

7 files changed

+43
-35
lines changed

TrackerWidget/TrackerWidget.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct BalanceWidgetProvider: TimelineProvider {
3636

3737
func getTimeline(in context: Context, completion: @escaping (Timeline<BalanceWidgetEntry>) -> Void) {
3838
let currentDate = Date()
39-
let refreshDate = Calendar.current.date(byAdding: .minute, value: 5, to: currentDate)!
39+
let refreshDate = Calendar.current.date(byAdding: .hour, value: 1, to: currentDate)!
4040

4141
viewModel.fetchBalance{ totalUsd in
4242

apple-watch-portfolio-tracker Watch App/BalanceViewModel.swift

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class BalanceViewModel: ObservableObject {
1414
struct Wallet: Codable {
1515
let address: String
1616
}
17-
17+
1818

1919
init() {
2020
self.wallet = UserDefaults.standard.string(forKey: "wallet") ?? "0x873351e707257C28eC6fAB1ADbc850480f6e0633"
@@ -30,6 +30,8 @@ class BalanceViewModel: ObservableObject {
3030

3131

3232
func fetchBalance() {
33+
self.wallet = UserDefaults.standard.string(forKey: "wallet") ?? "0x873351e707257C28eC6fAB1ADbc850480f6e0633"
34+
3335
guard let url = URL(string: "https://dashapi.onout.org/debank?address=\(self.wallet)&app=itracker") else {
3436
return
3537
}
@@ -56,6 +58,10 @@ class BalanceViewModel: ObservableObject {
5658
}
5759

5860
func fetchBalance(completion: @escaping (Double) -> Void) {
61+
62+
self.wallet = UserDefaults.standard.string(forKey: "wallet") ?? "0x873351e707257C28eC6fAB1ADbc850480f6e0633"
63+
64+
5965
guard let url = URL(string: "https://dashapi.onout.org/debank?address=\(self.wallet)&app=itracker") else {
6066
return
6167
}
@@ -103,14 +109,16 @@ class BalanceViewModel: ObservableObject {
103109
return
104110
}
105111
do {
106-
let decoder = JSONDecoder()
107-
let wallet = try decoder.decode(Wallet.self, from: data)
108-
completion(wallet)
109-
} catch {
110-
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
111-
self.updateWalletByUUID(uuid: uuid, completion: completion)
112-
}
113-
}
112+
let decoder = JSONDecoder()
113+
let wallet = try decoder.decode(Wallet.self, from: data)
114+
UserDefaults.standard.set(wallet.address, forKey: "wallet")
115+
self.wallet = wallet.address
116+
completion(wallet)
117+
} catch {
118+
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
119+
self.updateWalletByUUID(uuid: uuid, completion: completion)
120+
}
121+
}
114122
}
115123
task.resume()
116124
}

apple-watch-portfolio-tracker Watch App/ContentView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import SwiftUI
99

1010
struct ContentView: View {
1111
@StateObject private var viewModel = BalanceViewModel()
12-
12+
1313
@State private var inputString = ""
1414
@State private var showingInputDialog = false
1515

@@ -32,7 +32,7 @@ struct ContentView: View {
3232
}
3333
}
3434

35-
35+
3636
}
3737

3838

apple-watch-portfolio-tracker Watch App/WalletInfoView.swift

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@ struct WalletInfoView: View {
1616
@State private var inputString = ""
1717
@State private var showingInputDialog = false
1818

19-
20-
19+
20+
2121

2222
var body: some View {
2323
ScrollView{
2424
VStack {
25-
25+
2626
Text(viewModel.wallet)
2727
.allowsTightening(true)
2828
.font(.system(size: 12))
2929
.padding()
3030

31-
32-
31+
32+
3333
TextField("Enter new wallet", text: $inputString, onCommit: {
3434
viewModel.updateWallet(wallet: inputString)
3535

@@ -48,17 +48,17 @@ struct WalletInfoView: View {
4848

4949

5050

51-
51+
5252

5353
}
5454

5555
struct QRCodeView: View {
5656

5757
@ObservedObject var viewModel: BalanceViewModel
5858
@Environment(\.presentationMode) var presentationMode
59-
59+
6060
private let uuidString = UUID().uuidString
61-
61+
6262
var body: some View {
6363
VStack {
6464
Text("Scan via Phone")
@@ -73,24 +73,24 @@ struct QRCodeView: View {
7373
viewModel.updateWallet(wallet: wallet?.address ?? "")
7474
presentationMode.wrappedValue.dismiss()
7575
}
76-
76+
7777
})
7878
}
7979
}
8080

8181

8282
func generateQRCode(from string: String) -> UIImage {
83-
let content = "https://tracker.onout.org/?a=form&uuid=\(string)"
84-
let generator = EFQRCodeGenerator(content: content)
85-
generator.withMode(Optional.none)
86-
do {
87-
let image = generator.generate()!
88-
return UIImage(cgImage: image)
89-
} catch {
90-
print(error.localizedDescription)
91-
return UIImage(systemName: "xmark.circle") ?? UIImage()
92-
}
83+
let content = "https://tracker.onout.org/?a=form&uuid=\(string)"
84+
let generator = EFQRCodeGenerator(content: content)
85+
generator.withMode(Optional.none)
86+
do {
87+
let image = generator.generate()!
88+
return UIImage(cgImage: image)
89+
} catch {
90+
print(error.localizedDescription)
91+
return UIImage(systemName: "xmark.circle") ?? UIImage()
9392
}
93+
}
9494
}
9595

9696
#Preview {

apple-watch-portfolio-tracker.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@
461461
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
462462
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
463463
CODE_SIGN_STYLE = Automatic;
464-
CURRENT_PROJECT_VERSION = 1;
464+
CURRENT_PROJECT_VERSION = 3;
465465
DEVELOPMENT_ASSET_PATHS = "\"apple-watch-portfolio-tracker Watch App/Preview Content\"";
466466
DEVELOPMENT_TEAM = 36TMC58V7J;
467467
ENABLE_PREVIEWS = YES;
@@ -491,7 +491,7 @@
491491
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
492492
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
493493
CODE_SIGN_STYLE = Automatic;
494-
CURRENT_PROJECT_VERSION = 1;
494+
CURRENT_PROJECT_VERSION = 3;
495495
DEVELOPMENT_ASSET_PATHS = "\"apple-watch-portfolio-tracker Watch App/Preview Content\"";
496496
DEVELOPMENT_TEAM = 36TMC58V7J;
497497
ENABLE_PREVIEWS = YES;

apple-watch-portfolio-tracker.xcodeproj/xcuserdata/nikitaivanov.xcuserdatad/xcschemes/xcschememanagement.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
<key>TrackerWidgetExtension.xcscheme_^#shared#^_</key>
7171
<dict>
7272
<key>orderHint</key>
73-
<integer>0</integer>
73+
<integer>1</integer>
7474
</dict>
7575
<key>User Guide (Playground) 1.xcscheme</key>
7676
<dict>
@@ -96,7 +96,7 @@
9696
<key>apple-watch-portfolio-tracker Watch App.xcscheme_^#shared#^_</key>
9797
<dict>
9898
<key>orderHint</key>
99-
<integer>1</integer>
99+
<integer>0</integer>
100100
</dict>
101101
</dict>
102102
</dict>

0 commit comments

Comments
 (0)