8000 [LIVE-2186]: Bugfix - Fix NFT send making the app crash in prod (again) by lambertkevin · Pull Request #4958 · LedgerHQ/ledger-live-desktop · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jun 16, 2022. It is now read-only.

[LIVE-2186]: Bugfix - Fix NFT send making the app crash in prod (again) #4958

Merged
merged 1 commit into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 8 additions & 10 deletions src/renderer/components/Breadcrumb/NFTCrumb.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import React, { useCallback, useMemo, memo } from "react";
import { useHistory, useParams } from "react-router-dom";
import { useSelector } from "react-redux";
import { nftsByCollections } from "@ledgerhq/live-common/lib/nft";
import type { ProtoNFT } from "@ledgerhq/live-common/lib/nft";
import { accountSelector } from "~/renderer/reducers/accounts";
import DropDownSelector from "~/renderer/components/DropDownSelector";
import type { DropDownItemType } from "~/renderer/components/DropDownSelector";
import Button from "~/renderer/components/Button";
import Text from "~/renderer/components/Text";
import IconCheck from "~/renderer/icons/Check";
Expand All @@ -13,17 +15,13 @@ import IconAngleUp from "~/renderer/icons/AngleUp";
import { Separator, Item, TextLink, AngleDown, Check } from "./common";
import { setTrackingSource } from "~/renderer/analytics/TrackPage";
import CollectionName from "~/renderer/screens/nft/CollectionName";
import type { ProtoNFT } from "@ledgerhq/live-common/lib/nft";

const LabelWithMeta = ({
item,
isActive,
}: {
isActive: boolean,
item: {
label: string,
content?: ProtoNFT,
},
item: DropDownItemType<ProtoNFT>,
}) => (
<Item isActive={isActive}>
<Text ff={`Inter|${isActive ? "SemiBold" : "Regular"}`} fontSize={4}>
Expand All @@ -43,18 +41,18 @@ const NFTCrumb = () => {
const account = useSelector(state => accountSelector(state, { accountId: id }));
const collections = useMemo(() => nftsByCollections(account.nfts), [account.nfts]);

const items = useMemo(
const items: DropDownItemType<ProtoNFT>[] = useMemo(
() =>
Object.entries(collections).map(([contract, nfts]: any) => ({
Object.entries(collections).map(([contract, nfts]: [string, any]) => ({
key: contract,
label: contract,
content: nfts[0],
})),
[collections],
);

const activeItem = useMemo(
() => items.find((item: any) => item.key === collectionAddress) || items[0],
const activeItem: ?DropDownItemType<ProtoNFT> = useMemo(
() => items.find(item => item.key === collectionAddress) || items[0],
[collectionAddress, items],
);

Expand Down Expand Up @@ -98,7 +96,7 @@ const NFTCrumb = () => {
<TextLink>
<Button>
<CollectionName
nft={activeItem.content}
nft={activeItem?.content}
fallback={activeItem?.content?.contract}
/>
</Button>
Expand Down
12 changes: 6 additions & 6 deletions src/renderer/components/DropDownSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ const DropContainer: ThemedComponent<{}> = styled.div`
}
`;

export type DropDownItemType = {
export type DropDownItemType<ContentType = any> = {
key: string,
label: any,
disabled?: boolean,
content?: any,
content?: ContentType,
};

const OptionContainer = styled.div`
Expand All @@ -65,13 +65,13 @@ const ButtonContainer = styled.div`
`;

type Props = {
children: (props: { isOpen: ?boolean, value: ?DropDownItemType }) => React$Node,
items: DropDownItemType[],
children: (props: { isOpen: ?boolean, value: ?DropDownItemType<> }) => React$Node,
items: DropDownItemType<>[],
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need <> ?
Isn't putting nothing put any by default ? (just asking because i find this weird but if it's not possible it's fine)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes looks like it... I tried but looks like Flowtype is enforcing it for generic types even with a default value 😞

onChange?: (value: any) => void,
renderItem: (props: { isActive: boolean, item: any }) => React$Node | null,
value?: ?DropDownItemType,
value?: ?DropDownItemType<>,
controlled?: boolean,
defaultValue?: ?DropDownItemType,
defaultValue?: ?DropDownItemType<>,
buttonId?: string,
};

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/screens/accounts/AccountList/Order.js
8000
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default function Order() {
}

type ItemProps = {
item: DropDownItemType,
item: DropDownItemType<>,
isActive: boolean,
};

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/screens/accounts/AccountList/Range.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import DropDownSelector, { DropDownItem } from "~/renderer/components/DropDownSe
import { useTimeRange } from "~/renderer/actions/settings";

type RangeItemProps = {
item: DropDownItemType,
item: DropDownItemType<>,
isActive: boolean,
};

Expand Down
4 changes: 2 additions & 2 deletions src/renderer/screens/accounts/OptionsButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const Item: ThemedComponent<{
align-items: center;
`;

type ItemType = DropDownItemType & {
type ItemType = DropDownItemType<> & {
icon?: React$Element<*>,
onClick?: Function,
type?: "separator",
Expand All @@ -55,7 +55,7 @@ const OptionsButton = () => {
);
const { t } = useTranslation();

const items: DropDownItemType[] = [
const items: DropDownItemType<>[] = [
{
key: "exportOperations",
label: t("accounts.optionsMenu.exportOperations"),
Expand Down
6 changes: 3 additions & 3 deletions 6D40 src/renderer/screens/nft/CollectionName.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const Container: ThemedComponent<{}> = styled.div`
`;

type Props = {
nft: ProtoNFT,
nft?: ProtoNFT,
fallback?: string,
account?: Account,
showHideMenu?: boolean,
Expand All @@ -42,10 +42,10 @@ const CollectionName = ({ nft, fallback, account, showHideMenu }: Props) => {
<Skeleton width={80} minHeight={24} barHeight={10} show={loading}>
<Container>
{tokenName || fallback || "-"}
{account && showHideMenu && (
{account && showHideMenu && nft && (
<NFTCollectionContextMenu
collectionName={tokenName || fallback || "-"}
collectionAddress={nft?.contract}
collectionAddress={nft.contract || ""}
account={account}
leftClick={true}
>
Expand Down
0