Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(web3Hub): add recently used #8050

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You want to revert this change, the simplest way is usually to do a git checkout develop apps/ledger-live-mobile/ios/ledgerlivemobile.xcodeproj/project.pbxproj

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also it happens if we have xcode 16 installed I think and you can use https://github.com/XcodesOrg/xcodes to download any version like the 15.4 we currently use for develop and on CI (actually it's 15.3 I think)

Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
6D891D99F1084D459DBF667F /* FontAwesome5_Pro_Light.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = FontAwesome5_Pro_Light.ttf; path = ../assets/fonts/FontAwesome5_Pro_Light.ttf; sourceTree = "<group>"; };
793F2C3B8DC0475194262928 /* libRCTCamera.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libRCTCamera.a; sourceTree = "<group>"; };
9390D938BCB148F2A34703E3 /* AntDesign.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = AntDesign.ttf; path = "../node_modules/react-native-vector-icons/Fonts/AntDesign.ttf"; sourceTree = "<group>"; };
95143067A27F016C93751872 /* Pods-ledgerlivemobile.nightly.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ledgerlivemobile.nightly.xcconfig"; path = "Target Support Files/Pods-ledgerlivemobile/Pods-ledgerlivemobile.nightly.xcconfig"; sourceTree = "<group>"; };
991AA9919E4840DBB799E117 /* FontAwesome5_Pro_Solid.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = FontAwesome5_Pro_Solid.ttf; path = ../assets/fonts/FontAwesome5_Pro_Solid.ttf; sourceTree = "<group>"; };
99A82013C77445B4B2B54AB5 /* EvilIcons.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = EvilIcons.ttf; path = "../node_modules/react-native-vector-icons/Fonts/EvilIcons.ttf"; sourceTree = "<group>"; };
A80B735599C416373F147DED /* Pods-ledgerlivemobile-ledgerlivemobileTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ledgerlivemobile-ledgerlivemobileTests.release.xcconfig"; path = "Target Support Files/Pods-ledgerlivemobile-ledgerlivemobileTests/Pods-ledgerlivemobile-ledgerlivemobileTests.release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -160,6 +161,7 @@
68139B1F4BF967461F30D471 /* Pods-ledgerlivemobile-ledgerlivemobileTests.debug.xcconfig */,
A80B735599C416373F147DED /* Pods-ledgerlivemobile-ledgerlivemobileTests.release.xcconfig */,
C630F76F0E1C857DA405027E /* Pods-ledgerlivemobile-ledgerlivemobileTests.staging.xcconfig */,
95143067A27F016C93751872 /* Pods-ledgerlivemobile.nightly.xcconfig */,
);
path = Pods;
sourceTree = "<group>";
Expand Down Expand Up @@ -815,8 +817,14 @@
);
MTL_ENABLE_DEBUG_INFO = NO;
ONLY_ACTIVE_ARCH = YES;
OTHER_CFLAGS = "$(inherited) ";
OTHER_CPLUSPLUSFLAGS = "$(inherited) ";
OTHER_CFLAGS = (
"$(inherited)",
" ",
);
OTHER_CPLUSPLUSFLAGS = (
"$(inherited)",
" ",
);
OTHER_LDFLAGS = "$(inherited)";
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
Expand Down Expand Up @@ -937,8 +945,14 @@
);
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
OTHER_CFLAGS = "$(inherited) ";
OTHER_CPLUSPLUSFLAGS = "$(inherited) ";
OTHER_CFLAGS = (
"$(inherited)",
" ",
);
OTHER_CPLUSPLUSFLAGS = (
"$(inherited)",
" ",
);
OTHER_LDFLAGS = "$(inherited)";
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
Expand Down Expand Up @@ -1003,8 +1017,14 @@
"\"$(inherited)\"",
);
MTL_ENABLE_DEBUG_INFO = NO;
OTHER_CFLAGS = "$(inherited) ";
OTHER_CPLUSPLUSFLAGS = "$(inherited) ";
OTHER_CFLAGS = (
"$(inherited)",
" ",
);
OTHER_CPLUSPLUSFLAGS = (
"$(inherited)",
" ",
);
OTHER_LDFLAGS = "$(inherited)";
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
Expand Down Expand Up @@ -1071,8 +1091,14 @@
"\"$(inherited)\"",
);
MTL_ENABLE_DEBUG_INFO = NO;
OTHER_CFLAGS = "$(inherited) ";
OTHER_CPLUSPLUSFLAGS = "$(inherited) ";
OTHER_CFLAGS = (
"$(inherited)",
" ",
);
OTHER_CPLUSPLUSFLAGS = (
"$(inherited)",
" ",
);
OTHER_LDFLAGS = "$(inherited)";
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
Expand All @@ -1085,7 +1111,7 @@
};
BB0B80022CAAB47600AF2B0C /* Nightly */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = F77638C1F4BC132FB97FEEAF /* Pods-ledgerlivemobile.release.xcconfig */;
baseConfigurationReference = 95143067A27F016C93751872 /* Pods-ledgerlivemobile.nightly.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = NightlyAppIcon;
CLANG_ENABLE_MODULES = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ export default function useDisclaimerViewModel(goToApp: (manifestId: string) =>
}
}, [disclaimerManifest, dismissedManifests]);

useEffect(() => {
setWeb3HubDB(INITIAL_WEB3HUB_STATE);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Comment on lines -31 to -35
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that I was using this to avoid having the input selected if I close and open the disclaimer again, but we clearly don't want to reset the states when using the hook

const onPressItem = useCallback(
(manifest: AppManifest) => {
if (manifest.branch === "soon") {
Expand All @@ -43,11 +38,17 @@ export default function useDisclaimerViewModel(goToApp: (manifestId: string) =>
setDisclaimerManifest(manifest);
setDisclaimerOpened(true);
} else {
// TODO append recently used
setWeb3HubDB(state => {
const rest = state.recentlyUsed.filter(r => r.id !== manifest.id);
return {
...state,
recentlyUsed: [manifest, ...rest],
};
});
goToApp(manifest.id);
}
},
[dismissedManifests, goToApp],
[dismissedManifests, goToApp, setWeb3HubDB],
);

const toggleCheck = useCallback(() => {
Expand All @@ -57,15 +58,26 @@ export default function useDisclaimerViewModel(goToApp: (manifestId: string) =>
const onConfirm = useCallback(() => {
if (disclaimerManifest) {
if (isChecked) {
setWeb3HubDB(state => ({
...state,
dismissedManifests: {
...state.dismissedManifests,
[disclaimerManifest.id]: !state.dismissedManifests[disclaimerManifest.id],
},
}));
setWeb3HubDB(state => {
const rest = state.recentlyUsed.filter(r => r.id !== disclaimerManifest.id);
return {
...state,
recentlyUsed: [disclaimerManifest, ...rest],
dismissedManifests: {
...state.dismissedManifests,
[disclaimerManifest.id]: !state.dismissedManifests[disclaimerManifest.id],
},
};
});
} else {
setWeb3HubDB(state => {
const rest = state.recentlyUsed.filter(r => r.id !== disclaimerManifest.id);
return {
...state,
recentlyUsed: [disclaimerManifest, ...rest],
};
});
}

goToApp(disclaimerManifest.id);
}
}, [disclaimerManifest, goToApp, isChecked, setWeb3HubDB]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { AppManifest } from "@ledgerhq/live-common/wallet-api/types";
import { Flex, IconsLegacy, Text } from "@ledgerhq/native-ui";
import { useTheme } from "@react-navigation/native";
import React from "react";
import { Image, TouchableOpacity, View } from "react-native";

export default function RecentCard({
item,
onPress,
onClosePress,
}: {
item: AppManifest;
onPress: () => void;
onClosePress: () => void;
}) {
const { colors } = useTheme();

return (
<TouchableOpacity onPress={onPress}>
<Flex
bg={colors.lightGrey}
flexDirection={"row"}
mx={"6px"}
px={4}
py={1}
justifyContent={"center"}
alignItems={"center"}
height={45}
borderRadius={16}
columnGap={10}
>
{!item.icon ? (
<Image
style={{ height: 20, width: 20, borderRadius: 4 }}
source={{
uri: item.icon!,
}}
/>
) : (
<View style={{ height: 20, width: 20, borderRadius: 4, backgroundColor: colors.black }} />
)}
<Text fontWeight="semiBold" variant="body" color={colors.black}>
{item.name}
</Text>
<TouchableOpacity onPress={onClosePress}>
<IconsLegacy.CloseMedium size={18} color={colors.grey} />
</TouchableOpacity>
</Flex>
</TouchableOpacity>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { AppManifest } from "@ledgerhq/live-common/wallet-api/types";
import { Box, Flex, Text } from "@ledgerhq/native-ui";
import { useTheme } from "@react-navigation/native";
import { FlashList } from "@shopify/flash-list";
import React, { useCallback } from "react";
import { StyleSheet, TouchableOpacity, View } from "react-native";
import { NavigatorName, ScreenName } from "~/const";
import { SearchProps } from "~/newArch/features/Web3Hub/types";
import RecentCard from "./RecentCard";
import useRecentlyUsedViewModel, {
useRecentlyUsedViewModelExtraData,
} from "./useRecentlyUsedViewModel";

const identityFn = (item: AppManifest) => item.id;

type Props = {
navigation: SearchProps["navigation"];
};

const renderItem = ({
item,
extraData,
}: {
item: AppManifest;
extraData?: useRecentlyUsedViewModelExtraData;
}) => {
return (
<RecentCard
onPress={() => extraData?.onPressItem(item)}
onClosePress={() => extraData?.onCloseItem(item)}
item={item}
/>
);
};

export default function RecentlyUsed({ navigation }: Props) {
const { colors } = useTheme();

const goToApp = useCallback(
(manifestId: string) => {
navigation.push(NavigatorName.Web3Hub, {
screen: ScreenName.Web3HubApp,
params: {
manifestId: manifestId,
},
});
},
[navigation],
);

const { data, extraData, clearAll } = useRecentlyUsedViewModel(goToApp);

if (!data?.length) return null;

return (
<View
style={{
flex: 1,
borderBottomWidth: 2,
borderBottomColor: colors.lightGrey,
paddingBottom: 15,
}}
>
<Flex flexDirection={"row"} px={5} mb={2} mt={6} justifyContent={"space-between"} height={32}>
<Text variant="h5" color={colors.black}>
{"Recently used"}
</Text>
<TouchableOpacity onPress={clearAll}>
<Text fontWeight="semiBold" variant="body" color={"primary.c80"}>
{"Clear all"}
</Text>
</TouchableOpacity>
</Flex>

<FlashList
testID="web3hub-recently-used"
horizontal
contentContainerStyle={styles.container}
keyExtractor={identityFn}
renderItem={renderItem}
ListEmptyComponent={<Box height={50} />}
estimatedItemSize={50}
data={data}
showsHorizontalScrollIndicator={false}
extraData={extraData}
/>
</View>
);
}

const styles = StyleSheet.create({
container: {
paddingHorizontal: 5,
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { AppManifest } from "@ledgerhq/live-common/wallet-api/types";
import { INITIAL_WEB3HUB_STATE, WEB3HUB_STORE_KEY } from "LLM/features/Web3Hub/constants";
import { Web3HubDB } from "LLM/features/Web3Hub/types";
import { useCallback } from "react";
import { useDB } from "~/db";

export type useRecentlyUsedViewModelExtraData = {
onPressItem: (manifest: AppManifest) => void;
onCloseItem: (manifest: AppManifest) => void;
};

const recentlyUsedSelector = (state: Web3HubDB) => state.recentlyUsed;

export function useRecentlyUsed() {
return useDB<Web3HubDB, Web3HubDB["recentlyUsed"]>(
WEB3HUB_STORE_KEY,
INITIAL_WEB3HUB_STATE,
recentlyUsedSelector,
);
}

export default function useRecentlyUsedViewModel(goToApp: (manifestId: string) => void) {
const [recentlyUsed, setWeb3HubDB] = useRecentlyUsed();

const onPressItem = useCallback(
(manifest: AppManifest) => {
goToApp(manifest.id);
},
[goToApp],
);

const onCloseItem = (manifest: AppManifest) => {
setWeb3HubDB(state => ({
...state,
recentlyUsed: state.recentlyUsed.filter(i => i.id !== manifest.id),
}));
};

const clearAll = useCallback(() => {
setWeb3HubDB(state => ({
...state,
recentlyUsed: [],
}));
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const addToRecentlyUsed = (manifest: AppManifest) => {
setWeb3HubDB(state => {
const rest = state.recentlyUsed.filter(r => r.id !== manifest.id);
return {
...state,
recentlyUsed: [manifest, ...rest],
};
});
};

return {
data: recentlyUsed,
clearAll,
addToRecentlyUsed,
extraData: {
onPressItem,
onCloseItem,
},
};
}
Loading
Loading