Skip to content

Commit

Permalink
Fixed floating promises in example app
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronvoell committed Mar 6, 2024
1 parent 0b0561f commit 349e265
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 15 deletions.
2 changes: 1 addition & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -762,4 +762,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 95d6ace79946933ecf80684613842ee553dd76a2

COCOAPODS: 1.14.2
COCOAPODS: 1.15.2
15 changes: 13 additions & 2 deletions example/src/ConversationScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ export default function ConversationScreen({
}
const sendRemoteAttachmentMessage = () => {
if (remoteAttachment) {
sendMessage({ remoteAttachment }).then(() => setAttachment(null))
sendMessage({ remoteAttachment })
.then(() => setAttachment(null))
.catch((e) => {
console.error('Error sending message: ', e)
})
}
}
const sendTextMessage = () => sendMessage({ text }).then(() => setText(''))
Expand Down Expand Up @@ -982,7 +986,14 @@ function MessageItem({
visible={showNewReaction}
onReaction={(reaction) => {
setShowNewReaction(false)
performReaction && performReaction('added', reaction)
performReaction &&
performReaction('added', reaction)
.then(() => {
console.log('Reaction added successfully')
})
.catch((error) => {
console.error('Error adding reaction', error)
})
}}
/>
</View>
Expand Down
17 changes: 14 additions & 3 deletions example/src/GroupScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as ImagePicker from 'expo-image-picker'
import type { ImagePickerAsset } from 'expo-image-picker'
import { PermissionStatus } from 'expo-modules-core'
import moment from 'moment'
import React, { FC, useCallback, useMemo, useRef, useState } from 'react'
import React, { useCallback, useMemo, useRef, useState } from 'react'
import {
Button,
FlatList,
Expand Down Expand Up @@ -110,7 +110,11 @@ export default function GroupScreen({
}
const sendRemoteAttachmentMessage = () => {
if (remoteAttachment) {
sendMessage({ remoteAttachment }).then(() => setAttachment(null))
sendMessage({ remoteAttachment })
.then(() => setAttachment(null))
.catch((e) => {
console.error('Error sending message: ', e)
})
}
}
const sendTextMessage = () => sendMessage({ text }).then(() => setText(''))
Expand Down Expand Up @@ -982,7 +986,14 @@ function MessageItem({
visible={showNewReaction}
onReaction={(reaction) => {
setShowNewReaction(false)
performReaction && performReaction('added', reaction)
performReaction &&
performReaction('added', reaction)
.then(() => {
console.log('Reaction added successfully')
})
.catch((error) => {
console.error('Error adding reaction', error)
})
}}
/>
</View>
Expand Down
25 changes: 19 additions & 6 deletions example/src/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ function GroupListItem({
?.sync()
.then(() => group.messages())
.then(setMessages)
.catch((e) => {
console.error('Error fetching group messages: ', e)
})
}, [group])

return (
Expand Down Expand Up @@ -154,14 +157,24 @@ function ConversationItem({
const [getConsentState, setConsentState] = useState<string | undefined>()

useEffect(() => {
conversation.consentState().then((result) => {
setConsentState(result)
})
conversation
.consentState()
.then((result) => {
setConsentState(result)
})
.catch((e) => {
console.error('Error setting consent state: ', e)
})
}, [conversation])

const denyContact = () => {
client?.contacts.deny([conversation.peerAddress])
conversation.consentState().then(setConsentState)
const denyContact = async () => {
await client?.contacts.deny([conversation.peerAddress])
conversation
.consentState()
.then(setConsentState)
.catch((e) => {
console.error('Error denying contact: ', e)
})
}

return (
Expand Down
4 changes: 3 additions & 1 deletion example/src/LaunchScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ export default function LaunchScreen(
} else {
setSignerAddressDisplay('loading...')
}
})()
})().catch((e) => {
console.error("Error displaying signers's address", e)
})
}, [signer])

return (
Expand Down
4 changes: 3 additions & 1 deletion example/src/TestScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ function TestView({
useEffect(() => {
;(async () => {
await run()
})()
})().catch((e) => {
console.error(e)
})
}, [test])

const backgroundColor = {
Expand Down
9 changes: 8 additions & 1 deletion example/src/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ export function useConversationList(): UseQueryResult<
Conversation<SupportedContentTypes>[]
> {
const { client } = useXmtp()
client?.contacts.refreshConsentList()
client?.contacts
.refreshConsentList()
.then(() => {
console.log('Refreshed consent list successfully')
})
.catch((error) => {
console.error('Error refreshing consent list', error)
})
return useQuery<Conversation<SupportedContentTypes>[]>(
['xmtp', 'conversations', client?.address],
() => client!.conversations.list(),
Expand Down

0 comments on commit 349e265

Please sign in to comment.