Skip to content

Commit

Permalink
✨ (context.tsx, types.ts): add READY message type to handle iframe re…
Browse files Browse the repository at this point in the history
…adiness

♻️ (context.tsx): simplify iframe loaded check and use sendMessage for READY event

💡 (context.tsx): remove commented out iFrameResizer code for clarity and maintenance
  • Loading branch information
sebpalluel committed May 18, 2024
1 parent ccb5c7d commit f1ee48d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
11 changes: 3 additions & 8 deletions libs/next/iframe/src/lib/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
OffKeyState,
ReceiveMessageType,
ReceiveMessageValues,
SendMessageType,
} from './types';

interface IFrameContextType {
Expand Down Expand Up @@ -166,15 +167,9 @@ export const IFrameProvider: React.FC<IFrameProviderProps> = ({ children }) => {
}, [handleIFrameMessage]);

const handleIFrameLoaded = () => {
if (!window || iframeParent) return;
if (!window) return;
console.log('IFrame ready');
// (window as any).iFrameResizer = {
// onMessage: onMessageRef.current,
// onReady: () => {
// console.log('IFrame parent ready');
// setIFrameParent((window as any).parentIFrame);
// },
// };
iframeParent?.sendMessage({ type: SendMessageType.READY });
};
return (
<>
Expand Down
2 changes: 2 additions & 0 deletions libs/next/iframe/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export interface ReceiveMessageValues {
}

export enum SendMessageType {
READY = 'READY',
DISCONNECT = 'DISCONNECT',
SIGNATURE = 'SIGNATURE',
OFF_KEY_MINT = 'OFF_KEY_MINT',
Expand All @@ -78,6 +79,7 @@ export enum SendMessageType {
}

export interface SendMessageValues {
[SendMessageType.READY]: null;
[SendMessageType.DISCONNECT]: {
address: string;
};
Expand Down

0 comments on commit f1ee48d

Please sign in to comment.