From feafbc4071a371a330e89ad81f278503ee5604f4 Mon Sep 17 00:00:00 2001 From: cameronvoell Date: Thu, 5 Dec 2024 15:58:13 -0800 Subject: [PATCH 1/5] Fix use saved wallet function in example app --- example/ios/Podfile.lock | 4 ++-- example/src/hooks.tsx | 33 +++++++++++++++------------------ 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 9d3bc8eb2..146e2cc35 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -452,7 +452,7 @@ PODS: - CSecp256k1 (~> 0.2) - LibXMTP (= 3.0.10) - SQLCipher (= 4.5.7) - - XMTPReactNative (0.1.0): + - XMTPReactNative (3.1.1): - CSecp256k1 (~> 0.2) - ExpoModulesCore - MessagePacker @@ -757,7 +757,7 @@ SPEC CHECKSUMS: SQLCipher: 5e6bfb47323635c8b657b1b27d25c5f1baf63bf5 SwiftProtobuf: 4dbaffec76a39a8dc5da23b40af1a5dc01a4c02d XMTP: 3b586fa3703640bb5fec8a64daba9e157d9e5fdc - XMTPReactNative: ab20c0030e2092fb7201c42d6ec17a7055ec6bf8 + XMTPReactNative: f3e1cbf80b7278b817bd42982703a95a9250497d Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9 PODFILE CHECKSUM: 0e6fe50018f34e575d38dc6a1fdf1f99c9596cdd diff --git a/example/src/hooks.tsx b/example/src/hooks.tsx index 44576694d..1f09cae55 100644 --- a/example/src/hooks.tsx +++ b/example/src/hooks.tsx @@ -551,29 +551,26 @@ export function useSavedAddress(): { } } -export function getDbEncryptionKey( +export async function getDbEncryptionKey( network: string, clear: boolean = false -): Uint8Array { +): Promise { const key = `xmtp-${network}` - // eslint-disable-next-line no-unused-expressions - ;async () => { - const result = await EncryptedStorage.getItem(key) - if ((result && clear === true) || !result) { - if (result) { - await EncryptedStorage.removeItem(key) - } - - const randomBytes = crypto.getRandomValues(new Uint8Array(32)) - const randomBytesString = uint8ArrayToHexString(randomBytes) - await EncryptedStorage.setItem(key, randomBytesString) - return randomBytes - } else { - return hexStringToUint8Array(result) + + const result = await EncryptedStorage.getItem(key) + if ((result && clear === true) || !result) { + if (result) { + console.log('Removing existing dbEncryptionKey', key) + await EncryptedStorage.removeItem(key) } + + const randomBytes = crypto.getRandomValues(new Uint8Array(32)) + const randomBytesString = uint8ArrayToHexString(randomBytes) + await EncryptedStorage.setItem(key, randomBytesString) + return randomBytes + } else { + return hexStringToUint8Array(result) } - const randomBytes = crypto.getRandomValues(new Uint8Array(32)) - return randomBytes } function uint8ArrayToHexString(byteArray: Uint8Array): string { From 3f1b2962ffce75f2857d8e6ba094cd382aa23296 Mon Sep 17 00:00:00 2001 From: cameronvoell Date: Thu, 5 Dec 2024 16:31:14 -0800 Subject: [PATCH 2/5] add clipboard button so we can copy address in android --- example/ios/Podfile.lock | 6 ++++++ example/package.json | 1 + example/src/HomeScreen.tsx | 25 ++++++++++++++++++++++--- example/yarn.lock | 36 ++++++++---------------------------- 4 files changed, 37 insertions(+), 31 deletions(-) diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 146e2cc35..c4ec2128e 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -433,6 +433,8 @@ PODS: - React-perflogger (= 0.71.14) - RNCAsyncStorage (1.21.0): - React-Core + - RNCClipboard (1.5.1): + - React-Core - RNFS (2.20.0): - React-Core - RNScreens (3.20.0): @@ -524,6 +526,7 @@ DEPENDENCIES: - React-runtimeexecutor (from `../node_modules/react-native/ReactCommon/runtimeexecutor`) - ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`) - "RNCAsyncStorage (from `../node_modules/@react-native-async-storage/async-storage`)" + - "RNCClipboard (from `../node_modules/@react-native-community/clipboard`)" - RNFS (from `../node_modules/react-native-fs`) - RNScreens (from `../node_modules/react-native-screens`) - RNSVG (from `../node_modules/react-native-svg`) @@ -668,6 +671,8 @@ EXTERNAL SOURCES: :path: "../node_modules/react-native/ReactCommon" RNCAsyncStorage: :path: "../node_modules/@react-native-async-storage/async-storage" + RNCClipboard: + :path: "../node_modules/@react-native-community/clipboard" RNFS: :path: "../node_modules/react-native-fs" RNScreens: @@ -751,6 +756,7 @@ SPEC CHECKSUMS: React-runtimeexecutor: ffe826b7b1cfbc32a35ed5b64d5886c0ff75f501 ReactCommon: 7f3dd5e98a9ec627c6b03d26c062bf37ea9fc888 RNCAsyncStorage: 618d03a5f52fbccb3d7010076bc54712844c18ef + RNCClipboard: 41d8d918092ae8e676f18adada19104fa3e68495 RNFS: 4ac0f0ea233904cb798630b3c077808c06931688 RNScreens: 218801c16a2782546d30bd2026bb625c0302d70f RNSVG: d00c8f91c3cbf6d476451313a18f04d220d4f396 diff --git a/example/package.json b/example/package.json index 5fac9e8f2..4669ab643 100644 --- a/example/package.json +++ b/example/package.json @@ -9,6 +9,7 @@ }, "dependencies": { "@react-native-async-storage/async-storage": "^1.21.0", + "@react-native-community/clipboard": "^1.5.1", "@react-native-community/netinfo": "^11.2.0", "@react-navigation/native": "^6.1.6", "@react-navigation/native-stack": "^6.9.12", diff --git a/example/src/HomeScreen.tsx b/example/src/HomeScreen.tsx index e229a48ec..c94b8a63b 100644 --- a/example/src/HomeScreen.tsx +++ b/example/src/HomeScreen.tsx @@ -8,7 +8,9 @@ import { StyleSheet, Text, View, + TouchableOpacity, } from 'react-native' +import Clipboard from '@react-native-community/clipboard' import { Conversation, Client, @@ -56,9 +58,26 @@ export default function HomeScreen() { }} > Connected as - - {client?.address} - + + + {client?.address} + + { + if (client?.address) { + Clipboard.setString(client.address) + } + }} + style={{ + padding: 8, + backgroundColor: '#ddd', + borderRadius: 4, + marginLeft: 8, + }} + > + Copy + + } /> diff --git a/example/yarn.lock b/example/yarn.lock index 98edbc3fe..6da5487d9 100644 --- a/example/yarn.lock +++ b/example/yarn.lock @@ -5521,6 +5521,11 @@ prompts "^2.4.0" semver "^6.3.0" +"@react-native-community/clipboard@^1.5.1": + version "1.5.1" + resolved "https://registry.npmjs.org/@react-native-community/clipboard/-/clipboard-1.5.1.tgz#32abb3ea2eb91ee3f9c5fb1d32d5783253c9fabe" + integrity sha512-AHAmrkLEH5UtPaDiRqoULERHh3oNv7Dgs0bTC0hO5Z2GdNokAMPT5w8ci8aMcRemcwbtdHjxChgtjbeA38GBdA== + "@react-native-community/netinfo@^11.2.0": version "11.2.1" resolved "https://registry.npmjs.org/@react-native-community/netinfo/-/netinfo-11.2.1.tgz" @@ -14508,16 +14513,7 @@ strict-uri-encode@^2.0.0: resolved "https://registry.npmjs.org/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz" integrity sha512-QwiXZgpRcKkhTj2Scnn++4PKtWsH0kpzZ62L2R6c/LUVYv7hVnZqcg2+sMuT6R7Jusu1vviK/MFsu6kNJfWlEQ== -"string-width-cjs@npm:string-width@^4.2.0": - version "4.2.3" - resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz" - integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== - dependencies: - emoji-regex "^8.0.0" - is-fullwidth-code-point "^3.0.0" - strip-ansi "^6.0.1" - -string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: +"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: version "4.2.3" resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -14591,7 +14587,7 @@ string_decoder@~1.1.1: dependencies: safe-buffer "~5.1.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1": +"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -14605,13 +14601,6 @@ strip-ansi@^5.0.0, strip-ansi@^5.2.0: dependencies: ansi-regex "^4.1.0" -strip-ansi@^6.0.0, strip-ansi@^6.0.1: - version "6.0.1" - resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz" - integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== - dependencies: - ansi-regex "^5.0.1" - strip-ansi@^7.0.1: version "7.1.0" resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz" @@ -15882,7 +15871,7 @@ word-wrap@~1.2.3: resolved "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz" integrity sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA== -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== @@ -15900,15 +15889,6 @@ wrap-ansi@^6.2.0: string-width "^4.1.0" strip-ansi "^6.0.0" -wrap-ansi@^7.0.0: - version "7.0.0" - resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz" - integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== - dependencies: - ansi-styles "^4.0.0" - string-width "^4.1.0" - strip-ansi "^6.0.0" - wrap-ansi@^8.1.0: version "8.1.0" resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz" From 2307c5eb8f0c4fe928ab8d0e3ae7cc9305e50245 Mon Sep 17 00:00:00 2001 From: cameronvoell Date: Thu, 5 Dec 2024 16:59:06 -0800 Subject: [PATCH 3/5] fix conversation navigation in example app --- example/package.json | 1 + example/src/HomeScreen.tsx | 15 +++++++++------ example/src/hooks.tsx | 12 ++++++------ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/example/package.json b/example/package.json index 4669ab643..2ebe867ba 100644 --- a/example/package.json +++ b/example/package.json @@ -5,6 +5,7 @@ "start": "expo start --dev-client", "android": "expo run:android", "ios": "expo run:ios", + "ios:clean": "expo run:ios --no-build-cache", "web": "expo start --web" }, "dependencies": { diff --git a/example/src/HomeScreen.tsx b/example/src/HomeScreen.tsx index c94b8a63b..8d1c6e1c3 100644 --- a/example/src/HomeScreen.tsx +++ b/example/src/HomeScreen.tsx @@ -18,7 +18,6 @@ import { DecodedMessage, } from 'xmtp-react-native-sdk' -import { SupportedContentTypes } from './contentTypes/contentTypes' import { useConversationList } from './hooks' /// Show the user's list of conversations. @@ -95,7 +94,7 @@ function ConversationItem({ }) { const navigation = useContext(NavigationContext) const [messages, setMessages] = useState< - DecodedMessage[] + DecodedMessage[] >([]) const lastMessage = messages?.[0] const [consentState, setConsentState] = useState() @@ -122,10 +121,14 @@ function ConversationItem({ return ( - navigation!.navigate('conversation', { - id: conversation.id, - }) + onPress={() => + { + console.log('conversation pressed') + console.log(conversation.topic) + navigation!.navigate('conversation', { + topic: conversation.topic, + }) + } } > []> { +}): UseQueryResult { const { client } = useXmtp() const { data: conversation } = useConversation({ topic }) - return useQuery[]>( + return useQuery( ['xmtp', 'messages', client?.address, conversation?.topic], () => conversation!.messages(), { @@ -110,10 +110,10 @@ export function useGroupMessages({ id, }: { id: string -}): UseQueryResult[]> { +}): UseQueryResult { const { client } = useXmtp() const { data: group } = useGroup({ groupId: id }) - return useQuery[]>( + return useQuery( ['xmtp', 'groupMessages', client?.address, group?.id], async () => { await group!.sync() @@ -139,7 +139,7 @@ export function useMessage({ topic: string messageId: string }): { - message: DecodedMessage | undefined + message: DecodedMessage | undefined isSenderMe: boolean performReaction: | undefined @@ -183,7 +183,7 @@ export function useGroupMessage({ groupId: string messageId: string }): { - message: DecodedMessage | undefined + message: DecodedMessage | undefined isSenderMe: boolean performReaction: | undefined From 2e5ca0bb0b7fb11c98ea097e58552ae10c855b3d Mon Sep 17 00:00:00 2001 From: cameronvoell Date: Thu, 5 Dec 2024 17:12:38 -0800 Subject: [PATCH 4/5] fix conversation screen refresh --- example/src/hooks.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/example/src/hooks.tsx b/example/src/hooks.tsx index b032ba2fc..6867371d1 100644 --- a/example/src/hooks.tsx +++ b/example/src/hooks.tsx @@ -99,7 +99,10 @@ export function useMessages({ const { data: conversation } = useConversation({ topic }) return useQuery( ['xmtp', 'messages', client?.address, conversation?.topic], - () => conversation!.messages(), + async () => { + await conversation!.sync() + return conversation!.messages() + }, { enabled: !!client && !!topic && !!conversation, } From 4d60b0d70e82da2a1f31075a8c4559c78a878025 Mon Sep 17 00:00:00 2001 From: cameronvoell Date: Thu, 5 Dec 2024 17:29:28 -0800 Subject: [PATCH 5/5] lint fixes --- example/src/HomeScreen.tsx | 22 +++++++++------------- example/src/hooks.tsx | 2 +- example/src/tests/conversationTests.ts | 3 ++- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/example/src/HomeScreen.tsx b/example/src/HomeScreen.tsx index 8d1c6e1c3..d45c57ed4 100644 --- a/example/src/HomeScreen.tsx +++ b/example/src/HomeScreen.tsx @@ -1,3 +1,4 @@ +import Clipboard from '@react-native-community/clipboard' import { NavigationContext } from '@react-navigation/native' import moment from 'moment' import React, { useContext, useEffect, useState } from 'react' @@ -10,7 +11,6 @@ import { View, TouchableOpacity, } from 'react-native' -import Clipboard from '@react-native-community/clipboard' import { Conversation, Client, @@ -93,9 +93,7 @@ function ConversationItem({ client: Client | null }) { const navigation = useContext(NavigationContext) - const [messages, setMessages] = useState< - DecodedMessage[] - >([]) + const [messages, setMessages] = useState([]) const lastMessage = messages?.[0] const [consentState, setConsentState] = useState() @@ -121,15 +119,13 @@ function ConversationItem({ return ( - { - console.log('conversation pressed') - console.log(conversation.topic) - navigation!.navigate('conversation', { - topic: conversation.topic, - }) - } - } + onPress={() => { + console.log('conversation pressed') + console.log(conversation.topic) + navigation!.navigate('conversation', { + topic: conversation.topic, + }) + }} > { const key = `xmtp-${network}` - + const result = await EncryptedStorage.getItem(key) if ((result && clear === true) || !result) { if (result) { diff --git a/example/src/tests/conversationTests.ts b/example/src/tests/conversationTests.ts index 3bba5c17f..508e62ad4 100644 --- a/example/src/tests/conversationTests.ts +++ b/example/src/tests/conversationTests.ts @@ -1,4 +1,6 @@ +import { Wallet } from 'ethers' import RNFS from 'react-native-fs' + import { Test, assert, createClients, delayToPropogate } from './test-utils' import { Client, @@ -7,7 +9,6 @@ import { ConversationId, ConversationVersion, } from '../../../src/index' -import { Wallet } from 'ethers' export const conversationTests: Test[] = [] let counter = 1