Skip to content

Commit

Permalink
Merge pull request #1591 from stripe-ios/kg-smallcleanupv1
Browse files Browse the repository at this point in the history
Financial Connections: deleted some TODOs and did small rename cleanup.
  • Loading branch information
kgaidis-stripe authored Nov 23, 2022
2 parents 120ec80 + 2ee69db commit aeac5b6
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ extension STPAPIClient: FinancialConnectionsAPIClient {
"event_namespace": eventNamespace,
"event_name": eventName,
"client_timestamp": clientTimestamp,
// TODO(kgaidis): when we send failure events, correct this to send error details
"raw_event_details": "{}",
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class HostController {
private let returnURL: String?
private let analyticsClient: FinancialConnectionsAnalyticsClient

private var authFlowController: NativeFlowController?
private var nativeFlowController: NativeFlowController?
lazy var hostViewController = HostViewController(clientSecret: clientSecret, returnURL: returnURL, apiClient: api, delegate: self)
lazy var navigationController = FinancialConnectionsNavigationController(rootViewController: hostViewController)

Expand Down Expand Up @@ -97,12 +97,12 @@ extension HostController: HostViewControllerDelegate {
clientSecret: clientSecret,
analyticsClient: analyticsClient
)
authFlowController = NativeFlowController(
nativeFlowController = NativeFlowController(
dataManager: dataManager,
navigationController: navigationController
)
authFlowController?.delegate = self
authFlowController?.startFlow()
nativeFlowController?.delegate = self
nativeFlowController?.startFlow()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,30 @@ final class AccountPickerHelpers {
let numberFormatter = NumberFormatter()
numberFormatter.currencyCode = currency
numberFormatter.numberStyle = .currency
return numberFormatter.string(for: NSDecimalNumber.stp_decimalNumber(withAmount: Int(balanceAmount), currency: currency))
return numberFormatter.string(for: NSDecimalNumber.stp_fn_decimalNumber(withAmount: Int(balanceAmount), currency: currency))
}
}

// TODO(kgaidis): move this to StripeCore

extension NSDecimalNumber {
@objc class func stp_decimalNumber(
@objc class func stp_fn_decimalNumber(
withAmount amount: Int,
currency: String?
) -> NSDecimalNumber {
let isAmountNegative = amount < 0
let amount = abs(amount)

let noDecimalCurrencies = self.stp_currenciesWithNoDecimal()
let noDecimalCurrencies = self.stp_fn_currenciesWithNoDecimal()
let number = self.init(mantissa: UInt64(amount), exponent: 0, isNegative: isAmountNegative)
if noDecimalCurrencies.contains(currency?.lowercased() ?? "") {
return number
}
return number.multiplying(byPowerOf10: -2)
}

@objc func stp_amount(withCurrency currency: String?) -> Int {
let noDecimalCurrencies = NSDecimalNumber.stp_currenciesWithNoDecimal()
@objc func stp_fn_amount(withCurrency currency: String?) -> Int {
let noDecimalCurrencies = NSDecimalNumber.stp_fn_currenciesWithNoDecimal()

var ourNumber = self
if !(noDecimalCurrencies.contains(currency?.lowercased() ?? "")) {
Expand All @@ -65,7 +65,7 @@ extension NSDecimalNumber {
return Int(ourNumber.doubleValue)
}

class func stp_currenciesWithNoDecimal() -> [String] {
class func stp_fn_currenciesWithNoDecimal() -> [String] {
return [
"bif",
"clp",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class NativeFlowController {
guard
let viewController = CreatePaneViewController(
pane: dataManager.manifest.nextPane,
authFlowController: self,
nativeFlowController: self,
dataManager: dataManager
)
else {
Expand Down Expand Up @@ -121,7 +121,7 @@ extension NativeFlowController {
private func pushManualEntry() {
let manualEntryViewController = CreatePaneViewController(
pane: .manualEntry,
authFlowController: self,
nativeFlowController: self,
dataManager: dataManager
)
pushViewController(manualEntryViewController, animated: true)
Expand All @@ -139,7 +139,7 @@ extension NativeFlowController {
guard
let resetFlowViewController = CreatePaneViewController(
pane: .resetFlow,
authFlowController: self,
nativeFlowController: self,
dataManager: dataManager
)
else {
Expand Down Expand Up @@ -171,7 +171,7 @@ extension NativeFlowController {
guard
let terminalErrorViewController = CreatePaneViewController(
pane: .terminalError,
authFlowController: self,
nativeFlowController: self,
dataManager: dataManager
)
else {
Expand Down Expand Up @@ -286,7 +286,7 @@ extension NativeFlowController: ConsentViewControllerDelegate {

let viewController = CreatePaneViewController(
pane: manifest.nextPane,
authFlowController: self,
nativeFlowController: self,
dataManager: dataManager
)
pushViewController(viewController, animated: true)
Expand All @@ -307,7 +307,7 @@ extension NativeFlowController: InstitutionPickerViewControllerDelegate {

let partnerAuthViewController = CreatePaneViewController(
pane: .partnerAuth,
authFlowController: self,
nativeFlowController: self,
dataManager: dataManager
)
pushViewController(partnerAuthViewController, animated: true)
Expand Down Expand Up @@ -343,7 +343,7 @@ extension NativeFlowController: PartnerAuthViewControllerDelegate {

let accountPickerViewController = CreatePaneViewController(
pane: .accountPicker,
authFlowController: self,
nativeFlowController: self,
dataManager: dataManager
)
pushViewController(accountPickerViewController, animated: true)
Expand Down Expand Up @@ -372,7 +372,7 @@ extension NativeFlowController: AccountPickerViewControllerDelegate {
if shouldAttachLinkedPaymentAccount {
let attachLinkedPaymentMethodViewController = CreatePaneViewController(
pane: .attachLinkedPaymentAccount,
authFlowController: self,
nativeFlowController: self,
dataManager: dataManager
)
// this prevents an unnecessary push transition when presenting `attachLinkedPaymentAccount`
Expand All @@ -383,7 +383,7 @@ extension NativeFlowController: AccountPickerViewControllerDelegate {
} else {
let successViewController = CreatePaneViewController(
pane: .success,
authFlowController: self,
nativeFlowController: self,
dataManager: dataManager
)
pushViewController(successViewController, animated: true)
Expand Down Expand Up @@ -433,7 +433,7 @@ extension NativeFlowController: ManualEntryViewControllerDelegate {
if dataManager.manifest.manualEntryUsesMicrodeposits {
let manualEntrySuccessViewController = CreatePaneViewController(
pane: .manualEntrySuccess,
authFlowController: self,
nativeFlowController: self,
dataManager: dataManager
)
pushViewController(manualEntrySuccessViewController, animated: true)
Expand Down Expand Up @@ -475,7 +475,7 @@ extension NativeFlowController: ResetFlowViewControllerDelegate {
// go to the next pane (likely `institutionPicker`)
let nextViewController = CreatePaneViewController(
pane: manifest.nextPane,
authFlowController: self,
nativeFlowController: self,
dataManager: dataManager
)
pushViewController(nextViewController, animated: false)
Expand Down Expand Up @@ -517,7 +517,7 @@ extension NativeFlowController: AttachLinkedPaymentAccountViewControllerDelegate
) {
let viewController = CreatePaneViewController(
pane: paymentAccountResource.nextPane,
authFlowController: self,
nativeFlowController: self,
dataManager: dataManager
)
// the next pane is likely `success`
Expand All @@ -538,7 +538,7 @@ extension NativeFlowController: AttachLinkedPaymentAccountViewControllerDelegate
@available(iOSApplicationExtension, unavailable)
private func CreatePaneViewController(
pane: FinancialConnectionsSessionManifest.NextPane,
authFlowController: NativeFlowController,
nativeFlowController: NativeFlowController,
dataManager: NativeFlowDataManager
) -> UIViewController? {
let viewController: UIViewController?
Expand All @@ -554,7 +554,7 @@ private func CreatePaneViewController(
analyticsClient: dataManager.analyticsClient
)
let accountPickerViewController = AccountPickerViewController(dataSource: accountPickerDataSource)
accountPickerViewController.delegate = authFlowController
accountPickerViewController.delegate = nativeFlowController
viewController = accountPickerViewController
} else {
assertionFailure("Code logic error. Missing parameters for \(pane).")
Expand All @@ -574,7 +574,7 @@ private func CreatePaneViewController(
let attachedLinkedPaymentAccountViewController = AttachLinkedPaymentAccountViewController(
dataSource: dataSource
)
attachedLinkedPaymentAccountViewController.delegate = authFlowController
attachedLinkedPaymentAccountViewController.delegate = nativeFlowController
viewController = attachedLinkedPaymentAccountViewController
} else {
assertionFailure("Code logic error. Missing parameters for \(pane).")
Expand All @@ -589,7 +589,7 @@ private func CreatePaneViewController(
analyticsClient: dataManager.analyticsClient
)
let consentViewController = ConsentViewController(dataSource: consentDataSource)
consentViewController.delegate = authFlowController
consentViewController.delegate = nativeFlowController
viewController = consentViewController
case .institutionPicker:
let dataSource = InstitutionAPIDataSource(
Expand All @@ -599,7 +599,7 @@ private func CreatePaneViewController(
analyticsClient: dataManager.analyticsClient
)
let picker = InstitutionPickerViewController(dataSource: dataSource)
picker.delegate = authFlowController
picker.delegate = nativeFlowController
viewController = picker
case .linkConsent:
assertionFailure("Not supported")
Expand All @@ -615,7 +615,7 @@ private func CreatePaneViewController(
analyticsClient: dataManager.analyticsClient
)
let manualEntryViewController = ManualEntryViewController(dataSource: dataSource)
manualEntryViewController.delegate = authFlowController
manualEntryViewController.delegate = nativeFlowController
viewController = manualEntryViewController
case .manualEntrySuccess:
if let paymentAccountResource = dataManager.paymentAccountResource, let accountNumberLast4 = dataManager.accountNumberLast4 {
Expand All @@ -624,7 +624,7 @@ private func CreatePaneViewController(
accountNumberLast4: accountNumberLast4,
analyticsClient: dataManager.analyticsClient
)
manualEntrySuccessViewController.delegate = authFlowController
manualEntrySuccessViewController.delegate = nativeFlowController
viewController = manualEntrySuccessViewController
} else {
assertionFailure("Code logic error. Missing parameters for \(pane).")
Expand All @@ -646,7 +646,7 @@ private func CreatePaneViewController(
analyticsClient: dataManager.analyticsClient
)
let partnerAuthViewController = PartnerAuthViewController(dataSource: partnerAuthDataSource)
partnerAuthViewController.delegate = authFlowController
partnerAuthViewController.delegate = nativeFlowController
viewController = partnerAuthViewController
} else {
assertionFailure("Code logic error. Missing parameters for \(pane).")
Expand All @@ -663,7 +663,7 @@ private func CreatePaneViewController(
analyticsClient: dataManager.analyticsClient
)
let successViewController = SuccessViewController(dataSource: successDataSource)
successViewController.delegate = authFlowController
successViewController.delegate = nativeFlowController
viewController = successViewController
} else {
assertionFailure("Code logic error. Missing parameters for \(pane).")
Expand All @@ -688,15 +688,15 @@ private func CreatePaneViewController(
let resetFlowViewController = ResetFlowViewController(
dataSource: resetFlowDataSource
)
resetFlowViewController.delegate = authFlowController
resetFlowViewController.delegate = nativeFlowController
viewController = resetFlowViewController
case .terminalError:
if let terminalError = dataManager.terminalError {
let terminalErrorViewController = TerminalErrorViewController(
error: terminalError,
allowManualEntry: dataManager.manifest.allowManualEntry
)
terminalErrorViewController.delegate = authFlowController
terminalErrorViewController.delegate = nativeFlowController
viewController = terminalErrorViewController
} else {
assertionFailure("Code logic error. Missing parameters for \(pane).")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ final class PartnerAuthViewController: UIViewController {
self.dataSource.recordAuthSessionEvent(
eventName: "failure",
authSessionId: authorizationSession.id
) // TODO(kgaidis): we maybe need to send error_message and error_code here...
)

// cancel current auth session
self.dataSource.cancelPendingAuthSessionIfNeeded()
Expand Down

0 comments on commit aeac5b6

Please sign in to comment.