Skip to content

Commit

Permalink
pass the fields to the signer
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Sep 24, 2024
1 parent ea7bc5b commit e0ae49f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
21 changes: 17 additions & 4 deletions ios/Wrappers/AuthParamsWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,46 @@ struct AuthParamsWrapper {
let enableV3: Bool
let dbDirectory: String?
let historySyncUrl: String?

init(environment: String, appVersion: String?, enableV3: Bool, dbDirectory: String?, historySyncUrl: String?) {
let isSmartContractWallet: Bool
let chainId: UInt64
let blockNumber: UInt64

init(environment: String, appVersion: String?, enableV3: Bool, dbDirectory: String?, historySyncUrl: String?, isSmartContractWallet: Bool, chainId: UInt64, blockNumber: UInt64) {
self.environment = environment
self.appVersion = appVersion
self.enableV3 = enableV3
self.dbDirectory = dbDirectory
self.historySyncUrl = historySyncUrl
self.isSmartContractWallet = isSmartContractWallet
self.chainId = chainId
self.blockNumber = blockNumber
}

static func authParamsFromJson(_ authParams: String) -> AuthParamsWrapper {
guard let data = authParams.data(using: .utf8),
let jsonOptions = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] else {
return AuthParamsWrapper(environment: "dev", appVersion: nil, enableV3: false, dbDirectory: nil, historySyncUrl: nil)
return AuthParamsWrapper(environment: "dev", appVersion: nil, enableV3: false, dbDirectory: nil, historySyncUrl: nil, isSmartContractWallet: false, chainId: 1, blockNumber: 1)
}

let environment = jsonOptions["environment"] as? String ?? "dev"
let appVersion = jsonOptions["appVersion"] as? String
let enableV3 = jsonOptions["enableV3"] as? Bool ?? false
let dbDirectory = jsonOptions["dbDirectory"] as? String
let historySyncUrl = jsonOptions["historySyncUrl"] as? String
let isSmartContractWallet = jsonOptions["isSmartContractWallet"] as? Bool ?? false
let chainId = jsonOptions["chainId"] as? UInt64 ?? 1
let blockNumber = jsonOptions["blockNumber"] as? UInt64 ?? 1


return AuthParamsWrapper(
environment: environment,
appVersion: appVersion,
enableV3: enableV3,
dbDirectory: dbDirectory,
historySyncUrl: historySyncUrl
historySyncUrl: historySyncUrl,
isSmartContractWallet: isSmartContractWallet,
chainId: chainId,
blockNumber: blockNumber
)
}
}
4 changes: 2 additions & 2 deletions ios/XMTPModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ public class XMTPModule: Module {
}

AsyncFunction("createOrBuild") { (address: String, hasCreateIdentityCallback: Bool?, hasEnableIdentityCallback: Bool?, hasAuthenticateToInboxCallback: Bool?, dbEncryptionKey: [UInt8]?, authParams: String) in
let signer = ReactNativeSigner(module: self, address: address)
let authOptions = AuthParamsWrapper.authParamsFromJson(authParams)
let signer = ReactNativeSigner(module: self, address: address, isSmartContractWallet: authOptions.isSmartContractWallet, chainId: authOptions.chainId, blockNumber: authOptions.blockNumber)
self.signer = signer
if(hasCreateIdentityCallback ?? false) {
self.preCreateIdentityCallbackDeferred = DispatchSemaphore(value: 0)
Expand All @@ -333,7 +334,6 @@ public class XMTPModule: Module {
let preEnableIdentityCallback: PreEventCallback? = hasEnableIdentityCallback ?? false ? self.preEnableIdentityCallback : nil
let preAuthenticateToInboxCallback: PreEventCallback? = hasAuthenticateToInboxCallback ?? false ? self.preAuthenticateToInboxCallback : nil
let encryptionKeyData = dbEncryptionKey == nil ? nil : Data(dbEncryptionKey!)
let authOptions = AuthParamsWrapper.authParamsFromJson(authParams)

let options = self.createClientConfig(
env: authOptions.environment,
Expand Down

0 comments on commit e0ae49f

Please sign in to comment.