From 2424b8dba1a40b0f51f497514fe67c527e70b523 Mon Sep 17 00:00:00 2001 From: saksham Date: Tue, 16 Jul 2024 21:35:39 +0530 Subject: [PATCH] feat: language preference for mifinity added --- src/App.res | 4 +++- src/CardTheme.res | 2 +- src/Components/DynamicFields.res | 2 ++ src/LoaderController.res | 2 +- src/Payments/CardPayment.res | 2 +- src/Payments/PaymentMethodsRecord.res | 25 +++++++++++++++---------- src/Types/CardThemeType.res | 1 - src/Utilities/DynamicFieldsUtils.res | 8 ++++++++ src/Window.res | 3 +++ 9 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/App.res b/src/App.res index 0d2cbcc0a..67a787786 100644 --- a/src/App.res +++ b/src/App.res @@ -51,7 +51,9 @@ let make = () => { "hyperComponentName", )->Types.getHyperComponentNameFromStr - + } | "achBankTransfer" | "bacsBankTransfer" diff --git a/src/CardTheme.res b/src/CardTheme.res index 771a0a826..093d67adf 100644 --- a/src/CardTheme.res +++ b/src/CardTheme.res @@ -72,7 +72,7 @@ type recoilConfig = { let getLocaleObject = async string => { try { let locale = if string == "auto" { - navigator["language"] + Window.language } else { string } diff --git a/src/Components/DynamicFields.res b/src/Components/DynamicFields.res index 0d01e58d8..df8d89d3e 100644 --- a/src/Components/DynamicFields.res +++ b/src/Components/DynamicFields.res @@ -483,6 +483,7 @@ let make = ( | ShippingAddressPincode | ShippingAddressState | PhoneCountryCode + | LanguagePreference(_) | ShippingAddressCountry(_) => React.null }} @@ -767,6 +768,7 @@ let make = ( | DateOfBirth | PhoneCountryCode | VpaId + | LanguagePreference(_) | None => React.null }} diff --git a/src/LoaderController.res b/src/LoaderController.res index fcf2fa5af..05ccc78f0 100644 --- a/src/LoaderController.res +++ b/src/LoaderController.res @@ -123,7 +123,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime setConfig(_ => { config: { appearance, - locale: config.locale, + locale: config.locale === "auto" ? Window.language : config.locale, fonts: config.fonts, clientSecret: config.clientSecret, ephemeralKey: config.ephemeralKey, diff --git a/src/Payments/CardPayment.res b/src/Payments/CardPayment.res index e3e7b3191..9d4934d06 100644 --- a/src/Payments/CardPayment.res +++ b/src/Payments/CardPayment.res @@ -208,7 +208,7 @@ let make = ( isCustomerAcceptanceRequired, nickname, isCardBrandValid, - isManualRetryEnabled + isManualRetryEnabled, )) useSubmitPaymentData(submitCallback) diff --git a/src/Payments/PaymentMethodsRecord.res b/src/Payments/PaymentMethodsRecord.res index 38aba1c0a..afedb52cd 100644 --- a/src/Payments/PaymentMethodsRecord.res +++ b/src/Payments/PaymentMethodsRecord.res @@ -1,3 +1,5 @@ +open Utils + type paymentFlow = InvokeSDK | RedirectToURL | QrFlow type paymentFlowWithConnector = array<(paymentFlow, array)> @@ -38,6 +40,7 @@ type paymentMethodsFields = | CryptoCurrencyNetworks | DateOfBirth | VpaId + | LanguagePreference(array) let getPaymentMethodsFieldsOrder = paymentMethodField => { switch paymentMethodField { @@ -574,7 +577,7 @@ let getPaymentMethodsFieldTypeFromString = (str, isBancontact) => { } let getOptionsFromPaymentMethodFieldType = (dict, key, ~isAddressCountry=true) => { - let options = dict->Utils.getArrayValFromJsonDict(key, "options") + let options = dict->getArrayValFromJsonDict(key, "options") switch options->Array.get(0)->Option.getOr("") { | "" => None | "ALL" => { @@ -598,7 +601,7 @@ let getPaymentMethodsFieldTypeFromDict = dict => { let key = keysArr->Array.get(0)->Option.getOr("") switch key { | "user_currency" => { - let options = dict->Utils.getArrayValFromJsonDict("user_currency", "options") + let options = dict->getArrayValFromJsonDict("user_currency", "options") Currency(options) } | "user_country" => dict->getOptionsFromPaymentMethodFieldType("user_country") @@ -608,6 +611,10 @@ let getPaymentMethodsFieldTypeFromDict = dict => { "user_shipping_address_country", ~isAddressCountry=false, ) + | "language_preference" => { + let options = dict->getArrayValFromJsonDict("language_preference", "options") + LanguagePreference(options) + } | _ => None } } @@ -788,8 +795,6 @@ type paymentMethodList = { merchant_name: string, } -open Utils - let defaultPaymentMethodType = { payment_method_type: "", payment_experience: [], @@ -913,17 +918,17 @@ let getAchConnectors = (dict, str) => { let getDynamicFieldsFromJsonDict = (dict, isBancontact) => { let requiredFields = - Utils.getJsonFromDict(dict, "required_fields", JSON.Encode.null) - ->Utils.getDictFromJson + getJsonFromDict(dict, "required_fields", JSON.Encode.null) + ->getDictFromJson ->Dict.valuesToArray requiredFields->Array.map(requiredField => { - let requiredFieldsDict = requiredField->Utils.getDictFromJson + let requiredFieldsDict = requiredField->getDictFromJson { - required_field: requiredFieldsDict->Utils.getString("required_field", ""), - display_name: requiredFieldsDict->Utils.getString("display_name", ""), + required_field: requiredFieldsDict->getString("required_field", ""), + display_name: requiredFieldsDict->getString("display_name", ""), field_type: requiredFieldsDict->getFieldType(isBancontact), - value: requiredFieldsDict->Utils.getString("value", ""), + value: requiredFieldsDict->getString("value", ""), } }) } diff --git a/src/Types/CardThemeType.res b/src/Types/CardThemeType.res index ed526c19f..3db3322ed 100644 --- a/src/Types/CardThemeType.res +++ b/src/Types/CardThemeType.res @@ -2,7 +2,6 @@ type theme = Default | Brutal | Midnight | Soft | Charcoal | NONE type innerLayout = Spaced | Compressed -@val external navigator: 'a = "navigator" type showLoader = Auto | Always | Never type mode = diff --git a/src/Utilities/DynamicFieldsUtils.res b/src/Utilities/DynamicFieldsUtils.res index 16f5fe252..dec0ad117 100644 --- a/src/Utilities/DynamicFieldsUtils.res +++ b/src/Utilities/DynamicFieldsUtils.res @@ -400,6 +400,7 @@ let useSetInitialRequiredFields = ( } | None => () } + | LanguagePreference(_) | SpecialField(_) | InfoElement | CardNumber @@ -433,6 +434,7 @@ let useRequiredFieldsBody = ( ~isAllStoredCardsHaveName, ~setRequiredFieldsBody, ) => { + let configValue = Recoil.useRecoilValueFromAtom(configAtom) let email = Recoil.useRecoilValueFromAtom(userEmailAddress) let vpaId = Recoil.useRecoilValueFromAtom(userVpaId) let fullName = Recoil.useRecoilValueFromAtom(userFullName) @@ -464,6 +466,12 @@ let useRequiredFieldsBody = ( | PhoneCountryCode => phone.countryCode->Option.getOr("") | Currency(_) => currency | Country => country + | LanguagePreference(languageOptions) => + languageOptions->Array.includes( + configValue.config.locale->String.toUpperCase->String.split("-")->Array.joinWith("_"), + ) + ? configValue.config.locale + : "en" | Bank => ( Bank.getBanks(paymentMethodType) diff --git a/src/Window.res b/src/Window.res index 6224f3e33..4813fedac 100644 --- a/src/Window.res +++ b/src/Window.res @@ -118,6 +118,9 @@ external userAgent: string = "userAgent" @val @scope("navigator") external sendBeacon: (string, string) => unit = "sendBeacon" +@val @scope("navigator") +external language: string = "language" + @val @scope(("window", "location")) external hostname: string = "hostname"