groupAddress function
Visually group an address into space-separated, fixed-size groupSize chunks
("u1qx z9k2 …") so a long string is scannable character-by-character. The ONE
source of truth for the equal-weight VERIFICATION rendering (the send recipient
review + the swap refund-verification echo). Purely a render aid: it is
loss-free — stripping the inserted spaces yields the original verbatim (an
address never contains a space) — so a grouping bug could only mis-render,
never change the value a user verifies. Pure + total; tested at its boundaries.
Implementation
String groupAddress(String address, {int groupSize = 4}) {
assert(groupSize > 0, 'groupSize must be positive');
if (address.isEmpty) return '';
final buf = StringBuffer();
for (var i = 0; i < address.length; i += groupSize) {
if (i > 0) buf.write(' ');
final end = i + groupSize;
buf.write(
address.substring(i, end < address.length ? end : address.length),
);
}
return buf.toString();
}