Skip to content
This repository was archived by the owner on Jul 11, 2025. It is now read-only.

Account => Inbox ID Gigantic Refactor #1488

Closed
wants to merge 14 commits into from
Closed
48 changes: 24 additions & 24 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { ActionSheetProvider } from "@expo/react-native-action-sheet";
import { PortalProvider } from "@gorhom/portal";
import { useAppStateHandlers } from "@hooks/useAppStateHandlers";
import { PrivyProvider } from "@privy-io/expo";
// import { PrivyProvider } from "@privy-io/expo";
import { queryClient } from "@queries/queryClient";
import { MaterialDarkTheme, MaterialLightTheme } from "@styles/colors";
import { QueryClientProvider } from "@tanstack/react-query";
Expand Down Expand Up @@ -38,7 +38,7 @@
import { setAuthStatus } from "./data/store/authStore";
import Main from "./screens/Main";
import { registerBackgroundFetchTask } from "./utils/background";
import { privySecureStorage } from "./utils/keychain/helpers";
// import { privySecureStorage } from "./utils/keychain/helpers";
import { initSentry } from "./utils/sentry";
import "./utils/splash/splash";
import "./features/notifications/utils";
Expand Down Expand Up @@ -77,10 +77,10 @@
}, []);

const showDebugMenu = useCallback(() => {
if (!debugRef.current || !(debugRef.current as any).showDebugMenu) {

Check warning on line 80 in App.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
return;
}
(debugRef.current as any).showDebugMenu();

Check warning on line 83 in App.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
}, []);

