import { useEffect, useState } from "react"; import background from "../../assets/images/bg-sky-blue.jpg"; import { localImgLoad } from "../../lib"; import LoadingSpinner from "../Spinners/LoadingSpinner"; import FamilyWalletRedeemOptions from "./FamilyWalletRedeemOptions"; import {PriceFormatter} from '../Helpers/PriceFormatter' /** * Renders a list of wallet items or a loading spinner depending on the state of the `wallet` object. */ export default function FamilyWalletBox({ wallet, payment }) { // const { loading, data } = wallet; // const { userDetails } = useSelector((state) => state.userDetails); // const accountType = userDetails?.account_type === "FAMILY"; const [selectedWallet, setSelectedWallet] = useState(""); const [activeWalletBtn, setActiveWalletBtn] = useState(""); const handleChangeWallet = ({ target: { name } }) => { // FUNCTION TO SWITCH WALLET IF USER HAS MORE THAN TWO WALLETS const currentWalletSelected = wallet?.data?.filter( (item) => item.description == name ); setSelectedWallet(currentWalletSelected[0]); setActiveWalletBtn(name); // console.log(name, currentWalletSelected) }; const image = selectedWallet?.code ? `${selectedWallet?.code.toLowerCase()}.svg` : "default.png"; useEffect(() => { setSelectedWallet(wallet.data[0]); setActiveWalletBtn(wallet?.data[0]?.description); }, [wallet]); return (
Current Balance
{selectedWallet?.brand && selectedWallet?.card_last4 ? // FOR VIRTUAL CARD NUMBER ELSE WALLET BALANCE DISPLAY{selectedWallet.brand} **** **** ***** {selectedWallet?.card_last4}
:{PriceFormatter( selectedWallet?.amount / 100, selectedWallet?.code, undefined, "text-[2rem]" )}
}No Wallet Record Found