Skip to content

Commit

Permalink
chore: rename tentative to attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
mastro993 committed Jan 16, 2024
1 parent 6c72527 commit 84ff3dd
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 30 deletions.
12 changes: 6 additions & 6 deletions ts/features/walletV3/analytics/store/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ActionType, createStandardAction } from "typesafe-actions";
import { RptId } from "../../../../../../definitions/pagopa/ecommerce/RptId";

export const walletAnalyticsStorePaymentTentative = createStandardAction(
"WALLET_ANALYTICS_STORE_PAYMENT_TENTATIVE"
export const walletAnalyticsStorePaymentAttempt = createStandardAction(
"WALLET_ANALYTICS_STORE_PAYMENT_ATTEMPT"
)<RptId>();

export const walletAnalyticsResetPaymentTentative = createStandardAction(
"WALLET_ANALYTICS_RESET_PAYMENT_TENTATIVE"
export const walletAnalyticsResetPaymentAttempt = createStandardAction(
"WALLET_ANALYTICS_RESET_PAYMENT_ATTEMPT"
)<RptId>();

export type WalletAnalyticsActions =
| ActionType<typeof walletAnalyticsStorePaymentTentative>
| ActionType<typeof walletAnalyticsResetPaymentTentative>;
| ActionType<typeof walletAnalyticsStorePaymentAttempt>
| ActionType<typeof walletAnalyticsResetPaymentAttempt>;
28 changes: 13 additions & 15 deletions ts/features/walletV3/analytics/store/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import { getType } from "typesafe-actions";
import { RptId } from "../../../../../../definitions/pagopa/ecommerce/RptId";
import { Action } from "../../../../../store/actions/types";
import {
walletAnalyticsStorePaymentTentative,
walletAnalyticsResetPaymentTentative
walletAnalyticsStorePaymentAttempt,
walletAnalyticsResetPaymentAttempt
} from "../actions";

export type WalletAnalyticsState = {
paymentTentativeByRptId: Record<RptId, number>;
paymentAttemptsByRptId: Record<RptId, number>;
};

const INITIAL_STATE: WalletAnalyticsState = {
paymentTentativeByRptId: {}
paymentAttemptsByRptId: {}
};

// eslint-disable-next-line complexity
Expand All @@ -24,24 +24,22 @@ const reducer = (
): WalletAnalyticsState => {
switch (action.type) {
// Payment tentative
case getType(walletAnalyticsStorePaymentTentative):
const currentTentative =
state.paymentTentativeByRptId[action.payload] || 0;
case getType(walletAnalyticsStorePaymentAttempt):
const currentAttempts = state.paymentAttemptsByRptId[action.payload] || 0;

return {
...state,
paymentTentativeByRptId: {
...state.paymentTentativeByRptId,
[action.payload]: currentTentative + 1
paymentAttemptsByRptId: {
...state.paymentAttemptsByRptId,
[action.payload]: currentAttempts + 1
}
};
case getType(walletAnalyticsResetPaymentTentative):
const { [action.payload]: _, ...tentatives } =
state.paymentTentativeByRptId;
case getType(walletAnalyticsResetPaymentAttempt):
const { [action.payload]: _, ...attempts } = state.paymentAttemptsByRptId;

return {
...state,
paymentTentativeByRptId: tentatives
paymentAttemptsByRptId: attempts
};
}
return state;
Expand All @@ -53,7 +51,7 @@ const persistConfig: PersistConfig = {
key: "wallet_analytics",
storage: AsyncStorage,
version: CURRENT_REDUX_PAYMENT_ANALYTICS_STORE_VERSION,
whitelist: ["paymentTentativeByRptId"]
whitelist: ["paymentAttemptsByRptId"]
};

const persistedReducer = persistReducer<WalletAnalyticsState, Action>(
Expand Down
10 changes: 5 additions & 5 deletions ts/features/walletV3/analytics/store/selectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import { walletPaymentDetailsSelector } from "../../../payment/store/selectors";
const selectWalletAnalytics = (state: GlobalState) =>
state.features.wallet.analytics;

export const walletPaymentTentativeByRptIdSelector = createSelector(
export const walletPaymentAttemptsByRptIdSelector = createSelector(
selectWalletAnalytics,
state => state.paymentTentativeByRptId
state => state.paymentAttemptsByRptId
);

export const walletPaymentTentativeSelector = createSelector(
[walletPaymentTentativeByRptIdSelector, walletPaymentDetailsSelector],
(tentativeByRptId, paymentDetailsPot) =>
[walletPaymentAttemptsByRptIdSelector, walletPaymentDetailsSelector],
(attemptsByRptId, paymentDetailsPot) =>
pipe(
paymentDetailsPot,
pot.toOption,
O.map(({ rptId }) => tentativeByRptId[rptId]),
O.map(({ rptId }) => attemptsByRptId[rptId]),
O.toUndefined
)
);
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { pipe } from "fp-ts/lib/function";
import * as React from "react";
import URLParse from "url-parse";
import { useIODispatch, useIOSelector } from "../../../../store/hooks";
import { walletAnalyticsResetPaymentTentative } from "../../analytics/store/actions";
import { walletAnalyticsStorePaymentAttempt } from "../../analytics/store/actions";
import { WALLET_WEBVIEW_OUTCOME_SCHEMA } from "../../common/utils/const";
import {
WalletPaymentAuthorizePayload,
Expand Down Expand Up @@ -56,7 +56,7 @@ export const useWalletPaymentAuthorizationModal = ({
paymentDetailsPot,
pot.toOption,
O.map(({ rptId }) => rptId),
O.map(walletAnalyticsResetPaymentTentative),
O.map(walletAnalyticsStorePaymentAttempt),
O.map(dispatch)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import { WalletPaymentRoutes } from "../navigation/routes";
import { walletPaymentGetDetails } from "../store/actions/networking";
import { walletPaymentDetailsSelector } from "../store/selectors";
import { WalletPaymentFailure } from "../types/failure";
import { walletAnalyticsStorePaymentTentative } from "../../analytics/store/actions";
import { walletAnalyticsStorePaymentAttempt } from "../../analytics/store/actions";

type WalletPaymentDetailScreenNavigationParams = {
rptId: RptId;
Expand Down Expand Up @@ -134,7 +134,7 @@ const WalletPaymentDetailContent = ({
});

const handleGoToPayment = () => {
dispatch(walletAnalyticsStorePaymentTentative(rptId));
dispatch(walletAnalyticsStorePaymentAttempt(rptId));
navigation.push(WalletPaymentRoutes.WALLET_PAYMENT_MAIN, {
screen: WalletPaymentRoutes.WALLET_PAYMENT_PICK_METHOD
});
Expand Down

0 comments on commit 84ff3dd

Please sign in to comment.