Skip to content

Commit

Permalink
feat: crypto currency network added (#403)
Browse files Browse the repository at this point in the history
Co-authored-by: Pritish Budhiraja <[email protected]>
  • Loading branch information
PritishBudhiraja and Pritish Budhiraja authored Jun 11, 2024
1 parent 78ba856 commit 24f7297
Show file tree
Hide file tree
Showing 26 changed files with 109 additions and 54 deletions.
41 changes: 41 additions & 0 deletions src/Components/CryptoCurrencyNetworks.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
@react.component
let make = () => {
open DropdownField
let currencyVal = Recoil.useRecoilValueFromAtom(RecoilAtoms.userCurrency)
let {config, localeString} = Recoil.useRecoilValueFromAtom(RecoilAtoms.configAtom)
let (cryptoCurrencyNetworks, setCryptoCurrencyNetworks) = Recoil.useRecoilState(
RecoilAtoms.cryptoCurrencyNetworks,
)

let dropdownOptions =
Utils.currencyNetworksDict
->Dict.get(currencyVal)
->Option.getOr([])
->Array.map(item => {
label: Utils.toSpacedUpperCase(~str=item, ~delimiter="_"),
value: item,
})

let initialValue = (
dropdownOptions
->Array.get(0)
->Option.getOr({
label: "",
value: "",
})
).value

React.useEffect(() => {
setCryptoCurrencyNetworks(_ => initialValue)
None
}, [initialValue])

<DropdownField
appearance=config.appearance
fieldName=localeString.currencyNetwork
value=cryptoCurrencyNetworks
setValue=setCryptoCurrencyNetworks
disabled=false
options=dropdownOptions
/>
}
3 changes: 2 additions & 1 deletion src/Components/DynamicFields.res
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ let make = (
key={`outside-billing-${index->Int.toString}`}
className="flex flex-col w-full place-content-between"
style={
marginTop: index !== 0 || paymentMethod === "card" ? themeObj.spacingGridColumn : "",
gridColumnGap: themeObj.spacingGridRow,
}>
{switch item {
Expand Down Expand Up @@ -457,6 +456,7 @@ let make = (
optionalRequiredFields={Some(requiredFields)}
/>
</>
| CryptoCurrencyNetworks => <CryptoCurrencyNetworks />
| Email
| InfoElement
| Country
Expand Down Expand Up @@ -760,6 +760,7 @@ let make = (
| ShippingAddressPincode
| ShippingAddressState
| ShippingAddressCountry(_)
| CryptoCurrencyNetworks
| None => React.null
}}
</div>
Expand Down
1 change: 1 addition & 0 deletions src/LocaleStrings/ArabicLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@ let localeStrings: LocaleStringTypes.localeStrings = {
cardExpiredText: `انتهت صلاحية هذه البطاقة`,
cardHeader: `معلومات البطاقة`,
cardBrandConfiguredErrorText: str => `${str} غير مدعوم في الوقت الحالي.`,
currencyNetwork: `شبكات العملات`,
}
1 change: 1 addition & 0 deletions src/LocaleStrings/CatalanLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@ let localeStrings: LocaleStringTypes.localeStrings = {
cardExpiredText: `Aquesta targeta ha caducat`,
cardHeader: `Informació de la targeta`,
cardBrandConfiguredErrorText: str => `${str} no està suportat en aquest moment.`,
currencyNetwork: `Xarxes de Monedes`,
}
1 change: 1 addition & 0 deletions src/LocaleStrings/DeutschLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@ let localeStrings: LocaleStringTypes.localeStrings = {
cardExpiredText: `Diese Karte ist abgelaufen`,
cardHeader: `Kartendaten`,
cardBrandConfiguredErrorText: str => `${str} wird derzeit nicht unterstützt.`,
currencyNetwork: `Währungsnetzwerke`,
}
1 change: 1 addition & 0 deletions src/LocaleStrings/DutchLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@ let localeStrings: LocaleStringTypes.localeStrings = {
cardExpiredText: `Deze kaart is verlopen`,
cardHeader: `Kaartinformatie`,
cardBrandConfiguredErrorText: str => `${str} wordt op dit moment niet ondersteund.`,
currencyNetwork: `Valutanetwerken`,
}
1 change: 1 addition & 0 deletions src/LocaleStrings/EnglishGBLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@ let localeStrings: LocaleStringTypes.localeStrings = {
cardExpiredText: `This card has expired`,
cardHeader: `Card information`,
cardBrandConfiguredErrorText: str => `${str} is not supported at the moment.`,
currencyNetwork: `Currency Networks`,
}
1 change: 1 addition & 0 deletions src/LocaleStrings/EnglishLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@ let localeStrings: LocaleStringTypes.localeStrings = {
cardExpiredText: `This card has expired`,
cardHeader: `Card information`,
cardBrandConfiguredErrorText: str => `${str} is not supported at the moment.`,
currencyNetwork: `Currency Networks`,
}
1 change: 1 addition & 0 deletions src/LocaleStrings/FrenchBelgiumLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@ let localeStrings: LocaleStringTypes.localeStrings = {
cardExpiredText: `Cette carte a expiré`,
cardHeader: `Informations de carte`,
cardBrandConfiguredErrorText: str => `${str} n'est pas pris en charge pour le moment.`,
currencyNetwork: `Réseaux Monétaires`,
}
1 change: 1 addition & 0 deletions src/LocaleStrings/FrenchLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@ let localeStrings: LocaleStringTypes.localeStrings = {
cardExpiredText: `Cette carte a expiré`,
cardHeader: `Informations de carte`,
cardBrandConfiguredErrorText: str => `${str} n'est pas pris en charge pour le moment.`,
currencyNetwork: `Réseaux Monétaires`,
}
1 change: 1 addition & 0 deletions src/LocaleStrings/HebrewLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@ let localeStrings: LocaleStringTypes.localeStrings = {
cardExpiredText: `הכרטיס הזה פג תוקף`,
cardHeader: `מידע כרטיס`,
cardBrandConfiguredErrorText: str => `${str} לא נתמך כרגע.`,
currencyNetwork: `רשתות מטבעות`,
}
1 change: 1 addition & 0 deletions src/LocaleStrings/ItalianLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@ let localeStrings: LocaleStringTypes.localeStrings = {
cardExpiredText: `Questa carta è scaduta`,
cardHeader: `Informazioni sulla carta`,
cardBrandConfiguredErrorText: str => `${str} non è supportato al momento.`,
currencyNetwork: `Reti Valutarie`,
}
1 change: 1 addition & 0 deletions src/LocaleStrings/JapaneseLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@ let localeStrings: LocaleStringTypes.localeStrings = {
cardExpiredText: `このカードは期限切れです`,
cardHeader: `カード情報`,
cardBrandConfiguredErrorText: str => `${str} は現在サポートされていません。`,
currencyNetwork: `通貨ネットワーク`,
}
1 change: 1 addition & 0 deletions src/LocaleStrings/LocaleStringTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,5 @@ type localeStrings = {
cardExpiredText: string,
cardHeader: string,
cardBrandConfiguredErrorText: string => string,
currencyNetwork: string,
}
1 change: 1 addition & 0 deletions src/LocaleStrings/PolishLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@ let localeStrings: LocaleStringTypes.localeStrings = {
cardExpiredText: `Ta karta wygasła`,
cardHeader: `Informacje o karcie`,
cardBrandConfiguredErrorText: str => `${str} nie jest obecnie obsługiwany.`,
currencyNetwork: `Sieci Walutowe`,
}
1 change: 1 addition & 0 deletions src/LocaleStrings/PortugueseLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@ let localeStrings: LocaleStringTypes.localeStrings = {
cardExpiredText: `Este cartão expirou`,
cardHeader: `Informações do cartão`,
cardBrandConfiguredErrorText: str => `${str} não é suportado no momento.`,
currencyNetwork: `Redes de Moeda`,
}
1 change: 1 addition & 0 deletions src/LocaleStrings/RussianLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,5 @@ let localeStrings: LocaleStringTypes.localeStrings = {
cardHeader: `Информация о карте`,
cardBrandConfiguredErrorText: str =>
`${str} в данный момент не поддерживается.`,
currencyNetwork: `Валютные сети`,
}
1 change: 1 addition & 0 deletions src/LocaleStrings/SpanishLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@ let localeStrings: LocaleStringTypes.localeStrings = {
cardExpiredText: `Esta tarjeta ha caducado`,
cardHeader: `Información de la tarjeta`,
cardBrandConfiguredErrorText: str => `${str} no está soportado en este momento.`,
currencyNetwork: `Redes de Divisas`,
}
1 change: 1 addition & 0 deletions src/LocaleStrings/SwedishLocale.res
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@ let localeStrings: LocaleStringTypes.localeStrings = {
cardExpiredText: `Detta kort har gått ut`,
cardHeader: `Kortinformation`,
cardBrandConfiguredErrorText: str => `${str} stöds inte för tillfället.`,
currencyNetwork: `Valutanätverk`,
}
5 changes: 1 addition & 4 deletions src/Payments/CardPayment.res
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ let make = (
<div className="animate-slowShow">
<RenderIf condition={showFields || isBancontact}>
<div className="flex flex-col" style={gridGap: themeObj.spacingGridColumn}>
<div className="w-full">
<div className="flex flex-col w-full" style={gridGap: themeObj.spacingGridColumn}>
<RenderIf condition={innerLayout === Compressed}>
<div
style={
Expand Down Expand Up @@ -263,9 +263,6 @@ let make = (
<div
className="flex flex-row w-full place-content-between"
style={
marginTop: {
innerLayout === Spaced ? themeObj.spacingGridColumn : ""
},
gridColumnGap: {innerLayout === Spaced ? themeObj.spacingGridRow : ""},
}>
<div className={innerLayout === Spaced ? "w-[45%]" : "w-[50%]"}>
Expand Down
44 changes: 5 additions & 39 deletions src/Payments/PaymentMethodsRecord.res
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type paymentMethodsFields =
| ShippingAddressPincode
| ShippingAddressState
| ShippingAddressCountry(array<string>)
| CryptoCurrencyNetworks

let getPaymentMethodsFieldsOrder = paymentMethodField => {
switch paymentMethodField {
Expand All @@ -47,10 +48,11 @@ let getPaymentMethodsFieldsOrder = paymentMethodField => {
| AddressLine2 => 5
| AddressCity => 6
| AddressState => 7
| AddressCountry(_) => 8
| AddressPincode => 9
| StateAndCity => 7
| AddressCountry(_) => 8
| CountryAndPincode(_) => 8
| AddressPincode => 9
| CryptoCurrencyNetworks => 10
| InfoElement => 99
| _ => 3
}
Expand Down Expand Up @@ -546,6 +548,7 @@ let getPaymentMethodsFieldTypeFromString = (str, isBancontact) => {
| ("user_shipping_address_city", _) => ShippingAddressCity
| ("user_shipping_address_pincode", _) => ShippingAddressPincode
| ("user_shipping_address_state", _) => ShippingAddressState
| ("user_crypto_currency_network", _) => CryptoCurrencyNetworks
| _ => None
}
}
Expand Down Expand Up @@ -1061,40 +1064,3 @@ let getCardNetwork = (~paymentMethodType, ~cardBrand) => {
->Array.get(0)
->Option.getOr(defaultCardNetworks)
}

let paymentMethodFieldToStrMapper = (field: paymentMethodsFields) => {
switch field {
| Email => "Email"
| FullName => "FullName"
| InfoElement => "InfoElement"
| Country => "Country"
| Bank => "Bank"
| SpecialField(_) => "SpecialField"
| None => "None"
| BillingName => "BillingName"
| PhoneNumber => "PhoneNumber"
| AddressLine1 => "AddressLine1"
| AddressLine2 => "AddressLine2"
| AddressCity => "AddressCity"
| StateAndCity => "StateAndCity"
| CountryAndPincode(_) => "CountryAndPincode"
| AddressPincode => "AddressPincode"
| AddressState => "AddressState"
| AddressCountry(_) => "AddressCountry"
| BlikCode => "BlikCode"
| Currency(_) => "Currency"
| CardNumber => "CardNumber"
| CardExpiryMonth => "CardExpiryMonth"
| CardExpiryYear => "CardExpiryYear"
| CardExpiryMonthAndYear => "CardExpiryMonthAndYear"
| CardCvc => "CardCvc"
| CardExpiryAndCvc => "CardExpiryAndCvc"
| ShippingName => "ShippingName"
| ShippingAddressLine1 => "ShippingAddressLine1"
| ShippingAddressLine2 => "ShippingAddressLine2"
| ShippingAddressCity => "ShippingAddressCity"
| ShippingAddressPincode => "ShippingAddressPincode"
| ShippingAddressState => "ShippingAddressState"
| ShippingAddressCountry(_) => "ShippingAddressCountry"
}
}
1 change: 0 additions & 1 deletion src/Payments/PaymentMethodsWrapper.res
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ let make = (~paymentType: CardThemeType.mode, ~paymentMethodName: string) => {
phoneNumber.countryCode->Option.getOr("") ++ phoneNumber.value,
),
~paymentExperience=paymentFlow,
~currency,
)
->Dict.fromArray
->JSON.Encode.object
Expand Down
14 changes: 14 additions & 0 deletions src/Utilities/DynamicFieldsUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ let useRequiredFieldsEmptyAndValid = (
let setAreRequiredFieldsValid = Recoil.useSetRecoilState(areRequiredFieldsValid)
let setAreRequiredFieldsEmpty = Recoil.useSetRecoilState(areRequiredFieldsEmpty)
let {billingAddress} = Recoil.useRecoilValueFromAtom(optionAtom)
let cryptoCurrencyNetworks = Recoil.useRecoilValueFromAtom(cryptoCurrencyNetworks)

let fieldsArrWithBillingAddress = fieldsArr->addBillingAddressIfUseBillingAddress(billingAddress)

Expand All @@ -149,6 +150,7 @@ let useRequiredFieldsEmptyAndValid = (
| AddressPincode => postalCode.value !== ""
| AddressState => state.value !== ""
| BlikCode => blikCode.value !== ""
| CryptoCurrencyNetworks => cryptoCurrencyNetworks !== ""
| Currency(currencyArr) => currency !== "" || currencyArr->Array.length === 0
| CardNumber => isCardValid->Option.getOr(false)
| CardExpiryMonth
Expand Down Expand Up @@ -185,6 +187,7 @@ let useRequiredFieldsEmptyAndValid = (
| AddressPincode => postalCode.value === ""
| AddressState => state.value === ""
| BlikCode => blikCode.value === ""
| CryptoCurrencyNetworks => cryptoCurrencyNetworks === ""
| Currency(currencyArr) => currency === "" && currencyArr->Array.length > 0
| CardNumber => cardNumber === ""
| CardExpiryMonth =>
Expand Down Expand Up @@ -261,6 +264,9 @@ let useSetInitialRequiredFields = (
logger,
)
let (currency, setCurrency) = Recoil.useLoggedRecoilState(userCurrency, "currency", logger)
let (cryptoCurrencyNetworks, setCryptoCurrencyNetworks) = Recoil.useRecoilState(
cryptoCurrencyNetworks,
)

React.useEffect(() => {
let getNameValue = (item: PaymentMethodsRecord.required_fields) => {
Expand Down Expand Up @@ -353,6 +359,10 @@ let useSetInitialRequiredFields = (
if value !== "" && selectedBank === "" {
setSelectedBank(_ => value)
}
| CryptoCurrencyNetworks =>
if value !== "" && cryptoCurrencyNetworks === "" {
setCryptoCurrencyNetworks(_ => value)
}
| SpecialField(_)
| InfoElement
| CardNumber
Expand Down Expand Up @@ -399,6 +409,7 @@ let useRequiredFieldsBody = (
let selectedBank = Recoil.useRecoilValueFromAtom(userBank)
let currency = Recoil.useRecoilValueFromAtom(userCurrency)
let {billingAddress} = Recoil.useRecoilValueFromAtom(optionAtom)
let cryptoCurrencyNetworks = Recoil.useRecoilValueFromAtom(cryptoCurrencyNetworks)

let getFieldValueFromFieldType = (fieldType: PaymentMethodsRecord.paymentMethodsFields) => {
switch fieldType {
Expand Down Expand Up @@ -434,6 +445,7 @@ let useRequiredFieldsBody = (
| CardExpiryYear =>
let (_, year) = CardUtils.getExpiryDates(cardExpiry)
year
| CryptoCurrencyNetworks => cryptoCurrencyNetworks
| CardCvc => cvcNumber
| StateAndCity
| CountryAndPincode(_)
Expand Down Expand Up @@ -526,6 +538,7 @@ let useRequiredFieldsBody = (
cardExpiry,
cvcNumber,
selectedBank,
cryptoCurrencyNetworks,
])
}

Expand All @@ -538,6 +551,7 @@ let isFieldTypeToRenderOutsideBilling = (fieldType: PaymentMethodsRecord.payment
| CardExpiryMonthAndYear
| CardCvc
| CardExpiryAndCvc
| CryptoCurrencyNetworks
| Currency(_) => true
| _ => false
}
Expand Down
12 changes: 3 additions & 9 deletions src/Utilities/PaymentBody.res
Original file line number Diff line number Diff line change
Expand Up @@ -547,16 +547,11 @@ let applePayThirdPartySdkBody = (~connectors) => [
),
]

let cryptoBody = (~currency) => [
let cryptoBody = [
("payment_method", "crypto"->JSON.Encode.string),
("payment_method_type", "crypto_currency"->JSON.Encode.string),
("payment_experience", "redirect_to_url"->JSON.Encode.string),
(
"payment_method_data",
[
("crypto", [("pay_currency", currency->JSON.Encode.string)]->Utils.getJsonFromArrayOfJson),
]->Utils.getJsonFromArrayOfJson,
),
("payment_method_data", []->Utils.getJsonFromArrayOfJson),
]

let afterpayRedirectionBody = () => [
Expand Down Expand Up @@ -1055,11 +1050,10 @@ let getPaymentBody = (
~blikCode,
~paymentExperience: PaymentMethodsRecord.paymentFlow=RedirectToURL,
~phoneNumber,
~currency,
) =>
switch paymentMethodType {
| "afterpay_clearpay" => afterpayRedirectionBody()
| "crypto_currency" => cryptoBody(~currency)
| "crypto_currency" => cryptoBody
| "sofort" => sofortBody(~country, ~name=fullName, ~email)
| "ideal" => iDealBody(~name=fullName, ~bankName=bank)
| "eps" => epsBody(~name=fullName, ~bankName=bank)
Expand Down
1 change: 1 addition & 0 deletions src/Utilities/RecoilAtoms.res
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ let userBlikCode = Recoil.atom("userBlikCode", defaultFieldValues)
let fieldsComplete = Recoil.atom("fieldsComplete", false)
let isManualRetryEnabled = Recoil.atom("isManualRetryEnabled", false)
let userCurrency = Recoil.atom("userCurrency", "")
let cryptoCurrencyNetworks = Recoil.atom("cryptoCurrencyNetworks", "")
let isShowOrPayUsing = Recoil.atom("isShowOrPayUsing", false)
let areRequiredFieldsValid = Recoil.atom("areRequiredFieldsValid", true)
let areRequiredFieldsEmpty = Recoil.atom("areRequiredFieldsEmpty", false)
Expand Down
Loading

0 comments on commit 24f7297

Please sign in to comment.