Refactor/op icon + number formatting for notification system#100
Conversation
| expect(formatTokenAmount('1000000000000000000000')).toBe('1.0K'); // 1,000 tokens | ||
| expect(formatTokenAmount('1234000000000000000000')).toBe('1.2K'); // 1,234 tokens | ||
| expect(formatTokenAmount('12345000000000000000000')).toBe('12.3K'); // 12,345 tokens | ||
| expect(formatTokenAmount('999999000000000000000000')).toBe('1000.0K'); // 999,999 tokens |
| it('should format millions with M suffix', () => { | ||
| expect(formatTokenAmount('1000000000000000000000000')).toBe('1.0M'); // 1 million tokens | ||
| expect(formatTokenAmount('1234567000000000000000000')).toBe('1.2M'); // 1.234567 million tokens | ||
| expect(formatTokenAmount('999999999000000000000000000')).toBe('1000.0M'); // ~1 billion tokens |
There was a problem hiding this comment.
Same here.
It's good to have these numbers, but it's rare to find tokens with more supply than 1B. Imagine seeing a delegation near to that, almost impossible.
There was a problem hiding this comment.
I totally agree with you — that’s a great point. Because of that, I’ll remove the “Trillion” unit from the code.
However, I don’t think we should remove the “Billion” option. “Almost impossible” still means possible uheuheuheu.
But jokes aside, from a technical perspective, supporting “B” adds no real complexity — it’s just a matter of including 'B' in the array: const units = ['', 'K', 'M', 'B']. So keeping it improves robustness without adding overhead.
There was a problem hiding this comment.
Oh, btw, this function isn’t limited to votingPower changes. As noted at the top of the file, it’s meant to be a general utility for formatting numbers in a human-readable way. So restricting it based on token decimals could make it less useful for its purpose.
Context
This PR introduces two small but impactful improvements to enhance the notification system's user experience.
First, it adds the OP DAO icon to the Telegram bot's DAO emoji mapping. Previously, OP-related notifications would display with the generic DAO icon, but now they'll show the distinctive red circle emoji that's associated with Optimism.
Second, it implements human-readable number formatting for voting power change notifications. The system was previously displaying raw token amounts in wei format, which meant users would see confusing numbers like "100000000000000000" instead of "0.1". The new formatting converts these 18-decimal values into friendly notation, showing "1.2K" instead of "1234" or "<0.1" for very small amounts. This makes it immediately clear to users how much voting power they've gained or lost.
The implementation includes comprehensive test coverage to ensure the formatting handles edge cases correctly, from tiny wei amounts to billions of tokens.