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

refactor: belt function removal #422

Merged
merged 4 commits into from
Jun 11, 2024
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
6 changes: 3 additions & 3 deletions src/BrowserSpec.res
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ let broswerInfo = () => {
"text\/html,application\/xhtml+xml,application\/xml;q=0.9,image\/webp,image\/apng,*\/*;q=0.8"->JSON.Encode.string,
),
("language", navigator.language->JSON.Encode.string),
("color_depth", colorDepth->Belt.Int.toFloat->JSON.Encode.float),
("screen_height", screen.height->Belt.Int.toFloat->JSON.Encode.float),
("screen_width", screen.width->Belt.Int.toFloat->JSON.Encode.float),
("color_depth", colorDepth->Int.toFloat->JSON.Encode.float),
("screen_height", screen.height->Int.toFloat->JSON.Encode.float),
("screen_width", screen.width->Int.toFloat->JSON.Encode.float),
("time_zone", date.getTimezoneOffset()->JSON.Encode.float),
("java_enabled", true->JSON.Encode.bool),
("java_script_enabled", true->JSON.Encode.bool),
Expand Down
13 changes: 6 additions & 7 deletions src/CardUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ type options = {timeZone: string}
type dateTimeFormat = {resolvedOptions: unit => options}
@val @scope("Intl") external dateTimeFormat: unit => dateTimeFormat = "DateTimeFormat"

let toInt = val => val->Belt.Int.fromString->Option.getOr(0)
let toString = val => val->Belt.Int.toString
let toInt = val => val->Int.fromString->Option.getOr(0)
let toString = val => val->Int.toString

let getQueryParamsDictforKey = (searchParams, keyName) => {
let dict = Dict.make()
Expand Down Expand Up @@ -206,7 +206,7 @@ let getExpiryDates = val => {
let date = Date.make()->Date.toISOString
let (month, year) = splitExpiryDates(val)
let (_, currentYear) = getCurrentMonthAndYear(date)
let prefix = currentYear->Belt.Int.toString->String.slice(~start=0, ~end=2)
let prefix = currentYear->Int.toString->String.slice(~start=0, ~end=2)
(month, `${prefix}${year}`)
}
let formatExpiryToTwoDigit = expiry => {
Expand Down Expand Up @@ -269,7 +269,7 @@ let getCardBrand = cardNumber => {
isin
->String.replaceRegExp(%re("/[^\d]/g"), "")
->String.substring(~start=0, ~end=6)
->Belt.Int.fromString
->Int.fromString
->Option.getOr(0)

let range = cardRanges->Array.map(cardRange => {
Expand Down Expand Up @@ -317,12 +317,11 @@ let calculateLuhn = value => {
->Array.map(item => {
let val = item->toInt
let double = val * 2
let str = double->Belt.Int.toString
let str = double->Int.toString
let arr = str->String.split("")

switch (arr[0], arr[1]) {
| (Some(first), Some(second)) if double > 9 =>
(first->toInt + second->toInt)->Belt.Int.toString
| (Some(first), Some(second)) if double > 9 => (first->toInt + second->toInt)->Int.toString
| _ => str
}
})
Expand Down
6 changes: 3 additions & 3 deletions src/Components/AccordionContainer.res
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Loader = {
: ""
<div
className={`AccordionItem flex flex-row gap-3 animate-pulse cursor-default place-items-center`}
key={i->Belt.Int.toString}
key={i->Int.toString}
style={
minWidth: "80px",
minHeight: "60px",
Expand Down Expand Up @@ -131,7 +131,7 @@ let make = (~paymentOptions: array<string>, ~checkoutEle: React.element) => {
let isActive = payOption.paymentMethodName == selectedOption
let borderRadiusStyle = getBorderRadiusStyleForCardOptionDetails(i)
<Accordion
key={i->Belt.Int.toString}
key={i->Int.toString}
paymentOption=payOption
isActive
checkoutEle
Expand All @@ -149,7 +149,7 @@ let make = (~paymentOptions: array<string>, ~checkoutEle: React.element) => {
let isActive = payOption.paymentMethodName == selectedOption
let borderRadiusStyle = getBorderRadiusStyleForDropDownOptionDetails(i)
<Accordion
key={i->Belt.Int.toString}
key={i->Int.toString}
paymentOption=payOption
isActive
checkoutEle
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Loader.res
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ let make = (~showText=true) => {
size=52
style={
animation: "slowShow 1.5s ease-in-out infinite",
animationDelay: {((i + 1) * 180)->Belt.Int.toString ++ "ms"},
animationDelay: {((i + 1) * 180)->Int.toString ++ "ms"},
}
name=item
key={i->Belt.Int.toString}
key={i->Int.toString}
/>
})
->React.array}
Expand Down
2 changes: 1 addition & 1 deletion src/Components/SavedMethods.res
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ let make = (
}
let isActive = paymentTokenVal == obj.paymentToken
<SavedCardItem
key={i->Belt.Int.toString}
key={i->Int.toString}
setPaymentToken
isActive
paymentItem=obj
Expand Down
2 changes: 1 addition & 1 deletion src/Components/SurchargeUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ let useOneClickWalletsMessageGetter = (~paymentMethodListValue) => {
</>
let msgToConcat = if index === 0 {
myMsg
} else if index === oneClickWalletsArr->Belt.Array.length - 1 {
} else if index === oneClickWalletsArr->Array.length - 1 {
<>
{React.string(`${Utils.nbsp}${localeString.\"and"}${Utils.nbsp}`)}
{myMsg}
Expand Down
4 changes: 2 additions & 2 deletions src/PaymentOptions.res
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module TabLoader = {
->Array.mapWithIndex((_, i) => {
<div
className={`Tab flex flex-col gap-3 animate-pulse cursor-default`}
key={i->Belt.Int.toString}
key={i->Int.toString}
style={
minWidth: "5rem",
overflowWrap: "hidden",
Expand Down Expand Up @@ -118,7 +118,7 @@ let make = (
{cardOptionDetails
->Array.mapWithIndex((payOption, i) => {
let isActive = payOption.paymentMethodName == selectedOption
<TabCard key={i->Belt.Int.toString} paymentOption=payOption isActive />
<TabCard key={i->Int.toString} paymentOption=payOption isActive />
})
->React.array}
<TabLoader cardShimmerCount />
Expand Down
4 changes: 2 additions & 2 deletions src/Payments/ApplePay.res
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,12 @@ let make = (~sessionObj: option<JSON.t>) => {

let billingContact =
dict
->getDictfromDict("applePayBillingContact")
->getDictFromDict("applePayBillingContact")
->ApplePayTypes.billingContactItemToObjMapper

let shippingContact =
dict
->getDictfromDict("applePayShippingContact")
->getDictFromDict("applePayShippingContact")
->ApplePayTypes.shippingContactItemToObjMapper

let requiredFieldsBody = DynamicFieldsUtils.getApplePayRequiredFields(
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/GPay.res
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ let make = (~sessionObj: option<SessionsType.token>, ~thirdPartySessionObj: opti

<RenderIf condition={isRenderGooglePayButton}>
<div
style={height: `${height->Belt.Int.toString}px`}
style={height: `${height->Int.toString}px`}
id="google-pay-button"
className={`w-full flex flex-row justify-center rounded-md`}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/Payments/PayPal.res
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ let make = () => {
style={
display: "inline-block",
color: textColor,
height: `${height->Belt.Int.toString}px`,
height: `${height->Int.toString}px`,
borderRadius: "2px",
width: "100%",
backgroundColor: buttonColor,
Expand Down
4 changes: 2 additions & 2 deletions src/Payments/PaymentRequestButtonElement.res
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ let make = (~sessions, ~walletOptions, ~paymentType) => {
{walletOptions
->Array.mapWithIndex((item, i) => {
<ErrorBoundary
level={ErrorBoundary.RequestButton} key={`${item}-${i->Belt.Int.toString}-request-button`}>
<React.Suspense fallback={<WalletShimmer />} key={i->Belt.Int.toString}>
level={ErrorBoundary.RequestButton} key={`${item}-${i->Int.toString}-request-button`}>
<React.Suspense fallback={<WalletShimmer />} key={i->Int.toString}>
{switch clientSecret {
| Some(_) =>
switch item->paymentMode {
Expand Down
6 changes: 3 additions & 3 deletions src/Payments/PreMountLoader.res
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ let make = (~sessionId, ~publishableKey, ~clientSecret, ~endpoint) => {
| _ => JSON.Encode.null
}
let dict = json->Utils.getDictFromJson
if dict->Dict.get("sendPaymentMethodsResponse")->Belt.Option.isSome {
if dict->Dict.get("sendPaymentMethodsResponse")->Option.isSome {
paymentMethodsResponse->sendPromiseData("payment_methods")
} else if dict->Dict.get("sendCustomerPaymentMethodsResponse")->Belt.Option.isSome {
} else if dict->Dict.get("sendCustomerPaymentMethodsResponse")->Option.isSome {
customerPaymentMethodsResponse->sendPromiseData("customer_payment_methods")
} else if dict->Dict.get("sendSessionTokensResponse")->Belt.Option.isSome {
} else if dict->Dict.get("sendSessionTokensResponse")->Option.isSome {
sessionTokensResponse->sendPromiseData("session_tokens")
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/Payments/QRCodeDisplay.res
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ let make = () => {
Dict.set(headers, x, val->getStringFromJson(""))
})
let expiryTime =
metaDataDict->getString("expiryTime", "")->Belt.Float.fromString->Option.getOr(0.0)
metaDataDict->getString("expiryTime", "")->Float.fromString->Option.getOr(0.0)
let timeExpiry = expiryTime -. Date.now()
if timeExpiry > 0.0 && timeExpiry < 900000.0 {
setExpiryTime(_ => timeExpiry)
Expand Down Expand Up @@ -121,9 +121,8 @@ let make = () => {
}

let expiryString = React.useMemo(() => {
let minutes = (expiryTime /. 60000.0)->Belt.Float.toInt->Belt.Int.toString
let seconds =
mod(expiryTime->Belt.Float.toInt, 60000)->Belt.Int.toString->String.slice(~start=0, ~end=2)
let minutes = (expiryTime /. 60000.0)->Float.toInt->Int.toString
let seconds = mod(expiryTime->Float.toInt, 60000)->Int.toString->String.slice(~start=0, ~end=2)
let seconds = seconds->String.length == 1 ? `${seconds}0` : seconds
`${minutes}:${seconds}`
}, [expiryTime])
Expand Down
2 changes: 1 addition & 1 deletion src/Types/PaymentConfirmTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ let getNextAction = (dict, str) => {
->Option.flatMap(JSON.Decode.object)
->Option.map(json => json->getVoucherDetails)
},
next_action_data: Some(json->getDictfromDict("next_action_data")->JSON.Encode.object),
next_action_data: Some(json->getDictFromDict("next_action_data")->JSON.Encode.object),
}
})
->Option.getOr(defaultNextAction)
Expand Down
4 changes: 2 additions & 2 deletions src/Types/PaymentType.res
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ let getConfirmParams = dict => {
let getSdkHandleConfirmPaymentProps = dict => {
handleConfirm: dict->getBool("handleConfirm", false),
buttonText: ?dict->getOptionString("buttonText"),
confirmParams: dict->getDictfromDict("confirmParams")->getConfirmParams,
confirmParams: dict->getDictFromDict("confirmParams")->getConfirmParams,
}

let itemToObjMapper = (dict, logger) => {
Expand Down Expand Up @@ -1011,7 +1011,7 @@ let itemToObjMapper = (dict, logger) => {
showCardFormByDefault: getBool(dict, "showCardFormByDefault", true),
billingAddress: getBillingAddress(dict, "billingAddress", logger),
sdkHandleConfirmPayment: dict
->getDictfromDict("sdkHandleConfirmPayment")
->getDictFromDict("sdkHandleConfirmPayment")
->getSdkHandleConfirmPaymentProps,
paymentMethodsHeaderText: ?getOptionString(dict, "paymentMethodsHeaderText"),
savedPaymentMethodsHeaderText: ?getOptionString(dict, "savedPaymentMethodsHeaderText"),
Expand Down
8 changes: 4 additions & 4 deletions src/Types/PaypalSDKTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ let getShippingDetails = shippingAddressOverrideObj => {
}

let paypalShippingDetails = purchaseUnit => {
let shippingAddress = purchaseUnit->Utils.getDictfromDict("shipping")
let payee = purchaseUnit->Utils.getDictfromDict("payee")
let shippingAddress = purchaseUnit->Utils.getDictFromDict("shipping")
let payee = purchaseUnit->Utils.getDictFromDict("payee")

let address = shippingAddress->Utils.getDictfromDict("address")
let name = shippingAddress->Utils.getDictfromDict("name")
let address = shippingAddress->Utils.getDictFromDict("address")
let name = shippingAddress->Utils.getDictFromDict("name")

let recipientName = name->Utils.getOptionString("full_name")
let line1 = address->Utils.getOptionString("address_line_1")
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/ErrorUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ let unknownPropValueWarning = (
let valueOutRangeWarning = (num: int, dictType, range, ~logger: OrcaLogger.loggerMake) => {
manageErrorWarning(
VALUE_OUT_OF_RANGE,
~dynamicStr=`${num->Belt.Int.toString} value in ${dictType} Expected value between ${range}`,
~dynamicStr=`${num->Int.toString} value in ${dictType} Expected value between ${range}`,
~logger: OrcaLogger.loggerMake,
(),
)
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/PaymentHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ let rec intentCall = (
("paymentIntentId", clientSecret->JSON.Encode.string),
("publishableKey", confirmParam.publishableKey->JSON.Encode.string),
("headers", headerObj->JSON.Encode.object),
("expiryTime", expiryTime->Belt.Float.toString->JSON.Encode.string),
("expiryTime", expiryTime->Float.toString->JSON.Encode.string),
("url", url.href->JSON.Encode.string),
]->Dict.fromArray
handleLogging(
Expand Down
16 changes: 8 additions & 8 deletions src/Utilities/Utils.res
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ let getInt = (dict, key, default: int) => {
dict
->Dict.get(key)
->Option.flatMap(JSON.Decode.float)
->Option.getOr(default->Belt.Int.toFloat)
->Belt.Float.toInt
->Option.getOr(default->Int.toFloat)
->Float.toInt
}

let getFloatFromString = (str, default) => str->Float.fromString->Option.getOr(default)
Expand Down Expand Up @@ -148,7 +148,7 @@ let getDictFromJson = (json: JSON.t) => {
json->JSON.Decode.object->Option.getOr(Dict.make())
}

let getDictfromDict = (dict, key) => {
let getDictFromDict = (dict, key) => {
dict->getJsonObjectFromDict(key)->getDictFromJson
}

Expand All @@ -172,7 +172,7 @@ let getNumberWithWarning = (dict, key, ~logger, default) => {
switch dict->Dict.get(key) {
| Some(val) =>
switch val->JSON.Decode.float {
| Some(val) => val->Belt.Float.toInt
| Some(val) => val->Float.toInt
| None =>
manageErrorWarning(TYPE_INT_ERROR, ~dynamicStr=key, ~logger, ())
default
Expand Down Expand Up @@ -361,7 +361,7 @@ let rec transformKeys = (json: JSON.t, to: case) => {
}
(key->toCase, val->JSON.Encode.string)
}
| Number(val) => (key->toCase, val->Belt.Float.toString->JSON.Encode.string)
| Number(val) => (key->toCase, val->Float.toString->JSON.Encode.string)
| _ => (key->toCase, value)
}
x
Expand Down Expand Up @@ -631,14 +631,14 @@ let addSize = (str: string, value: float, unit: sizeunit) => {
arr
->Array.slice(~start=0, ~end={arr->Array.length - unitInString->String.length})
->Array.joinWith("")
->Belt.Float.fromString
->Float.fromString
->Option.getOr(0.0)
(val +. value)->Belt.Float.toString ++ unitInString
(val +. value)->Float.toString ++ unitInString
} else {
str
}
}
let toInt = val => val->Belt.Int.fromString->Option.getOr(0)
let toInt = val => val->Int.fromString->Option.getOr(0)

let validateRountingNumber = str => {
if str->String.length != 9 {
Expand Down
Loading
Loading