11import { Wallet } from 'ethers'
22import { Platform } from 'expo-modules-core'
3+ import Config from 'react-native-config'
34import {
45 Client ,
56 GroupUpdatedCodec ,
@@ -17,6 +18,8 @@ import {
1718 ReplyCodec ,
1819} from 'xmtp-react-native-sdk'
1920
21+ import { getTestEnv } from '../testEnv'
22+
2023// Debug logging state
2124let debugLoggingEnabled = false
2225
@@ -59,16 +62,37 @@ export async function createClients(
5962 env ?: XMTPEnvironment | undefined ,
6063 customCodecs ?: JSContentCodec < any > [ ]
6164) : Promise < Client [ ] > {
65+ const keyBytes = new Uint8Array ( [
66+ 233 , 120 , 198 , 96 , 154 , 65 , 132 , 17 , 132 , 96 , 250 , 40 , 103 , 35 , 125 , 64 ,
67+ 166 , 83 , 208 , 224 , 254 , 44 , 205 , 227 , 175 , 49 , 234 , 129 , 74 , 252 , 135 , 145 ,
68+ ] )
69+
70+ let resolvedEnv : XMTPEnvironment
71+ let gatewayHost : string | undefined
72+ if ( env !== undefined ) {
73+ resolvedEnv = env
74+ } else {
75+ const testEnvOption = getTestEnv ( )
76+ if ( testEnvOption === 'd14n' ) {
77+ debugLog ( 'Using d14n test environment' )
78+ resolvedEnv = 'dev'
79+ gatewayHost = Config . GATEWAY_HOST
80+ if ( ! gatewayHost ) {
81+ throw new Error (
82+ 'Test env is "d14n" but GATEWAY_HOST is not set. Copy EXAMPLE.env to .env, set GATEWAY_HOST, and rebuild the app.'
83+ )
84+ }
85+ } else {
86+ resolvedEnv = testEnvOption
87+ }
88+ }
89+
6290 const clients = [ ]
6391 for ( let i = 0 ; i < numClients ; i ++ ) {
64- const keyBytes = new Uint8Array ( [
65- 233 , 120 , 198 , 96 , 154 , 65 , 132 , 17 , 132 , 96 , 250 , 40 , 103 , 35 , 125 , 64 ,
66- 166 , 83 , 208 , 224 , 254 , 44 , 205 , 227 , 175 , 49 , 234 , 129 , 74 , 252 , 135 ,
67- 145 ,
68- ] )
6992 const client = await Client . createRandom ( {
70- env : env ?? 'local' ,
93+ env : resolvedEnv ,
7194 dbEncryptionKey : keyBytes ,
95+ ...( gatewayHost !== undefined && { gatewayHost } ) ,
7296 } )
7397 Client . register ( new GroupUpdatedCodec ( ) )
7498 Client . register ( new RemoteAttachmentCodec ( ) )
0 commit comments