diff --git a/src/components/Send/helpers.ts b/src/components/Send/helpers.ts index 2b986867..50159368 100644 --- a/src/components/Send/helpers.ts +++ b/src/components/Send/helpers.ts @@ -1,4 +1,3 @@ -import { ServiceConfigContextEntry } from '../../context/ServiceConfigContext' import { isValidNumber } from '../../utils' export const initialNumCollaborators = (minValue: number) => { @@ -28,49 +27,3 @@ export const isValidAmount = (candidate: number | null, isSweep: boolean) => { export const isValidNumCollaborators = (candidate: number | null, minNumCollaborators: number) => { return candidate !== null && isValidNumber(candidate) && candidate >= minNumCollaborators && candidate <= 99 } - -export const enhanceDirectPaymentErrorMessageIfNecessary = async ( - httpStatus: number, - errorMessage: string, - onBadRequest: (errorMessage: string) => string, -) => { - const tryEnhanceMessage = httpStatus === 400 - if (tryEnhanceMessage) { - return onBadRequest(errorMessage) - } - - return errorMessage -} - -export const enhanceTakerErrorMessageIfNecessary = async ( - loadConfigValue: ServiceConfigContextEntry['loadConfigValueIfAbsent'], - httpStatus: number, - errorMessage: string, - onMaxFeeSettingsMissing: (errorMessage: string) => string, -) => { - const tryEnhanceMessage = httpStatus === 409 - if (tryEnhanceMessage) { - const abortCtrl = new AbortController() - - const configExists = (section: string, field: string) => - loadConfigValue({ - signal: abortCtrl.signal, - key: { section, field }, - }) - .then((val) => val.value !== null) - .catch(() => false) - - const maxFeeSettingsPresent = await Promise.all([ - configExists('POLICY', 'max_cj_fee_rel'), - configExists('POLICY', 'max_cj_fee_abs'), - ]) - .then((arr) => arr.every((e) => e)) - .catch(() => false) - - if (!maxFeeSettingsPresent) { - return onMaxFeeSettingsMissing(errorMessage) - } - } - - return errorMessage -} diff --git a/src/components/Send/index.tsx b/src/components/Send/index.tsx index 36d4cec2..de9eb8fe 100644 --- a/src/components/Send/index.tsx +++ b/src/components/Send/index.tsx @@ -28,8 +28,6 @@ import { JM_MINIMUM_MAKERS_DEFAULT } from '../../constants/config' import { SATS, formatSats, isValidNumber, scrollToTop } from '../../utils' import { - enhanceDirectPaymentErrorMessageIfNecessary, - enhanceTakerErrorMessageIfNecessary, initialNumCollaborators, isValidAddress, isValidAmount, @@ -354,13 +352,11 @@ export default function Send({ wallet }: SendProps) { setWaitForUtxosToBeSpent(inputs.map((it: any) => it.outpoint)) success = true } else { - const message = await Api.Helper.extractErrorMessage(res) - const displayMessage = await enhanceDirectPaymentErrorMessageIfNecessary( - res.status, - message, - (errorMessage) => `${errorMessage} ${t('send.direct_payment_error_message_bad_request')}`, - ) - setAlert({ variant: 'danger', message: displayMessage }) + const errorMessage = await Api.Helper.extractErrorMessage(res) + const message = `${errorMessage} ${ + res.status === 400 ? t('send.direct_payment_error_message_bad_request') : '' + }` + setAlert({ variant: 'danger', message }) } setIsSending(false) @@ -399,14 +395,7 @@ export default function Send({ wallet }: SendProps) { success = true } else { const message = await Api.Helper.extractErrorMessage(res) - const displayMessage = await enhanceTakerErrorMessageIfNecessary( - loadConfigValue, - res.status, - message, - (errorMessage) => `${errorMessage} ${t('send.taker_error_message_max_fees_config_missing')}`, - ) - - setAlert({ variant: 'danger', message: displayMessage }) + setAlert({ variant: 'danger', message }) } setIsSending(false)