Skip to content

Commit

Permalink
feat(Bonus Pagamenti Digitali): [#175909052] Display only internal pa…
Browse files Browse the repository at this point in the history
…yment methods (#2471)

* [#175909052] [#175949561] refactoring

* [#175909052] [#175949561] add visible in wallet selector

* [#175909052] filter onboarded methods

Co-authored-by: Cristiano Tofani <[email protected]>
  • Loading branch information
fabriziofff and CrisTofani authored Dec 3, 2020
1 parent 10ce988 commit e5eb533
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { GlobalState } from "../../../../../../../store/reducers/types";
import { PaymentMethodGroupedList } from "../../../../components/paymentMethodActivationToggle/list/PaymentMethodGroupedList";
import {
atLeastOnePaymentMethodHasBpdEnabledSelector,
walletV2WithActivationStatusSelector
paymentMethodsWithActivationStatusSelector
} from "../../../../store/reducers/details/combiner";

type Props = ReturnType<typeof mapDispatchToProps> &
Expand Down Expand Up @@ -108,7 +108,7 @@ const mapDispatchToProps = (dispatch: Dispatch) => ({
});

const mapStateToProps = (state: GlobalState) => ({
potWallets: walletV2WithActivationStatusSelector(state),
potWallets: paymentMethodsWithActivationStatusSelector(state),
atLeastOnePaymentMethodActive: atLeastOnePaymentMethodHasBpdEnabledSelector(
state
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { PaymentMethod } from "../../../../../types/pagopa";
import { emptyContextualHelp } from "../../../../../utils/emptyContextualHelp";
import { FooterTwoButtons } from "../../../bonusVacanze/components/markdown/FooterTwoButtons";
import { PaymentMethodGroupedList } from "../../components/paymentMethodActivationToggle/list/PaymentMethodGroupedList";
import { walletV2WithActivationStatusSelector } from "../../store/reducers/details/combiner";
import { paymentMethodsWithActivationStatusSelector } from "../../store/reducers/details/combiner";

const loadLocales = () => ({
headerTitle: I18n.t("bonus.bpd.title"),
Expand Down Expand Up @@ -89,7 +89,7 @@ const mapDispatchToProps = (dispatch: Dispatch) => ({
});

const mapStateToProps = (state: GlobalState) => ({
potWallets: walletV2WithActivationStatusSelector(state)
potWallets: paymentMethodsWithActivationStatusSelector(state)
});

export default connect(
Expand Down
2 changes: 1 addition & 1 deletion ts/features/bonus/bpd/store/reducers/details/combiner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export type PaymentMethodWithActivation = PaymentMethod &
* Add the information of activationStatus to a PatchedWalletV2
* in order to group the elements "notActivable"
*/
export const walletV2WithActivationStatusSelector = createSelector(
export const paymentMethodsWithActivationStatusSelector = createSelector(
[paymentMethodsSelector, bpdPaymentMethodActivationSelector],
(paymentMethodsPot, bpdActivations) =>
pot.map(paymentMethodsPot, paymentMethods =>
Expand Down
8 changes: 4 additions & 4 deletions ts/features/wallet/component/WalletV2PreviewCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { connect } from "react-redux";
import { Dispatch } from "redux";
import { GlobalState } from "../../../store/reducers/types";
import {
bancomatListSelector,
satispayListSelector
bancomatListVisibleInWalletSelector,
satispayListVisibleInWalletSelector
} from "../../../store/reducers/wallet/wallets";
import BancomatWalletPreview from "../bancomat/component/BancomatWalletPreview";
import SatispayWalletPreview from "../satispay/SatispayWalletPreview";
Expand Down Expand Up @@ -52,8 +52,8 @@ const WalletV2PreviewCards: React.FunctionComponent<Props> = props => (
const mapDispatchToProps = (_: Dispatch) => ({});

const mapStateToProps = (state: GlobalState) => ({
bancomatList: bancomatListSelector(state),
satispayList: satispayListSelector(state)
bancomatList: bancomatListVisibleInWalletSelector(state),
satispayList: satispayListVisibleInWalletSelector(state)
});

export default connect(
Expand Down
50 changes: 50 additions & 0 deletions ts/store/reducers/wallet/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,56 @@ export const bPayListSelector = createSelector(
pot.map(paymentMethodPot, paymentMethod => paymentMethod.filter(isBPay))
);

/**
* return true if the payment method is visible in the wallet (the onboardingChannel
* is IO or WISP)
* @param pm
*/
export const isVisibleInWallet = (pm: PaymentMethod) =>
pm.onboardingChannel === "IO" || pm.onboardingChannel === "WISP";

/**
* Return a credit card list visible in the wallet
*/
export const creditCardListVisibleInWalletSelector = createSelector(
[creditCardListSelector],
(creditCardListPot): pot.Pot<ReadonlyArray<CreditCardPaymentMethod>, Error> =>
pot.map(creditCardListPot, creditCardList =>
creditCardList.filter(isVisibleInWallet)
)
);

/**
* Return a bancomat list visible in the wallet
*/
export const bancomatListVisibleInWalletSelector = createSelector(
[bancomatListSelector],
(bancomatListPot): pot.Pot<ReadonlyArray<BancomatPaymentMethod>, Error> =>
pot.map(bancomatListPot, bancomatList =>
bancomatList.filter(isVisibleInWallet)
)
);

/**
* Return a satispay list visible in the wallet
*/
export const satispayListVisibleInWalletSelector = createSelector(
[satispayListSelector],
(satispayListPot): pot.Pot<ReadonlyArray<SatispayPaymentMethod>, Error> =>
pot.map(satispayListPot, satispayList =>
satispayList.filter(isVisibleInWallet)
)
);

/**
* Return a BPay list visible in the wallet
*/
export const bPayListVisibleInWalletSelector = createSelector(
[bPayListSelector],
(bPayListPot): pot.Pot<ReadonlyArray<BPayPaymentMethod>, Error> =>
pot.map(bPayListPot, bPayList => bPayList.filter(isVisibleInWallet))
);

/**
* Get the list of credit cards using the info contained in v2 (Walletv2) to distinguish
*/
Expand Down

0 comments on commit e5eb533

Please sign in to comment.