-
-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(suite-native): add getNetworkSymbolColorBold method to theme
- Loading branch information
Showing
6 changed files
with
105 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
suite-native/theme/src/__tests__/getNetworkSymbolColorBold.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]', | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters