Skip to content

Commit

Permalink
feat: add depdency management strategy (#1283)
Browse files Browse the repository at this point in the history
  • Loading branch information
technoplato authored Dec 3, 2024
1 parent 87e0c8a commit e4c7178
Show file tree
Hide file tree
Showing 54 changed files with 1,794 additions and 106 deletions.
4 changes: 2 additions & 2 deletions assets/Encrypted.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from "react";
import Svg, { Path } from "react-native-svg";

interface EncryptedProps {
type EncryptedProps = {
width?: number;
height?: number;
color?: string;
}
};

const Encrypted: React.FC<EncryptedProps> = ({
width = 40,
Expand Down
8 changes: 4 additions & 4 deletions components/Banner/AnimatedBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import Reanimated, {

import Banner from "./Banner";

interface AnimatedBannerProps {
type AnimatedBannerProps = {
title: string;
description: string;
cta?: string;
onButtonPress?: () => void;
onDismiss?: () => void;
style?: StyleProp<ViewStyle>;
}
};

const VERTICAL_MARGIN = Margins.default;

Expand Down Expand Up @@ -66,8 +66,8 @@ const AnimatedBanner: React.FC<AnimatedBannerProps> = React.memo((props) => {
height: isAnimating
? height.value
: measuredHeight.current !== null
? height.value
: "auto",
? height.value
: "auto",
overflow: "hidden",
}));

Expand Down
4 changes: 2 additions & 2 deletions components/Banner/Banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
Platform,
} from "react-native";

interface BannerProps {
type BannerProps = {
title: string;
description: string;
cta?: string;
Expand All @@ -29,7 +29,7 @@ interface BannerProps {
onDismiss: () => void;
style?: StyleProp<ViewStyle>;
onLayout?: (event: LayoutChangeEvent) => void;
}
};

const Banner: React.FC<BannerProps> = ({
title,
Expand Down
14 changes: 7 additions & 7 deletions components/Chat/ChatNullState.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import Recommendations from "@components/Recommendations/Recommendations";
import { useSettingsStore } from "@data/store/accountsStore";
import {
useSettingsStore,
useProfilesStore,
useRecommendationsStore,
} from "@data/store/accountsStore";
import { translate } from "@i18n/index";
import {
backgroundColor,
Expand All @@ -14,10 +18,6 @@ import React from "react";
import { Platform, StyleSheet, Text, useColorScheme, View } from "react-native";

import config from "../../config";
import {
useProfilesStore,
useRecommendationsStore,
} from "../../data/store/accountsStore";
import { ShareProfileContent } from "../../screens/ShareProfile";
import {
getPreferredAvatar,
Expand All @@ -27,11 +27,11 @@ import {
} from "../../utils/profile";
import NewConversationButton from "../ConversationList/NewConversationButton";

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

const ChatNullState: React.FC<ChatNullStateProps> = ({
currentAccount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ const initialMessageReactionsState: RolledUpReactions = {
detailed: [],
};

export interface IMessageReactionsStore {
export type IMessageReactionsStore = {
rolledUpReactions: RolledUpReactions;
setRolledUpReactions: (reactions: RolledUpReactions) => void;

// TODO: update state when new reactions come up and drawer is open
// updateReactions: (updates: Partial<RolledUpReactions>) => void;
}
};

export const useMessageReactionsStore = create<IMessageReactionsStore>(
(set) => ({
Expand Down
8 changes: 4 additions & 4 deletions components/Chat/Message/MessageTail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ class MessageTailComponent extends React.Component<SvgProps> {
const MessageTailAnimated =
Reanimated.createAnimatedComponent(MessageTailComponent);

interface MessageTailProps {
type MessageTailProps = {
fromMe: boolean;
colorScheme: ColorSchemeName;
hideBackground: boolean;
style?: StyleProp<AnimatedStyle<StyleProp<ViewStyle>>>;
}
};

const MessageTail: React.FC<MessageTailProps> = ({
fromMe,
Expand All @@ -40,8 +40,8 @@ const MessageTail: React.FC<MessageTailProps> = ({
hideBackground
? "transparent"
: fromMe
? myMessageBubbleColor(colorScheme)
: messageBubbleColor(colorScheme)
? myMessageBubbleColor(colorScheme)
: messageBubbleColor(colorScheme)
}
/>
);
Expand Down
2 changes: 2 additions & 0 deletions components/ConversationList/NewConversationButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import Picto from "../Picto/Picto";

export default function NewConversationButton() {
const colorScheme = useColorScheme();

const onPress = useCallback(() => {
navigate("NewConversation");
}, []);

const showDebug = useCallback(() => {
converseEventEmitter.emit("showDebugMenu");
}, []);
Expand Down
4 changes: 2 additions & 2 deletions components/ConversationList/RequestsSegmentedController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import {
useColorScheme,
} from "react-native";

interface SegmentedControllerProps {
type SegmentedControllerProps = {
options: string[];
selectedIndex: number;
onSelect: (index: number) => void;
}
};

const RequestsSegmentedController: React.FC<SegmentedControllerProps> = ({
options,
Expand Down
8 changes: 4 additions & 4 deletions components/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,27 @@ const DRAWER_ANIMATION_DURATION = 300;
const DRAWER_THRESHOLD = 100;
const TRANSLATION = 1000;

export interface DrawerProps {
export type DrawerProps = {
visible: boolean;
children: React.ReactNode;
onClose?: () => void;
style?: ViewStyle;
showHandle?: boolean;
}
};

export const DrawerContext = React.createContext<{
closeDrawer: () => void;
}>({
closeDrawer: () => {},
});

export interface DrawerRef {
export type DrawerRef = {
/**
* Will tell the drawer to close, but still needs
* @returns
*/
closeDrawer: (callback: () => void) => void;
}
};

export const Drawer = forwardRef<DrawerRef, DrawerProps>(function Drawer(
{ children, visible, onClose, style, showHandle },
Expand Down
4 changes: 2 additions & 2 deletions components/EmojiPicker/EmojiRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { CategorizedEmojisRecord, Emoji } from "@utils/emojis/interfaces";
import { FC, memo, useMemo } from "react";
import { Platform, Pressable, StyleSheet, Text, View } from "react-native";

interface EmojiRowProps {
type EmojiRowProps = {
item: CategorizedEmojisRecord;
onPress: (emoji: string) => void;
}
};

export const EmojiRow: FC<EmojiRowProps> = memo(({ item, onPress }) => {
const items = useMemo(() => {
Expand Down
4 changes: 2 additions & 2 deletions components/ErroredHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { StyleSheet, useColorScheme, View, ViewStyle } from "react-native";

import Picto from "./Picto/Picto";

interface ErroredHeaderProps {
type ErroredHeaderProps = {
style?: ViewStyle;
}
};

export const ErroredHeader: FC<ErroredHeaderProps> = ({ style }) => {
const colorScheme = useColorScheme();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function useConnectViaWalletDisconnect() {

logger.debug("[Connect Wallet] Disconnected");
},
// eslint-disable-next-line react-hooks/exhaustive-deps

[thirdwebWallet]
);
}
16 changes: 8 additions & 8 deletions components/Screen/ScreenComp/Screen.props.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ScrollViewProps, StyleProp, ViewStyle } from "react-native";

import { ExtendedEdge } from "./Screen.helpers";

interface BaseScreenProps {
type BaseScreenProps = {
/**
* Children components.
*/
Expand Down Expand Up @@ -40,13 +40,13 @@ interface BaseScreenProps {
* By how much should we offset the keyboard? Defaults to 0.
*/
keyboardOffset?: number;
}
};

export interface FixedScreenProps extends BaseScreenProps {
export type FixedScreenProps = {
preset?: "fixed";
}
} & BaseScreenProps;

export interface ScrollScreenProps extends BaseScreenProps {
export type ScrollScreenProps = {
preset?: "scroll";
/**
* Should keyboard persist on screen tap. Defaults to handled.
Expand All @@ -57,16 +57,16 @@ export interface ScrollScreenProps extends BaseScreenProps {
* Pass any additional props directly to the ScrollView component.
*/
ScrollViewProps?: ScrollViewProps;
}
} & BaseScreenProps;

export interface AutoScreenProps extends Omit<ScrollScreenProps, "preset"> {
export type AutoScreenProps = {
preset?: "auto";
/**
* Threshold to trigger the automatic disabling/enabling of scroll ability.
* Defaults to `{ percent: 0.92 }`.
*/
scrollEnabledToggleThreshold?: { percent?: number; point?: number };
}
} & Omit<ScrollScreenProps, "preset">;

export type IScreenProps =
| ScrollScreenProps
Expand Down
4 changes: 2 additions & 2 deletions components/Snackbar/Snackbar.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { ISnackbar } from "@components/Snackbar/Snackbar.types";
import { create } from "zustand";
import { subscribeWithSelector } from "zustand/middleware";

export interface ISnackBarStore {
export type ISnackBarStore = {
snackbars: ISnackbar[];
showSnackbar: (snackbar: ISnackbar) => void;
clearAllSnackbars: () => void;
}
};

export const useSnackBarStore = create<ISnackBarStore>()(
subscribeWithSelector((set) => ({
Expand Down
2 changes: 1 addition & 1 deletion components/Snackbar/Snackbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
SNACKBAR_BOTTOM_OFFSET,
SNACKBAR_HEIGHT,
SNACKBAR_LARGE_TEXT_HEIGHT,
SNACKBAR_SPACE_BETWEEN_SNACKBARS,
} from "@components/Snackbar/Snackbar.constants";
import {
getNumberOfSnackbars,
Expand All @@ -28,7 +29,6 @@ import {
withSpring,
withTiming,
} from "react-native-reanimated";
import { SNACKBAR_SPACE_BETWEEN_SNACKBARS } from "./Snackbar.constants";

type SnackbarProps = {
snackbar: ISnackbar;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const SimulationResult = ({
}: SimulationResultProps) => {
const profiles = useProfilesStore((s) => s.profiles);
const accountAddress = useCurrentAccount() as string;

const myChanges = useMemo(() => {
const myAddresses = [accountAddress.toLowerCase()];
if (walletAddress) {
Expand Down
39 changes: 36 additions & 3 deletions data/store/accountsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ import {
initRecommendationsStore,
RecommendationsStoreType,
} from "./recommendationsStore";
import { initSettingsStore, SettingsStoreType } from "./settingsStore";
import {
GroupStatus,
initSettingsStore,
SettingsStoreType,
} from "./settingsStore";
import {
initTransactionsStore,
TransactionsStoreType,
} from "./transactionsStore";
import { initWalletStore, WalletStoreType } from "./walletStore";
import { removeLogoutTask } from "../../utils/logout";
import { removeLogoutTask } from "@utils/logout";
import mmkv, { zustandMMKVStorage } from "../../utils/mmkv";

type AccountStoreType = {
Expand Down Expand Up @@ -230,8 +234,37 @@ const getAccountStore = (account: string) => {
}
};

export const currentAccount = () => useAccountsStore.getState().currentAccount;
export const currentAccount = (): string =>
(useAccountsStore.getState() as AccountsStoreStype).currentAccount;

//
/**
* TODO: determine if this is the way we want to transition to imperatively
* calling our Zustand store.
* TODO: move this to a different file
*
* It isn't very ergonomic and mocking things seems a little difficult.
*
* We might want to look into creating a subscription to our stores and a
* behavior subject by which to observe it across the app.
*
* Set the group status for the current account
* @param groupStatus The group status to set
*/
export const setGroupStatus = (groupStatus: GroupStatus) => {
const account = currentAccount();
if (!account) {
logger.warn("[setGroupStatus] No current account");
return;
}
const setGroupStatus = getSettingsStore(account).getState().setGroupStatus;
setGroupStatus(groupStatus);
};

// we'll be able to create a subscription to our stores and a behavior subject
// by which to observe it across the app
// We'll seed the behaviorsubject with the getState.value api
// export const _currentAccount = () => useAccountsStore.subscribe((s) => s.);
export const useCurrentAccount = () => {
const currentAccount = useAccountsStore((s) => s.currentAccount);
return currentAccount === TEMPORARY_ACCOUNT_NAME ? undefined : currentAccount;
Expand Down
4 changes: 2 additions & 2 deletions data/store/authStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { subscribeWithSelector } from "zustand/middleware";

export type IAuthStatus = "idle" | "signedOut" | "signedIn";

export interface IAuthStore {
export type IAuthStore = {
status: IAuthStatus;
}
};

export const useAuthStore = create<IAuthStore>()(
subscribeWithSelector((set, get) => ({
Expand Down
4 changes: 1 addition & 3 deletions data/store/settingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ export type SettingsStoreType = {
}) => void;

groupStatus: GroupStatus;
setGroupStatus: (groupStatus: {
[groupId: string]: "allowed" | "denied";
}) => void;
setGroupStatus: (groupStatus: GroupStatus) => void;

ephemeralAccount: boolean;
setEphemeralAccount: (ephemeral: boolean) => void;
Expand Down
Loading

0 comments on commit e4c7178

Please sign in to comment.