fix: a token symbol read off a contract is never stored cut mid-emoji (closes #458)
lookupTokenInfo() cut the symbol at 12 and the name at 64 UTF-16 units, so an emoji outside the Basic Multilingual Plane could be cut between its two halves and the half left over stored and shown as U+FFFD. Both are now cut on code points, as displaySymbol() does. A symbol already stored broken is not repaired. Model: opus-5-5
This commit is contained in:
@@ -334,9 +334,12 @@ async function lookupTokenInfo(contractAddress, rpcUrl, networkId, signal) {
|
||||
name = symbol;
|
||||
}
|
||||
|
||||
// Truncate to prevent storage of excessively long values from RPC
|
||||
name = String(name).slice(0, 64);
|
||||
symbol = String(symbol).slice(0, 12);
|
||||
// Truncate to prevent storage of excessively long values from RPC.
|
||||
// Counted in code points, as displaySymbol() counts them, so the cut never
|
||||
// falls between the two halves of an emoji and stores a half that renders
|
||||
// as U+FFFD.
|
||||
name = Array.from(String(name)).slice(0, 64).join("");
|
||||
symbol = Array.from(String(symbol)).slice(0, 12).join("");
|
||||
|
||||
log.infof("Token resolved:", symbol, "decimals", Number(decimals));
|
||||
return { name, symbol, decimals: Number(decimals) };
|
||||
|
||||
Reference in New Issue
Block a user