Skip to content

Instantly share code, notes, and snippets.

@matux
Last active September 16, 2019 18:18
Show Gist options
  • Save matux/a98196ccff5fb93ad68182887b606b85 to your computer and use it in GitHub Desktop.
Save matux/a98196ccff5fb93ad68182887b606b85 to your computer and use it in GitHub Desktop.
Env.net.request(.signup, result:
tap(AppId.init • ^\.[.registrationRequest] >>> assign(to: &Env.vars.id.app)) >>>
select(\.[.registrationId], \.[.registrationRequest], or: .badRequest) >>>
when(success: async(partial(presentBiometrics, __, __, succeed, fail)),
failure: when(.noSession, createAccount, otherwise: fail)))
or:
Env.net.request(.signup, result:
select(\.[.registrationId], \.[.registrationRequest], or: .badRequest) >>>
tap { Env.vars.id.app = AppId(message: .init($0.1)) } >>>
when(success: async(partial(presentBiometrics, __, __, succeed, fail)),
failure: when(.noSession, createAccount, otherwise: fail)))
vs.
Env.net.request(.signup) { (result: Result<Dictionary<String, Any>, APIError>) in
switch result {
case .success(let json):
let registrationIdKey = "registrationRequestId"
let registrationRequestKey = "fidoRegistrationRequest"
let optionalRegistrationId = json[registrationIdKey] as? String
let optionalRegistrationRequest = json[registrationRequestKey] as? String
guard
let registrationId = optionalRegistrationId,
let registrationRequest = optionalRegistrationRequest
else {
return fail()
}
Env.vars.id.app = AppId(message: .init(registrationRequest))
DispatchQueue.main.async {
presentBiometrics(
id: registrationId,
message: registrationRequest,
success: succeed, failure: fail)
}
case .failure(.noSession):
createAccount()
case .failure:
fail()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment