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(Bonus Pagamenti Digitali): [#177145461] Show privative cards in wallet home #2878

Merged
merged 48 commits into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
916fde2
[#177145461] add privative type
debiff Mar 5, 2021
9a2e4a2
[#177145461] add enhancement for privative cards
debiff Mar 5, 2021
e9a4b3f
[#177145461] wip privative
debiff Mar 5, 2021
63f4890
[#177145461] add privative type
debiff Mar 8, 2021
34db6ac
[#177145461] enhance privative card
debiff Mar 8, 2021
974ac2e
[#177145461] update CardInfo definition in Logo file
debiff Mar 8, 2021
bf37cd0
[#177145461] modify privative card logo return type
debiff Mar 8, 2021
9927b27
[#177145461] modify privative selector
debiff Mar 8, 2021
f3ab332
[#177145461] Add the card layout preview component
debiff Mar 8, 2021
76106af
[#177145461] use new CardLogoPreview component to favor composition
debiff Mar 8, 2021
1163c40
[#177145461] add PrivativeWalletPreview component
debiff Mar 8, 2021
ede945c
[#177145461] add unknown-gdo logo
debiff Mar 8, 2021
67122ea
[#177145461] add the privative cards to the wallet home
debiff Mar 8, 2021
8f1c5c6
[#177145461] add placeholder PrivativeDetailScreen
debiff Mar 8, 2021
705b1f4
[#177145461] add routes and action to go to PrivativeDetailScreen
debiff Mar 8, 2021
22c9781
[#177145461] use fallback image if there isn't the gdo logo
debiff Mar 8, 2021
9ff9e07
[#177145461] add CardLayoutPreview test
debiff Mar 8, 2021
0b74b0f
[#177145461] add CardLogoPreview tests
debiff Mar 8, 2021
5e07afa
[#177145461] add PrivativeWalletPreview tests
debiff Mar 8, 2021
0b2acaa
[#177145461] Merge branch 'master' into 177145461-preview-privative-card
debiff Mar 9, 2021
3f3037a
[#177145461] Merge branch 'master' into 177145461-preview-privative-card
debiff Mar 9, 2021
04582f5
[#177145461] Merge branch 'master' into 177145461-preview-privative-card
debiff Mar 9, 2021
1086a9f
[#177145461] add key to avoid image cache
debiff Mar 9, 2021
6d1188a
[#177145461] Merge branch 'master' into 177145461-preview-privative-card
debiff Mar 10, 2021
28ba80b
[#177145461] Merge branch 'master' into 177145461-preview-privative-card
debiff Mar 10, 2021
68cb1ce
Merge branch 'master' into 177145461-preview-privative-card
fabriziofff Mar 10, 2021
96cd0d9
Merge branch 'master' into 177145461-preview-privative-card
fabriziofff Mar 10, 2021
8e73e4b
Merge branch 'master' into 177145461-preview-privative-card
debiff Mar 12, 2021
495640a
[#177145461] Merge branch 'master' into 177145461-preview-privative-card
debiff Mar 12, 2021
ebb3dc4
[#177145461] update method type guards
debiff Mar 12, 2021
a62709b
[#177145461] add RawPrivativePaymentMethod type
debiff Mar 12, 2021
eb2435d
[#177145461] modify gdo logo prop name and type guard
debiff Mar 12, 2021
441ef7e
[#177145461] modify privative selector
debiff Mar 12, 2021
bcb91a6
[#177145461] modify privative paymentMethod utils
debiff Mar 12, 2021
b408156
[#177145461] fix wrong naming
debiff Mar 12, 2021
4baa476
[#177145461] fix typo in comments
debiff Mar 12, 2021
6faa89f
[#177145461] use shorter syntax for declare component in tests
debiff Mar 12, 2021
7822b59
[#177145461] modify tests description
debiff Mar 12, 2021
b34f19d
[#177145461] add Privative kind in fromPatchedWalletV2ToRawPaymentMethod
debiff Mar 12, 2021
0e3cde4
[#177145461] return getPrivativeLoyaltyLogoUrl as ImageSourcePropType
debiff Mar 12, 2021
7402c36
[#177145461] update PrivativeWalletPreview
debiff Mar 12, 2021
d5502d3
[#177145461] update tests
debiff Mar 12, 2021
8f74a79
[#177145461] remove inline style
debiff Mar 12, 2021
36d8c72
[#177145461] Merge branch 'master' into 177145461-preview-privative-card
debiff Mar 12, 2021
d01753e
[#177145461] update naming
debiff Mar 12, 2021
9932623
[#177145461] Merge branch 'master' into 177145461-preview-privative-card
debiff Mar 12, 2021
7be89f9
Update ts/features/wallet/privative/screen/PrivativeDetailScreen.tsx
Undermaken Mar 12, 2021
388fada
[#177145461] Merge remote-tracking branch 'origin/master' into 177145…
fabriziofff Mar 15, 2021
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
Binary file added img/wallet/unknown-gdo-2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/wallet/unknown-gdo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions img/wallet/unknown-gdo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import I18n from "../../../../i18n";
import { navigateToBancomatDetailScreen } from "../../../../store/actions/navigation";
import { GlobalState } from "../../../../store/reducers/types";
import { BancomatPaymentMethod } from "../../../../types/pagopa";
import { CardPreview } from "../../component/CardPreview";
import { CardLogoPreview } from "../../component/CardLogoPreview";
import { useImageResize } from "../../onboarding/bancomat/screens/hooks/useImageResize";

type OwnProps = { bancomat: BancomatPaymentMethod };
Expand Down Expand Up @@ -59,7 +59,7 @@ const BancomatWalletPreview: React.FunctionComponent<Props> = props => {
);

return (
<CardPreview
<CardLogoPreview
left={renderLeft(props, imgDimensions)}
image={pagoBancomatImage}
onPress={() => props.navigateToBancomatDetails(props.bancomat)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import bPayImage from "../../../../../img/wallet/cards-icons/bPay.png";
import { Body } from "../../../../components/core/typography/Body";
import { IOStyles } from "../../../../components/core/variables/IOStyles";
import { GlobalState } from "../../../../store/reducers/types";
import { CardPreview } from "../../component/CardPreview";
import { CardLogoPreview } from "../../component/CardLogoPreview";
import { navigateToBPayDetailScreen } from "../../../../store/actions/navigation";
import { BPayPaymentMethod } from "../../../../types/pagopa";
import { useImageResize } from "../../onboarding/bancomat/screens/hooks/useImageResize";
Expand Down Expand Up @@ -62,7 +62,7 @@ const BPayWalletPreview: React.FunctionComponent<Props> = props => {
props.bPay.abiInfo?.logoUrl
);
return (
<CardPreview
<CardLogoPreview
left={renderLeft(props, imgDimensions)}
image={bPayImage}
onPress={() => props.navigateToBPayDetails(props.bPay)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getCardIconFromBrandLogo } from "../../../../components/wallet/card/Log
import { navigateToCobadgeDetailScreen } from "../../../../store/actions/navigation";
import { GlobalState } from "../../../../store/reducers/types";
import { CreditCardPaymentMethod } from "../../../../types/pagopa";
import { CardPreview } from "../../component/CardPreview";
import { CardLogoPreview } from "../../component/CardLogoPreview";
import { useImageResize } from "../../onboarding/bancomat/screens/hooks/useImageResize";

type OwnProps = {
Expand Down Expand Up @@ -65,7 +65,7 @@ const CobadgeWalletPreview: React.FunctionComponent<Props> = props => {

const brandLogo = getCardIconFromBrandLogo(props.cobadge.info);
return (
<CardPreview
<CardLogoPreview
left={renderLeft(props, imgDimensions)}
image={brandLogo}
onPress={() => props.navigateToCobadgeDetails(props.cobadge)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { View } from "native-base";
import * as React from "react";
import { Image, ImageSourcePropType, Platform, StyleSheet } from "react-native";
import { Platform, StyleSheet } from "react-native";
import TouchableDefaultOpacity from "../../../components/TouchableDefaultOpacity";
import I18n from "../../../i18n";
import variables from "../../../theme/variables";

type Props = {
left: React.ReactNode;
image: ImageSourcePropType;
right: React.ReactNode;
onPress?: () => void;
};

Expand Down Expand Up @@ -37,10 +37,7 @@ const styles = StyleSheet.create({
spaced: {
justifyContent: "space-between"
},
cardLogo: {
height: 30,
width: 48
},

rotatedCard: {
shadowColor: "#000",
marginBottom: -30,
Expand All @@ -60,13 +57,12 @@ const styles = StyleSheet.create({
});

/**
* A Generic preview card layout extracted from {@link CardComponent} and simplified.
* A preview card layout that generalizes {@link CardPreview}.
* Can be used to render a generic wallet preview card.
* TODO: in this phase the CardComponent is preserved and no refactoring has been done on the pre-existing code
* @param props
* @constructor
*/
export const CardPreview: React.FunctionComponent<Props> = props => (
export const CardLayoutPreview: React.FunctionComponent<Props> = props => (
<>
{/* In order to render the shadow on android */}
{Platform.OS === "android" && <View style={styles.shadowBox} />}
Expand All @@ -82,11 +78,7 @@ export const CardPreview: React.FunctionComponent<Props> = props => (
<View style={[styles.cardInner]}>
<View style={[styles.row, styles.spaced]}>
{props.left}
<Image
source={props.image}
style={styles.cardLogo}
testID={"cardImage"}
/>
{props.right}
</View>
<View spacer={true} />
</View>
Expand Down
35 changes: 35 additions & 0 deletions ts/features/wallet/component/CardLogoPreview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as React from "react";
import { Image, ImageSourcePropType, StyleSheet } from "react-native";
import { CardLayoutPreview } from "./CardLayoutPreview";

type Props = {
left: React.ReactNode;
image: ImageSourcePropType;
onPress?: () => void;
};

const styles = StyleSheet.create({
cardLogo: {
height: 30,
width: 48
}
});

/**
* A preview card that shows as right section an image of fixed dimensions.
* @param props
* @constructor
*/
export const CardLogoPreview: React.FunctionComponent<Props> = props => (
<CardLayoutPreview
left={props.left}
onPress={props.onPress}
right={
<Image
source={props.image}
style={styles.cardLogo}
testID={"cardImage"}
/>
}
/>
);
17 changes: 16 additions & 1 deletion ts/features/wallet/component/WalletV2PreviewCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import {
bancomatListVisibleInWalletSelector,
bPayListVisibleInWalletSelector,
cobadgeListVisibleInWalletSelector,
privativeListVisibleInWalletSelector,
satispayListVisibleInWalletSelector
} from "../../../store/reducers/wallet/wallets";
import BancomatWalletPreview from "../bancomat/component/BancomatWalletPreview";
import BPayWalletPreview from "../bancomatpay/component/BPayWalletPreview";
import CobadgeWalletPreview from "../cobadge/component/CobadgeWalletPreview";
import PrivativeWalletPreview from "../privative/component/PrivativeWalletPreview";
import SatispayWalletPreview from "../satispay/SatispayWalletPreview";

type Props = ReturnType<typeof mapDispatchToProps> &
Expand Down Expand Up @@ -71,6 +73,18 @@ const WalletV2PreviewCards: React.FunctionComponent<Props> = props => (
</>
))
)}
{pot.toUndefined(
pot.mapNullable(props.privativeList, c => (
<>
{c.map(privativeMethod => (
<PrivativeWalletPreview
key={privativeMethod.idWallet}
privative={privativeMethod}
/>
))}
</>
))
)}
</>
);

Expand All @@ -80,7 +94,8 @@ const mapStateToProps = (state: GlobalState) => ({
bancomatList: bancomatListVisibleInWalletSelector(state),
bPayList: bPayListVisibleInWalletSelector(state),
satispayList: satispayListVisibleInWalletSelector(state),
cobadgeList: cobadgeListVisibleInWalletSelector(state)
cobadgeList: cobadgeListVisibleInWalletSelector(state),
privativeList: privativeListVisibleInWalletSelector(state)
});

export default connect(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { render } from "@testing-library/react-native";
import { View } from "native-base";
import * as React from "react";
import { CardLayoutPreview } from "../CardLayoutPreview";

describe("CardLayoutPreview", () => {
it("should show the left and the right received components", () => {
const left = () => <View testID="leftComponent" />;
const right = () => <View testID="right" />;
const component = render(
<CardLayoutPreview left={left()} right={right()} />
);

expect(component.queryByTestId("leftComponent")).not.toBeNull();
expect(component.queryByTestId("right")).not.toBeNull();
});
});
26 changes: 26 additions & 0 deletions ts/features/wallet/component/__test__/CardLogoPreview.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { fireEvent, render } from "@testing-library/react-native";
import { View } from "native-base";
import * as React from "react";
import { CardLogoPreview } from "../CardLogoPreview";
import anImage from "../../../../../img/wallet/cards-icons/bPay.png";

describe("CardLogoPreview", () => {
it("should show the left component, the image and when press should run the onPress", () => {
const left = () => <View testID="leftComponent" />;
const onPress = jest.fn();
const component = render(
<CardLogoPreview left={left()} image={anImage} onPress={onPress} />
);
const cardImage = component.queryByTestId("cardImage");
const cardPreview = component.queryByTestId("cardPreview");

expect(component.queryByTestId("leftComponent")).not.toBeNull();
expect(cardImage).not.toBeNull();
expect(cardImage).toHaveProp("source", anImage);

if (cardPreview !== null) {
fireEvent.press(cardPreview);
expect(onPress).toHaveBeenCalledTimes(1);
}
});
});
113 changes: 113 additions & 0 deletions ts/features/wallet/privative/component/PrivativeWalletPreview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import * as React from "react";
import { connect } from "react-redux";
import { Dispatch } from "redux";
import { Option } from "fp-ts/lib/Option";
import {
Image,
ImageSourcePropType,
ImageStyle,
ImageURISource,
StyleProp,
StyleSheet
} from "react-native";
import { Body } from "../../../../components/core/typography/Body";
import { navigateToPrivativeDetailScreen } from "../../../../store/actions/navigation";
import { GlobalState } from "../../../../store/reducers/types";
import { PrivativePaymentMethod } from "../../../../types/pagopa";
import { IOStyles } from "../../../../components/core/variables/IOStyles";
import { useImageResize } from "../../onboarding/bancomat/screens/hooks/useImageResize";
import { CardLayoutPreview } from "../../component/CardLayoutPreview";
import unknownGdo from "../../../../../img/wallet/unknown-gdo.png";

type OwnProps = {
privative: PrivativePaymentMethod;
};

type Props = ReturnType<typeof mapDispatchToProps> &
ReturnType<typeof mapStateToProps> &
OwnProps;

const BASE_IMG_W = 160;
const BASE_IMG_H = 20;

const styles = StyleSheet.create({
unknownLoyaltyLogo: {
width: 40,
height: 40,
resizeMode: "contain"
}
});
const fallbackLoyaltyLogo: React.ReactElement = (
<Image
source={unknownGdo}
style={styles.unknownLoyaltyLogo}
key={"unknownLoyaltyLogo"}
testID={"unknownLoyaltyLogo"}
/>
);

const renderRight = (props: Props, size: Option<[number, number]>) =>
size.fold(fallbackLoyaltyLogo, imgDim => {
const imageUrl = props.privative.icon;

const imageStyle: StyleProp<ImageStyle> = {
width: imgDim[0],
height: imgDim[1],
resizeMode: "contain"
};
return (
<Image
source={imageUrl}
style={imageStyle}
key={"loyaltyLogo"}
testID={"loyaltyLogo"}
/>
);
});

/**
* Typeguard for handle backward compatibility of icon type
* @param image
*/
const isImageURISource = (
image: ImageSourcePropType
): image is ImageURISource =>
typeof image !== "number" && (image as ImageURISource).uri !== undefined;

/**
* A card preview for a privative card
* @param props
* @constructor
*/
const PrivativeWalletPreview: React.FunctionComponent<Props> = props => {
const rightElement = isImageURISource(props.privative.icon)
? renderRight(
props,
useImageResize(BASE_IMG_W, BASE_IMG_H, props.privative.icon.uri)
)
: fallbackLoyaltyLogo;

return (
<CardLayoutPreview
left={
<Body style={IOStyles.flex} numberOfLines={1} testID={"caption"}>
{props.privative.caption}
</Body>
}
right={rightElement}
onPress={() => props.navigateToPrivativeDetails(props.privative)}
/>
);
};

const mapDispatchToProps = (dispatch: Dispatch) => ({
navigateToPrivativeDetails: (privative: PrivativePaymentMethod) =>
dispatch(navigateToPrivativeDetailScreen(privative))
});

const mapStateToProps = (_: GlobalState) => ({});

export default connect(
mapStateToProps,
mapDispatchToProps
)(PrivativeWalletPreview);
Loading