Skip to content

Commit

Permalink
feat: added LOADER_CHANGED event on loader state update (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
vsrivatsa-edinburgh authored Feb 27, 2024
1 parent c93e44c commit 42abaf0
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 27 deletions.
58 changes: 40 additions & 18 deletions src/LoaderController.res
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,22 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger) => {
handlePostMessage([("iframeMounted", true->Js.Json.boolean)])
handlePostMessage([("applePayMounted", true->Js.Json.boolean)])
logger.setLogInitiated()
switch paymentlist {
| Loaded(_)
| LoadError => ()
| _ =>
setList(._ =>
showCardFormByDefault && Utils.checkPriorityList(paymentMethodOrder) ? SemiLoaded : Loading
let updatedState: PaymentType.loadType = switch paymentlist {
| Loading =>
showCardFormByDefault && Utils.checkPriorityList(paymentMethodOrder) ? SemiLoaded : Loading
| x => x
}
switch updatedState {
| Loaded(_) => logger.setLogInfo(~value="Loaded", ~eventName=LOADER_CHANGED, ())
| Loading => logger.setLogInfo(~value="Loading", ~eventName=LOADER_CHANGED, ())
| SemiLoaded => {
setList(._ => updatedState)
logger.setLogInfo(~value="SemiLoaded", ~eventName=LOADER_CHANGED, ())
}
| LoadError(x) => logger.setLogError(
~value="LoadError: " ++ x->Js.Json.stringify,
~eventName=LOADER_CHANGED,
(),
)
}
Window.addEventListener("click", ev =>
Expand Down Expand Up @@ -340,18 +350,30 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger) => {
}
if dict->getDictIsSome("paymentMethodList") {
let list = dict->getJsonObjectFromDict("paymentMethodList")
list == Js.Dict.empty()->Js.Json.object_
? setList(._ => LoadError)
: switch list->Utils.getDictFromJson->Js.Dict.get("error") {
| Some(_) => setList(._ => LoadError)
| None =>
let isNonEmptyPaymentMethodList =
list
->Utils.getDictFromJson
->Utils.getArray("payment_methods")
->Js.Array2.length > 0
setList(._ => isNonEmptyPaymentMethodList ? Loaded(list) : LoadError)
}
let updatedState: PaymentType.loadType =
list == Js.Dict.empty()->Js.Json.object_
? LoadError(list)
: switch list->Utils.getDictFromJson->Js.Dict.get("error") {
| Some(_) => LoadError(list)
| None =>
let isNonEmptyPaymentMethodList =
list
->Utils.getDictFromJson
->Utils.getArray("payment_methods")
->Js.Array2.length > 0
isNonEmptyPaymentMethodList ? Loaded(list) : LoadError(list)
}
switch updatedState {
| Loaded(_) => logger.setLogInfo(~value="Loaded", ~eventName=LOADER_CHANGED, ())
| LoadError(x) =>
logger.setLogError(
~value="LoadError: " ++ x->Js.Json.stringify,
~eventName=LOADER_CHANGED,
(),
)
| _ => ()
}
setList(._ => updatedState)
}
if dict->getDictIsSome("customerPaymentMethods") {
let customerPaymentMethods = dict->PaymentType.createCustomerObjArr
Expand Down
6 changes: 3 additions & 3 deletions src/PaymentElement.res
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ let make = (
)
}
: ()
| LoadError
| LoadError(_)
| SemiLoaded =>
setPaymentOptions(_ =>
showCardFormByDefault && Utils.checkPriorityList(paymentMethodOrder) ? ["card"] : []
Expand Down Expand Up @@ -143,7 +143,7 @@ let make = (
? ""
: switch methodslist {
| SemiLoaded
| LoadError =>
| LoadError(_) =>
showCardFormByDefault && Utils.checkPriorityList(paymentMethodOrder) ? "card" : ""
| Loaded(_) =>
paymentOptions->Js.Array2.includes(selectedOption) && showCardFormByDefault
Expand Down Expand Up @@ -320,7 +320,7 @@ let make = (
<PoweredBy />
</RenderIf>
{switch methodslist {
| LoadError => React.null
| LoadError(_) => React.null
| _ =>
<RenderIf
condition={paymentOptions->Js.Array2.length == 0 && walletOptions->Js.Array2.length == 0}>
Expand Down
2 changes: 1 addition & 1 deletion src/Types/PaymentType.res
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ let itemToObjMapper = (dict, logger) => {
}
}

type loadType = Loading | Loaded(Js.Json.t) | SemiLoaded | LoadError
type loadType = Loading | Loaded(Js.Json.t) | SemiLoaded | LoadError(Js.Json.t)

let getIsAllStoredCardsHaveName = (savedCards: array<customerMethods>) => {
savedCards
Expand Down
7 changes: 2 additions & 5 deletions src/Utilities/PaymentHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,7 @@ let usePaymentSync = (optLogger: option<OrcaLogger.loggerMake>, paymentType: pay
}
switch list {
| Loaded(_) => paymentSync()
| SemiLoaded
| Loading
| LoadError => ()
| _ => ()
}
| None =>
postFailedSubmitResponse(
Expand Down Expand Up @@ -636,8 +634,7 @@ let usePaymentIntent = (optLogger: option<OrcaLogger.loggerMake>, paymentType: p
| None => intentWithoutMandate()
}
| SemiLoaded => intentWithoutMandate()
| Loading
| LoadError => ()
| _ => ()
}
| None =>
postFailedSubmitResponse(
Expand Down
2 changes: 2 additions & 0 deletions src/orca-log-catcher/OrcaLogger.res
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type eventName =
| DISPLAY_BANK_TRANSFER_INFO_PAGE
| DISPLAY_QR_CODE_INFO_PAGE
| PAYMENT_METHODS_RESPONSE
| LOADER_CHANGED

let eventNameToStrMapper = eventName => {
switch eventName {
Expand Down Expand Up @@ -109,6 +110,7 @@ let eventNameToStrMapper = eventName => {
| DISPLAY_BANK_TRANSFER_INFO_PAGE => "DISPLAY_BANK_TRANSFER_INFO_PAGE"
| DISPLAY_QR_CODE_INFO_PAGE => "DISPLAY_QR_CODE_INFO_PAGE"
| PAYMENT_METHODS_RESPONSE => "PAYMENT_METHODS_RESPONSE"
| LOADER_CHANGED => "LOADER_CHANGED"
}
}

Expand Down

0 comments on commit 42abaf0

Please sign in to comment.