diff --git a/Cryato.xcodeproj/project.pbxproj b/Cryato.xcodeproj/project.pbxproj index 9530eed..691ea35 100644 --- a/Cryato.xcodeproj/project.pbxproj +++ b/Cryato.xcodeproj/project.pbxproj @@ -43,6 +43,7 @@ 1A510D232994488B00F65B0D /* .gitignore in Resources */ = {isa = PBXBuildFile; fileRef = 1A510D222994488B00F65B0D /* .gitignore */; }; 1A510D252994BBD500F65B0D /* SharedPreferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A510D242994BBD500F65B0D /* SharedPreferences.swift */; }; 1A510D282994C07000F65B0D /* SharedPreferenceType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A510D272994C07000F65B0D /* SharedPreferenceType.swift */; }; + 1A736E34299FB76F001E6921 /* AddRecordsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A736E33299FB76F001E6921 /* AddRecordsView.swift */; }; 1A7B04EC2993D547008D46C3 /* ScannerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A7B04EB2993D547008D46C3 /* ScannerView.swift */; }; 1A7B04EE2993E6FB008D46C3 /* RecordsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A7B04ED2993E6FB008D46C3 /* RecordsView.swift */; }; 1A7BC4DF299786A70046D622 /* BybitEncryption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A7BC4DE299786A70046D622 /* BybitEncryption.swift */; }; @@ -128,6 +129,7 @@ 1A510D242994BBD500F65B0D /* SharedPreferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharedPreferences.swift; sourceTree = ""; }; 1A510D272994C07000F65B0D /* SharedPreferenceType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharedPreferenceType.swift; sourceTree = ""; }; 1A510D292994F7B300F65B0D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 1A736E33299FB76F001E6921 /* AddRecordsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddRecordsView.swift; sourceTree = ""; }; 1A7B04EB2993D547008D46C3 /* ScannerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScannerView.swift; sourceTree = ""; }; 1A7B04ED2993E6FB008D46C3 /* RecordsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecordsView.swift; sourceTree = ""; }; 1A7BC4DE299786A70046D622 /* BybitEncryption.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BybitEncryption.swift; sourceTree = ""; }; @@ -383,6 +385,7 @@ 1A93904C299533F1004AB56D /* AssetsView.swift */, 1A0242CE299B832F005C40BE /* ScamView.swift */, 1A0242EC299CC764005C40BE /* AddScamList.swift */, + 1A736E33299FB76F001E6921 /* AddRecordsView.swift */, ); path = Views; sourceTree = ""; @@ -579,6 +582,7 @@ 1A1B55D3298989BF00C2C773 /* Calculator.swift in Sources */, 1A7B04EC2993D547008D46C3 /* ScannerView.swift in Sources */, 1AF58EBD2998FF04003BD1DA /* Cryptocurrencies.swift in Sources */, + 1A736E34299FB76F001E6921 /* AddRecordsView.swift in Sources */, 1A1B55D629899CD800C2C773 /* Double.swift in Sources */, 1A0242DA299BA278005C40BE /* InAppWeb.swift in Sources */, 1A7BC4DF299786A70046D622 /* BybitEncryption.swift in Sources */, diff --git a/Cryato/Views/AddRecordsView.swift b/Cryato/Views/AddRecordsView.swift new file mode 100644 index 0000000..85871bd --- /dev/null +++ b/Cryato/Views/AddRecordsView.swift @@ -0,0 +1,20 @@ +// +// AddRecordsView.swift +// Cryato +// +// Created by John Melody Me on 17/02/2023. +// + +import SwiftUI + +struct AddRecordsView: View { + var body: some View { + Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + } +} + +struct AddRecordsView_Previews: PreviewProvider { + static var previews: some View { + AddRecordsView() + } +} diff --git a/Cryato/Views/AddScamList.swift b/Cryato/Views/AddScamList.swift index bb4cb59..2df2f69 100644 --- a/Cryato/Views/AddScamList.swift +++ b/Cryato/Views/AddScamList.swift @@ -34,85 +34,92 @@ struct AddScamList: View { private var TechniquePlaceholder :String = "What's the technique the scammer used?" public var body: some View { - VStack(alignment: .leading) { - Section(header: Text("")) { - TextField(self.WalletIdPlaceholder, text: self.$walletID) - .textFieldStyle(.roundedBorder) - .font(Font.system(size: 12)) - .padding(5) - - TextField(self.PaymentMethodPlaceholder, text: self.$paymentMethod) - .textFieldStyle(.roundedBorder) - .font(Font.system(size: 12)) - .padding(5) - - TextField(self.CurrencyPlaceholder, text: self.$currency) - .textFieldStyle(.roundedBorder) - .font(Font.system(size: 12)) - .padding(5) - - TextField(self.PlatformPlaceholder, text: self.$platform) - .textFieldStyle(.roundedBorder) - .font(Font.system(size: 12)) - .padding(5) - - TextField(self.NamePlaceholder, text: self.$name) - .textFieldStyle(.roundedBorder) - .font(Font.system(size: 12)) - .padding(5) - - TextField(self.TechniquePlaceholder, text: self.$technique) - .textFieldStyle(.roundedBorder) - .font(Font.system(size: 12)) - .padding(5) - - Button { - if self.currency.isEmpty || - self.platform.isEmpty || - self.name.isEmpty || - self.technique.isEmpty { - self.showAlert = true - } else { + NavigationView { + Form { + VStack(alignment: .leading) { + Section(header: Text("")) { + TextField(self.WalletIdPlaceholder, text: self.$walletID) + .textFieldStyle(.roundedBorder) + .font(Font.system(size: 12)) + .padding(5) - let data :[String: String] = [ - "Name" : self.name, - "WalletID" : self.walletID, - "PaymentMethod" : self.paymentMethod, - "Currency" : self.currency, - "Platform" : self.platform, - "Techniques" : self.technique - ] + TextField(self.PaymentMethodPlaceholder, text: self.$paymentMethod) + .textFieldStyle(.roundedBorder) + .font(Font.system(size: 12)) + .padding(5) - if let discordChannel = Bundle.main.infoDictionary?["DISCORD_WEBHOOK"] as? String { - try! LogToDiscord( - appName: "Cryato APP", - webhookUrl: "https://\(discordChannel)" - ).send(message: "\(data)", level: Level.Debug, delay: 0x1) + TextField(self.CurrencyPlaceholder, text: self.$currency) + .textFieldStyle(.roundedBorder) + .font(Font.system(size: 12)) + .padding(5) + + TextField(self.PlatformPlaceholder, text: self.$platform) + .textFieldStyle(.roundedBorder) + .font(Font.system(size: 12)) + .padding(5) + + TextField(self.NamePlaceholder, text: self.$name) + .textFieldStyle(.roundedBorder) + .font(Font.system(size: 12)) + .padding(5) + + TextField(self.TechniquePlaceholder, text: self.$technique) + .textFieldStyle(.roundedBorder) + .font(Font.system(size: 12)) + .padding(5) + + NavigationLink { + ScamView() + } label: { + Button { + if self.currency.isEmpty || + self.platform.isEmpty || + self.name.isEmpty || + self.technique.isEmpty { + self.showAlert = true + } else { + + let data :[String: String] = [ + "Name" : self.name, + "WalletID" : self.walletID, + "PaymentMethod" : self.paymentMethod, + "Currency" : self.currency, + "Platform" : self.platform, + "Techniques" : self.technique + ] + + if let discordChannel = Bundle.main.infoDictionary?["DISCORD_WEBHOOK"] as? String { + try! LogToDiscord( + appName: "Cryato APP", + webhookUrl: "https://\(discordChannel)" + ).send(message: "\(data)", level: Level.Debug, delay: 0x1) + } + } + + hideKeyboard() + } label: { + Text("ADD TO DATABASE") + .frame(minWidth: 0, maxWidth: .infinity) + } } - } - - hideKeyboard() - } label: { - Text("ADD TO DATABASE") .frame(minWidth: 0, maxWidth: .infinity) - .foregroundColor(.white) + .buttonStyle(.borderedProminent) + .buttonBorderShape(.roundedRectangle) + .tint(.blue) + .frame(height: 60) + .controlSize(.large) + .padding() + } } - .frame(minWidth: 0, maxWidth: .infinity) - .buttonStyle(.borderedProminent) - .buttonBorderShape(.roundedRectangle) - .tint(.blue) - .frame(height: 60) - .controlSize(.large) - .padding() + .toast(isPresenting: self.$showAlert, alert: { + AlertToast( + type: .error(.red), + title: "Warning", + subTitle: "Please fill in all the required field!\n(except for \"walletid\")" + ) + }) } } - .toast(isPresenting: self.$showAlert, alert: { - AlertToast( - type: .error(.red), - title: "Warning", - subTitle: "Please fill in all the required field!\n(except for \"walletid\")" - ) - }) } } diff --git a/Cryato/Views/AssetsView.swift b/Cryato/Views/AssetsView.swift index 5739630..0507a2a 100644 --- a/Cryato/Views/AssetsView.swift +++ b/Cryato/Views/AssetsView.swift @@ -8,7 +8,9 @@ import SwiftUI struct AssetsView: View { - var body: some View { + @Environment(\.colorScheme) private var colorScheme + + public var body: some View { NavigationView { Form { VStack { @@ -18,13 +20,22 @@ struct AssetsView: View { .navigationBarTitle("Assets") .refreshable { // @TODO + }.toolbar { + ToolbarItem(placement: .navigationBarTrailing) { + NavigationLink { + /** Navigate to app preference page */ + PreferenceView() + } label: { + Image(systemName: "gearshape").foregroundColor(self.colorScheme == .dark ? Color.white : Color.black) + } + } } } } } struct AssetsView_Previews: PreviewProvider { - static var previews: some View { + public static var previews: some View { AssetsView() } } diff --git a/Cryato/Views/BuyView.swift b/Cryato/Views/BuyView.swift index 5e75128..e0849b3 100644 --- a/Cryato/Views/BuyView.swift +++ b/Cryato/Views/BuyView.swift @@ -58,137 +58,139 @@ struct BuyView: View { } public var body: some View { - VStack { - Form { - Section(header: Text("Arbitraging calculator")) { - VStack { - Picker(selection: self.$selectedCurrency) { - ForEach(CryptoSelector.cryptoCurrenciesChoices, id:\.self) { - Text($0) + NavigationView { + VStack { + Form { + Section(header: Text("Arbitraging calculator")) { + VStack { + Picker(selection: self.$selectedCurrency) { + ForEach(CryptoSelector.cryptoCurrenciesChoices, id:\.self) { + Text($0) + } + + Text(self.selectedCurrency).foregroundColor(.black) + } label: { + Text("Cryptocurrency") + .font(Font.system(size: 20)) + .foregroundColor(.gray) + } + .frame(height:60) + .font(Font.system(size: 20)) + .pickerStyle(.menu) + .onChange(of: self.selectedCurrency) { currency in + self.selectedCurrency = currency } - Text(self.selectedCurrency).foregroundColor(.black) - } label: { - Text("Cryptocurrency") - .font(Font.system(size: 20)) - .foregroundColor(.gray) - } - .frame(height:60) - .font(Font.system(size: 20)) - .pickerStyle(.menu) - .onChange(of: self.selectedCurrency) { currency in - self.selectedCurrency = currency - } - - TextField( - self.sectionOneOriginalPrice, - text: self.$originalPricePlaceholder - ) - .frame(height:60) - .font(Font.system(size: 20)) - .textFieldStyle(.plain) - .listRowSeparator(.hidden) - .keyboardType(.decimalPad) - .onChange(of: self.originalPricePlaceholder) { input in - try! self.validate(input, 0x0) - } - - TextField( - self.sectionTwoBuyingPrice, - text: self.$buyingPricePlaceholder - ) - .frame(height: 60) - .font(Font.system(size: 20)) - .textFieldStyle(.plain) - .listRowSeparator(.hidden) - .keyboardType(.decimalPad) - .controlSize(.large) - .onChange(of: self.buyingPricePlaceholder) { input in - try! self.validate(input, 0x1) - } - - TextField( - self.sectionThreeBuyUnit, - text: self.$currentunitPlaceholder - ) - .frame(height: 60) - .font(Font.system(size: 20)) - .textFieldStyle(.plain) - .listRowSeparator(.hidden) - .keyboardType(.decimalPad) - .onChange(of: self.currentunitPlaceholder) { input in } - - Button { - if (!(self.originalPricePlaceholder.isEmpty) && !(self.buyingPricePlaceholder.isEmpty) && - !(self.currentunitPlaceholder.isEmpty) - ) { - self.isShowingResult = true - - if try! Calculator.saved( - original: self.originalPricePlaceholder, - buying: self.buyingPricePlaceholder, - unit: self.currentunitPlaceholder, - cryptoCurrency: self.selectedCurrency - )[1] == PNL.SAVED.rawValue { - self.isProfit = true - } + TextField( + self.sectionOneOriginalPrice, + text: self.$originalPricePlaceholder + ) + .frame(height:60) + .font(Font.system(size: 20)) + .textFieldStyle(.plain) + .listRowSeparator(.hidden) + .keyboardType(.decimalPad) + .onChange(of: self.originalPricePlaceholder) { input in + try! self.validate(input, 0x0) } - if(self.originalPricePlaceholder == "" && - self.currentProfitPlaceholder == "" && - self.currentunitPlaceholder == "" - ) { - self.isInvalidate = true; - self.showAlert = true; + TextField( + self.sectionTwoBuyingPrice, + text: self.$buyingPricePlaceholder + ) + .frame(height: 60) + .font(Font.system(size: 20)) + .textFieldStyle(.plain) + .listRowSeparator(.hidden) + .keyboardType(.decimalPad) + .controlSize(.large) + .onChange(of: self.buyingPricePlaceholder) { input in + try! self.validate(input, 0x1) } - hideKeyboard() + TextField( + self.sectionThreeBuyUnit, + text: self.$currentunitPlaceholder + ) + .frame(height: 60) + .font(Font.system(size: 20)) + .textFieldStyle(.plain) + .listRowSeparator(.hidden) + .keyboardType(.decimalPad) + .onChange(of: self.currentunitPlaceholder) { input in } - } label: { - Text("Calculate") - .frame(minWidth: 0, maxWidth: .infinity) - .foregroundColor(.white) + Button { + if (!(self.originalPricePlaceholder.isEmpty) && !(self.buyingPricePlaceholder.isEmpty) && + !(self.currentunitPlaceholder.isEmpty) + ) { + self.isShowingResult = true + + if try! Calculator.saved( + original: self.originalPricePlaceholder, + buying: self.buyingPricePlaceholder, + unit: self.currentunitPlaceholder, + cryptoCurrency: self.selectedCurrency + )[1] == PNL.SAVED.rawValue { + self.isProfit = true + } + } + + if(self.originalPricePlaceholder == "" && + self.currentProfitPlaceholder == "" && + self.currentunitPlaceholder == "" + ) { + self.isInvalidate = true; + self.showAlert = true; + } + + hideKeyboard() + + } label: { + Text("Calculate") + .frame(minWidth: 0, maxWidth: .infinity) + .foregroundColor(.white) + } + .frame(minWidth: 0, maxWidth: .infinity) + .buttonStyle(.borderedProminent) + .buttonBorderShape(.roundedRectangle) + .tint(.green) + .frame(height: 60) + .controlSize(.large) } - .frame(minWidth: 0, maxWidth: .infinity) - .buttonStyle(.borderedProminent) - .buttonBorderShape(.roundedRectangle) - .tint(.green) - .frame(height: 60) - .controlSize(.large) - } - - if self.isShowingResult { - VStack { - Text( - try! Calculator.saved( - original: self.originalPricePlaceholder, - buying: self.buyingPricePlaceholder, - unit: self.currentunitPlaceholder, - cryptoCurrency: self.selectedCurrency - )[0] - ) - .foregroundColor(self.isProfit ? .green : .red) - .font(.headline) + + if self.isShowingResult { + VStack { + Text( + try! Calculator.saved( + original: self.originalPricePlaceholder, + buying: self.buyingPricePlaceholder, + unit: self.currentunitPlaceholder, + cryptoCurrency: self.selectedCurrency + )[0] + ) + .foregroundColor(self.isProfit ? .green : .red) + .font(.headline) + } } } } + .scrollDismissesKeyboard(.interactively) + .background(self.colorScheme == .dark ? .black : .white) + .refreshable { + self.isShowingResult = false + self.buyingPricePlaceholder = "" + self.originalPricePlaceholder = "" + self.currentunitPlaceholder = "" + self.isProfit = false + } + .toast(isPresenting: self.$showAlert, alert: { + AlertToast( + type: .error(.red), + title: "Warning", + subTitle: "Please fill in all the required field!" + ) + }) } - .scrollDismissesKeyboard(.interactively) - .background(self.colorScheme == .dark ? .black : .white) - .refreshable { - self.isShowingResult = false - self.buyingPricePlaceholder = "" - self.originalPricePlaceholder = "" - self.currentunitPlaceholder = "" - self.isProfit = false - } - .toast(isPresenting: self.$showAlert, alert: { - AlertToast( - type: .error(.red), - title: "Warning", - subTitle: "Please fill in all the required field!" - ) - }) } } } diff --git a/Cryato/Views/ContentView.swift b/Cryato/Views/ContentView.swift index 21e9f1f..373bad4 100644 --- a/Cryato/Views/ContentView.swift +++ b/Cryato/Views/ContentView.swift @@ -14,16 +14,17 @@ struct ContentView: View { @State private var options :[String] = ["Sell", "Buy"] private var navigationTitle :String = "Cryato" - + public var body: some View { NavigationView { VStack { TabView { + VStack { Picker(selection: $selectedId, label: Text("")) { - Text(options[0]).tag(0x0) - Text(options[1]).tag(0x1) - }.pickerStyle(SegmentedPickerStyle()).listRowSeparator( + Text(options[0]).tag(0x0).font(Font.system(size: 12)) + Text(options[1]).tag(0x1).font(Font.system(size: 12)) + }.pickerStyle(.segmented).listRowSeparator( .hidden, edges: [.top] ).padding() @@ -42,7 +43,6 @@ struct ContentView: View { Text("Scanner") } - RecordsView().tabItem { Image(systemName: "note.text.badge.plus") Text("Record") @@ -62,22 +62,12 @@ struct ContentView: View { .scrollDismissesKeyboard(.interactively) .background(self.colorScheme == .dark ? .black : .white) .refreshable {} - .toolbar { - ToolbarItem(placement: .navigationBarTrailing) { - NavigationLink { - /** Navigate to app preference page */ - PreferenceView() - } label: { - Image(systemName: "gearshape").foregroundColor(self.colorScheme == .dark ? Color.white : Color.black) - } - } - } }.background(self.colorScheme == .dark ? .black : .white) } } struct ContentView_Previews: PreviewProvider { - static var previews: some View { + public static var previews: some View { ContentView().environment(\.locale, .init(identifier: "zh")) } } diff --git a/Cryato/Views/RecordsView.swift b/Cryato/Views/RecordsView.swift index cb03ca7..c36bd7a 100644 --- a/Cryato/Views/RecordsView.swift +++ b/Cryato/Views/RecordsView.swift @@ -10,13 +10,15 @@ import SwiftUI struct RecordsView: View { @Environment(\.colorScheme) private var colorScheme - var body: some View { + private func addRecords() throws -> Void { + + } + + public var body: some View { NavigationView { Form { VStack { - Text("Records here") - .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading) - + Text("asdassd") } } .navigationBarTitle("Records") @@ -24,12 +26,22 @@ struct RecordsView: View { .refreshable { // @TODO } + .toolbar { + NavigationLink { + AddRecordsView() + } label: { + Image(systemName: "doc.fill.badge.plus").foregroundColor( + colorScheme.self == .dark ? .white : .black + ) + } + + } } } } struct RecordsView_Previews: PreviewProvider { - static var previews: some View { + public static var previews: some View { RecordsView() } } diff --git a/Cryato/Views/ScamView.swift b/Cryato/Views/ScamView.swift index 94ecb58..755a248 100644 --- a/Cryato/Views/ScamView.swift +++ b/Cryato/Views/ScamView.swift @@ -33,63 +33,46 @@ struct ScamView: View { public var body: some View { NavigationStack { Form { - if self.isListView { - List(self.scam) { data in - Section(header: Text("Scammer User ID: \(data.userId!)")) { - Button() { - // Do Nothing - } label: { - VStack(alignment: .leading) { - Text("Wallet ID: \(data.walletId == "" ? "Not Specified" : data.walletId!)") - .listRowSeparator(.hidden) - .font(Font.system(size: 12)) - Text("Payment Method: \(data.paymentMethod!)") - .listRowSeparator(.hidden) - .font(Font.system(size: 12)) - Text("Currency: \(data.currency!)") - .listRowSeparator(.hidden) - .font(Font.system(size: 12)) - Text("Platform: \(data.platform!)") - .listRowSeparator(.hidden) - .font(Font.system(size: 12)) - Text("Reported By: \(data.reportedBy!)") - .listRowSeparator(.hidden) - .font(Font.system(size: 12)) - Text("Scam Technique: \"\(data.scamTechnique!)\"") - .listRowSeparator(.hidden) - .font(Font.system(size: 12)) - } - } - } - } - } - else { - AddScamList().refreshable { - self.scam = [] - if self.isListView == false { - self.isListView = true - } - } - } - if self.isListView { - Section(header: Text("Click Here To Add")) { - Button( - action: { - self.isListView = false + List(self.scam) { data in + Section(header: Text("Scammer User ID: \(data.userId!)")) { + Button() { + // Do Nothing + } label: { + VStack(alignment: .leading) { + Text("Wallet ID: \(data.walletId == "" ? "Not Specified" : data.walletId!)") + .listRowSeparator(.hidden) + .font(Font.system(size: 12)) + Text("Payment Method: \(data.paymentMethod!)") + .listRowSeparator(.hidden) + .font(Font.system(size: 12)) + Text("Currency: \(data.currency!)") + .listRowSeparator(.hidden) + .font(Font.system(size: 12)) + Text("Platform: \(data.platform!)") + .listRowSeparator(.hidden) + .font(Font.system(size: 12)) + Text("Reported By: \(data.reportedBy!)") + .listRowSeparator(.hidden) + .font(Font.system(size: 12)) + Text("Scam Technique: \"\(data.scamTechnique!)\"") + .listRowSeparator(.hidden) + .font(Font.system(size: 12)) } - ){ - Text("ADD SCAMMER") - .frame(maxWidth: .infinity) - .foregroundColor(.white) - .padding(10) - .background(.blue) - .cornerRadius(10) } } } } .navigationBarTitle("Scams") + .toolbar { + NavigationLink { + AddScamList() + } label: { + Image(systemName: "person.fill.badge.plus").foregroundColor( + colorScheme.self == .dark ? .white : .black + ) + } + } .refreshable { self.scam = [] try! self.onLoad() diff --git a/Cryato/Views/ScannerView.swift b/Cryato/Views/ScannerView.swift index e945c46..3183e78 100644 --- a/Cryato/Views/ScannerView.swift +++ b/Cryato/Views/ScannerView.swift @@ -26,6 +26,7 @@ struct ScannerView: View { @State private var transaction :[Transaction] = [Transaction]() @State private var walletId :String = "" @State private var showAlert :Bool = false + @State private var showAlertEmpty :Bool = false @State private var showSafari :Bool = false @State private var selectedCurrency :String = CryptoSelector.cryptoCurrenciesChoices[0] @@ -53,9 +54,11 @@ struct ScannerView: View { NSLog("User Input an invalid Wallet Address") } - Task { - TransactionsHelper.loadTransactions(WalletID: self.walletId) { (result) in - self.transaction = result.data ?? [] + TransactionsHelper.loadTransactions(WalletID: self.walletId) { (result) in + self.transaction = result.data ?? [] + + if result.data?.isEmpty == nil { + self.showAlertEmpty = true } } } @@ -77,7 +80,7 @@ struct ScannerView: View { List(self.transaction) { data in - if data.transaction_id.isEmpty { + if self.showAlertEmpty { Text("No Transactions Found") } else { Button(action: { @@ -126,6 +129,7 @@ struct ScannerView: View { .refreshable { self.walletId = "" self.showAlert = false + self.showAlertEmpty = false } .onAppear { /** Remove Underline */ @@ -143,12 +147,23 @@ struct ScannerView: View { subTitle: "Please Input a Valid Wallet Address" ) }) + .toast(isPresenting: self.$showAlertEmpty, alert: { + AlertToast( + type: .error(.red), + title: "Warning", + subTitle: "No Transactions Found" + ) + }) .background(.gray.opacity(0.1)) .fullScreenCover(isPresented: $showSafari, content: { SFSafariViewWrapper(url:URL(string:"https://tronscan.org/#/address/\(self.walletId)")!) }) .scrollDismissesKeyboard(.interactively) - .onSubmit { try! self.search() } + .onSubmit { + Task { + try! self.search() + } + } .submitLabel(.search) } } diff --git a/Cryato/Views/SellView.swift b/Cryato/Views/SellView.swift index b10a15a..44559af 100644 --- a/Cryato/Views/SellView.swift +++ b/Cryato/Views/SellView.swift @@ -59,141 +59,143 @@ struct SellView: View { } public var body: some View { - VStack { - Form { - Section(header: Text("Arbitraging calculator")) { - VStack { - Picker(selection: self.$selectedCurrency) { - ForEach(CryptoSelector.cryptoCurrenciesChoices, id:\.self) { - Text($0) + NavigationView { + VStack { + Form { + Section(header: Text("Arbitraging calculator")) { + VStack { + Picker(selection: self.$selectedCurrency) { + ForEach(CryptoSelector.cryptoCurrenciesChoices, id:\.self) { + Text($0) + } + + Text(self.selectedCurrency).foregroundColor(.black) + } label: { + Text("Cryptocurrency") + .font(Font.system(size: 20)) + .foregroundColor(.gray) + } + .frame(height:60) + .font(Font.system(size: 20)) + .pickerStyle(.menu) + .onChange(of: self.selectedCurrency) { currency in + self.selectedCurrency = currency } - Text(self.selectedCurrency).foregroundColor(.black) - } label: { - Text("Cryptocurrency") - .font(Font.system(size: 20)) - .foregroundColor(.gray) - } - .frame(height:60) - .font(Font.system(size: 20)) - .pickerStyle(.menu) - .onChange(of: self.selectedCurrency) { currency in - self.selectedCurrency = currency - } - - TextField( - self.sectionOneOriginalPrice, - text: self.$originalPricePlaceholder - ) - .frame(height:60) - .font(Font.system(size: 20)) - .textFieldStyle(.plain) - .listRowSeparator(.hidden) - .keyboardType(.decimalPad) - .onChange(of: self.originalPricePlaceholder) { input in - try! self.validate(input, 0x0) - } - - TextField( - self.sectionTwoSellingPrice, - text: self.$sellingPricePlaceholder - ) - .frame(height: 60) - .font(Font.system(size: 20)) - .textFieldStyle(.plain) - .listRowSeparator(.hidden) - .keyboardType(.decimalPad) - .controlSize(.large) - .onChange(of: self.sellingPricePlaceholder) { input in - try! self.validate(input, 0x1) - } - - TextField( - self.sectionThreeSellingUnit, - text: self.$currentunitPlaceholder - ) - .frame(height: 60) - .font(Font.system(size: 20)) - .textFieldStyle(.plain) - .listRowSeparator(.hidden) - .keyboardType(.decimalPad) - .onChange(of: self.currentunitPlaceholder) { input in - // Do nothing here - } - - Button { - if (!(self.originalPricePlaceholder.isEmpty) && !(self.sellingPricePlaceholder.isEmpty) && - !(self.currentunitPlaceholder.isEmpty) - ) { - self.isShowingResult = true - - if try! Calculator.profit( - original: self.originalPricePlaceholder, - selling: self.sellingPricePlaceholder, - unit: self.currentunitPlaceholder, - cryptoCurrency: self.selectedCurrency - )[1] == PNL.PROFIT.rawValue { - self.isProfit = true - } + TextField( + self.sectionOneOriginalPrice, + text: self.$originalPricePlaceholder + ) + .frame(height:60) + .font(Font.system(size: 20)) + .textFieldStyle(.plain) + .listRowSeparator(.hidden) + .keyboardType(.decimalPad) + .onChange(of: self.originalPricePlaceholder) { input in + try! self.validate(input, 0x0) } - if(self.originalPricePlaceholder == "" && - self.currentProfitPlaceholder == "" && - self.currentunitPlaceholder == "" - ) { - self.isInvalidate = true; - self.showAlert = true; + TextField( + self.sectionTwoSellingPrice, + text: self.$sellingPricePlaceholder + ) + .frame(height: 60) + .font(Font.system(size: 20)) + .textFieldStyle(.plain) + .listRowSeparator(.hidden) + .keyboardType(.decimalPad) + .controlSize(.large) + .onChange(of: self.sellingPricePlaceholder) { input in + try! self.validate(input, 0x1) } - hideKeyboard() + TextField( + self.sectionThreeSellingUnit, + text: self.$currentunitPlaceholder + ) + .frame(height: 60) + .font(Font.system(size: 20)) + .textFieldStyle(.plain) + .listRowSeparator(.hidden) + .keyboardType(.decimalPad) + .onChange(of: self.currentunitPlaceholder) { input in + // Do nothing here + } - } label: { - Text("Calculate") - .frame(minWidth: 0, maxWidth: .infinity) - .foregroundColor(.white) + Button { + if (!(self.originalPricePlaceholder.isEmpty) && !(self.sellingPricePlaceholder.isEmpty) && + !(self.currentunitPlaceholder.isEmpty) + ) { + self.isShowingResult = true + + if try! Calculator.profit( + original: self.originalPricePlaceholder, + selling: self.sellingPricePlaceholder, + unit: self.currentunitPlaceholder, + cryptoCurrency: self.selectedCurrency + )[1] == PNL.PROFIT.rawValue { + self.isProfit = true + } + } + + if(self.originalPricePlaceholder == "" && + self.currentProfitPlaceholder == "" && + self.currentunitPlaceholder == "" + ) { + self.isInvalidate = true; + self.showAlert = true; + } + + hideKeyboard() + + } label: { + Text("Calculate") + .frame(minWidth: 0, maxWidth: .infinity) + .foregroundColor(.white) + } + .frame(minWidth: 0, maxWidth: .infinity) + .buttonStyle(.borderedProminent) + .buttonBorderShape(.roundedRectangle) + .tint(.red) + .frame(height: 60) + .controlSize(.large) + } + }.scrollContentBackground(.hidden) + + if self.isShowingResult { + VStack { + Text( + try! Calculator.profit( + original: self.originalPricePlaceholder, + selling: self.sellingPricePlaceholder, + unit: self.currentunitPlaceholder, + cryptoCurrency: self.selectedCurrency + )[0] + ) + .foregroundColor(self.isProfit ? .green : .red) + .font(.headline) } - .frame(minWidth: 0, maxWidth: .infinity) - .buttonStyle(.borderedProminent) - .buttonBorderShape(.roundedRectangle) - .tint(.red) - .frame(height: 60) - .controlSize(.large) - } - }.scrollContentBackground(.hidden) - - if self.isShowingResult { - VStack { - Text( - try! Calculator.profit( - original: self.originalPricePlaceholder, - selling: self.sellingPricePlaceholder, - unit: self.currentunitPlaceholder, - cryptoCurrency: self.selectedCurrency - )[0] - ) - .foregroundColor(self.isProfit ? .green : .red) - .font(.headline) } + } - + .toast(isPresenting: self.$showAlert, alert: { + AlertToast( + type: .error(.red), + title: "Warning", + subTitle: "Please fill in all the required field!" + ) + }) + } + .scrollDismissesKeyboard(.interactively) + .background(self.colorScheme == .dark ? .black : .white) + .refreshable { + self.isShowingResult = false + self.sellingPricePlaceholder = "" + self.originalPricePlaceholder = "" + self.currentunitPlaceholder = "" + self.isProfit = false + self.showAlert = false } - .toast(isPresenting: self.$showAlert, alert: { - AlertToast( - type: .error(.red), - title: "Warning", - subTitle: "Please fill in all the required field!" - ) - }) - } - .scrollDismissesKeyboard(.interactively) - .background(self.colorScheme == .dark ? .black : .white) - .refreshable { - self.isShowingResult = false - self.sellingPricePlaceholder = "" - self.originalPricePlaceholder = "" - self.currentunitPlaceholder = "" - self.isProfit = false - self.showAlert = false } }