feat: enhance wallet transfer handling and improve HTML safety

- Added emitWalletRefresh function to trigger wallet refresh events after successful transfers and error handling.
- Introduced removeScriptTags function to sanitize HTML content by removing script tags, preventing potential security issues.
- Updated transfer handling logic to ensure wallet refresh is emitted in relevant scenarios, improving user experience.
This commit is contained in:
2026-05-26 09:57:08 +08:00
parent 81870bd010
commit d768a3f6ba
2 changed files with 22 additions and 3 deletions

View File

@@ -7,6 +7,15 @@ const KEY_NE = "frontend.play_rules_html_ne";
type SettingItem = { key: string; value: unknown };
function removeScriptTags(html: string | null): string | null {
if (!html) return html;
// React won't execute scripts injected via `dangerouslySetInnerHTML`.
// Removing them avoids the warning and prevents unintended script injection.
return html
.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, "")
.replace(/<script\b[^>]*\/>/gi, "");
}
function asNonEmptyString(value: unknown): string | null {
if (typeof value !== "string") {
return null;
@@ -29,10 +38,10 @@ export function resolvePlayRulesHtml(
const lang: AppLanguage = normalizeLanguage(language);
if (lang === "zh") {
return zh ?? legacy;
return removeScriptTags(zh ?? legacy);
}
if (lang === "ne") {
return ne ?? en ?? zh ?? legacy;
return removeScriptTags(ne ?? en ?? zh ?? legacy);
}
return en ?? zh ?? legacy;
return removeScriptTags(en ?? zh ?? legacy);
}