Skip to content

Commit

Permalink
chore: handle authorization dismiss
Browse files Browse the repository at this point in the history
  • Loading branch information
mastro993 committed Jan 23, 2024
1 parent 07b2479 commit 602c5ef
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {

type Props = {
onAuthorizationOutcome: (outcome: WalletPaymentOutcome) => void;
onDismiss: () => void;
};

export type WalletPaymentAuthorizationModal = {
Expand All @@ -29,7 +30,8 @@ export type WalletPaymentAuthorizationModal = {
};

export const useWalletPaymentAuthorizationModal = ({
onAuthorizationOutcome
onAuthorizationOutcome,
onDismiss
}: Props): WalletPaymentAuthorizationModal => {
const dispatch = useIODispatch();
const authorizationUrlPot = useIOSelector(
Expand Down Expand Up @@ -73,6 +75,7 @@ export const useWalletPaymentAuthorizationModal = ({
);
},
() => {
onDismiss();
dispatch(walletPaymentAuthorization.cancel());
setIsPendingAuthorization(false);
}
Expand All @@ -86,6 +89,7 @@ export const useWalletPaymentAuthorizationModal = ({
isPendingAuthorization,
authorizationUrlPot,
handleAuthorizationResult,
onDismiss,
dispatch
]);

Expand Down
37 changes: 23 additions & 14 deletions ts/features/walletV3/payment/screens/WalletPaymentConfirmScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ import {
walletPaymentPickedPspSelector,
walletPaymentTransactionSelector
} from "../store/selectors";
import { WalletPaymentOutcome } from "../types/PaymentOutcomeEnum";
import {
WalletPaymentOutcome,
WalletPaymentOutcomeEnum
} from "../types/PaymentOutcomeEnum";

const WalletPaymentConfirmScreen = () => {
const navigation = useNavigation<IOStackNavigationProp<AppParamsList>>();
Expand Down Expand Up @@ -67,31 +70,37 @@ const WalletPaymentConfirmScreen = () => {
)
);

const handleAuthorizationOutcome = (outcome: WalletPaymentOutcome) => {
navigation.navigate(WalletPaymentRoutes.WALLET_PAYMENT_MAIN, {
screen: WalletPaymentRoutes.WALLET_PAYMENT_OUTCOME,
params: {
outcome
}
});
};
const handleAuthorizationOutcome = React.useCallback(
(outcome: WalletPaymentOutcome) => {
navigation.navigate(WalletPaymentRoutes.WALLET_PAYMENT_MAIN, {
screen: WalletPaymentRoutes.WALLET_PAYMENT_OUTCOME,
params: {
outcome
}
});
},
[navigation]
);

const {
isLoading: isAuthUrlLoading,
isError: isAuthUrlError,
isPendingAuthorization,
startPaymentAuthorizaton
} = useWalletPaymentAuthorizationModal({
onAuthorizationOutcome: handleAuthorizationOutcome
onAuthorizationOutcome: handleAuthorizationOutcome,
onDismiss: () =>
handleAuthorizationOutcome(WalletPaymentOutcomeEnum.CANCELED_BY_USER)
});

const isLoading = isAuthUrlLoading || isPendingAuthorization;
const isError = isAuthUrlError;

if (isError) {
// TODO: Failure handling (https://pagopa.atlassian.net/browse/IOBP-471)
return <></>;
}
React.useEffect(() => {
if (isError) {
handleAuthorizationOutcome(WalletPaymentOutcomeEnum.GENERIC_ERROR);
}
}, [isError, handleAuthorizationOutcome]);

const LoadingContent = () => (
<SafeAreaView style={styles.loadingContainer}>
Expand Down

0 comments on commit 602c5ef

Please sign in to comment.