Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
rygine committed Sep 26, 2024
1 parent 0897c65 commit 8cf211a
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 16 deletions.
17 changes: 17 additions & 0 deletions example2/src/hooks/useCreateGroup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Client } from '@xmtp/react-native-sdk'

import { SupportedContentTypes } from './useCreateClient'

export const useCreateGroup = (
client: Client<SupportedContentTypes> | undefined
) => {
if (!client) {
return () => undefined
}

return () => {
return client.conversations.newGroup([], {
name: 'Smart Contract Wallet Group',
})
}
}
15 changes: 15 additions & 0 deletions example2/src/hooks/useListMessages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Group } from '@xmtp/react-native-sdk'

import { SupportedContentTypes } from './useCreateClient'

export const useListMessages = (
group: Group<SupportedContentTypes> | undefined
) => {
if (!group) {
return () => undefined
}

return () => {
return group.messages()
}
}
52 changes: 36 additions & 16 deletions example2/src/wagmiDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
createConnectorFromWallet,
Wallets,
} from '@mobile-wallet-protocol/wagmi-connectors'
import { Client } from '@xmtp/react-native-sdk'
import { Client, DecodedMessage, Group } from '@xmtp/react-native-sdk'
import * as Linking from 'expo-linking'
import { useMemo, useState } from 'react'
import { ScrollView, StyleSheet, Text } from 'react-native'
Expand All @@ -20,6 +20,8 @@ import { base } from 'wagmi/chains'

import Section from './components/section'
import { SupportedContentTypes, useCreateClient } from './hooks/useCreateClient'
import { useCreateGroup } from './hooks/useCreateGroup'
import { useListMessages } from './hooks/useListMessages'

polyfillForWagmi()

Expand All @@ -45,19 +47,22 @@ export default function WagmiDemo() {
const [client, setClient] = useState<
Client<SupportedContentTypes> | undefined
>(undefined)
const [group, setGroup] = useState<Group<SupportedContentTypes> | undefined>(
undefined
)
const [messages, setMessages] = useState<
DecodedMessage<SupportedContentTypes>[] | undefined
>(undefined)
const insets = useSafeAreaInsets()
const { address, chainId } = useAccount()

const { connect, connectors } = useConnect()
const { disconnect } = useDisconnect()
const {
data: signMessageHash,
error: signMessageError,
signMessage,
reset,
} = useSignMessage()
const { reset } = useSignMessage()
const { data: walletClient } = useWalletClient()
const createClient = useCreateClient(walletClient)
const createGroup = useCreateGroup(client)
const listMessages = useListMessages(group)

const contentContainerStyle = useMemo(
() => ({
Expand Down Expand Up @@ -102,24 +107,39 @@ export default function WagmiDemo() {
void client?.deleteLocalDatabase()
}}
/>
<Section
key="useSignMessage"
title="useSignMessage"
result={signMessageHash ?? signMessageError}
onPress={() => signMessage({ message: 'hello world' })}
/>
<Section
key="useCreateClient"
title="useCreateClient"
result={client?.address ?? "MOOOOO"}
buttonLabel="Create Client"
result={client?.address ?? 'No client created'}
onPress={async () => {
console.log('hi there');
console.log('hi there')

const client = await createClient()
console.log(client?.address)
setClient(client)
}}
/>
<Section
key="useCreateGroup"
title="useCreateGroup"
buttonLabel="Create Group"
result={group?.id ?? 'No group created'}
onPress={async () => {
const group = await createGroup()
setGroup(group)
}}
/>
<Section
key="useListMessages"
title="useListMessages"
buttonLabel="List Messages"
result={JSON.stringify(messages)}
onPress={async () => {
const messages = await listMessages()
setMessages(messages)
}}
/>
</>
)}
</ScrollView>
Expand Down

0 comments on commit 8cf211a

Please sign in to comment.