Skip to content

Commit

Permalink
feat: improve UI and add candle pricing
Browse files Browse the repository at this point in the history
  • Loading branch information
Ph0enixKM committed Jan 1, 2023
1 parent fda3a43 commit 32411d1
Show file tree
Hide file tree
Showing 14 changed files with 684 additions and 352 deletions.
54 changes: 47 additions & 7 deletions OandaChandler.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,35 @@
objects = {

/* Begin PBXBuildFile section */
3B5B5B20296199840084E90F /* Request.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B5B5B1F296199840084E90F /* Request.swift */; };
3B5B5B222961B6500084E90F /* Granularity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B5B5B212961B6500084E90F /* Granularity.swift */; };
3B714143295B24BC00B5358A /* OandaChandlerApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B714142295B24BC00B5358A /* OandaChandlerApp.swift */; };
3B714145295B24BC00B5358A /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B714144295B24BC00B5358A /* ContentView.swift */; };
3B714147295B24BE00B5358A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3B714146295B24BE00B5358A /* Assets.xcassets */; };
3B71414A295B24BE00B5358A /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3B714149295B24BE00B5358A /* Preview Assets.xcassets */; };
3B714152295B254400B5358A /* Candles.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B714151295B254400B5358A /* Candles.swift */; };
3B79971C295C6DB500AD242A /* CreatingPhase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B79971B295C6DB500AD242A /* CreatingPhase.swift */; };
3B79971C295C6DB500AD242A /* Creating.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B79971B295C6DB500AD242A /* Creating.swift */; };
3B87BEC52961001800CCE50D /* AuthData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B87BEC42961001800CCE50D /* AuthData.swift */; };
3B87BEC62961019500CCE50D /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3B714149295B24BE00B5358A /* Preview Assets.xcassets */; };
3BD8BCCA2960779800B7A908 /* Date.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BD8BCC92960779800B7A908 /* Date.swift */; };
3BD8BCCE29607E5600B7A908 /* Auth.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BD8BCCD29607E5600B7A908 /* Auth.swift */; };
3BD8BCD029608A3F00B7A908 /* KeychainController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BD8BCCF29608A3F00B7A908 /* KeychainController.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
3B5B5B1F296199840084E90F /* Request.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Request.swift; sourceTree = "<group>"; };
3B5B5B212961B6500084E90F /* Granularity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Granularity.swift; sourceTree = "<group>"; };
3B71413F295B24BC00B5358A /* OandaChandler.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = OandaChandler.app; sourceTree = BUILT_PRODUCTS_DIR; };
3B714142295B24BC00B5358A /* OandaChandlerApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OandaChandlerApp.swift; sourceTree = "<group>"; };
3B714144295B24BC00B5358A /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
3B714146295B24BE00B5358A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
3B714149295B24BE00B5358A /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
3B71414B295B24BE00B5358A /* OandaChandler.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = OandaChandler.entitlements; sourceTree = "<group>"; };
3B714151295B254400B5358A /* Candles.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Candles.swift; sourceTree = "<group>"; };
3B79971B295C6DB500AD242A /* CreatingPhase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreatingPhase.swift; sourceTree = "<group>"; };
3B79971B295C6DB500AD242A /* Creating.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Creating.swift; sourceTree = "<group>"; };
3B87BEC42961001800CCE50D /* AuthData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthData.swift; sourceTree = "<group>"; };
3BD8BCC92960779800B7A908 /* Date.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Date.swift; sourceTree = "<group>"; };
3BD8BCCD29607E5600B7A908 /* Auth.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Auth.swift; sourceTree = "<group>"; };
3BD8BCCF29608A3F00B7A908 /* KeychainController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeychainController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -56,10 +68,13 @@
3B714141295B24BC00B5358A /* OandaChandler */ = {
isa = PBXGroup;
children = (
3BD8BCCC2960781700B7A908 /* Data */,
3BD8BCCB296077EE00B7A908 /* Views */,
3B5B5B1F296199840084E90F /* Request.swift */,
3BD8BCCF29608A3F00B7A908 /* KeychainController.swift */,
3B714142295B24BC00B5358A /* OandaChandlerApp.swift */,
3B714144295B24BC00B5358A /* ContentView.swift */,
3B79971B295C6DB500AD242A /* CreatingPhase.swift */,
3B714151295B254400B5358A /* Candles.swift */,
3B5B5B212961B6500084E90F /* Granularity.swift */,
3B714146295B24BE00B5358A /* Assets.xcassets */,
3B71414B295B24BE00B5358A /* OandaChandler.entitlements */,
3B714148295B24BE00B5358A /* Preview Content */,
Expand All @@ -75,6 +90,25 @@
path = "Preview Content";
sourceTree = "<group>";
};
3BD8BCCB296077EE00B7A908 /* Views */ = {
isa = PBXGroup;
children = (
3B79971B295C6DB500AD242A /* Creating.swift */,
3BD8BCCD29607E5600B7A908 /* Auth.swift */,
);
path = Views;
sourceTree = "<group>";
};
3BD8BCCC2960781700B7A908 /* Data */ = {
isa = PBXGroup;
children = (
3BD8BCC92960779800B7A908 /* Date.swift */,
3B714151295B254400B5358A /* Candles.swift */,
3B87BEC42961001800CCE50D /* AuthData.swift */,
);
path = Data;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -133,7 +167,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
3B71414A295B24BE00B5358A /* Preview Assets.xcassets in Resources */,
3B87BEC62961019500CCE50D /* Preview Assets.xcassets in Resources */,
3B714147295B24BE00B5358A /* Assets.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -145,10 +179,16 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
3B79971C295C6DB500AD242A /* CreatingPhase.swift in Sources */,
3B79971C295C6DB500AD242A /* Creating.swift in Sources */,
3BD8BCCA2960779800B7A908 /* Date.swift in Sources */,
3B5B5B222961B6500084E90F /* Granularity.swift in Sources */,
3B714145295B24BC00B5358A /* ContentView.swift in Sources */,
3B714152295B254400B5358A /* Candles.swift in Sources */,
3BD8BCD029608A3F00B7A908 /* KeychainController.swift in Sources */,
3B714143295B24BC00B5358A /* OandaChandlerApp.swift in Sources */,
3BD8BCCE29607E5600B7A908 /* Auth.swift in Sources */,
3B5B5B20296199840084E90F /* Request.swift in Sources */,
3B87BEC52961001800CCE50D /* AuthData.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Binary file not shown.
172 changes: 0 additions & 172 deletions OandaChandler/Candles.swift

This file was deleted.

36 changes: 30 additions & 6 deletions OandaChandler/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,37 @@ struct ContentView: View {
@State var downloadProgress = 0.0
@State var saveProgress = 0.0
@State var isSavingFile = false
@State var candles = Candles()
@State var candles: [Candle] = []
@State var error: String? = nil

func getPricing(candle: Candle) -> CandlePricing {
return (candle.mid ?? candle.bid ?? candle.ask)!
}

func generateCSV(_ url: URL, callback: (Double) -> Void) throws {
var row = ""
for (index, candle) in self.candles.enumerated() {
let pricing = getPricing(candle: candle)
row += [
formatDateString(candle.time),
pricing.o,
pricing.h,
pricing.l,
pricing.c,
String(candle.volume)
].joined(separator: ",") + "\n"
if index % 100 == 0 {
callback(Double(index) / Double(self.candles.count))
}
}
try row.data(using: .utf8)!.write(to: url)
}

var body: some View {
ZStack {
switch state {
case .Creating:
CreatingPhase(state: $state, candles: $candles, progress: $downloadProgress)
CreatingPhase(state: $state, candles: $candles, error: $error, progress: $downloadProgress)
case .Fetching:
ProgressView(value: downloadProgress, label: {
Text("Downloading...")
Expand All @@ -65,7 +89,7 @@ struct ContentView: View {
isSavingFile = true
backgroundQueue.async {
do {
try self.candles.generateCSV(save) { value in
try self.generateCSV(save) { value in
DispatchQueue.main.async {
self.saveProgress = value
}
Expand Down Expand Up @@ -101,7 +125,7 @@ struct ContentView: View {
}
Button(action: {
self.state = .Creating
self.candles.candles = nil
self.candles = []
}) { Text("Back") }.padding().disabled(isSavingFile)
}
}
Expand All @@ -113,10 +137,10 @@ struct ContentView: View {
.frame(width: 50, height: 50)
.padding()
Text("Could not download the data")
Text(self.candles.error ?? "[unknown reason]").monospaced().padding()
Text(self.error ?? "[unknown reason]").monospaced().padding()
Button(action: {
self.state = .Creating
self.candles.candles = nil
self.candles = []
}) { Text("Back") }.padding()
}
}
Expand Down
Loading

0 comments on commit 32411d1

Please sign in to comment.