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

chore(Bonus Pagamenti Digitali): [#175419552] Enhance add bancomat response #2315

Merged
merged 3 commits into from
Oct 27, 2020
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { call, put } from "redux-saga/effects";
import { readableReport } from "italia-ts-commons/lib/reporters";
import { ActionType } from "typesafe-actions";
import { fromNullable } from "fp-ts/lib/Option";
import { index } from "fp-ts/lib/Array";
import { SagaCallReturnType } from "../../../../../../types/utils";
import { PaymentManagerClient } from "../../../../../../api/pagopa";
import { SessionManager } from "../../../../../../utils/SessionManager";
Expand Down Expand Up @@ -116,15 +115,19 @@ export function* handleAddPan(
if (addPansWithRefreshResult.isRight()) {
if (addPansWithRefreshResult.value.status === 200) {
const wallets = addPansWithRefreshResult.value.value.data ?? [];
// since we add only one bancomat we should have a response of size 1
const maybeWallet = index(0, [...wallets]);
// search for the added bancomat.
const maybeWallet = fromNullable(
wallets.find(w => w.info.hashPan === action.payload.hpan)
);
if (maybeWallet.isSome()) {
yield put(
// access
// success
addBancomatToWallet.success(maybeWallet.value)
);
} else {
throw new Error(`success payload is empty`);
throw new Error(
`cannot find added bancomat in wallets list response`
);
}
} else {
throw new Error(
Expand Down