Skip to content

Commit

Permalink
CCS-20 Add credit card point/cashback information in Convert History …
Browse files Browse the repository at this point in the history
…page

CCS-23 Make rates all percentage or number
CCS-25 Implementing best price
CCS-18 系統容許信用卡名稱為空值
CCS-27 PopUp for Convert History URL too long
  • Loading branch information
Rayer committed Nov 8, 2020
1 parent 4f29b9a commit 290aee5
Show file tree
Hide file tree
Showing 10 changed files with 239 additions and 63 deletions.
12 changes: 6 additions & 6 deletions CurrencyConverter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -336,7 +336,7 @@
};
};
buildConfigurationList = 625712C82371982500466679 /* Build configuration list for PBXProject "CurrencyConverter" */;
compatibilityVersion = "Xcode 9.3";
compatibilityVersion = "Xcode 12.0";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
Expand Down Expand Up @@ -602,7 +602,7 @@
CODE_SIGN_ENTITLEMENTS = "CurrencyConverter Extension/CurrencyConverter_Extension.entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = 8AA96R6MF3;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "CurrencyConverter Extension/Info.plist";
Expand All @@ -626,7 +626,7 @@
CODE_SIGN_ENTITLEMENTS = "CurrencyConverter Extension/CurrencyConverter_Extension.entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = 8AA96R6MF3;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "CurrencyConverter Extension/Info.plist";
Expand Down Expand Up @@ -698,7 +698,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_ASSET_PATHS = "\"CurrencyConverter/Preview Content\"";
DEVELOPMENT_TEAM = 8AA96R6MF3;
ENABLE_HARDENED_RUNTIME = YES;
Expand Down Expand Up @@ -726,7 +726,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_ASSET_PATHS = "\"CurrencyConverter/Preview Content\"";
DEVELOPMENT_TEAM = 8AA96R6MF3;
ENABLE_HARDENED_RUNTIME = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@
filePath = "CurrencyConverter/CreditCardManagerViewModel.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "49"
endingLineNumber = "49"
startingLineNumber = "64"
endingLineNumber = "64"
landmarkName = "init()"
landmarkType = "7">
<Locations>
Expand Down Expand Up @@ -398,8 +398,8 @@
filePath = "CurrencyConverter/CreditCardManagerViewModel.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "50"
endingLineNumber = "50"
startingLineNumber = "65"
endingLineNumber = "65"
landmarkName = "init()"
landmarkType = "7">
</BreakpointContent>
Expand All @@ -414,9 +414,73 @@
filePath = "CurrencyConverter/CreditCardProfile.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "146"
endingLineNumber = "146"
landmarkName = "estimatedPrice(price:targetSymbol:)"
startingLineNumber = "153"
endingLineNumber = "153"
landmarkName = "estimatedPrice(price:sourceSymbol:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "3925D709-60E0-41A0-A61D-27BE4C7AC6E8"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "CurrencyConverter/CreditCardProfile.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "157"
endingLineNumber = "157"
landmarkName = "estimateRewardAmount(price:sourceSymbol:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "A824D9D8-6FD9-4210-AA6C-F21E554C1291"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "CurrencyConverter/CreditCardProfile.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "122"
endingLineNumber = "122"
landmarkName = "estimatedPrice(price:sourceSymbol:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "B5158FBD-0DD2-4D38-9A31-513218C5797D"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "CurrencyConverter/CreditCardManagerViewModel.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "148"
endingLineNumber = "148"
landmarkName = "persist()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "3CAB2DC9-9C0B-4A6D-84B6-71A7EEF1FDC3"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "CurrencyConverter/CreditCardManagerViewModel.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "143"
endingLineNumber = "143"
landmarkName = "persist()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
Expand Down
3 changes: 2 additions & 1 deletion CurrencyConverter/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ struct ContentView: View {
if self.showInstallButton {
Button("Enable/Disable Extension") {
SFSafariApplication.showPreferencesForExtension(withIdentifier: "com.rayer.CurrencyConverter-Extension") { error in
if let _ = error {
if let e = error {
// Insert code to inform the user that something went wrong.
print("Error opening preference for extension : \(e)")
}
}

Expand Down
25 changes: 22 additions & 3 deletions CurrencyConverter/ConvertHistoryUIBean.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,33 @@ struct ConvertHistoryUIBean : Identifiable {
var fromSymbol: String
var toSymbol: String
var fromAmount: Float
var fxFee: Float

var toAmount : Float {
get {
return fromAmount * ratio
}
}

var fxFee : Float {
get {
return toAmount * fxFeeRate
}
}

var toAmountWithFx : Float {
get {
return toAmount + fxFee
}
}

var fxFeeRate: Float
var ratio: Float
var isChecked = false

static func fromCoreData(c: ConvertHistory) -> ConvertHistoryUIBean{
return ConvertHistoryUIBean(id: c.id ?? UUID(), title: c.title ?? "", url: c.url ?? "", fromSymbol: c.fromSymbol ?? "", toSymbol: c.toSymbol ?? "", fromAmount: c.fromAmount, fxFee: c.fxFee, ratio: c.ratio)
//due to some migration concern, entity still "fxFee" to represent "fxFeeRate"
return ConvertHistoryUIBean(id: c.id ?? UUID(), title: c.title ?? "", url: c.url ?? "", fromSymbol: c.fromSymbol ?? "", toSymbol: c.toSymbol ?? "", fromAmount: c.fromAmount, fxFeeRate: c.fxFee, ratio: c.ratio)
}

}

class ConvertHistoryDMCollection : ObservableObject {
Expand Down
32 changes: 22 additions & 10 deletions CurrencyConverter/CreditCardManageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ struct CreditCardManageView: View {
.pickerStyle(RadioGroupPickerStyle())
.padding()


UnifiedView(title: "Card Profile Name", description: "Card Indentifier, must be unique", bindedValue: self.$model.creditCardName, is2liner: false).padding()
UnifiedView(title: "Card Profile Name", description: "Card Indentifier, must be unique and between length of 1 to 24", errorMessage: "Invalid name, it must be between 1-24", bindedValue: self.$model.creditCardName, isValid: self.model.creditCardNameValid, is2liner: false).padding()

Picker(selection: self.$model.clearinghouseCurrency, label: Text("Clearinghouse Currency")){
ForEach(self.model.clearinghouseCurrencyList, id:\.self) { (symbol) in
Expand All @@ -33,24 +32,31 @@ struct CreditCardManageView: View {

Group {
if self.model.creditCardType == CreditCardType.CashBack {
UnifiedView(title: "Domestic Cash-Back Rate", description: "Cash Back rate while applying domestic currency", errorMessage: "Value must be a number", bindedValue: self.$model.cbDomesticRate, isValid: self.model.cbDomesticRateValidate, is2liner: true, textFieldWidth: 80)
UnifiedView(title: "Domestic Cash-Back Rate", description: "Cash Back rate while applying domestic currency", errorMessage: "Value must be a number", bindedValue: self.$model.cbDomesticRate, isValid: self.model.cbDomesticRateValidate, is2liner: true, textFieldWidth: 80, withSuffix: "%")

UnifiedView(title: "International Cash-Back Rate", description: "Cash Back rate while applying foreign currency", errorMessage: "Value must be a number", bindedValue: self.$model.cbInternationalRate, isValid: self.model.cbInternationalRateValidate, is2liner: true, textFieldWidth: 80)
UnifiedView(title: "International Cash-Back Rate", description: "Cash Back rate while applying foreign currency", errorMessage: "Value must be a number", bindedValue: self.$model.cbInternationalRate, isValid: self.model.cbInternationalRateValidate, is2liner: true, textFieldWidth: 80, withSuffix: "%")

UnifiedView(title: "FX Rate", description: "International FX Rate", errorMessage: "Must be a number and between 0 and 100", bindedValue: self.$model.FxRate, isValid: self.model.FxRateValidate, is2liner: true,
textFieldWidth: 80)
textFieldWidth: 80, withSuffix: "%")


} else if self.model.creditCardType == CreditCardType.Mileage {

Picker(selection: $model.mConvertType, label: Text("Convert Type"), content:{
Text("Dollars per point").tag(0)
Text("Points per dollar").tag(1)
})
.pickerStyle(SegmentedPickerStyle())


UnifiedView(title: "Mileage/Point domestic rate", description: "Mileage(Point) rate while applying domestic currency", errorMessage: "Value must be a number", bindedValue: self.$model.mDomesticRate, isValid: self.model.mDomesticRateValidate, is2liner: true,
textFieldWidth: 80)
textFieldWidth: 80, withSuffix: model.mConvertType == 0 ? "per Point" : "per Dollar")
UnifiedView(title: "Mileage / Point international rate", description: "Mileage(Point) ratewhile applying international currency", errorMessage: "Value must be a number", bindedValue: self.$model.mInternationalRate, isValid: self.model.mInternationalRateValidate, is2liner: true,
textFieldWidth: 80)
textFieldWidth: 80, withSuffix: model.mConvertType == 0 ? "per Point" : "per Dollar")

UnifiedView(title: "FX Rate", description: "International FX Rate", errorMessage: "Must be a number and between 0 and 100", bindedValue: self.$model.FxRate, isValid: self.model.FxRateValidate, is2liner: true,
textFieldWidth: 80)
UnifiedView(title: "Estimated Mileage(point) value", description: "Estimated Mileage(Point) value per point", errorMessage: "Must be a number!", bindedValue: self.$model.mEstimatedValuePerMile, isValid: self.model.mEstimatedValuePerMileValid, is2liner: true, textFieldWidth: 80)
textFieldWidth: 80, withSuffix: "%")
UnifiedView(title: "Estimated Mileage(point) value", description: "Estimated Mileage(Point) value per point", errorMessage: "Must be a number!", bindedValue: self.$model.mEstimatedValuePerMile, isValid: self.model.mEstimatedValuePerMileValid, is2liner: true, textFieldWidth: 80, withSuffix: " ")

}
}
Expand All @@ -65,6 +71,7 @@ struct CreditCardManageView: View {
model.loadProfile(profile)
}
.foregroundColor(profile.name! == self.model.creditCardName ? .red : .none)
.frame(minWidth: 100, idealWidth: 100, maxWidth: .infinity)
}
}

Expand Down Expand Up @@ -103,6 +110,7 @@ struct UnifiedView: View {
var isValid: Bool = false
var is2liner = false
var textFieldWidth : CGFloat?
var suffix : String?

init(title: String, description: String, bindedValue: Binding<String>, is2liner: Bool) {
self.title = title
Expand All @@ -111,14 +119,15 @@ struct UnifiedView: View {
self.is2liner = is2liner
}

init(title: String, description: String, errorMessage: String, bindedValue: Binding<String>, isValid: Bool, is2liner: Bool, textFieldWidth: CGFloat? = nil) {
init(title: String, description: String, errorMessage: String, bindedValue: Binding<String>, isValid: Bool, is2liner: Bool, textFieldWidth: CGFloat? = nil, withSuffix: String? = nil) {
self.title = title
self.description = description
self.bindedValue = bindedValue
self.errorMessage = errorMessage
self.isValid = isValid
self.is2liner = is2liner
self.textFieldWidth = textFieldWidth
self.suffix = withSuffix
}

var body: some View {
Expand All @@ -133,6 +142,9 @@ struct UnifiedView: View {
} else {
TextField(description, text: bindedValue)
}
if let s = self.suffix {
Text(s)
}
}
} else {
Text(title)
Expand Down
Loading

0 comments on commit 290aee5

Please sign in to comment.