Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show error message if redeem amount is less than minimum required amount #297

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 34 additions & 19 deletions app/components/redeem-flow/InforError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useEffect, useState } from "react"
import { makeStyles, Text } from "@rneui/themed"

// hooks
import { useDisplayCurrency } from "@app/hooks"
import { useDisplayCurrency, usePriceConversion } from "@app/hooks"
import { useI18nContext } from "@app/i18n/i18n-react"
import { usePersistentStateContext } from "@app/store/persistent-state"

Expand Down Expand Up @@ -31,34 +31,49 @@ const InforError: React.FC<Props> = ({
const { LL } = useI18nContext()
const { persistentState } = usePersistentStateContext()
const { formatMoneyAmount } = useDisplayCurrency()
const { convertMoneyAmount } = usePriceConversion()

const [errorMsg, setErrorMsg] = useState("")

useEffect(() => {
fetchLimits()
}, [])

const fetchLimits = async () => {
if (
persistentState.defaultWallet?.walletCurrency === "BTC" &&
persistentState.isAdvanceMode
) {
fetchLimits()
}
}, [])

const fetchLimits = async () => {
const limits = await fetchBreezLightningLimits()
const limits = await fetchBreezLightningLimits()

if (limits.receive.minSat > unitOfAccountAmount.amount) {
setHasError(true)
setErrorMsg(
LL.SendBitcoinScreen.minAmountInvoiceError({ amount: limits.receive.minSat }),
)
} else if (limits.receive.maxSat < unitOfAccountAmount.amount) {
setHasError(true)
setErrorMsg(
LL.SendBitcoinScreen.maxAmountInvoiceError({ amount: limits.receive.maxSat }),
)
if (limits.receive.minSat > unitOfAccountAmount.amount) {
setHasError(true)
setErrorMsg(
LL.SendBitcoinScreen.minAmountInvoiceError({ amount: limits.receive.minSat }),
)
} else if (limits.receive.maxSat < unitOfAccountAmount.amount) {
setHasError(true)
setErrorMsg(
LL.SendBitcoinScreen.maxAmountInvoiceError({ amount: limits.receive.maxSat }),
)
} else {
setHasError(false)
setErrorMsg("")
}
} else {
setHasError(false)
setErrorMsg("")
if (convertMoneyAmount) {
const convertedAmount = convertMoneyAmount(unitOfAccountAmount, "USD")
if (convertedAmount.amount < 1) {
setHasError(true)
setErrorMsg(
LL.SendBitcoinScreen.minAmountInvoiceError({
amount: formatMoneyAmount({
moneyAmount: { amount: 1, currency: "USD", currencyCode: "USD" },
}),
}),
)
}
}
}
}

Expand Down