Skip to content

Commit

Permalink
fix(widget): always listen activation event (#4670) (#4673)
Browse files Browse the repository at this point in the history
(cherry picked from commit 8e0b44d)
  • Loading branch information
shoom3301 authored Jul 4, 2024
1 parent 9ba9950 commit a74244d
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions libs/widget-lib/src/cowSwapWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CowEventListeners } from '@cowprotocol/events'
import { IframeCowEventEmitter } from './IframeCowEventEmitter'
import { IframeRpcProviderBridge } from './IframeRpcProviderBridge'
import { IframeSafeSdkBridge } from './IframeSafeSdkBridge'
import { WindowListener, listenToMessageFromWindow, postMessageToWindow, stopListeningWindowListener } from './messages'
import { WindowListener, listenToMessageFromWindow, postMessageToWindow } from './messages'
import {
CowSwapWidgetParams,
CowSwapWidgetProps,
Expand Down Expand Up @@ -190,17 +190,12 @@ function updateParams(contentWindow: Window, params: CowSwapWidgetParams, provid
* @param appCode - A unique identifier for the app.
*/
function sendAppCodeOnActivation(contentWindow: Window, appCode: string | undefined) {
const listener = listenToMessageFromWindow(window, WidgetMethodsEmit.ACTIVATE, () => {
// Stop listening for the ACTIVATE (once is enough)
stopListeningWindowListener(window, listener)

return listenToMessageFromWindow(window, WidgetMethodsEmit.ACTIVATE, () => {
// Update the appData
postMessageToWindow(contentWindow, WidgetMethodsListen.UPDATE_APP_DATA, {
metaData: appCode ? { appCode } : undefined,
})
})

return listener
}

/**
Expand Down

0 comments on commit a74244d

Please sign in to comment.