@@ -21,7 +21,7 @@ class ShippingLineDetailsViewModel: ObservableObject {
2121
2222 /// Placeholder for amount text field
2323 ///
24- let amountPlaceholder : String
24+ let amountPlaceholder : String = " 0 "
2525
2626 /// Stores the amount entered by the merchant.
2727 ///
@@ -36,7 +36,7 @@ class ShippingLineDetailsViewModel: ObservableObject {
3636 ///
3737 @Published var methodTitle : String
3838
39- private let initialAmount : Decimal
39+ private let initialAmount : Decimal ?
4040 private let initialMethodTitle : String
4141
4242 /// Returns true when existing shipping line is edited.
@@ -52,7 +52,7 @@ class ShippingLineDetailsViewModel: ObservableObject {
5252 /// Returns true when there are no valid pending changes.
5353 ///
5454 var shouldDisableDoneButton : Bool {
55- guard let amountDecimal = priceFieldFormatter. amountDecimal, amountDecimal != . zero else {
55+ guard let amountDecimal = priceFieldFormatter. amountDecimal else {
5656 return true
5757 }
5858
@@ -71,7 +71,6 @@ class ShippingLineDetailsViewModel: ObservableObject {
7171 self . priceFieldFormatter = . init( locale: locale, storeCurrencySettings: storeCurrencySettings, allowNegativeNumber: true )
7272 self . currencySymbol = storeCurrencySettings. symbol ( from: storeCurrencySettings. currencyCode)
7373 self . currencyPosition = storeCurrencySettings. currencyPosition
74- self . amountPlaceholder = priceFieldFormatter. formatAmount ( " 0 " )
7574
7675 self . isExistingShippingLine = isExistingShippingLine
7776 self . initialMethodTitle = initialMethodTitle
@@ -81,10 +80,10 @@ class ShippingLineDetailsViewModel: ObservableObject {
8180 if let initialAmount = currencyFormatter. convertToDecimal ( from: shippingTotal) {
8281 self . initialAmount = initialAmount as Decimal
8382 } else {
84- self . initialAmount = . zero
83+ self . initialAmount = nil
8584 }
8685
87- if initialAmount != . zero , let formattedInputAmount = currencyFormatter. formatAmount ( initialAmount) {
86+ if let initialAmount = initialAmount , let formattedInputAmount = currencyFormatter. formatAmount ( initialAmount) {
8887 self . amount = priceFieldFormatter. formatAmount ( formattedInputAmount)
8988 }
9089
0 commit comments