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

fix(fee-randomization): fix fee range in PaymentConfirmModal #655

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
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
22 changes: 14 additions & 8 deletions src/components/PaymentConfirmModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ import { AmountSats } from '../libs/JmWalletApi'
import { jarInitial } from './jars/Jar'
import { isValidNumber } from '../utils'

const feeRange: (feeValues: FeeValues) => [number, number] = (feeValues) => {
const feeTargetInSatsPerVByte = feeValues.tx_fees! / 1_000
const minFeeSatsPerVByte = Math.max(1, feeTargetInSatsPerVByte)
const maxFeeSatsPerVByte = feeTargetInSatsPerVByte * (1 + feeValues.tx_fees_factor!)
return [minFeeSatsPerVByte, maxFeeSatsPerVByte]
}

const useMiningFeeText = ({ feeConfigValues }: { feeConfigValues?: FeeValues }) => {
const { t } = useTranslation()

Expand All @@ -24,24 +31,23 @@ const useMiningFeeText = ({ feeConfigValues }: { feeConfigValues?: FeeValues })
} else if (unit === 'blocks') {
return t('send.confirm_send_modal.text_miner_fee_in_targeted_blocks', { count: feeConfigValues.tx_fees })
} else {
const feeTargetInSatsPerVByte = feeConfigValues.tx_fees! / 1_000
if (feeConfigValues.tx_fees_factor === 0) {
const [minFeeSatsPerVByte, maxFeeSatsPerVByte] = feeRange(feeConfigValues)
const fractionDigits = 2

if (minFeeSatsPerVByte.toFixed(fractionDigits) === maxFeeSatsPerVByte.toFixed(fractionDigits)) {
return t('send.confirm_send_modal.text_miner_fee_in_satspervbyte_exact', {
value: feeTargetInSatsPerVByte.toLocaleString(undefined, {
value: minFeeSatsPerVByte.toLocaleString(undefined, {
maximumFractionDigits: Math.log10(1_000),
}),
})
}

const minFeeSatsPerVByte = Math.max(1, feeTargetInSatsPerVByte * (1 - feeConfigValues.tx_fees_factor!))
const maxFeeSatsPerVByte = feeTargetInSatsPerVByte * (1 + feeConfigValues.tx_fees_factor!)

return t('send.confirm_send_modal.text_miner_fee_in_satspervbyte_randomized', {
min: minFeeSatsPerVByte.toLocaleString(undefined, {
maximumFractionDigits: 1,
maximumFractionDigits: fractionDigits,
}),
max: maxFeeSatsPerVByte.toLocaleString(undefined, {
maximumFractionDigits: 1,
maximumFractionDigits: fractionDigits,
}),
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/settings/FeeConfigModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ const FeeConfigForm = forwardRef(
: '',
})}
</rb.Form.Label>
<rb.Form.Text>{t('settings.fees.description_tx_fees_factor')}</rb.Form.Text>
<rb.Form.Text>{t('settings.fees.description_tx_fees_factor_^0.9.10')}</rb.Form.Text>
<rb.InputGroup hasValidation>
<rb.InputGroup.Text id="txFeesFactor-addon1" className={styles.inputGroupText}>
%
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
"feedback_invalid_tx_fees_blocks": "Please provide a valid block target between {{ min }} and {{ max }}.",
"feedback_invalid_tx_fees_satspervbyte": "Please provide a valid transaction fee in sats/vByte between {{ min }} and {{ max }}.",
"label_tx_fees_factor": "Fee randomization",
"description_tx_fees_factor": "Random fees improve privacy. The percentage is to be understood as a +/- around the base fee. Example: If you set the base fee to 10 sats/vByte and the randomization to 30%, a value between 7 and 13 sats/vByte will be used. Default: 20%.",
"description_tx_fees_factor_^0.9.10": "Random fees improve privacy. The percentage is an upward randomization factor of the base fee. Example: If you set the base fee to 10 sats/vByte and the randomization to 30%, a value between 10 and 13 sats/vByte will be used. Default: 20%.",
"feedback_invalid_tx_fees_factor": "Please provide a valid fee randomization value between {{ min }} and {{ max }}.",
"title_max_cj_fee_settings": "Collaborator fees",
"description_max_cj_fee_settings": "Collaborator fees relate to liquidity price and depend on market conditions. Total fees paid for each transaction depend on the amount of collaborators. Additional collaborators increase privacy, but also fees.",
Expand Down