Skip to content

Commit

Permalink
Merge branch 'main' into cameronvoell/example-wallet-auth
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronvoell committed Dec 18, 2023
2 parents 41d0934 + e6053cd commit 76feee8
Show file tree
Hide file tree
Showing 30 changed files with 25,628 additions and 25,952 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
with:
node-version: 18.14.0
- name: Install dependencies
run: npm ci
run: yarn install --frozen-lockfile
- name: Build typedocs
run: npm run typedoc
- name: Deploy
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v3
- name: Install dependencies
run: npm ci
run: yarn install --frozen-lockfile
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ jobs:
fetch-depth: 0
- uses: actions/setup-node@v3
# Note: this triggers `prepare` which compiles the types.
- run: npm ci
- run: yarn install --frozen-lockfile
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ Use the [XMTP React Native example app](example) as a tool to start building an
Follow the [React Native guide](https://reactnative.dev/docs/environment-setup) to set up a CLI environment.

```bash
npm install
yarn
cd example
npm install --force
npm run [ios or android]
yarn
yarn run [ios or android]
```

## Install in a managed Expo project
Expand All @@ -41,10 +41,10 @@ npx expo prebuild

For bare React Native projects, [install and configure the `expo` package](https://docs.expo.dev/bare/installing-expo-modules/) before continuing.

### Add the package to your npm dependencies
### Add the package to your yarn dependencies

```bash
npm i @xmtp/react-native-sdk
yarn i @xmtp/react-native-sdk
```

### Configure for iOS
Expand All @@ -55,7 +55,7 @@ In the `ios` directory, update your `Podfile` file as follows:
- Add this line: `pod 'secp256k1.swift', :modular_headers => true`. This is required for web3.swift.

```bash
npm pod-install
npx pod-install
```

### Configure for Android
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ repositories {
dependencies {
implementation project(':expo-modules-core')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
implementation "org.xmtp:android:0.6.20"
implementation "org.xmtp:android:0.7.0"
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.facebook.react:react-native:0.71.3'
implementation "com.daveanthonythomas.moshipack:moshipack:1.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import org.xmtp.android.library.Client
import org.xmtp.android.library.ClientOptions
import org.xmtp.android.library.ConsentState
import org.xmtp.android.library.Conversation
import org.xmtp.android.library.PreEventCallback
import org.xmtp.android.library.PreparedMessage
import org.xmtp.android.library.SendOptions
import org.xmtp.android.library.SigningKey
Expand Down Expand Up @@ -128,7 +129,14 @@ class XMTPModule : Module() {

override fun definition() = ModuleDefinition {
Name("XMTP")
Events("sign", "authed", "conversation", "message")
Events(
"sign",
"authed",
"conversation",
"message",
"preEnableIdentityCallback",
"preCreateIdentityCallback"
)

Function("address") { clientAddress: String ->
logV("address")
Expand All @@ -139,12 +147,21 @@ class XMTPModule : Module() {
//
// Auth functions
//
AsyncFunction("auth") { address: String, environment: String, appVersion: String? ->
AsyncFunction("auth") { address: String, environment: String, appVersion: String?, hasCreateIdentityCallback: Boolean?, hasEnableIdentityCallback: Boolean? ->
logV("auth")
val reactSigner = ReactNativeSigner(module = this@XMTPModule, address = address)
signer = reactSigner
val options = ClientOptions(api = apiEnvironments(environment, appVersion))
val preCreateIdentityCallback: PreEventCallback? =
preCreateIdentityCallback.takeIf { hasCreateIdentityCallback == true }
val preEnableIdentityCallback: PreEventCallback? =
preEnableIdentityCallback.takeIf { hasEnableIdentityCallback == true }
val options = ClientOptions(
api = apiEnvironments(environment, appVersion),
preCreateIdentityCallback = preCreateIdentityCallback,
preEnableIdentityCallback = preEnableIdentityCallback
)
clients[address] = Client().create(account = reactSigner, options = options)
ContentJson.Companion
signer = null
sendEvent("authed")
}
Expand All @@ -155,11 +172,21 @@ class XMTPModule : Module() {
}

// Generate a random wallet and set the client to that
AsyncFunction("createRandom") { environment: String, appVersion: String? ->
AsyncFunction("createRandom") { environment: String, appVersion: String?, hasCreateIdentityCallback: Boolean?, hasEnableIdentityCallback: Boolean? ->
logV("createRandom")
val privateKey = PrivateKeyBuilder()
val options = ClientOptions(api = apiEnvironments(environment, appVersion))
val preCreateIdentityCallback: PreEventCallback? =
preCreateIdentityCallback.takeIf { hasCreateIdentityCallback == true }
val preEnableIdentityCallback: PreEventCallback? =
preEnableIdentityCallback.takeIf { hasEnableIdentityCallback == true }

val options = ClientOptions(
api = apiEnvironments(environment, appVersion),
preCreateIdentityCallback = preCreateIdentityCallback,
preEnableIdentityCallback = preEnableIdentityCallback
)
val randomClient = Client().create(account = privateKey, options = options)
ContentJson.Companion
clients[randomClient.address] = randomClient
randomClient.address
}
Expand All @@ -176,6 +203,7 @@ class XMTPModule : Module() {
)
)
val client = Client().buildFromBundle(bundle = bundle, options = options)
ContentJson.Companion
clients[client.address] = client
client.address
} catch (e: Exception) {
Expand Down Expand Up @@ -684,6 +712,14 @@ class XMTPModule : Module() {
Log.v("XMTPModule", msg)
}
}

private val preEnableIdentityCallback: suspend () -> Unit = {
sendEvent("preEnableIdentityCallback")
}

private val preCreateIdentityCallback: suspend () -> Unit = {
sendEvent("preCreateIdentityCallback")
}
}


7 changes: 3 additions & 4 deletions example/App.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { NavigationContainer } from '@react-navigation/native'
import React from 'react'
import { Button, Platform } from 'react-native'
import { QueryClient, QueryClientProvider } from 'react-query'
import { XmtpProvider } from 'xmtp-react-native-sdk'

import ConversationCreateScreen from './src/ConversationCreateScreen'
import ConversationScreen from './src/ConversationScreen'
import HomeScreen from './src/HomeScreen'
import LaunchScreen from './src/LaunchScreen'
import { Navigator } from './src/Navigation'
import TestScreen from './src/TestScreen'
import { XmtpContextProvider } from './src/XmtpContext'
import { ThirdwebProvider, walletConnect } from "@thirdweb-dev/react-native";

const queryClient = new QueryClient()
Expand All @@ -30,7 +29,7 @@ export default function App() {
})
]}>
<QueryClientProvider client={queryClient}>
<XmtpContextProvider>
<XmtpProvider>
<NavigationContainer>
<Navigator.Navigator>
<Navigator.Screen
Expand Down Expand Up @@ -86,7 +85,7 @@ export default function App() {
/>
</Navigator.Navigator>
</NavigationContainer>
</XmtpContextProvider>
</XmtpProvider>
</QueryClientProvider>
</ThirdwebProvider>
)
Expand Down
7 changes: 4 additions & 3 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ Follow the [React Native guide](https://reactnative.dev/docs/environment-setup)
To use the example app, run:

```bash
npm install
yarn
cd example
npm install --force
npm run [ios or android]
yarn
npx pod-install
yarn run [ios or android]
```

## Run example app unit tests on local emulators
Expand Down
26 changes: 13 additions & 13 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ PODS:
- Connect-Swift (0.3.0):
- SwiftProtobuf (~> 1.20.3)
- DoubleConversion (1.1.6)
- EXApplication (5.1.1):
- EXApplication (5.4.0):
- ExpoModulesCore
- EXConstants (14.2.1):
- ExpoModulesCore
- EXFileSystem (15.2.2):
- EXFileSystem (15.6.0):
- ExpoModulesCore
- EXFont (11.1.1):
- ExpoModulesCore
Expand Down Expand Up @@ -313,7 +313,7 @@ PODS:
- React-jsinspector (0.71.14)
- React-logger (0.71.14):
- glog
- react-native-blob-util (0.19.4):
- react-native-blob-util (0.19.6):
- React-Core
- react-native-encrypted-storage (4.0.3):
- React-Core
Expand All @@ -322,7 +322,7 @@ PODS:
- react-native-mmkv (2.11.0):
- MMKV (>= 1.2.13)
- React-Core
- react-native-netinfo (11.2.0):
- react-native-netinfo (11.2.1):
- React-Core
- react-native-quick-base64 (2.0.8):
- React-Core
Expand Down Expand Up @@ -437,15 +437,15 @@ PODS:
- GenericJSON (~> 2.0)
- Logging (~> 1.0.0)
- secp256k1.swift (~> 0.1)
- XMTP (0.7.2-alpha0):
- XMTP (0.7.3-alpha0):
- Connect-Swift (= 0.3.0)
- GzipSwift
- web3.swift
- XMTPRust (= 0.3.7-beta0)
- XMTPReactNative (0.1.0):
- ExpoModulesCore
- MessagePacker
- XMTP (= 0.7.2-alpha0)
- XMTP (= 0.7.3-alpha0)
- XMTPRust (0.3.7-beta0)
- Yoga (1.14.0)

Expand Down Expand Up @@ -667,9 +667,9 @@ SPEC CHECKSUMS:
CoinbaseWalletSDKExpo: 89f8ad7f799227be7aff2b9353b7a77d37eb8283
Connect-Swift: d38eedc1907d440314f8d26d5a038a00cbb0f6f1
DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54
EXApplication: d8f53a7eee90a870a75656280e8d4b85726ea903
EXApplication: 2a0d9abd4feace9c6faedfe541c1dec02e3702cd
EXConstants: f348da07e21b23d2b085e270d7b74f282df1a7d9
EXFileSystem: 844e86ca9b5375486ecc4ef06d3838d5597d895d
EXFileSystem: aec89226b638b82cdd6d6c15d75a8b7f0696226d
EXFont: 6ea3800df746be7233208d80fe379b8ed74f4272
EXImageLoader: 03063370bc06ea1825713d3f55fe0455f7c88d04
Expo: 0d9f112757acc6bf32103eabccf91267780bd580
Expand Down Expand Up @@ -707,11 +707,11 @@ SPEC CHECKSUMS:
React-jsiexecutor: 94cfc1788637ceaf8841ef1f69b10cc0d62baadc
React-jsinspector: 7bf923954b4e035f494b01ac16633963412660d7
React-logger: 655ff5db8bd922acfbe76a4983ffab048916343e
react-native-blob-util: 30a6c9fd067aadf9177e61a998f2c7efb670598d
react-native-blob-util: d8fa1a7f726867907a8e43163fdd8b441d4489ea
react-native-encrypted-storage: db300a3f2f0aba1e818417c1c0a6be549038deb7
react-native-get-random-values: 384787fd76976f5aec9465aff6fa9e9129af1e74
react-native-mmkv: e97c0c79403fb94577e5d902ab1ebd42b0715b43
react-native-netinfo: 25c87e28495d955b30aeca9c22594691668c907a
react-native-netinfo: 8a7fd3f7130ef4ad2fb4276d5c9f8d3f28d2df3d
react-native-quick-base64: 777057ea4286f806b00259ede65dc79c7c706320
react-native-quick-crypto: 455c1b411db006dba1026a30681ececb19180187
react-native-randombytes: 421f1c7d48c0af8dbcd471b0324393ebf8fe7846
Expand All @@ -735,11 +735,11 @@ SPEC CHECKSUMS:
secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634
SwiftProtobuf: b02b5075dcf60c9f5f403000b3b0c202a11b6ae1
web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959
XMTP: 4930b80dc99a6a8ebcf1f292a162c1f316f78c50
XMTPReactNative: 68c723488857950d10fc8ee969de0baae8f9b2ca
XMTP: dc02c96b475e326a4a7b3d3912cc45cf3527bd0b
XMTPReactNative: 5c1111c5bd3456e75b3fa67d1ddccabb7a01df11
XMTPRust: 8848a2ba761b2c961d666632f2ad27d1082faa93
Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9

PODFILE CHECKSUM: 198f653f81532688b4006dd0f4b2ac66df8b4f37
PODFILE CHECKSUM: 5f3d4a00346ba8cdc06e9f714da38d292b3f8a38

COCOAPODS: 1.14.3
6 changes: 4 additions & 2 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "xmtp-react-native-sdk-example",
"version": "1.0.0",
"scripts": {
"preinstall": "npm install --package-lock-only --ignore-scripts && npx npm-force-resolutions",
"start": "expo start --dev-client",
"android": "expo run:android",
"ios": "expo run:ios",
Expand Down Expand Up @@ -60,7 +59,10 @@
"private": true,
"expo": {
"autolinking": {
"nativeModulesDir": ".."
"nativeModulesDir": "..",
"exclude": [
"expo-file-system"
]
}
}
}
2 changes: 1 addition & 1 deletion example/src/ConversationCreateScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { NativeStackScreenProps } from '@react-navigation/native-stack'
import React, { useState } from 'react'
import { Button, ScrollView, Text, TextInput } from 'react-native'
import { useXmtp } from 'xmtp-react-native-sdk'

import { NavigationParamList } from './Navigation'
import { useXmtp } from './XmtpContext'

export default function ConversationCreateScreen({
route,
Expand Down
Loading

0 comments on commit 76feee8

Please sign in to comment.