Skip to content

Commit

Permalink
chore(suite-native): add getNetworkSymbolColorBold method to theme
Browse files Browse the repository at this point in the history
  • Loading branch information
jbazant committed Jan 28, 2025
1 parent eee6b04 commit 0a3e0cc
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 2 deletions.
4 changes: 3 additions & 1 deletion suite-native/theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
"main": "src/index",
"scripts": {
"depcheck": "yarn g:depcheck",
"type-check": "yarn g:tsc --build"
"type-check": "yarn g:tsc --build",
"test:unit": "yarn g:jest -c ../../jest.config.native.js"
},
"dependencies": {
"@suite-native/analytics": "workspace:*",
"@suite-native/storage": "workspace:*",
"@trezor/theme": "workspace:*",
"@trezor/utils": "workspace:*",
"jotai": "1.9.1",
"react": "18.2.0",
"react-fela": "^12.2.1",
Expand Down
41 changes: 41 additions & 0 deletions suite-native/theme/src/__tests__/getNetworkSymbolColorBold.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { NetworkSymbol } from '@suite-common/wallet-config/libDev/src';
import { palette } from '@trezor/theme';

import { getNetworkSymbolColorBold } from '../getNetworkSymbolColorBold';

describe('getNetworkSymbolColorBold', () => {
it.each([
// simple (no need to list all of them)
['btc', 'coinsBtcBold'],
['eth', 'coinsEthBold'],
['doge', 'coinsDogeBold'],
// special cases
['nmc', 'coinsNameBold'],
['pol', 'coinsMaticBold'],
['bsc', 'coinsBnbBold'],
// other L2s
['arb', 'coinsEthBold'],
['base', 'coinsEthBold'],
['op', 'coinsEthBold'],
// testnets
['test', 'coinsTnetBold'],
['regtest', 'coinsTnetBold'],
['tsep', 'coinsTnetBold'],
['thol', 'coinsTnetBold'],
['txrp', 'coinsTnetBold'],
['tada', 'coinsTnetBold'],
['dsol', 'coinsTnetBold'],
] as [NetworkSymbol, string][])(
'should correctly construct %s color',
(symbol, expectedColor) => {
expect(getNetworkSymbolColorBold(symbol)).toBeDefined();
expect(getNetworkSymbolColorBold(symbol)).toBe(palette[expectedColor]);
},
);

it('should fail for invalid NetworkSymbol', () => {
expect(() => getNetworkSymbolColorBold('invalid' as NetworkSymbol)).toThrow(
'Unknown symbol: ["invalid"]',
);
});
});
57 changes: 57 additions & 0 deletions suite-native/theme/src/getNetworkSymbolColorBold.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { UnreachableCaseError } from '@suite-common/suite-utils';
import { NetworkSymbol } from '@suite-common/wallet-config';
import { capitalizeFirstLetter } from '@trezor/utils';
import { palette } from '@trezor/theme';

export const getNetworkSymbolColorBold = (symbol: NetworkSymbol) => {
switch (symbol) {
case 'btc':
case 'ltc':
case 'eth':
case 'etc':
case 'xrp':
case 'bch':
case 'btg':
case 'dash':
case 'dgb':
case 'doge':
case 'vtc':
case 'zec':
case 'ada':
case 'sol': {
const colorKey = `coins${capitalizeFirstLetter(symbol)}Bold`;
const networkSymbolColor = palette[colorKey];

if (!networkSymbolColor) {
throw new Error(`Color ${colorKey} not found in palette`);
}

return networkSymbolColor;
}
case 'nmc':
return palette.coinsNameBold;

case 'pol':
return palette.coinsMaticBold;

case 'bsc':
return palette.coinsBnbBold;

case 'arb':
case 'base':
case 'op':
return palette.coinsEthBold;

case 'test':
case 'regtest':
case 'tsep':
case 'thol':
case 'txrp':
case 'tada':
case 'dsol':
return palette.coinsTnetBold;

default:
throw new UnreachableCaseError(symbol, 'Unknown symbol');
}
};
1 change: 1 addition & 0 deletions suite-native/theme/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './InvertedThemeProvider';
export * from './useSystemColorScheme';
export * from './useUserColorScheme';
export * from './useActiveColorScheme';
export * from './getNetworkSymbolColorBold';
3 changes: 2 additions & 1 deletion suite-native/theme/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"references": [
{ "path": "../analytics" },
{ "path": "../storage" },
{ "path": "../../packages/theme" }
{ "path": "../../packages/theme" },
{ "path": "../../packages/utils" }
]
}
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11191,6 +11191,7 @@ __metadata:
"@suite-native/analytics": "workspace:*"
"@suite-native/storage": "workspace:*"
"@trezor/theme": "workspace:*"
"@trezor/utils": "workspace:*"
jotai: "npm:1.9.1"
react: "npm:18.2.0"
react-fela: "npm:^12.2.1"
Expand Down

0 comments on commit 0a3e0cc

Please sign in to comment.