Skip to content

Commit

Permalink
feat: Reactions
Browse files Browse the repository at this point in the history
Added Reaction support for messages

Added persistance handling
Refactored providers
Removed conversation screen
  • Loading branch information
Alex Risch authored and Alex Risch committed May 17, 2024
1 parent ade4757 commit df4d6f1
Show file tree
Hide file tree
Showing 26 changed files with 805 additions and 819 deletions.
81 changes: 4 additions & 77 deletions App.tsx
Original file line number Diff line number Diff line change
@@ -1,87 +1,14 @@
import './src/polyfills';

import {QueryClient, QueryClientProvider} from '@tanstack/react-query';
import {Ethereum} from '@thirdweb-dev/chains';
import {
ThirdwebProvider,
localWallet,
metamaskWallet,
walletConnect,
} from '@thirdweb-dev/react-native';
import {NativeBaseProvider, extendTheme} from 'native-base';
import React from 'react';
import Config from 'react-native-config';
import {mainnet} from 'viem/chains';
import {WagmiConfig, configureChains, createConfig} from 'wagmi';
import {publicProvider} from 'wagmi/providers/public';
import {ClientProvider} from './src/context/ClientContext';
import {AppNavigation} from './src/navigation/AppNavigation';
import {colors} from './src/theme/colors';

const {publicClient, webSocketPublicClient} = configureChains(
[mainnet],
[publicProvider()],
);

const config = createConfig({
autoConnect: true,
publicClient,
webSocketPublicClient,
});

const queryClient = new QueryClient();
import {Providers} from './src/providers';

function App(): React.JSX.Element {
const newColorTheme = {
primary: {
900: colors.actionPrimary,
800: colors.actionPrimary,
700: colors.actionPrimary,
600: colors.actionPrimary,
500: colors.actionPrimary,
400: colors.actionPrimary,
300: colors.actionPrimary,
},
brand: {
900: colors.actionPrimary,
800: colors.actionPrimary,
700: colors.actionPrimary,
600: colors.actionPrimary,
500: colors.actionPrimary,
400: colors.actionPrimary,
300: colors.actionPrimary,
},
};
const theme = extendTheme({colors: newColorTheme});
return (
<WagmiConfig config={config}>
<ThirdwebProvider
activeChain={Ethereum}
autoConnect={true}
clientId={Config.THRID_WEB_CLIENT_ID}
dAppMeta={{
name: 'XMTP Example',
description:
'This basic messaging app has an intentionally unopinionated UI to help make it easier for you to build with.',
logoUrl:
'https://pbs.twimg.com/profile_images/1668323456935510016/2c_Ue8dF_400x400.jpg',
url: 'https://xmtp.org',
}}
supportedWallets={[
localWallet(),
metamaskWallet(),
// coinbaseWallet(),
walletConnect({recommended: true}),
]}>
<NativeBaseProvider theme={theme}>
<QueryClientProvider client={queryClient}>
<ClientProvider>
<AppNavigation />
</ClientProvider>
</QueryClientProvider>
</NativeBaseProvider>
</ThirdwebProvider>
</WagmiConfig>
<Providers>
<AppNavigation />
</Providers>
);
}

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
"@react-native-community/netinfo": "^11.2.1",
"@react-navigation/native": "^6.1.9",
"@react-navigation/native-stack": "^6.9.17",
"@tanstack/react-query": "^5.17.19",
"@tanstack/query-sync-storage-persister": "^5.36.1",
"@tanstack/react-query": "^5.36.2",
"@tanstack/react-query-persist-client": "^5.36.2",
"@thirdweb-dev/react-native": "^0.5.4",
"@thirdweb-dev/react-native-compat": "^0.5.4",
"@xmtp/frames-client": "^0.5.1",
Expand Down
210 changes: 0 additions & 210 deletions src/components/ConversationMessageContent.tsx

This file was deleted.

62 changes: 62 additions & 0 deletions src/components/Message.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import {DecodedMessage} from '@xmtp/react-native-sdk';
import {Box, VStack} from 'native-base';
import React, {FC} from 'react';
import {Pressable} from 'react-native';
import {ContentTypes, SupportedContentTypes} from '../consts/ContentTypes';
import {MessageIdReactionsMapping} from '../queries/useGroupMessagesQuery';
import {mmkvStorage} from '../services/mmkvStorage';
import {colors} from '../theme/colors';
import {formatAddress} from '../utils/formatAddress';
import {getMessageTimeDisplay} from '../utils/getMessageTimeDisplay';
import {Text} from './common/Text';
import {ConversationMessageContent} from './messageContent/ConversationMessageContent';

export interface MessageProps {
message: DecodedMessage<SupportedContentTypes>;
isMe: boolean;
reactions: MessageIdReactionsMapping[string];
}

export const Message: FC<MessageProps> = ({message, isMe, reactions}) => {
if (message.contentTypeId === ContentTypes.Reaction) {
return null;
}
return (
<Pressable>
<Box marginLeft={6} marginRight={6} marginY={2} flexShrink={1}>
<VStack>
{!isMe && (
<VStack justifyItems={'flex-end'}>
<Text
color={colors.primaryN200}
textAlign={'end'}
typography="text-xs/semi-bold"
alignSelf={'flex-start'}>
{mmkvStorage.getEnsName(message.senderAddress) ??
formatAddress(message.senderAddress)}
</Text>
</VStack>
)}
<ConversationMessageContent
message={message}
isMe={isMe}
reactions={reactions}
/>
<Text
flexShrink={1}
color={colors.primaryN200}
typography="text-xs/semi-bold"
alignSelf={
message.contentTypeId === ContentTypes.GroupMembershipChange
? 'center'
: isMe
? 'flex-end'
: 'flex-start'
}>
{getMessageTimeDisplay(message.sent)}
</Text>
</VStack>
</Box>
</Pressable>
);
};
Loading

0 comments on commit df4d6f1

Please sign in to comment.