Files
solace-bg-dubai/frontend/lib/memo.ts
defiQUG a03417be98
All checks were successful
CI / lint-and-test (push) Successful in 9m52s
chore: consolidate local WIP (repo cleanup 20260707)
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-07 09:41:38 -07:00

21 lines
522 B
TypeScript

import { hexToString, stringToHex } from "viem";
export function encodeMemoData(memo: string): `0x${string}` {
const trimmed = memo.trim();
if (!trimmed) return "0x";
return stringToHex(trimmed);
}
export function decodeMemoData(data: string | null | undefined): string | null {
if (!data || data === "0x") return null;
try {
const text = hexToString(data as `0x${string}`);
if (text && /^[\x20-\x7E\s]+$/.test(text)) {
return text.trim();
}
} catch {
return null;
}
return null;
}