feat: 增强 iframe 通信机制与通知处理功能
实现 resolvePostMessageTargetOrigin,优化 iframe 消息通信中的目标来源(origin)解析与校验。 更新 IframeBridge:支持定期刷新允许的来源列表,并优化消息事件管理机制。 重构 usePendingWalletReconcile:优化待对账通知的获取与缓存逻辑,提升性能与用户体验。 增强 NotificationsScreen:新增待对账通知内容,并优化界面展示效果。 更新英文、尼泊尔语与中文语言包,新增待对账通知相关翻译文案。
This commit is contained in:
@@ -7,6 +7,7 @@ import { setPlayerBearerToken } from "@/lib/lottery-auth";
|
||||
import {
|
||||
isIframeOriginAllowed,
|
||||
loadIframeAllowedOrigins,
|
||||
resolvePostMessageTargetOrigin,
|
||||
} from "@/lib/iframe-origins";
|
||||
|
||||
/**
|
||||
@@ -34,7 +35,7 @@ export function IframeBridge({ children }: { children: ReactNode }): ReactNode {
|
||||
timestamp: Date.now(),
|
||||
source: "lottery-iframe",
|
||||
},
|
||||
"*", // 生产环境应指定具体域名
|
||||
resolvePostMessageTargetOrigin(),
|
||||
);
|
||||
},
|
||||
[],
|
||||
@@ -93,7 +94,7 @@ export function IframeBridge({ children }: { children: ReactNode }): ReactNode {
|
||||
|
||||
const handleMessage = async (event: MessageEvent): Promise<void> => {
|
||||
if (!isIframeOriginAllowed(event.origin)) {
|
||||
await loadIframeAllowedOrigins();
|
||||
await loadIframeAllowedOrigins(true);
|
||||
if (!isIframeOriginAllowed(event.origin)) {
|
||||
console.warn("[IframeBridge] Rejected message from:", event.origin);
|
||||
return;
|
||||
@@ -159,6 +160,10 @@ export function IframeBridge({ children }: { children: ReactNode }): ReactNode {
|
||||
notifyReady();
|
||||
});
|
||||
|
||||
const originsRefresh = setInterval(() => {
|
||||
void loadIframeAllowedOrigins(true);
|
||||
}, 60_000);
|
||||
|
||||
// 定期发送心跳
|
||||
const heartbeat = setInterval(() => {
|
||||
sendToParent("HEARTBEAT", {
|
||||
@@ -168,6 +173,7 @@ export function IframeBridge({ children }: { children: ReactNode }): ReactNode {
|
||||
|
||||
return () => {
|
||||
window.removeEventListener("message", handleMessage);
|
||||
clearInterval(originsRefresh);
|
||||
clearInterval(heartbeat);
|
||||
};
|
||||
}, [notifyReady, notifyTokenRefreshed, sendToParent, setBearerToken]);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { Bell } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { useEffect, type ReactElement } from "react";
|
||||
import { type ReactElement } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { usePendingWalletReconcile } from "@/hooks/use-pending-wallet-reconcile";
|
||||
@@ -13,14 +13,10 @@ type PlayerNotificationBellProps = {
|
||||
className?: string;
|
||||
};
|
||||
|
||||
/** 顶栏铃铛:待对账划转等提醒(Popover 右上角展开) */
|
||||
/** 顶栏铃铛:待对账划转提醒 */
|
||||
export function PlayerNotificationBell({ className }: PlayerNotificationBellProps): ReactElement {
|
||||
const { t } = useTranslation("common");
|
||||
const { hasUnread, refresh } = usePendingWalletReconcile();
|
||||
|
||||
useEffect(() => {
|
||||
void refresh();
|
||||
}, [refresh]);
|
||||
const { hasUnread } = usePendingWalletReconcile();
|
||||
|
||||
return (
|
||||
<Link
|
||||
|
||||
Reference in New Issue
Block a user