Skip to content

Commit 76702c2

Browse files
authored
feat: Clean up XMTP functions + new Prettier configs to match BE + other fixes (#1620) (#1620)
1 parent ee26dfa commit 76702c2

File tree

205 files changed

+3383
-5949
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

205 files changed

+3383
-5949
lines changed

.cursorrules

+130-290
Large diffs are not rendered by default.

.prettierrc

-3
This file was deleted.

.prettierrc.cjs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module.exports = {
2+
arrowParens: "always",
3+
bracketSameLine: false,
4+
bracketSpacing: true,
5+
embeddedLanguageFormatting: "auto",
6+
endOfLine: "lf",
7+
htmlWhitespaceSensitivity: "css",
8+
jsxSingleQuote: false,
9+
printWidth: 80,
10+
proseWrap: "preserve",
11+
quoteProps: "as-needed",
12+
semi: true,
13+
singleAttributePerLine: false,
14+
singleQuote: false,
15+
tabWidth: 2,
16+
trailingComma: "all",
17+
useTabs: false,
18+
plugins: [
19+
"prettier-plugin-packagejson",
20+
"@ianvs/prettier-plugin-sort-imports",
21+
],
22+
importOrder: [
23+
"<BUILTIN_MODULES>",
24+
"<THIRD_PARTY_MODULES>",
25+
"^@(/.*)$",
26+
"^@test(/.*)$",
27+
"^[.]",
28+
],
29+
importOrderTypeScriptVersion: "5.7.3",
30+
};

App.tsx

+11-14
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
import { ActionSheet } from "@/components/action-sheet";
2-
import { DebugProvider } from "@/components/debug-provider";
3-
import { Snackbars } from "@/components/snackbar/snackbars";
4-
import { useHydrateAuth } from "@/features/authentication/use-hydrate-auth";
5-
import { useLogoutOnJwtRefreshError } from "@/features/authentication/use-logout-on-jwt-refresh-error";
6-
import { useInitializeMultiInboxClient } from "@/features/multi-inbox/multi-inbox.client";
7-
import { useSetupStreamingSubscriptions } from "@/features/streams/streams";
8-
import { $globalStyles } from "@/theme/styles";
9-
import { useThemeProvider } from "@/theme/use-app-theme";
101
import { configure as configureCoinbase } from "@coinbase/wallet-mobile-sdk";
112
import { BottomSheetModalProvider } from "@design-system/BottomSheet/BottomSheetModalProvider";
123
import { useReactQueryDevTools } from "@dev-plugins/react-query";
@@ -17,6 +8,14 @@ import { queryClient } from "@queries/queryClient";
178
import { QueryClientProvider } from "@tanstack/react-query";
189
import { useCoinbaseWalletListener } from "@utils/coinbaseWallet";
1910
import * as Clipboard from "expo-clipboard";
11+
import { ActionSheet } from "@/components/action-sheet";
12+
import { DebugProvider } from "@/components/debug-provider";
13+
import { Snackbars } from "@/components/snackbar/snackbars";
14+
import { useHydrateAuth } from "@/features/authentication/use-hydrate-auth";
15+
import { useLogoutOnJwtRefreshError } from "@/features/authentication/use-logout-on-jwt-refresh-error";
16+
import { useSetupStreamingSubscriptions } from "@/features/streams/streams";
17+
import { $globalStyles } from "@/theme/styles";
18+
import { useThemeProvider } from "@/theme/use-app-theme";
2019
import "expo-dev-client";
2120
import React, { useEffect } from "react";
2221
import { Platform } from "react-native";
@@ -25,8 +24,8 @@ import { KeyboardProvider } from "react-native-keyboard-controller";
2524
import { Provider as PaperProvider } from "react-native-paper";
2625
import { DevToolsBubble } from "react-native-react-query-devtools";
2726
import {
28-
ReanimatedLogLevel,
2927
configureReanimatedLogger,
28+
ReanimatedLogLevel,
3029
} from "react-native-reanimated";
3130
import { ThirdwebProvider } from "thirdweb/react";
3231
import { config } from "./config";
@@ -60,7 +59,6 @@ configureCoinbase({
6059
const coinbaseUrl = new URL(`https://${config.websiteDomain}/coinbase`);
6160

6261
export function App() {
63-
useInitializeMultiInboxClient();
6462
useLogoutOnJwtRefreshError();
6563
useMonitorNetworkConnectivity();
6664
useHydrateAuth();
@@ -90,8 +88,7 @@ export function App() {
9088
<QueryClientProvider client={queryClient}>
9189
<PrivyProvider
9290
appId={config.privy.appId}
93-
clientId={config.privy.clientId}
94-
>
91+
clientId={config.privy.clientId}>
9592
<SmartWalletsProvider>
9693
<ThirdwebProvider>
9794
<AppKeyboardProvider>
@@ -104,7 +101,7 @@ export function App() {
104101
{/* <AuthenticateWithPasskeyProvider> */}
105102
<AppNavigator />
106103
{/* </AuthenticateWithPasskeyProvider> */}
107-
{__DEV__ && <DevToolsBubble onCopy={onCopy} />}
104+
{/* {__DEV__ && <DevToolsBubble onCopy={onCopy} />} */}
108105
<ActionSheet />
109106
<Snackbars />
110107
</BottomSheetModalProvider>

ReactotronConfig.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
reactotronReactQuery,
55
} from "reactotron-react-query";
66
import { queryClient } from "./queries/queryClient";
7+
78
const queryClientManager = new QueryClientManager({
89
queryClient,
910
});

app.config.ts

-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ const settings: Record<Environment, EnvironmentConfig> = {
9797
},
9898
};
9999

100-
// eslint-disable-next-line import/no-default-export
101100
export default (): ExpoConfig => {
102101
const expoEnv = (process.env.EXPO_ENV || "development") as Environment;
103102
const config = settings[expoEnv];

components/avatar.tsx

+19-26
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
import { Image } from "expo-image";
2+
import React, { memo, useCallback, useState } from "react";
3+
import { Platform, StyleProp, ViewStyle } from "react-native";
14
import { Center } from "@/design-system/Center";
25
import { Icon } from "@/design-system/Icon/Icon";
36
import { Text } from "@/design-system/Text";
47
import { useAppTheme } from "@/theme/use-app-theme";
58
import { Nullable } from "@/types/general";
69
import { getCapitalizedLettersForAvatar } from "@/utils/get-capitalized-letters-for-avatar";
7-
import { Image } from "expo-image";
8-
import React, { memo, useCallback, useState } from "react";
9-
import { Platform, StyleProp, ViewStyle } from "react-native";
1010

1111
export type IAvatarProps = {
1212
uri: Nullable<string>;
@@ -34,48 +34,41 @@ export const Avatar = memo(function Avatar({
3434
setDidError(false);
3535
}, []);
3636

37-
if (uri && !didError) {
38-
return (
39-
<Center style={style}>
37+
return (
38+
<Center
39+
style={[
40+
{
41+
borderRadius: 9999,
42+
width: avatarSize,
43+
height: avatarSize,
44+
backgroundColor: theme.colors.fill.tertiary,
45+
},
46+
style,
47+
]}
48+
testID="avatar-placeholder">
49+
{uri && !didError ? (
4050
<Image
4151
onLoad={handleImageLoad}
4252
onError={handleImageError}
4353
source={{ uri }}
4454
style={{
55+
position: "absolute",
4556
borderRadius: avatarSize / 2,
4657
width: avatarSize,
4758
height: avatarSize,
4859
}}
4960
cachePolicy="memory-disk"
5061
testID="avatar-image"
5162
/>
52-
</Center>
53-
);
54-
}
55-
56-
return (
57-
<Center
58-
style={[
59-
{
60-
borderRadius: 9999,
61-
width: avatarSize,
62-
height: avatarSize,
63-
backgroundColor: theme.colors.fill.tertiary,
64-
},
65-
style,
66-
]}
67-
testID="avatar-placeholder"
68-
>
69-
{name ? (
63+
) : name ? (
7064
<Text
7165
weight="medium"
7266
style={{
7367
color: theme.colors.global.white, // white looks better for both dark/light themes
7468
fontSize: avatarSize / 2.4, // 2.4 is the ratio in the Figma design
7569
lineHeight: avatarSize / 2.4, // 2.4 is the ratio in the Figma design
7670
paddingTop: avatarSize / 15, // 15 is totally random and padding top shouldn't be needed but otherwise the text is not centered
77-
}}
78-
>
71+
}}>
7972
{firstLetter}
8073
</Text>
8174
) : (

components/debug-provider.tsx

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
import { VStack } from "@/design-system/VStack";
2-
import { useLogout } from "@/features/authentication/use-logout.hook";
3-
import { translate } from "@/i18n";
4-
import { navigate } from "@/navigation/navigation.utils";
5-
import { $globalStyles } from "@/theme/styles";
6-
import { getEnv } from "@/utils/getEnv";
7-
import { getNativeLogFile } from "@/utils/xmtpRN/logs";
81
import * as Sentry from "@sentry/react-native";
92
import {
103
getPreviousSessionLoggingFile,
@@ -17,6 +10,13 @@ import { Image } from "expo-image";
1710
import * as Updates from "expo-updates";
1811
import { useCallback, useEffect, useMemo, useRef } from "react";
1912
import { Alert, Platform } from "react-native";
13+
import { VStack } from "@/design-system/VStack";
14+
import { useLogout } from "@/features/authentication/use-logout.hook";
15+
import { getXmtpNativeLogFile } from "@/features/xmtp/utils/xmtp-logs";
16+
import { translate } from "@/i18n";
17+
import { navigate } from "@/navigation/navigation.utils";
18+
import { $globalStyles } from "@/theme/styles";
19+
import { getEnv } from "@/utils/getEnv";
2020
import { showActionSheet } from "./action-sheet";
2121

2222
export function DebugProvider(props: { children: React.ReactNode }) {
@@ -64,7 +64,7 @@ export function DebugProvider(props: { children: React.ReactNode }) {
6464
await RNFS.unlink(
6565
`file://${RNFS.CachesDirectoryPath}${
6666
RNFS.CachesDirectoryPath.endsWith("/") ? "" : "/"
67-
}mediacache`
67+
}mediacache`,
6868
);
6969
alert("Done!");
7070
},
@@ -95,7 +95,7 @@ export function DebugProvider(props: { children: React.ReactNode }) {
9595
: "",
9696
]
9797
.filter(Boolean)
98-
.join("\n")
98+
.join("\n"),
9999
);
100100
},
101101
"Check for Updates": async () => {
@@ -123,7 +123,7 @@ export function DebugProvider(props: { children: React.ReactNode }) {
123123
}
124124
},
125125
},
126-
]
126+
],
127127
);
128128
} else {
129129
Alert.alert("No Updates", "You are running the latest version");
@@ -144,7 +144,7 @@ export function DebugProvider(props: { children: React.ReactNode }) {
144144
});
145145
},
146146
"Share native logs": async () => {
147-
const nativeLogFilePath = await getNativeLogFile();
147+
const nativeLogFilePath = await getXmtpNativeLogFile();
148148
Share.open({
149149
title: translate("debug.libxmtp_log_session"),
150150
url: `file://${nativeLogFilePath}`,
@@ -167,7 +167,7 @@ export function DebugProvider(props: { children: React.ReactNode }) {
167167
navigate("WebviewPreview", { uri: loggingFilePath });
168168
},
169169
"Display native logs": async () => {
170-
const nativeLogFilePath = await getNativeLogFile();
170+
const nativeLogFilePath = await getXmtpNativeLogFile();
171171
navigate("WebviewPreview", { uri: nativeLogFilePath });
172172
},
173173
"Display previous session logs": async () => {

components/group-avatar.tsx

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1+
import { ConversationTopic, InboxId } from "@xmtp/react-native-sdk";
2+
import React, { memo, useMemo } from "react";
3+
import { StyleProp, TextStyle, ViewStyle } from "react-native";
14
import { Center } from "@/design-system/Center";
25
import { Text } from "@/design-system/Text";
36
import { VStack } from "@/design-system/VStack";
4-
import { useCurrentSenderEthAddress } from "@/features/multi-inbox/multi-inbox.store";
7+
import { useSafeCurrentSender } from "@/features/authentication/multi-inbox.store";
58
import { useProfilesQueries } from "@/features/profiles/profiles.query";
69
import { useGroupMembersQuery } from "@/queries/useGroupMembersQuery";
710
import { useGroupQuery } from "@/queries/useGroupQuery";
811
import { $globalStyles } from "@/theme/styles";
912
import { ThemedStyle, useAppTheme } from "@/theme/use-app-theme";
1013
import { Nullable } from "@/types/general";
11-
import { ConversationTopic, InboxId } from "@xmtp/react-native-sdk";
12-
import React, { memo, useMemo } from "react";
13-
import { StyleProp, TextStyle, ViewStyle } from "react-native";
1414
import { Avatar } from "./avatar";
1515

1616
/**
@@ -34,7 +34,7 @@ export const GroupAvatarInboxIds = memo(function GroupAvatarInboxIds(props: {
3434
uri: profile.avatar,
3535
name: profile.name,
3636
}
37-
: null
37+
: null,
3838
)
3939
.filter(Boolean);
4040
}, [profiles]);
@@ -53,16 +53,16 @@ export const GroupAvatar = memo(function GroupAvatar(props: {
5353

5454
const { theme } = useAppTheme();
5555

56-
const currentAccount = useCurrentSenderEthAddress()!;
56+
const currentSender = useSafeCurrentSender();
5757

5858
const { data: group } = useGroupQuery({
59-
account: currentAccount,
59+
account: currentSender.ethereumAddress,
6060
topic: groupTopic,
6161
});
6262

6363
const { data: members } = useGroupMembersQuery({
6464
caller: "GroupAvatar",
65-
account: currentAccount,
65+
account: currentSender.ethereumAddress,
6666
topic: groupTopic,
6767
});
6868

@@ -71,17 +71,17 @@ export const GroupAvatar = memo(function GroupAvatar(props: {
7171
return [];
7272
}
7373

74-
return members.ids.reduce<string[]>((addresses, memberId) => {
75-
const memberAddress = members.byId[memberId]?.addresses[0];
74+
return members.ids.reduce<InboxId[]>((inboxIds, memberId) => {
75+
const memberInboxId = members.byId[memberId].inboxId;
7676
if (
77-
memberAddress &&
78-
memberAddress.toLowerCase() !== currentAccount?.toLowerCase()
77+
memberInboxId &&
78+
memberInboxId.toLowerCase() !== currentSender?.inboxId?.toLowerCase()
7979
) {
80-
addresses.push(memberAddress);
80+
inboxIds.push(memberInboxId);
8181
}
82-
return addresses;
82+
return inboxIds;
8383
}, []);
84-
}, [members, currentAccount]);
84+
}, [members, currentSender]);
8585

8686
const { data: profiles } = useProfilesQueries({
8787
xmtpInboxIds: memberAddresses,
@@ -97,7 +97,7 @@ export const GroupAvatar = memo(function GroupAvatar(props: {
9797
uri: profile.avatar,
9898
name: profile.name,
9999
}
100-
: null
100+
: null,
101101
)
102102
.filter(Boolean) ?? []
103103
);
@@ -148,7 +148,7 @@ const GroupAvatarUI = memo(function GroupAvatarUI(props: IGroupAvatarUIProps) {
148148

149149
const positions = useMemo(
150150
() => calculatePositions(memberCount, MAIN_CIRCLE_RADIUS),
151-
[memberCount]
151+
[memberCount],
152152
);
153153

154154
return (
@@ -194,7 +194,7 @@ const GroupAvatarUI = memo(function GroupAvatarUI(props: IGroupAvatarUIProps) {
194194

195195
const calculatePositions = (
196196
memberCount: number,
197-
mainCircleRadius: number
197+
mainCircleRadius: number,
198198
): Position[] => {
199199
const positionMaps: { [key: number]: Position[] } = {
200200
0: [],

config/config.types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// import { IXmtpEnv } from "@/utils/xmtpRN/xmtp.types";
22

3-
import type { IXmtpEnv } from "@/utils/xmtpRN/xmtp.types";
3+
import type { IXmtpEnv } from "@/features/xmtp/xmtp.types";
44

55
type IWalletConnectConfig = {
66
projectId: string | undefined;

config/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const EXPO_ENV = process.env.EXPO_ENV;
2828
if (API_URL.includes("localhost")) {
2929
if (EXPO_ENV && EXPO_ENV !== "development") {
3030
throw new Error(
31-
"Using localhost API URL in non-dev environment. Did you forget to pull env vars?"
31+
"Using localhost API URL in non-dev environment. Did you forget to pull env vars?",
3232
);
3333
}
3434
}

config/shared.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-nocheck note(lustig) env types aren't working for me OOTB
22

3-
import { IConfig, ILoggerColorScheme } from "@/config/config.types";
43
import Constants from "expo-constants";
4+
import { IConfig, ILoggerColorScheme } from "@/config/config.types";
55

66
function maybeReplaceLocalhost(uri: string) {
77
try {

0 commit comments

Comments
 (0)