Skip to content

Commit f3ff4db

Browse files
technoplatolourouthierryskoda
authored
Ml/cleanup auth and types and stuff (#1605)
Co-authored-by: Louis Rouffineau <[email protected]> Co-authored-by: Thierry <[email protected]>
1 parent a478810 commit f3ff4db

File tree

136 files changed

+1276
-3606
lines changed

Some content is hidden

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

136 files changed

+1276
-3606
lines changed

.cursorrules

+11-5
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
- Write concise TypeScript code.
66
- Use functional programming patterns.
77
- Prefer clean, readable code over compact code, using empty lines to separate logical blocks and improve readability.
8-
- Use descriptive variable names with auxiliary verbs (e.g., isLoading, hasError). Doesn't mater if it's long. For example this is good: "useGroupMembersInfoForCurrentAccount".
8+
- Use descriptive variable names with auxiliary verbs (e.g., isLoading, hasError). Doesn't mater if it's long. For example this is good: "useGroupMembersInfo".
99
- Prefer clean and easy to read code over compact code.
1010
- Don't create function(s) inside other functions unless it's specified
1111
- Add clear, concise comments to explain non-obvious logic or unconventional implementation decisions.
1212
- When refactoring code, preserve existing comments unless explicitly instructed otherwise or the related code is removed. Comments often explain important context or implementation decisions that should be maintained.
1313
- Comments should be above the code they are describing.
14-
- Use the suffix 'ForCurrentAccount' when using useCurrentAccount inside components or hooks.
1514
- Handle errors at the caller level. Unless if we really need to log something but make sure to throw back the error to the caller.
1615
- Minimize using external hooks inside custom hooks to prevent unnecessary rerenders. Instead, use getter functions to access data, especially in mutations.
1716
- Use Zod for external API response validation. Define zod schema and infer types from it.
@@ -129,13 +128,11 @@ Always import using the @alias as examplified below:
129128
// ✅ Good: Using the @ to simplify imports
130129
import { isConversationGroup } from "@/features/conversation/utils/is-conversation-group";
131130
import { isConversationDm } from "@/features/conversation/utils/is-conversation-dm";
132-
import { getReadableProfile } from "@/utils/getReadableProfile";
133131
import { IConversationMembershipSearchResult } from "@/features/search/search.types";
134132

135133
// ❌ Bad: Using relative paths
136134
import { isConversationGroup } from "../../../features/conversation/utils/is-conversation-group";
137135
import { isConversationDm } from "../../../features/conversation/utils/is-conversation-dm";
138-
import { getReadableProfile } from "../../../../utils/getReadableProfile";
139136
import { IConversationMembershipSearchResult } from "../../../features/search/search.types";
140137

141138
## Theming & Styling
@@ -174,7 +171,16 @@ enabled: !!args.account
174171
- Export query options generators for cross-component usage
175172
- Handle conditional fetching with `enabled` and `skipToken`
176173
- Create an `enabled` variable before returning query options to avoid duplicating logic
177-
-
174+
- Never create a conditional queryKey:
175+
@example
176+
// ❌ conditional queryKey
177+
queryKey: enabled ? queryKeyFactory(args) : ["profile"],
178+
179+
// ✅ Good: Explicit property usage
180+
queryKey: queryKeyFactory(args),
181+
182+
- Always use a ternary checking enabled to return liveQueryFn if enabled is true and skipToken if enabled is false
183+
- queryFn: enabled ? () => liveQueryFn(args) : skipToken,
178184

179185
@example
180186
// queries/use-conversation-messages-query.ts

App.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ import {
4848
// import { useAppStateHandlers } from "./hooks/useAppStateHandlers";
4949
// import { useInstalledWallets } from "@/features/wallets/use-installed-wallets.hook";
5050
import logger from "./utils/logger";
51+
import { AuthenticateWithPasskeyProvider } from "./features/onboarding/contexts/signup-with-passkey.context";
52+
import { PrivyPlaygroundLandingScreen } from "./features/privy-playground/privy-playground-landing.screen";
5153
// import { useAccountsStore } from "./features/multi-inbox/multi-inbox.store";
5254
// import { AuthenticateWithPasskeyProvider } from "./features/onboarding/contexts/signup-with-passkey.context";
5355
// import { PrivyPlaygroundLandingScreen } from "./features/privy-playground/privy-playground-landing.screen";
@@ -203,10 +205,10 @@ export function AppWithProviders() {
203205
<PaperProvider theme={paperTheme}>
204206
<GestureHandlerRootView style={{ flex: 1 }}>
205207
<BottomSheetModalProvider>
206-
<App />
207-
{/* <AuthenticateWithPasskeyProvider>
208+
{/* <App /> */}
209+
<AuthenticateWithPasskeyProvider>
208210
<PrivyPlaygroundLandingScreen />
209-
</AuthenticateWithPasskeyProvider> */}
211+
</AuthenticateWithPasskeyProvider>
210212
{__DEV__ && <DevToolsBubble onCopy={onCopy} />}
211213
<Snackbars />
212214
</BottomSheetModalProvider>

app.config.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ type EnvironmentConfig = {
2727
alchemyApiKey: string;
2828
};
2929

30+
// Type assertion for process.env to include our Expo public variables
31+
const env = process.env as {
32+
EXPO_PUBLIC_ALCHEMY_API_KEY?: string;
33+
EXPO_ENV?: string;
34+
};
35+
3036
const settings: Record<Environment, EnvironmentConfig> = {
3137
development: {
3238
scheme: "converse-dev",
@@ -53,7 +59,7 @@ const settings: Record<Environment, EnvironmentConfig> = {
5359
appDomainGetConverse: "dev.getconverse.app",
5460
appName: "Converse DEV",
5561
icon: "./assets/icon-preview.png",
56-
alchemyApiKey: process.env.EXPO_PUBLIC_ALCHEMY_API_KEY || "",
62+
alchemyApiKey: env.EXPO_PUBLIC_ALCHEMY_API_KEY || "",
5763
},
5864
preview: {
5965
scheme: "converse-preview",
@@ -80,7 +86,7 @@ const settings: Record<Environment, EnvironmentConfig> = {
8086
appDomainGetConverse: "preview.getconverse.app",
8187
appName: "Converse PREVIEW",
8288
icon: "./assets/icon-preview.png",
83-
alchemyApiKey: process.env.EXPO_PUBLIC_ALCHEMY_API_KEY || "",
89+
alchemyApiKey: env.EXPO_PUBLIC_ALCHEMY_API_KEY || "",
8490
},
8591
production: {
8692
scheme: "converse",
@@ -107,14 +113,13 @@ const settings: Record<Environment, EnvironmentConfig> = {
107113
appDomainGetConverse: "getconverse.app",
108114
appName: "Converse",
109115
icon: "./assets/icon.png",
110-
alchemyApiKey: process.env.EXPO_PUBLIC_ALCHEMY_API_KEY || "",
116+
alchemyApiKey: env.EXPO_PUBLIC_ALCHEMY_API_KEY || "",
111117
},
112118
};
113119

114120
// eslint-disable-next-line import/no-default-export
115121
export default (): ExpoConfig => {
116-
// @ts-expect-error note(lustig) env types aren't working for me OOTB
117-
const expoEnv = (process.env.EXPO_ENV || "development") as Environment;
122+
const expoEnv = (env.EXPO_ENV || "development") as Environment;
118123
const config = settings[expoEnv];
119124

120125
return {

components/CurrentAccount.tsx

+6-5
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import { spacing } from "@theme/spacing";
55
import { ViewStyle, StyleSheet } from "react-native";
66

77
import { Avatar } from "./Avatar";
8-
import { usePreferredName } from "@/hooks/usePreferredName";
9-
import { usePreferredAvatarUri } from "@/hooks/usePreferredAvatarUri";
108
import { useSafeCurrentSender } from "@/features/multi-inbox/multi-inbox.store";
9+
import { useInboxAvatar, useInboxName } from "@/features/inbox/inbox.api";
1110

1211
type ICurrentAccountProps = {
1312
style?: ViewStyle;
@@ -19,9 +18,11 @@ const styles = StyleSheet.create({
1918
});
2019

2120
export function CurrentAccount(props: ICurrentAccountProps) {
22-
const account = useSafeCurrentSender().ethereumAddress;
23-
const name = usePreferredName(account);
24-
const avatarUri = usePreferredAvatarUri(account);
21+
const inboxId = useSafeCurrentSender().inboxId;
22+
const { data: name, isLoading } = useInboxName({ inboxId });
23+
const { data: avatarUri, isLoading: isAvatarLoading } = useInboxAvatar({
24+
inboxId,
25+
});
2526

2627
return (
2728
<HStack style={[styles.container, props.style]}>

components/StateHandlers/HydrationStateHandler.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { prefetchConversationMetadataQuery } from "@/queries/conversation-metada
22
import { fetchAllowedConsentConversationsQuery } from "@/queries/conversations-allowed-consent-query";
33
import { captureError } from "@/utils/capture-error";
44
import { useAppStore } from "@data/store/appStore";
5-
import logger from "@utils/logger";
5+
import { logger } from "@utils/logger";
66
import { Conversation } from "@xmtp/react-native-sdk";
77
import { MultiInboxClient } from "@/features/multi-inbox/multi-inbox.client";
88
import { useEffect } from "react";

components/StateHandlers/InitialStateHandler.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useAppStore } from "../../data/store/appStore";
77
import { useSelect } from "../../data/store/storeHelpers";
88
import { getSchemedURLFromUniversalURL } from "../../utils/navigation";
99
import { hideSplashScreen } from "../../utils/splash/splash";
10-
import logger from "@utils/logger";
10+
import { logger } from "@utils/logger";
1111
import { useAuthStatus } from "@/features/authentication/useAuthStatus.hook";
1212

1313
const isDevelopmentClientURL = (url: string) => {

components/StateHandlers/NetworkStateHandler.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import NetInfo from "@react-native-community/netinfo";
2-
import logger from "@utils/logger";
2+
import { logger } from "@utils/logger";
33
import { useEffect, useRef } from "react";
44

55
import { config } from "../../config";

containers/GroupPendingRequestsTable.tsx

-136
This file was deleted.

0 commit comments

Comments
 (0)