Skip to content

Commit

Permalink
fix(Bonus Vacanze): [#175744639] Bancomat expiration date is build as…
Browse files Browse the repository at this point in the history
… invalid (#2393)
  • Loading branch information
Undermaken authored Nov 16, 2020
1 parent 2539fdb commit 3547f9f
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ type Props = ReturnType<typeof mapDispatchToProps> &
ReturnType<typeof mapStateToProps> &
OwnProps;

const getExpireDate = (fullYear?: string, month?: string): Date | undefined => {
if (!fullYear || !month) {
return undefined;
}
const year = parseInt(fullYear, 10);
const indexedMonth = parseInt(month, 10);
if (isNaN(year) || isNaN(indexedMonth)) {
return undefined;
}
return new Date(year, indexedMonth - 1);
};

/**
* Render a bancomat already added to the wallet
* @param props
Expand All @@ -20,11 +32,10 @@ type Props = ReturnType<typeof mapDispatchToProps> &
const BancomatCard: React.FunctionComponent<Props> = props => (
<BaseBancomatCard
abiLogo={props.bancomat.abiInfo?.logoUrl}
expiringDate={
new Date(
`${props.bancomat.info.expireYear}/${props.bancomat.info.expireMonth}/01`
)
}
expiringDate={getExpireDate(
props.bancomat.info.expireYear,
props.bancomat.info.expireMonth
)}
user={props.nameSurname ?? ""}
/>
);
Expand Down

0 comments on commit 3547f9f

Please sign in to comment.