Skip to content

Commit

Permalink
fix(functions): change the fucntions structure
Browse files Browse the repository at this point in the history
  • Loading branch information
lariane-guerra committed Feb 26, 2025
1 parent c2c6b25 commit 595ad20
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/events/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class Events {

public on<T extends keyof EventPayloadReturnObject>(
eventType: T,
eventHandler: (payload: EventPayloadReturnObject[T]) => void,
eventHandler: (data: EventPayloadReturnObject[T]) => void,
) {
if (!this.events[eventType]) {
this.events[eventType] = []
Expand All @@ -45,14 +45,14 @@ export class Events {

public emit<T extends keyof EventPayloadReturnObject>(
eventType: T,
payload: EventPayloadReturnObject[T],
data: EventPayloadReturnObject[T],
) {
if (!this.events[eventType]) {
return
}

this.events[eventType]?.forEach((eventHandler) => {
eventHandler(payload)
eventHandler(data)
})
}
}
1 change: 1 addition & 0 deletions src/iframes/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export function listener() {
if (event.origin !== 'https://develop.d3krxmg1839vaa.amplifyapp.com')
return
const { eventType, data } = event.data

const parentNode = document.querySelector(`#${data?.field}`)

if (!parentNode) {
Expand Down
3 changes: 2 additions & 1 deletion src/iframes/submit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function submit(configurations: MalgaConfigurations) {
const iframeCardNumber = document.querySelector(
'iframe[name=card-number]',
) as HTMLIFrameElement

console.log('entrou aqui no submit')
if (!iframeCardNumber || !iframeCardNumber.contentWindow) {
console.error(
'iframeCardNumber is null or has no contentWindow, cannot send postMessage',
Expand All @@ -18,6 +18,7 @@ export function submit(configurations: MalgaConfigurations) {
iframeCardNumber.contentWindow!,
'*',
)
console.log({ iframePostMessage })

iframePostMessage.send(Event.Submit, {
authorizationData: {
Expand Down
28 changes: 26 additions & 2 deletions src/tokenization.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import type { EventTypeReturn, MalgaConfigurations } from 'src/interfaces'
import type {
EventPayloadReturnObject,
EventTypeReturn,
MalgaConfigurations,
} from 'src/interfaces'

import { Tokenize } from './tokenize'
import { Events } from './events'
Expand Down Expand Up @@ -27,7 +31,27 @@ export class MalgaTokenization {
return tokenize.handle()
}

public on(eventType: EventTypeReturn, eventHandler: (event: any) => void) {
/**
* Configures the event provider and registers an event handler for the specified event type.
*
* This method allows you to react the specifics events emitted by the MalgaTokenization component.
*
* @param eventType - The type of event to be watched. Possible values are:
* - 'validity': Triggered when the validity of the field data is changed (valid/invalid).
* - 'cardTypeChanged': Triggered when the card type is detected or changed.
* - 'focus': Triggered when a input field receives focus.
* - 'blur': Triggered when a input field loses focus.
* @param eventHandler - The event handler function.
* @returns {void}
*/

public on<T extends EventTypeReturn>(
eventType: T,
eventHandler: (data: EventPayloadReturnObject[T]) => void,
) {
return eventsEmitter.on(eventType, eventHandler)
}
// public on(eventType: EventTypeReturn, eventHandler: (event: any) => void) {
// return eventsEmitter.on(eventType, eventHandler)
// }
}

0 comments on commit 595ad20

Please sign in to comment.