Skip to content

Commit

Permalink
refactor: absolute fee offer constants
Browse files Browse the repository at this point in the history
  • Loading branch information
theborakompanioni committed Oct 30, 2024
1 parent 268dcf8 commit 00dffa0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/components/Earn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import { CurrentWallet, useCurrentWalletInfo, useReloadCurrentWalletInfo, Wallet
import { useServiceInfo, useReloadServiceInfo, Offer } from '../context/ServiceInfoContext'
import { factorToPercentage, isAbsoluteOffer, isRelativeOffer, isValidNumber, percentageToFactor } from '../utils'
import { JM_DUST_THRESHOLD } from '../constants/jm'
import { OFFER_FEE_REL_MAX, OFFER_FEE_REL_MIN, OFFER_FEE_REL_STEP } from '../constants/jam'
import {
OFFER_FEE_ABS_MIN,
OFFER_FEE_REL_MAX,
OFFER_FEE_REL_MIN,
OFFER_FEE_REL_STEP,
OFFER_MINSIZE_MIN,
} from '../constants/jam'
import * as Api from '../libs/JmWalletApi'
import * as fb from './fb/utils'
import Sprite from './Sprite'
Expand Down Expand Up @@ -225,8 +231,6 @@ const EarnForm = ({
)
}, [walletInfo])

const offerMinsizeMin = JM_DUST_THRESHOLD

const offerMinsizeMax = useMemo(() => {
return Math.max(0, maxAvailableBalanceInJar - JM_DUST_THRESHOLD)
}, [maxAvailableBalanceInJar])
Expand All @@ -251,7 +255,7 @@ const EarnForm = ({
}

if (isAbsOffer) {
if (!isValidNumber(values.feeAbs?.value) || values.feeAbs!.value! < 0) {
if (!isValidNumber(values.feeAbs?.value) || values.feeAbs!.value! < OFFER_FEE_ABS_MIN) {
errors.feeAbs = t('earn.feedback_invalid_abs_fee')
}
}
Expand All @@ -260,11 +264,11 @@ const EarnForm = ({
errors.minsize = t('earn.feedback_invalid_min_amount')
} else {
const minsize = values.minsize?.value || 0
if (offerMinsizeMin > offerMinsizeMax) {
if (OFFER_MINSIZE_MIN > offerMinsizeMax) {
errors.minsize = t('earn.feedback_invalid_min_amount_insufficient_funds')
} else if (minsize < offerMinsizeMin || minsize > offerMinsizeMax) {
} else if (minsize < OFFER_MINSIZE_MIN || minsize > offerMinsizeMax) {
errors.minsize = t('earn.feedback_invalid_min_amount_range', {
minAmountMin: offerMinsizeMin.toLocaleString(),
minAmountMin: OFFER_MINSIZE_MIN.toLocaleString(),
minAmountMax: offerMinsizeMax.toLocaleString(),
})
}
Expand Down
5 changes: 5 additions & 0 deletions src/constants/jam.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { percentageToFactor } from '../utils'
import { JM_DUST_THRESHOLD } from './jm'

export const TX_FEES_FACTOR_MIN = 0 // 0%
/**
Expand All @@ -18,3 +19,7 @@ export const MAX_SWEEP_FEE_CHANGE_MAX = percentageToFactor(100)
export const OFFER_FEE_REL_MIN = percentageToFactor(0.0001)
export const OFFER_FEE_REL_MAX = percentageToFactor(10)
export const OFFER_FEE_REL_STEP = percentageToFactor(0.0001)

export const OFFER_FEE_ABS_MIN = 0

export const OFFER_MINSIZE_MIN = JM_DUST_THRESHOLD

0 comments on commit 00dffa0

Please sign in to comment.