Skip to content

Commit

Permalink
Merge branch 'master' into 175090703-align-text-cta-bonus-request-inf…
Browse files Browse the repository at this point in the history
…ormation-android
  • Loading branch information
Undermaken authored Oct 9, 2020
2 parents 259a2a8 + c6a0f5f commit d24ff71
Show file tree
Hide file tree
Showing 10 changed files with 3,308 additions and 25 deletions.
8 changes: 8 additions & 0 deletions locales/en/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,14 @@ payment:
iuv: IUV payment {{iuv}}
wallet:
wallet: Payments
searchAbi:
title: Add Bancomat card
description:
text1: If you prefer, you can indicate the bank
text2: " on which you have an active Pagobancomat card. Otherwise we will look for all the cards associated with you: by continuing you accept the "
text3: information on the processing of personal data
bankName: Name of the bank
noName: Name not found
accessibility:
cardsPreview: Payment methods' preview. Activate to navigate to the the list of payment methods.
transactionListItem:
Expand Down
8 changes: 8 additions & 0 deletions locales/it/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,14 @@ payment:
iuv: Codice IUV {{iuv}}
wallet:
wallet: Pagamenti
searchAbi:
title: Aggiungi carta Bancomat
description:
text1: Se vuoi, puoi indicare la banca
text2: " su cui hai un carta Pagobancomat attiva. Altrimenti cercheremo tutte le carta associate a te: proseguendo accetti l’"
text3: informativa sul trattamento dei dati personali
bankName: Denominazione della banca
noName: Nome non trovato
accessibility:
cardsPreview: Anteprima dei metodi di pagamento. Attiva per accedere alla lista dei tuoi metodi
transactionListItem:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"io_bonus_vacanze_specs": "https://raw.githubusercontent.com/pagopa/io-backend/master/api_bonus.yaml",
"io_bpd_citizen": "https://raw.githubusercontent.com/pagopa/io-services-metadata/master/bonus/specs/bpd/citizen.json",
"pagopa_api": "https://wisp2.pagopa.gov.it/pp-restapi-CD/v2/api-docs",
"pagopa_api_bancomat": "https://raw.githubusercontent.com/pagopa/io-services-metadata/master/bonus/specs/bpd/pm/swagger_bancomat.yaml",
"pagopa_api_bancomat": "https://raw.githubusercontent.com/pagopa/io-services-metadata/master/bonus/specs/bpd/pm/swagger_bancomat.json",
"private": true,
"scripts": {
"start": "react-native start",
Expand Down
38 changes: 21 additions & 17 deletions ts/api/pagopa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
TypeofApiParams
} from "italia-ts-commons/lib/requests";
import { Omit } from "italia-ts-commons/lib/types";
import { fromNullable } from "fp-ts/lib/Option";
import {
addWalletCreditCardUsingPOSTDecoder,
AddWalletCreditCardUsingPOSTT,
Expand Down Expand Up @@ -62,13 +63,13 @@ import {
} from "../types/pagopa";
import { getLocalePrimaryWithFallback } from "../utils/locale";
import { fixWalletPspTagsValues } from "../utils/wallet";
import { PatchedCards } from "../features/bonus/bpd/api/patchedTypes";
import {
getAbiUsingGetDefaultDecoder,
GetAbiUsingGetT,
getPansUsingGetDecoder,
GetPansUsingGetT
getAbiListUsingGETDefaultDecoder,
GetAbiListUsingGETT,
getPansUsingGETDecoder,
GetPansUsingGETT
} from "../../definitions/pagopa/bancomat/requestTypes";
import { PatchedCards } from "../features/bonus/bpd/api/patchedTypes";

/**
* A decoder that ignores the content of the payload and only decodes the status
Expand Down Expand Up @@ -371,26 +372,32 @@ const deleteWallet: DeleteWalletUsingDELETET = {
response_decoder: constantEmptyDecoder
};

const getAbi: GetAbiUsingGetT = {
const getAbi: GetAbiListUsingGETT = {
method: "get",
url: () => `/v1/bancomat/abi`,
url: () => `/v1/bancomat/abi?size=10000`, // FIXME to retrieve whole list
query: () => ({}),
headers: ParamAuthorizationBearerHeader,
response_decoder: getAbiUsingGetDefaultDecoder()
response_decoder: getAbiListUsingGETDefaultDecoder()
};

// map the response 200 with a patched codec
type GetPansUsingGetTExtra = MapResponseType<
GetPansUsingGetT,
GetPansUsingGETT,
200,
PatchedCards
>;

const getPans: GetPansUsingGetTExtra = {
method: "get",
url: () => `/v1/bancomat/pans`,
query: ({ abi }) => ({ abi }),
// TODO check abi length === 5 if it is defined
url: ({ abi }) => {
const abiParameter = fromNullable(abi)
.map(a => `?abi=${a}`)
.getOrElse("");
return `/v1/bancomat/pans${abiParameter}`;
},
query: () => ({}),
headers: ParamAuthorizationBearerHeader,
response_decoder: getPansUsingGetDecoder(PatchedCards)
response_decoder: getPansUsingGETDecoder(PatchedCards)
};

const withPaymentManagerToken = <P extends { Bearer: string }, R>(
Expand Down Expand Up @@ -551,10 +558,7 @@ export function PaymentManagerClient(
getPans: (abi?: string) =>
flip(
withPaymentManagerToken(createFetchRequestForApi(getPans, altOptions))
)(
// empty abi if it's undefined
{ abi: abi || "" }
)
)({ abi })
};
}

Expand Down
2 changes: 2 additions & 0 deletions ts/features/bonus/bpd/api/patchedTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ const CardO = t.partial({

expiringDate: t.string,

hpan: t.string,

productType: enumType<ProductTypeEnum>(ProductTypeEnum, "productType"),

tokens: t.readonlyArray(t.string, "array of string"),
Expand Down
121 changes: 121 additions & 0 deletions ts/features/wallet/onboarding/bancomat/components/BankPreviewItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import { fromNullable } from "fp-ts/lib/Option";
import { ListItem, View } from "native-base";
import * as React from "react";
import { Image, ImageStyle, StyleProp, StyleSheet } from "react-native";
import I18n from "../../../../../i18n";
import { Abi } from "../../../../../../definitions/pagopa/bancomat/Abi";
import ButtonDefaultOpacity from "../../../../../components/ButtonDefaultOpacity";
import { LabelSmall } from "../../../../../components/core/typography/LabelSmall";
import { IOColors } from "../../../../../components/core/variables/IOColors";
import IconFont from "../../../../../components/ui/IconFont";

type Props = {
bank: Abi;
inList: boolean;
onPress: () => void;
};

const BASE_IMG_H = 40;
const BASE_IMG_W = 160;

const styles = StyleSheet.create({
flexRow: {
flex: 1,
flexDirection: "row",
alignItems: "center",
justifyContent: "space-between",
height: 105
},
listItem: {
flexDirection: "column",
alignItems: "flex-start"
},
gridItem: {
margin: 16,
padding: 30,
height: 72,
width: 156,
flexDirection: "column",
flex: 1
},
boundaryImage: {
height: BASE_IMG_H,
width: BASE_IMG_W,
justifyContent: "center",
alignItems: "flex-start"
}
});

type ImageSize = {
width: number;
height: number;
};
export const BankPreviewItem: React.FunctionComponent<Props> = (
props: Props
) => {
const [imageDimensions, setImageDimensions] = React.useState<
ImageSize | undefined
>();

/**
* To keep the image bounded in the predefined maximum dimensions (40x160) we use the resizeMode "contain"
* and always calculate the resize width keeping fixed the height to 40, in this way all images will have an height of 40
* and a variable width until the limit of 160.
* Calculating the new image height based on its width may cause an over boundary dimension in some case.
* @param width
* @param height
*/
const handleImageDimensionSuccess = (width: number, height: number) => {
if (width > 0 && height > 0) {
const ratio = Math.min(BASE_IMG_W / width, BASE_IMG_H / height);
setImageDimensions({ width: width * ratio, height: height * ratio });
}
};

React.useEffect(() => {
fromNullable(props.bank.logoUrl).map(url =>
Image.getSize(url, handleImageDimensionSuccess)
);
}, []);

const imageStyle: StyleProp<ImageStyle> = {
...imageDimensions,
resizeMode: "contain"
};

const bankName = props.bank.name || I18n.t("wallet.searchAbi.noName");
const bankLogo = (
<View style={styles.boundaryImage}>
{props.bank.logoUrl && imageDimensions && (
<Image style={imageStyle} source={{ uri: props.bank.logoUrl }} />
)}
</View>
);

return props.inList ? (
<ListItem style={styles.flexRow} onPress={props.onPress}>
<View style={styles.listItem}>
<View spacer={true} />
{bankLogo}
<View spacer={true} small={true} />
<LabelSmall color={"bluegrey"} weight={"Bold"}>
{bankName}
</LabelSmall>
<View spacer={true} />
</View>
<IconFont name={"io-right"} color={IOColors.blue} />
</ListItem>
) : (
<ButtonDefaultOpacity
white={true}
style={styles.gridItem}
onPress={props.onPress}
>
{bankLogo}
<View spacer={true} />
<LabelSmall color={"bluegrey"} weight={"Bold"}>
{bankName}
</LabelSmall>
</ButtonDefaultOpacity>
);
};
Loading

0 comments on commit d24ff71

Please sign in to comment.