Skip to content

Commit

Permalink
fix: message event handler (#3131)
Browse files Browse the repository at this point in the history
Co-authored-by: MK <[email protected]>
Co-authored-by: MK <[email protected]>
  • Loading branch information
3 people authored Oct 23, 2024
1 parent 8d841f0 commit e16f0fe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/cyan-plums-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@reown/appkit-wallet': minor
---

Fixed message event handler when payload type was not a string
15 changes: 12 additions & 3 deletions packages/wallet/src/W3mFrame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ export class W3mFrame {
signal: AbortSignal
) => {
function eventHandler({ data }: MessageEvent) {
if (!data.type?.includes(W3mFrameConstants.FRAME_EVENT_KEY)) {
if (
typeof data.type !== 'string' ||
!data.type.includes(W3mFrameConstants.FRAME_EVENT_KEY)
) {
return
}
const frameEvent = W3mFrameSchema.frameEvent.parse(data)
Expand All @@ -127,7 +130,10 @@ export class W3mFrame {
onFrameEvent: (callback: (event: W3mFrameTypes.FrameEvent) => void) => {
if (W3mFrameHelpers.isClient) {
window.addEventListener('message', ({ data }) => {
if (!data.type?.includes(W3mFrameConstants.FRAME_EVENT_KEY)) {
if (
typeof data.type !== 'string' ||
!data.type.includes(W3mFrameConstants.FRAME_EVENT_KEY)
) {
return
}
const frameEvent = W3mFrameSchema.frameEvent.parse(data)
Expand All @@ -139,7 +145,10 @@ export class W3mFrame {
onAppEvent: (callback: (event: W3mFrameTypes.AppEvent) => void) => {
if (W3mFrameHelpers.isClient) {
window.addEventListener('message', ({ data }) => {
if (!data.type?.includes(W3mFrameConstants.APP_EVENT_KEY)) {
if (
typeof data.type !== 'string' ||
!data.type.includes(W3mFrameConstants.APP_EVENT_KEY)
) {
return
}
const appEvent = W3mFrameSchema.appEvent.parse(data)
Expand Down

0 comments on commit e16f0fe

Please sign in to comment.