diff options
author | Sebastian <sebasjm@gmail.com> | 2024-03-05 14:58:52 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-03-05 14:58:52 -0300 |
commit | a63b2a878b374f3076990131977f16d923d8a63b (patch) | |
tree | da81043ed5610817cce846343337ecdfa1e4367c /packages/demobank-ui/src/pages/ConversionConfig.tsx | |
parent | 73ab9970e17f2a4749bad88631a4bd4d8e64721e (diff) |
check min in conversion admin
Diffstat (limited to 'packages/demobank-ui/src/pages/ConversionConfig.tsx')
-rw-r--r-- | packages/demobank-ui/src/pages/ConversionConfig.tsx | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/packages/demobank-ui/src/pages/ConversionConfig.tsx b/packages/demobank-ui/src/pages/ConversionConfig.tsx index 37dd580c2..2d52cd99f 100644 --- a/packages/demobank-ui/src/pages/ConversionConfig.tsx +++ b/packages/demobank-ui/src/pages/ConversionConfig.tsx @@ -198,7 +198,7 @@ function useComponentState({ estimateByDebit: calculateCashinFromDebit, } = useCashinEstimator(); - const [calc, setCalc] = useState<{ cashin: TransferCalculation, cashout: TransferCalculation }>() + const [calculationResult, setCalc] = useState<{ cashin: TransferCalculation, cashout: TransferCalculation }>() useEffect(() => { async function doAsync() { @@ -209,7 +209,10 @@ function useComponentState({ const in_fee = Amounts.parseOrThrow(info.conversion_rate.cashin_fee) const cashin = await calculateCashinFromDebit(in_amount, in_fee); - + if (cashin === "amount-is-too-small") { + setCalc(undefined) + return; + } // const out_amount = Amounts.parseOrThrow(`${info.regional_currency}:${form.amount.value}`) const out_fee = Amounts.parseOrThrow(info.conversion_rate.cashout_fee) const cashout = await calculateCashoutFromDebit(cashin.credit, out_fee); @@ -221,7 +224,8 @@ function useComponentState({ }, [form.amount?.value, form.conv?.cashin_fee?.value, form.conv?.cashout_fee?.value]); const [section, setSection] = useState<"detail" | "cashout" | "cashin">("detail") - + const cashinCalc = calculationResult?.cashin === "amount-is-too-small" ? undefined : calculationResult?.cashin + const cashoutCalc = calculationResult?.cashout === "amount-is-too-small" ? undefined : calculationResult?.cashout async function doUpdate() { if (!creds) return await handleError(async () => { @@ -447,7 +451,7 @@ function useComponentState({ </div> </div> - {!calc ? undefined : ( + {!cashoutCalc || !cashinCalc ? undefined : ( <div class="px-6 pt-6"> <div class="sm:col-span-5"> <dl class="mt-4 space-y-4"> @@ -457,7 +461,7 @@ function useComponentState({ </dt> <dd class="text-sm text-gray-900"> <RenderAmount - value={calc.cashin.debit} + value={cashinCalc.debit} negative withColor spec={info.regional_currency_specification} @@ -465,7 +469,7 @@ function useComponentState({ </dd> </div> - {Amounts.isZero(calc.cashin.beforeFee) ? undefined : ( + {Amounts.isZero(cashinCalc.beforeFee) ? undefined : ( <div class="flex items-center justify-between afu "> <dt class="flex items-center text-sm text-gray-600"> <span> @@ -474,7 +478,7 @@ function useComponentState({ </dt> <dd class="text-sm text-gray-900"> <RenderAmount - value={calc.cashin.beforeFee} + value={cashinCalc.beforeFee} spec={info.fiat_currency_specification} /> </dd> @@ -486,7 +490,7 @@ function useComponentState({ </dt> <dd class="text-lg text-gray-900 font-medium"> <RenderAmount - value={calc.cashin.credit} + value={cashinCalc.credit} withColor spec={info.fiat_currency_specification} /> @@ -503,7 +507,7 @@ function useComponentState({ </dt> <dd class="text-sm text-gray-900"> <RenderAmount - value={calc.cashout.debit} + value={cashoutCalc.debit} negative withColor spec={info.fiat_currency_specification} @@ -511,7 +515,7 @@ function useComponentState({ </dd> </div> - {Amounts.isZero(calc.cashout.beforeFee) ? undefined : ( + {Amounts.isZero(cashoutCalc.beforeFee) ? undefined : ( <div class="flex items-center justify-between afu"> <dt class="flex items-center text-sm text-gray-600"> <span> @@ -520,7 +524,7 @@ function useComponentState({ </dt> <dd class="text-sm text-gray-900"> <RenderAmount - value={calc.cashout.beforeFee} + value={cashoutCalc.beforeFee} spec={info.regional_currency_specification} /> </dd> @@ -532,7 +536,7 @@ function useComponentState({ </dt> <dd class="text-lg text-gray-900 font-medium"> <RenderAmount - value={calc.cashout.credit} + value={cashoutCalc.credit} withColor spec={info.regional_currency_specification} /> @@ -541,7 +545,7 @@ function useComponentState({ </dl> </div> - {calc && status.status === "ok" && Amounts.cmp(status.result.amount, calc.cashout.credit) < 0 ? <div class="p-4"> + {cashoutCalc && status.status === "ok" && Amounts.cmp(status.result.amount, cashoutCalc.credit) < 0 ? <div class="p-4"> <Attention title={i18n.str`Bad configuration`} type="warning"> <i18n.Translate> This configuration allows users to cash out more of what has been cashed in. |