import type { PaymentStackScreenComponentProps } from "@/navigations/Types"; import BeasyLogoIcon from "@components/BeasyLogoIcon"; import Button from "@components/Button"; import GoBackIconButton from "@components/GoBackIconButton"; import Input from "@components/Input"; import PaymentOption from "@components/PaymentOption"; import BackgroundDefault from "@components/backgrounds/BackgroundDefault"; import Box from "@components/bases/Box"; import Text from "@components/bases/Text"; import useOrangeMoney from "@hooks/useOrangeMoney"; import { useCallback, useState } from "react"; import { Keyboard, View } from "react-native"; import { useSafeAreaInsets } from "react-native-safe-area-context"; const PaymentAmountInputScreen: PaymentStackScreenComponentProps<"paymentAmountInputScreen"> = ({ route, navigation, }) => { const { paymentType } = route.params; const [amountToPay, setAmountToPay] = useState(0); const { orangeTransactionInitializerMutation, handlePaymentUsingBrowser, isBrowserOpen, isWaitingForOmPaymentUrl, isCheckingForTransactionStatus, transactionsStatusMutation, } = useOrangeMoney(); const insets = useSafeAreaInsets(); console.log("isWaitingForPaymentUrl", isWaitingForOmPaymentUrl); console.log("isBrowserOpen", isBrowserOpen); const updateAmountToPay = (amount: string) => { const amountParsed = Number.parseInt(amount); if (!Number.isNaN(amountParsed)) { return setAmountToPay(amountParsed); } return setAmountToPay(0); }; const handlePaymentButton = useCallback(async () => { switch (paymentType) { case "OM": { Keyboard.dismiss(); console.log("OM so we stays on screen !!"); console.log("Calling api with amount :: ", amountToPay); await orangeTransactionInitializerMutation.mutateAsync(amountToPay); console.log( "Browser got closed !! ", orangeTransactionInitializerMutation.isSuccess, ); if (orangeTransactionInitializerMutation.isSuccess) { console.log("initilization was a success"); await transactionsStatusMutation.mutateAsync( orangeTransactionInitializerMutation.data.order_id, ); console.log("result of transactions", transactionsStatusMutation.data); } // console.log("Response transaction", response); break; } default: navigation.navigate("numberAndOtpForPaymentScreen"); break; } }, [ amountToPay, orangeTransactionInitializerMutation, paymentType, navigation, transactionsStatusMutation, ]); return ( {/* */} {transactionsStatusMutation.isPending && } navigation.goBack()} /> {/* */} Montant à payé {amountToPay} {}} paymentMethod={paymentType} /> updateAmountToPay(e)} />