Skip to content

Commit

Permalink
fix: fix useMessageGetter
Browse files Browse the repository at this point in the history
  • Loading branch information
seekshiva committed Mar 13, 2024
1 parent 165fec0 commit 8e323c6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
10 changes: 5 additions & 5 deletions src/Components/Surcharge.res
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ let make = (
let paymentMethodTypes = paymentMethodType->getPaymentMethodTypes

let getOneClickWalletsMessage = SurchargeUtils.useOneClickWalletsMessageGetter(~list)
let getSurchargeUtilsMessage = SurchargeUtils.useMessageGetter()

let getSurchargeMessage = () => {
if isForWallets {
getOneClickWalletsMessage()
} else {
switch paymentMethodTypes.surcharge_details {
| Some(surchargeDetails) =>
SurchargeUtils.getMessage(~paymentMethod, ~surchargeDetails, ~list)
| Some(surchargeDetails) => getSurchargeUtilsMessage(~paymentMethod, ~surchargeDetails, ~list)
| None =>
if paymentMethod === "card" {
let creditPaymentMethodTypes = getPaymentMethodTypes("credit")
Expand All @@ -47,21 +47,21 @@ let make = (
let debitCardSurcharge = debitSurchargeDetails.displayTotalSurchargeAmount

if creditCardSurcharge >= debitCardSurcharge {
SurchargeUtils.getMessage(
getSurchargeUtilsMessage(
~paymentMethod,
~surchargeDetails={creditSurchargeDetails},
~list,
)
} else {
SurchargeUtils.getMessage(
getSurchargeUtilsMessage(
~paymentMethod,
~surchargeDetails={debitSurchargeDetails},
~list,
)
}
| (None, Some(surchargeDetails))
| (Some(surchargeDetails), None) =>
SurchargeUtils.getMessage(~paymentMethod, ~surchargeDetails, ~list)
getSurchargeUtilsMessage(~paymentMethod, ~surchargeDetails, ~list)
| (None, None) => None
}
} else {
Expand Down
32 changes: 16 additions & 16 deletions src/Components/SurchargeUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,26 @@ let useSurchargeDetailsForOneClickWallets = (~list) => {
}, (areOneClickWalletsRendered, list))
}

let getMessage = (
~surchargeDetails: PaymentMethodsRecord.surchargeDetails,
~paymentMethod,
~list: PaymentMethodsRecord.list,
) => {
let useMessageGetter = () => {
let {localeString} = Recoil.useRecoilValueFromAtom(RecoilAtoms.configAtom)
let surchargeValue = surchargeDetails.displayTotalSurchargeAmount->Js.Float.toString

let getLocaleStrForSurcharge = (cardLocale, altPaymentLocale) => {
paymentMethod === "card"
? cardLocale(list.currency, surchargeValue)
: altPaymentLocale(list.currency, surchargeValue)
let getMessage = (
~surchargeDetails: PaymentMethodsRecord.surchargeDetails,
~paymentMethod,
~list: PaymentMethodsRecord.list,
) => {
let surchargeValue = surchargeDetails.displayTotalSurchargeAmount->Js.Float.toString

let localeStrForSurcharge = if paymentMethod === "card" {
localeString.surchargeMsgAmountForCard(list.currency, surchargeValue)
} else {
localeString.surchargeMsgAmount(list.currency, surchargeValue)
}

Some(localeStrForSurcharge)
}

Some(
getLocaleStrForSurcharge(
localeString.surchargeMsgAmountForCard,
localeString.surchargeMsgAmount,
),
)
getMessage
}

let useOneClickWalletsMessageGetter = (~list) => {
Expand Down

0 comments on commit 8e323c6

Please sign in to comment.