Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | 1x 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x | import NiceModal, { useModal } from "@ebay/nice-modal-react";
import { CircularProgress, Stack } from "@mui/material";
import GiveButton from "@shared/Button/GiveButton";
import GiveBaseModal from "@shared/modals/GiveBaseModal";
import { useSendMoney } from "../../hooks/useSendMoney";
import { FormProvider } from "react-hook-form";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import SendMoneyStep from "./SendMoneyStep";
import { SendMoneyStepEnum } from "./types";
import VerificationStep from "./VerificationStep";
import GiveIconButton from "@shared/IconButton/GiveIconButton";
import { ArrowLeftIcon } from "@phosphor-icons/react";
import { useAppTheme } from "@theme/v2/Provider";
import { checkPortals } from "@utils/routing";
import { useGetBalancesById } from "@features/MerchantPortal/ManageMoney/hooks/useBalances";
type Props = {
balance: number;
reserveFunds?: number;
minimumReserveBPS?: number;
imageURL: string;
};
const SendMoneyModalV2 = NiceModal.create(
({ balance, imageURL, reserveFunds, minimumReserveBPS }: Props) => {
const modal = useModal();
const open = modal.visible;
const { palette } = useAppTheme();
const { isMobileView } = useCustomThemeV2();
const { isAcquirerManageMoney } = checkPortals();
const { data, isLoading: isLoadingBalances } = useGetBalancesById(
undefined,
isAcquirerManageMoney,
);
const processorBalances = data?.filter((item) => !!item.processorID);
const totalBalance = data?.filter((item) => !item.processorID);
const usedTotalBalance = !!totalBalance
? totalBalance[0]?.availableBalance / 100
: balance;
const {
methods,
onSubmit,
bankAccountList,
isLoading,
isLoadingBankAccounts,
newBalance,
fees,
totalAmount,
selectedStep,
setSelectedStep,
selectedBankAccount,
isDisabled,
minimumReserveBPSFee,
isPayfac,
} = useSendMoney({
balance: usedTotalBalance,
minimumReserveBPS,
reserveFunds,
isProcessorRequired: processorBalances && processorBalances.length > 0,
});
const Step = {
[SendMoneyStepEnum.SEND_MONEY]: (
<SendMoneyStep
bankAccountList={bankAccountList}
isLoadingBankAccounts={isLoadingBankAccounts || isLoadingBalances}
isLoadingBalances={isLoadingBalances}
newBalance={Number(newBalance)}
balance={usedTotalBalance}
totalAmount={totalAmount}
fees={fees}
imageURL={imageURL}
selectedBankAccount={selectedBankAccount}
reserveFunds={reserveFunds}
minimumReserveBPS={minimumReserveBPS}
processorBalances={processorBalances}
isPayfac={isPayfac}
/>
),
[SendMoneyStepEnum.VERIFICATION]: (
<VerificationStep
fees={fees}
totalAmount={totalAmount}
selectedBankAccount={selectedBankAccount}
minimumReserveBPSFee={minimumReserveBPSFee}
/>
),
};
const handleCancel = () => {
modal.hide();
};
return (
<GiveBaseModal
open={open}
title={
selectedStep === SendMoneyStepEnum.SEND_MONEY
? "Transfer"
: "Enter Verification Code"
}
headerLeftContent={
selectedStep === SendMoneyStepEnum.SEND_MONEY ? undefined : (
<GiveIconButton
Icon={ArrowLeftIcon}
sx={{ background: "transparent" }}
onClick={() => setSelectedStep(SendMoneyStepEnum.SEND_MONEY)}
/>
)
}
width={isMobileView ? "100%" : "640px"}
height="fit-content"
onClose={handleCancel}
buttons={
<Stack direction="row" spacing={1.5} justifyContent="flex-end">
<GiveButton
variant="ghost"
size="large"
label="Cancel"
onClick={handleCancel}
/>
<GiveButton
size="large"
variant="filled"
label="Confirm"
type="submit"
form="send-money-form"
sx={{ border: "none" }}
disabled={isDisabled || isLoading}
endIcon={
isLoading ? (
<CircularProgress
size={14}
style={{
color: palette.primitive?.neutral?.[0],
}}
/>
) : undefined
}
/>
</Stack>
}
>
<FormProvider {...methods}>
<Stack
spacing={selectedStep === SendMoneyStepEnum.SEND_MONEY ? 3 : 5}
component="form"
id="send-money-form"
onSubmit={methods.handleSubmit(onSubmit)}
>
{Step[selectedStep]}
</Stack>
</FormProvider>
</GiveBaseModal>
);
},
);
export default SendMoneyModalV2;
|