API Module

The API layer will require the Frontend SDK as well as integrating several API calls on your backend to set and fetch data to and from the Lucra system at appropriate times. View the API Integration document for more information.

The API layer can be accessed through your LucraClient object via lucraClient.api.<API Call>

All functions utilize Swift async/await and throw errors that need to be handled. For UserStateErrors you will need to present the appropriate flow from our UI Module.

Example API Call

Below is a sample SwiftUI implementation of an api layer call.

Task { @MainActor [weak self] in
       guard let self else { return }
        do {
            let matchup = try await lucraClient.api.createGamesMatchup(gameTypeId: "DARTS", atStake: wagerAmount)
            createClientMatchup(lucraMatchup: matchup)
        } catch let userError as UserStateError {
             switch userError {
             case .notInitialized:
                 flow = .onboarding
             case .unverified:
                 flow = .verifyIdentity
             case .notAllowed:
                  self.errorMessage = "You are not allowed to perform this action."
             case .insufficientFunds:
                  flow = .addFunds
             @unknown default:
                  fatalError()
             }
        } catch let locationError as LocationError {
          // Could also show custom location handling here
          self.errorMessage = locationError.localizedDescription
        } catch let error {
          self.errorMessage = error.localizedDescription
        }
     }

Event Listeners

Overview

Lucra’s iOS SDK provides a way to listen for events that occur within the SDK, such as when contests are created, accepted, or canceled. These events allow your app to respond in real-time to user actions and SDK flows.

Events are exposed through the LucraClient object via a Combine publisher.

Listening for Events

To listen for Lucra events, subscribe to the event publisher on your LucraClient instance.

Example Usage

Configure User

Pass in any info (except for DOB) you have already collected from your user to pre-populate the SDK with their data. This pre-fills screens like phone number entry, KYC name/address, the users profile image and username etc to simplify the users journey and keep data uniform throughout your app.

NOTES:

  1. Pass in nil for any fields you have not already collected. All nil values will be ignored persisting any values the user has entered through the Lucra SDK.

  2. Once set, changing first_name, last_name, or city will result in the user being set to unverified and they will need to go thru the KYC flow again. This is due to legal/compliance measures.

Receive User Updates

To receive updates when the user manually enters profile info inside the LucraSDK, subscribe to the user publisher value on LucraClient. This allows you to capture fields such as user address if you have not previously collected that in your app. Returns nil if user is not logged in.

Last updated