-
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.
Merge pull request #169 from xmtp/np/bump-pod-for-new-pppp
Move React Native to latest User Preferences
- Loading branch information
Showing
11 changed files
with
170 additions
and
32 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
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
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