getEcashRowColors throws on the default theme: buttonGradient is an array, blendHexColors expects a string
Summary
getEcashRowColors throws on the default theme, so the balance-based warning tint on the ecash row never appears. The failure is swallowed by a try/catch, so the row still renders — just always in the plain gradient, with a console.error on every call.
Chain
DEFAULT_THEME is kyriaki (stores/SettingsStore.ts:1271), and Kyriaki is the only theme that defines buttonGradient (utils/ThemeUtils.ts:26):
buttonGradient: ['#FF9000', '#FFA900'],
It is an array. components/LayerBalances/index.tsx:112 takes it:
const buttonBg = themeColor('buttonGradient') || themeColor('secondary');
The || does not fall through, because an array is truthy. The guard below checks only truthiness, not shape:
if (!buttonBg || !warningColor || !errorColor) { ... }
and then blendHexColors calls a string method on it (utils/ThemeUtils.ts:498):
hex1 = hex1.replace('#', '');
TypeError: hex1.replace is not a function
caught at index.tsx:130, logged, return false.
Every other theme falls back to Dark['buttonGradient'], which is undefined, so buttonBg becomes themeColor('secondary') — a hex string — and the path works. Only the default theme has the array.
Effect
index.tsx:182 reads:
isEcash && ecashRowColors
? ecashRowColors
: themeColor('buttonGradient')
...
With ecashRowColors === false it falls back to the flat gradient. So nothing looks broken — the row simply never tints toward warning/error as the ecash balance grows past 10,000 sats. On the default theme that nudge has never been visible.
Reproducing without a device
Running blendHexColors as it stands in the file:
array (Kyriaki buttonGradient) -> TypeError: hex1.replace is not a function
valid hex pair -> #803637
3-char shorthand ('#abc') -> #c62cNaN
named colour ('white') -> #NaNNaN2d
The last two are worth noting separately: blendHexColors has no input validation, so a short hex or a named colour produces a syntactically invalid colour string rather than failing. Themes do contain named colours — Kyriaki has text: 'white' — so that is reachable if the function is ever pointed at one.
getUpgradeBackgroundColor avoids this by validating with /^#?[0-9a-fA-F]{6}$/ before calling. The LayerBalances caller does not.
Possible fixes
- At the call site — take the first stop when the theme value is an array:
Array.isArray(buttonBg) ? buttonBg[0] : buttonBg. Smallest change, and arguably correct since a blend needs one colour, not a gradient. - In
blendHexColors— validate both inputs the waygetUpgradeBackgroundColoralready does and return early rather than emitting#NaN.... Fixes the shorthand and named-colour cases too, but changes the function's contract. - Both — (1) for the live bug, (2) so the next caller cannot reintroduce it.
I have not opened a PR because it changes what renders and I have no device to capture before/after on, which CONTRIBUTING asks for. Happy to send whichever of these you prefer.
Related: #4686, also in ThemeUtils, on the two upgrade ramps disagreeing.
Disclosure: found and written with AI assistance. The trace above comes from running blendHexColors as it stands in the file; the theme and call-site references were read from the repository.
Was only able to recreate this in the Junkie theme which has been removed in a theme cleanup in d3f15bc9f6d05c9d72a11217a2fb99db37955117
I think the theme cleanup missed this one, and I can now show it rather than argue it.
buttonGradient is defined exactly once in utils/ThemeUtils.ts, and it is in Kyriaki — line 26, which is the DEFAULT_THEME (stores/SettingsStore.ts:1271). I checked the file as it stood before d3f15bc: Junkie starts at line 91 and never defined buttonGradient, nor did BPM, Desert, Mint or Watermelon. So none of the five themes that commit removed could have been the source, and it is still reproducible on current master.
Which makes me think what you saw in Junkie was something else — for a theme without the key, themeColor('buttonGradient') returns undefined, the || falls through to themeColor('secondary'), and the path works. It is specifically the theme that has the key that breaks.
Runnable proof
utils/ThemeUtils.ts imports stores/Stores, which pulls in the native stack, so it cannot be imported in jest as-is — that is presumably why there is no ThemeUtils.test.ts. One mock gets past it:
jest.mock('../stores/Stores', () => ({
settingsStore: { settings: { display: { theme: 'kyriaki' } } },
nodeInfoStore: {}
}));
import { blendHexColors, themeColor } from '../utils/ThemeUtils';
it('themeColor returns the raw array for the default theme', () => {
expect(themeColor('buttonGradient')).toEqual(['#FF9000', '#FFA900']);
});
it('blendHexColors survives being handed that array', () => {
const buttonBg = themeColor('buttonGradient');
expect(() => blendHexColors(buttonBg, '#FFC300', 0.5)).not.toThrow();
});
On master as of today:
√ themeColor returns the raw array for the default theme
× blendHexColors survives being handed that array
Error name: "TypeError"
Error message: "hex1.replace is not a function"
at replace (utils/ThemeUtils.ts:411:17)
First assertion passes, second fails exactly where the issue said it would. No device needed.
The user-visible effect, restated
It is swallowed. components/LayerBalances/index.tsx:130 catches it and returns false, so nothing crashes — the ecash row just never gets its balance-based warning tint, on the default theme, and logs a console.error every time it renders.
Fix
The guard at index.tsx:118 checks truthiness where it needs to check shape:
if (!buttonBg || !warningColor || !errorColor) {
An array is truthy, so it sails through. Either tighten that to typeof buttonBg !== 'string', or make blendHexColors reject a non-string argument so the next caller cannot make the same mistake — I'd lean to the second, plus the shape check at the call site, since the function's signature already says hex1: string and TypeScript is not enforcing it here because themeColor returns any.
Happy to send that as a PR with the two tests above — it would also be the first ThemeUtils.test.ts, which seems worth having given how much of the theming is any-typed. Say the word, or take it yourself if you would rather fold it into the theme work you already have in flight.
The quote of the call site leaves out its first operand. On master, components/LayerBalances/index.tsx:110 reads:
const buttonBg =
themeColor('buttonBackground') ||
themeColor('buttonGradient') ||
themeColor('secondary');
Kyriaki defines buttonBackground: '#FFA900' (utils/ThemeUtils.ts:25, there since a4cd57136), so on the default theme buttonBg is that string and buttonGradient is never read. No other theme falls back to Kyriaki in themeColor, so no theme can pass the array to blendHexColors from getEcashRowColors.
The jest repro calls blendHexColors on the array directly. That shows the function throws on non-string input, not that the app ever passes it one. A failing test through getEcashRowColors on kyriaki, or a device log showing the console.error, would change my mind.
Input validation in blendHexColors (the #NaN output for '#abc' or 'white') is a separate hardening change. A PR for that is welcome, but it shouldn't be framed as the fix for this issue, and the array test shouldn't go into ThemeUtils.test.ts as a regression test for it.
You're right, and I should not have argued the point.
I dropped the first operand. buttonBackground: '#FFA900' sits one line above buttonGradient in Kyriaki and is a truthy string, so themeColor('buttonGradient') is never evaluated and the array never reaches blendHexColors. There is no theme that defines buttonGradient without buttonBackground, so there is no path to it at all.
Worse than the misread: the test I posted called blendHexColors with the array directly instead of going through the call site. That proves the function is not array-safe, which is true and irrelevant — it does not prove the code does it. I built the check around my conclusion rather than around the actual path, and then used it to contradict you.
Sorry for the round trip. Please close this.
The only thing I would still ask, and it is much smaller than what I originally claimed: blendHexColors(hex1: string, ...) is reachable from themeColor(), which returns any, so the signature is not enforced at any call site. Happy to leave that alone if it is not worth the churn.
Closing per the discussion above: buttonBackground is defined wherever buttonGradient is, so the array never reaches blendHexColors from getEcashRowColors. Tightening blendHexColors input handling (non-string or short-hex input, and themeColor() returning any) is a separate hardening change if someone wants to pick it up.