-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
211 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/ConsentWrapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package expo.modules.xmtpreactnativesdk.wrappers | ||
|
||
import com.google.gson.GsonBuilder | ||
import org.xmtp.android.library.ConsentListEntry | ||
import org.xmtp.android.library.ConsentState | ||
import org.xmtp.android.library.codecs.description | ||
import org.xmtp.android.library.messages.DecryptedMessage | ||
|
||
class ConsentWrapper { | ||
|
||
companion object { | ||
fun encode(model: ConsentListEntry): String { | ||
val gson = GsonBuilder().create() | ||
val message = encodeMap(model) | ||
return gson.toJson(message) | ||
} | ||
|
||
fun encodeMap(model: ConsentListEntry): Map<String, Any> = mapOf( | ||
"type" to model.entryType.name.lowercase(), | ||
"value" to model.value.lowercase(), | ||
"state" to consentStateToString(model.consentType), | ||
) | ||
|
||
fun consentStateToString(state: ConsentState): String { | ||
return when (state) { | ||
ConsentState.ALLOWED -> "allowed" | ||
ConsentState.DENIED -> "denied" | ||
ConsentState.UNKNOWN -> "unknown" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# XMTP React Native example app | ||
|
||
This basic messaging app has an intentionally unopinionated UI to help make it easier for you to build with. | ||
|
||
## Run the example app | ||
Follow the [React Native guide](https://reactnative.dev/docs/environment-setup) to set up a CLI environment. | ||
|
||
To use the example app, run: | ||
|
||
```bash | ||
npm install | ||
cd example | ||
npm install --force | ||
npm run [ios or android] | ||
``` | ||
|
||
## Run example app unit tests on local emulators | ||
Running tests locally is useful when updating GitHub actions, or locally testing between changes. | ||
|
||
1. [Install Docker](https://docs.docker.com/get-docker/) | ||
|
||
2. Start a local XMTP server (from example directory) | ||
```bash | ||
docker-compose -p xmtp -f dev/local/docker-compose.yml up -d | ||
``` | ||
3. Verify the XMTP server is running | ||
```bash | ||
docker-compose ls | ||
NAME STATUS CONFIG FILES | ||
xmtp running(3) <REPO_DIRECTORY>/xmtp-react-native/example/dev/local/docker-compose.yml | ||
``` | ||
4. You can now run unit tests on your local emulators | ||
5. You can stop the XMTP server with the following command: | ||
```bash | ||
docker-compose -p xmtp -f dev/local/docker-compose.yml down | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Foundation | ||
import XMTP | ||
|
||
struct ConsentWrapper { | ||
static func encodeToObj(_ entry: XMTP.ConsentListEntry) throws -> [String: Any] { | ||
return [ | ||
"type": entry.entryType.rawValue, | ||
"value": entry.value, | ||
"state": consentStateToString(state: entry.consentType), | ||
] | ||
} | ||
|
||
static func encode(_ entry: XMTP.ConsentListEntry) throws -> String { | ||
let obj = try encodeToObj(entry) | ||
let data = try JSONSerialization.data(withJSONObject: obj) | ||
guard let result = String(data: data, encoding: .utf8) else { | ||
throw WrapperError.encodeError("could not encode consent") | ||
} | ||
return result | ||
} | ||
|
||
static func consentStateToString(state: ConsentState) -> String { | ||
switch state { | ||
case .allowed: return "allowed" | ||
case .denied: return "denied" | ||
case .unknown: return "unknown" | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
export type ConsentState = 'allowed' | 'denied' | 'unknown' | ||
|
||
export type ConsentListEntryType = 'address' | ||
|
||
export class ConsentListEntry { | ||
value: string | ||
entryType: ConsentListEntryType | ||
permissionType: ConsentState | ||
|
||
constructor( | ||
value: string, | ||
entryType: ConsentListEntryType, | ||
permissionType: ConsentState | ||
) { | ||
this.value = value | ||
this.entryType = entryType | ||
this.permissionType = permissionType | ||
} | ||
|
||
static from(json: string): ConsentListEntry { | ||
const entry = JSON.parse(json) | ||
return new ConsentListEntry(entry.value, entry.type, entry.state) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters