Skip to content

Commit

Permalink
refactor: rescript core changes json, dict, string, nullable & array (#…
Browse files Browse the repository at this point in the history
…212)

Co-authored-by: Shiva Nandan <shiva.nandan@juspay.in>
  • Loading branch information
Pritish Budhiraja and seekshiva committed Mar 14, 2024
1 parent e5ce5ae commit fb53bf2
Show file tree
Hide file tree
Showing 110 changed files with 2,934 additions and 3,243 deletions.
302 changes: 150 additions & 152 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/App.res
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let make = () => {
let sessionId = CardUtils.getQueryParamsDictforKey(url.search, "sessionId")
let publishableKey = CardUtils.getQueryParamsDictforKey(url.search, "publishableKey")
let endpoint =
CardUtils.getQueryParamsDictforKey(url.search, "endpoint")->Js.Global.decodeURIComponent
CardUtils.getQueryParamsDictforKey(url.search, "endpoint")->decodeURIComponent
<PreMountLoader publishableKey sessionId clientSecret endpoint />
}
| "achBankTransfer"
Expand Down
26 changes: 13 additions & 13 deletions src/BrowserSpec.res
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ type screen = {colorDepth: int, height: int, width: int}

let checkIsSafari = () => {
let userAgentString = navigator.userAgent
let chromeAgent = userAgentString->Js.String2.indexOf("Chrome") > -1
let safariAgent = userAgentString->Js.String2.indexOf("Safari") > -1
let chromeAgent = userAgentString->String.indexOf("Chrome") > -1
let safariAgent = userAgentString->String.indexOf("Safari") > -1
chromeAgent && safariAgent ? false : safariAgent ? true : false
}

Expand All @@ -23,20 +23,20 @@ let broswerInfo = () => [
(
"browser_info",
[
("user_agent", navigator.userAgent->Js.Json.string),
("user_agent", navigator.userAgent->JSON.Encode.string),
(
"accept_header",
"text\/html,application\/xhtml+xml,application\/xml;q=0.9,image\/webp,image\/apng,*\/*;q=0.8"->Js.Json.string,
"text\/html,application\/xhtml+xml,application\/xml;q=0.9,image\/webp,image\/apng,*\/*;q=0.8"->JSON.Encode.string,
),
("language", navigator.language->Js.Json.string),
("color_depth", screen.colorDepth->Belt.Int.toFloat->Js.Json.number),
("screen_height", screen.height->Belt.Int.toFloat->Js.Json.number),
("screen_width", screen.width->Belt.Int.toFloat->Js.Json.number),
("time_zone", date.getTimezoneOffset(.)->Js.Json.number),
("java_enabled", true->Js.Json.boolean),
("java_script_enabled", true->Js.Json.boolean),
("language", navigator.language->JSON.Encode.string),
("color_depth", screen.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),
("time_zone", date.getTimezoneOffset(.)->JSON.Encode.float),
("java_enabled", true->JSON.Encode.bool),
("java_script_enabled", true->JSON.Encode.bool),
]
->Js.Dict.fromArray
->Js.Json.object_,
->Dict.fromArray
->JSON.Encode.object,
),
]
2 changes: 1 addition & 1 deletion src/CardPattern.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type patterns = {
issuer: string,
pattern: Js.Re.t,
pattern: Re.t,
cvcLength: array<int>,
length: array<int>,
maxCVCLenth: int,
Expand Down
38 changes: 19 additions & 19 deletions src/CardTheme.res
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ let defaultAppearance = {
variables: DefaultTheme.default,
componentType: "payment",
labels: Above,
rules: Js.Dict.empty()->Js.Json.object_,
rules: Dict.make()->JSON.Encode.object,
}
let defaultFonts = {
cssSrc: "",
Expand Down Expand Up @@ -76,9 +76,9 @@ let getLocaleObject = string => {
string
}
LocaleString.localeStrings
->Js.Array2.filter(item => item.locale == val)
->Belt.Array.get(0)
->Belt.Option.getWithDefault(LocaleString.defaultLocale)
->Array.filter(item => item.locale == val)
->Array.get(0)
->Option.getOr(LocaleString.defaultLocale)
}
let defaultRecoilConfig: recoilConfig = {
config: defaultConfig,
Expand All @@ -89,9 +89,9 @@ let defaultRecoilConfig: recoilConfig = {

let getVariables = (str, dict, default, logger) => {
dict
->Js.Dict.get(str)
->Belt.Option.flatMap(Js.Json.decodeObject)
->Belt.Option.map(json => {
->Dict.get(str)
->Option.flatMap(JSON.Decode.object)
->Option.map(json => {
let validKeys = [
"fontFamily",
"fontSizeBase",
Expand Down Expand Up @@ -287,20 +287,20 @@ let getVariables = (str, dict, default, logger) => {
),
}
})
->Belt.Option.getWithDefault(default)
->Option.getOr(default)
}

let getAppearance = (
str,
dict,
default: OrcaPaymentPage.CardThemeType.themeClass,
defaultRules: OrcaPaymentPage.CardThemeType.themeClass => Js.Json.t,
defaultRules: OrcaPaymentPage.CardThemeType.themeClass => JSON.t,
logger,
) => {
dict
->Js.Dict.get(str)
->Belt.Option.flatMap(Js.Json.decodeObject)
->Belt.Option.map(json => {
->Dict.get(str)
->Option.flatMap(JSON.Decode.object)
->Option.map(json => {
unknownKeysWarning(["theme", "variables", "rules", "labels"], json, "appearance", ~logger)

let rulesJson = defaultRules(getVariables("variables", json, default, logger))
Expand All @@ -321,15 +321,15 @@ let getAppearance = (
},
}
})
->Belt.Option.getWithDefault(defaultAppearance)
->Option.getOr(defaultAppearance)
}
let getFonts = (str, dict, logger) => {
dict
->Js.Dict.get(str)
->Belt.Option.flatMap(Js.Json.decodeArray)
->Belt.Option.getWithDefault([])
->Belt.Array.keepMap(Js.Json.decodeObject)
->Js.Array2.map(json => {
->Dict.get(str)
->Option.flatMap(JSON.Decode.array)
->Option.getOr([])
->Belt.Array.keepMap(JSON.Decode.object)
->Array.map(json => {
unknownKeysWarning(["cssSrc", "family", "src", "weight"], json, "fonts", ~logger)
{
cssSrc: getWarningString(json, "cssSrc", "", ~logger),
Expand All @@ -342,7 +342,7 @@ let getFonts = (str, dict, logger) => {
let itemToObjMapper = (
dict,
default: OrcaPaymentPage.CardThemeType.themeClass,
defaultRules: OrcaPaymentPage.CardThemeType.themeClass => Js.Json.t,
defaultRules: OrcaPaymentPage.CardThemeType.themeClass => JSON.t,
logger,
) => {
unknownKeysWarning(
Expand Down
Loading

0 comments on commit fb53bf2

Please sign in to comment.