useEffect(() => {
Expand All @@ -92,8 +92,8 @@

// For now we use persit with zustand to get the accounts when the app launch so here is okay to see if we're logged in or not
useEffect(() => {
const currentAccount = useAccountsStore.getState().currentAccount;
if (currentAccount && currentAccount !== TEMPORARY_ACCOUNT_NAME) {
const currentInboxId = useAccountsStore.getState().currentInboxId;
if (currentInboxId && currentInboxId !== TEMPORARY_ACCOUNT_NAME) {
setAuthStatus("signedIn");
} else {
setAuthStatus("signedOut");
Expand Down Expand Up @@ -124,7 +124,7 @@
const AppKeyboardProvider =
Platform.OS === "ios" ? KeyboardProvider : React.Fragment;

export default function AppWithProviders() {

Check warning on line 127 in App.tsx

View workflow job for this annotation

GitHub Actions / lint

Prefer named exports
const colorScheme = useColorScheme();

const paperTheme = useMemo(() => {
Expand All @@ -136,26 +136,26 @@

return (
<QueryClientProvider client={queryClient}>
<PrivyProvider appId={config.privy.appId} storage={privySecureStorage}>
<ThirdwebProvider>
<AppKeyboardProvider>
<ActionSheetProvider>
<ThemeProvider value={{ themeScheme, setThemeContextOverride }}>
<PaperProvider theme={paperTheme}>
<GestureHandlerRootView style={{ flex: 1 }}>
<BottomSheetModalProvider>
<PortalProvider>
<App />
<Snackbars />
</PortalProvider>
</BottomSheetModalProvider>
</GestureHandlerRootView>
</PaperProvider>
</ThemeProvider>
</ActionSheetProvider>
</AppKeyboardProvider>
</ThirdwebProvider>
</PrivyProvider>
{/* <PrivyProvider appId={config.privy.appId} storage={privySecureStorage}> */}
<ThirdwebProvider>
<AppKeyboardProvider>
<ActionSheetProvider>
<ThemeProvider value={{ themeScheme, setThemeContextOverride }}>
<PaperProvider theme={paperTheme}>
<GestureHandlerRootView style={{ flex: 1 }}>

Check warning on line 145 in App.tsx

View workflow job for this annotation

GitHub Actions / lint

Inline style: { flex: 1 }
<BottomSheetModalProvider>
<PortalProvider>
<App />
<Snackbars />
</PortalProvider>
</BottomSheetModalProvider>
</GestureHandlerRootView>
</PaperProvider>
</ThemeProvider>
</ActionSheetProvider>
</AppKeyboardProvider>
</ThirdwebProvider>
{/* </PrivyProvider> */}
</QueryClientProvider>
);
}
Expand Down
31 changes: 16 additions & 15 deletions components/AccountSettingsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@
import { TableViewPicto } from "./TableView/TableViewImage";
import { NotificationPermissionStatus } from "../features/notifications/types/Notifications.types";
import { invalidateProfileSocialsQuery } from "@/queries/useProfileSocialsQuery";
import { invalidateInboxProfileSocialsQuery } from "@/queries/useInboxProfileSocialsQuery";

type Props = {
account: string;
inboxId: string;
};

export default function AccountSettingsButton({ account }: Props) {
export default function AccountSettingsButton({ inboxId }: Props) {

Check warning on line 39 in components/AccountSettingsButton.tsx

View workflow job for this annotation

GitHub Actions / lint

Prefer named exports
const router = useRouter();

const {
Expand All @@ -52,29 +51,31 @@
])
);

const { setCurrentAccount } = useAccountsStore(
useSelect(["setCurrentAccount"])
const { setCurrentInboxId } = useAccountsStore(
useSelect(["setCurrentInboxId"])
);
const erroredAccountsMap = useErroredAccountsMap();

const colorScheme = useColorScheme();
const showDisconnectActionSheet = useDisconnectActionSheet(account);
const showDisconnectActionSheet = useDisconnectActionSheet({ inboxId });

const onPress = useCallback(() => {
Keyboard.dismiss();

const methods = {
[translate("your_profile_page")]: async () => {
if (account) {
invalidateProfileSocialsQuery(account, account);
setCurrentAccount(account, false);
if (inboxId) {
invalidateProfileSocialsQuery({ profileLookupInboxId: inboxId });
setCurrentInboxId({ inboxId, createIfNew: false });
// setCurrentAccount(inboxId, false);
router.navigate("Chats");
navigate("Profile", {
address: account,
inboxId,
});
}
},
[translate("copy_wallet_address")]: () => {
Clipboard.setString(account || "");
Clipboard.setString(inboxId || "");
},
[translate("turn_on_notifications")]: () => {
// @todo => move that to a helper because also used in Profile
Expand Down Expand Up @@ -110,7 +111,7 @@

const options = Object.keys(methods);
const icons = [];
if (erroredAccountsMap[account] && isInternetReachable) {
if (erroredAccountsMap[inboxId] && isInternetReachable) {
icons.push(
<Picto
style={{
Expand All @@ -135,7 +136,7 @@
translate("disconnect_this_account")
),
cancelButtonIndex: options.indexOf(translate("cancel")),
title: account || undefined,
title: inboxId || undefined,
...actionSheetColors(colorScheme),
},
(selectedIndex?: number) => {
Expand All @@ -149,11 +150,11 @@
}, [
router,
erroredAccountsMap,
account,
inboxId,
isInternetReachable,
notificationsPermissionStatus,
colorScheme,
setCurrentAccount,
setCurrentInboxId,
setNotificationsPermissionStatus,
showDisconnectActionSheet,
]);
Expand Down
2 changes: 1 addition & 1 deletion components/Chat/Frame/FramePreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
// try {
// // const participantAccountAddresses: string[] = conversation.isGroup
// // ? conversation.groupMembers || []
// // : [account, conversation.peerAddress];
// // : [account, conversation.peerEthereumAddress];
// // TODO: Frames when supported by V3
// const actionInput: FrameActionInputs = {
// frameUrl: actionPostUrl,
Expand Down
2 changes: 1 addition & 1 deletion components/Chat/Transaction/TransactionPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
// // const colorScheme = useColorScheme();
// // const styles = useStyles();
// // const { transaction, transactionDisplay, amountToDisplay } =
// // useTransactionForMessage(message, conversation?.peerAddress);
// // useTransactionForMessage(message, conversation?.peerEthereumAddress);

// // const showTransactionActionSheet = useCallback(() => {
// // const methods: { [key: string]: () => void } = {};
Expand Down
9 changes: 6 additions & 3 deletions components/ClickableText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ export function ClickableText({ children, style }: Props) {
Linking.openURL(uri);
}, []);

const handleNewConversationPress = useCallback((peer: string) => {
navigate("NewConversation", { peer });
}, []);
const handleNewConversationPress = useCallback(
(peerEthereumAddress: string) => {
navigate("NewConversation", { peerEthereumAddress });
},
[]
);

const showCopyActionSheet = useCallback(
(cta: string) => (content: string) => {
Expand Down
2 changes: 1 addition & 1 deletion components/Connecting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const useShouldShowConnecting = () => {
};

export const useShouldShowConnectingOrSyncing = () => {
const currentAccount = useCurrentAccount();
const currentInboxId = useCurrentInboxId()();
const { isLoading } = useConversationListQuery({ account: currentAccount! });
const initialLoadDoneOnce = !isLoading;
const shouldShowConnecting = useShouldShowConnecting();
Expand Down
16 changes: 5 additions & 11 deletions components/ConversationList/ChatNullState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,16 @@ import { usePreferredName } from "@/hooks/usePreferredName";
import { usePreferredAvatarUri } from "@/hooks/usePreferredAvatarUri";

type ChatNullStateProps = {
currentAccount: string;
navigation: any;
route: any;
currentInboxId: string;
};

const ChatNullState: React.FC<ChatNullStateProps> = ({
currentAccount,
navigation,
route,
}) => {
const ChatNullState: React.FC<ChatNullStateProps> = ({ currentInboxId }) => {
const colorScheme = useColorScheme();
const styles = useStyles();

const username = usePreferredUsername(currentAccount);
const displayName = usePreferredName(currentAccount);
const avatar = usePreferredAvatarUri(currentAccount);
const username = usePreferredUsername({ peerInboxId: currentInboxId });
const displayName = usePreferredName(currentInboxId);
const avatar = usePreferredAvatarUri(currentInboxId);

const profileUrl = `https://${config.websiteDomain}/dm/${
username || currentAccount
Expand Down
12 changes: 6 additions & 6 deletions components/ConversationList/ProfileSettingsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ import { AvatarSizes } from "@styles/sizes";
import React, { useCallback } from "react";
import { Platform, TouchableOpacity } from "react-native";

import { currentAccount } from "@data/store/accountsStore";
import { navigate } from "@utils/navigation";
import Avatar from "../Avatar";
import { usePreferredName } from "@/hooks/usePreferredName";
import { usePreferredAvatarUri } from "@/hooks/usePreferredAvatarUri";
import { useCurrentInboxId } from "@data/store/accountsStore";

export default function ProfileSettingsButton() {
const account = currentAccount();
const inboxId = useCurrentInboxId();

const displayName = usePreferredName(account);
const avatarUri = usePreferredAvatarUri(account);
const displayName = usePreferredName({ inboxId: inboxId! });
const avatarUri = usePreferredAvatarUri({ inboxId: inboxId! });

const openProfile = useCallback(() => {
navigate("Profile", { address: currentAccount() });
}, []);
navigate("Profile", { inboxId: inboxId! });
}, [inboxId]);

return (
<TouchableOpacity activeOpacity={0.2} onPress={openProfile}>
Expand Down
2 changes: 1 addition & 1 deletion components/CurrentAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const styles = StyleSheet.create({
});

export function CurrentAccount(props: ICurrentAccountProps) {
const account = currentAccount();
const inboxId = getCurrentInboxId();
const name = usePreferredName(account);
const avatarUri = usePreferredAvatarUri(account);

Expand Down
26 changes: 3 additions & 23 deletions components/DebugButton.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import Clipboard from "@react-native-clipboard/clipboard";
import * as Sentry from "@sentry/react-native";
import {
getDbEncryptionKey,
getDbEncryptionSalt,
} from "@utils/keychain/helpers";
import {
getPreviousSessionLoggingFile,
loggingFilePath,
Expand All @@ -21,22 +16,12 @@ import { Platform, Alert } from "react-native";

import config from "../config";
import { showActionSheetWithOptions } from "./StateHandlers/ActionSheetStateHandler";
import { useAccountsList } from "../data/store/accountsStore";
import mmkv from "../utils/mmkv";
import { translate } from "@/i18n";
import { isDev } from "@/utils/getEnv";

export const useDebugEnabled = (address?: string) => {
const accounts = useAccountsList();
if (address && debugEnabled(address)) {
return true;
}
for (const account of accounts) {
if (debugEnabled(account)) {
return true;
}
}

return false;
export const useDebugEnabled = () => {
return isDev;
};

export const debugEnabled = (address?: string) => {
Expand All @@ -46,11 +31,6 @@ export const debugEnabled = (address?: string) => {
);
};

export async function delayToPropogate(): Promise<void> {
// delay 1s to avoid clobbering
return new Promise((r) => setTimeout(r, 100));
}

const DebugButton = forwardRef((props, ref) => {
const appVersion = Constants.expoConfig?.version;
const debugEnabled = useDebugEnabled();
Expand Down
25 changes: 16 additions & 9 deletions components/GroupAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import {
} from "react-native";

import Avatar from "./Avatar";
import { useCurrentAccount } from "../data/store/accountsStore";
import { useGroupMembers } from "../hooks/useGroupMembers";
import {
getPreferredInboxAvatar,
getPreferredInboxName,
} from "../utils/profile";
import { ConversationTopic } from "@xmtp/react-native-sdk";
import { useGroupMembersSocials } from "@/hooks/useGroupMembersSocials";
import { isCurrentUser } from "@/features/shared/utils/user";

const MAIN_CIRCLE_RADIUS = 50;
const MAX_VISIBLE_MEMBERS = 4;
Expand Down Expand Up @@ -191,22 +191,29 @@ const GroupAvatar: React.FC<GroupAvatarProps> = ({
}) => {
const colorScheme = useColorScheme();
const styles = getStyles(colorScheme);
const { members: groupMembers } = useGroupMembers(topic!);
const { members: groupMembers } = useGroupMembers({ topic: topic! });
const socialsData = useGroupMembersSocials(groupMembers);
const account = useCurrentAccount();

const memoizedAndSortedGroupMembers = useMemo(() => {
if (!groupMembers) return [];
const members = groupMembers.ids.reduce(
(acc: { address: string; uri?: string; name?: string }[], id) => {
(
acc: {
inboxId: string;
address: string;
uri?: string;
name?: string;
}[],
id
) => {
const member = groupMembers.byId[id];
const address = member.addresses[0].toLowerCase();
const groupMemberInboxId = member.inboxId;
const senderSocials = socialsData[id];
const shouldExclude =
excludeSelf && account && address === account.toLowerCase();
const shouldExclude = excludeSelf && isCurrentUser(groupMemberInboxId);
if (shouldExclude) return acc;
const newMember = {
address,
inboxId: groupMemberInboxId,
address: member.addresses[0],
uri: getPreferredInboxAvatar(senderSocials),
name: getPreferredInboxName(senderSocials),
};
Expand All @@ -217,7 +224,7 @@ const GroupAvatar: React.FC<GroupAvatarProps> = ({
);
// Sort the members so that members with avatars are positioned first
return members.sort((a, b) => (a.uri ? -1 : 1));
}, [groupMembers, socialsData, excludeSelf, account]);
}, [groupMembers, socialsData, excludeSelf]);

const membersToDisplay = pendingGroupMembers || memoizedAndSortedGroupMembers;
const memberCount = membersToDisplay.length;
Expand Down
Loading
Loading