Skip to content

Commit

Permalink
feat: add icon support in default erc20 tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
khanti42 committed Nov 18, 2024
1 parent d0feda0 commit 119f4db
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ module.exports = {
'**/public',
'**/.cache',
'**/example',
'**/svg.d.ts',
],
};
4 changes: 4 additions & 0 deletions packages/starknet-snap/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ module.exports = {
coverageProvider: 'babel',
// A list of reporter names that Jest uses when writing coverage reports
coverageReporters: ['html', 'json-summary', 'text'],
// Map .svg files to a mock module
moduleNameMapper: {
'\\.svg$': '<rootDir>/test/svg.mock.ts',
},
};
4 changes: 4 additions & 0 deletions packages/starknet-snap/src/assets/images/dai-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/starknet-snap/src/assets/images/eth-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions packages/starknet-snap/src/assets/images/starknet-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/starknet-snap/src/assets/images/usdc-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/starknet-snap/src/assets/images/usdt-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions packages/starknet-snap/src/svg.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module '*.svg' {
const content: string;
export default content;
}
1 change: 1 addition & 0 deletions packages/starknet-snap/src/types/snapState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export type Erc20Token = {
symbol: string;
decimals: number;
chainId: string; // in hex
icon?: string;
};

export type Network = {
Expand Down
14 changes: 14 additions & 0 deletions packages/starknet-snap/src/ui/icons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import daiIcon from '../assets/images/dai-icon.svg';
import ethIcon from '../assets/images/eth-icon.svg';
import strkIcon from '../assets/images/starknet-icon.svg';
import usdcIcon from '../assets/images/usdc-icon.svg';
import usdtIcon from '../assets/images/usdt-icon.svg';

// Define a Record that maps token names to SVG components
export const icons: Record<string, string> = {
daiIcon,
ethIcon,
strkIcon,
usdcIcon,
usdtIcon,
};
10 changes: 10 additions & 0 deletions packages/starknet-snap/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const ETHER_MAINNET: Erc20Token = {
symbol: 'ETH',
decimals: 18,
chainId: STARKNET_MAINNET_NETWORK.chainId,
icon: 'ethIcon',
};

export const ETHER_SEPOLIA_TESTNET: Erc20Token = {
Expand All @@ -73,6 +74,7 @@ export const ETHER_SEPOLIA_TESTNET: Erc20Token = {
symbol: 'ETH',
decimals: 18,
chainId: SN_SEPOLIA.chainId,
icon: 'ethIcon',
};

export const DAI_MAINNET: Erc20Token = {
Expand All @@ -81,6 +83,7 @@ export const DAI_MAINNET: Erc20Token = {
symbol: 'DAI',
decimals: 18,
chainId: STARKNET_MAINNET_NETWORK.chainId,
icon: 'daiIcon',
};

export const DAI_SEPOLIA_TESTNET: Erc20Token = {
Expand All @@ -89,6 +92,7 @@ export const DAI_SEPOLIA_TESTNET: Erc20Token = {
symbol: 'DAI',
decimals: 18,
chainId: SN_SEPOLIA.chainId,
icon: 'daiIcon',
};

export const STRK_MAINNET: Erc20Token = {
Expand All @@ -97,6 +101,7 @@ export const STRK_MAINNET: Erc20Token = {
symbol: 'STRK',
decimals: 18,
chainId: STARKNET_MAINNET_NETWORK.chainId,
icon: 'strkIcon',
};

export const STRK_SEPOLIA_TESTNET: Erc20Token = {
Expand All @@ -105,6 +110,7 @@ export const STRK_SEPOLIA_TESTNET: Erc20Token = {
symbol: 'STRK',
decimals: 18,
chainId: SN_SEPOLIA.chainId,
icon: 'strkIcon',
};

export const USDC_MAINNET: Erc20Token = {
Expand All @@ -113,6 +119,7 @@ export const USDC_MAINNET: Erc20Token = {
symbol: 'USDC',
decimals: 6,
chainId: STARKNET_MAINNET_NETWORK.chainId,
icon: 'usdcIcon',
};

export const USDC_SEPOLIA_TESTNET: Erc20Token = {
Expand All @@ -121,6 +128,7 @@ export const USDC_SEPOLIA_TESTNET: Erc20Token = {
symbol: 'USDC',
decimals: 6,
chainId: SN_SEPOLIA.chainId,
icon: 'usdcIcon',
};

export const USDT_MAINNET: Erc20Token = {
Expand All @@ -129,6 +137,7 @@ export const USDT_MAINNET: Erc20Token = {
symbol: 'USDT',
decimals: 6,
chainId: STARKNET_MAINNET_NETWORK.chainId,
icon: 'usdtIcon',
};

export const USDT_SEPOLIA_TESTNET: Erc20Token = {
Expand All @@ -137,6 +146,7 @@ export const USDT_SEPOLIA_TESTNET: Erc20Token = {
symbol: 'USDT',
decimals: 6,
chainId: SN_SEPOLIA.chainId,
icon: 'usdtIcon',
};

export const TEST_TOKEN_MAINNET: Erc20Token = {
Expand Down
2 changes: 2 additions & 0 deletions packages/starknet-snap/test/svg.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module.exports = 'SvgMock';
module.exports.ReactComponent = 'svg';

0 comments on commit 119f4db

Please sign in to comment.