Skip to content
Merged

gzil #1393

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/core/utils/pick.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const pickInsensitiveKey = (obj: any, key: string) => {
for (const k in obj) {
if (k?.toLowerCase() === key?.toLowerCase()) {
return obj[k];
}
}
return undefined;
};
15 changes: 7 additions & 8 deletions src/redux/tokens/static-selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@ import { ITokenConfigState } from './state';
import { IAccountState, ITokensAccountState, ITokenState } from '../wallets/state';
import { getChainId } from '../preferences/selectors';
import { addTokenForBlockchain } from './actions';
import { pickInsensitiveKey } from '../../core/utils/pick';

export const getTokenConfig = (blockchain: Blockchain, symbol: string): ITokenConfigState => {
const blockchainTokens = getBlockchain(blockchain).config.tokens;
const state = store.getState();
const chainId = getChainId(state, blockchain);

const reduxToken = state.tokens;
if (
reduxToken[blockchain] &&
reduxToken[blockchain][chainId] &&
reduxToken[blockchain][chainId][symbol]
) {
return reduxToken[blockchain][chainId][symbol];
if (reduxToken[blockchain] && reduxToken[blockchain][chainId]) {
const token = pickInsensitiveKey(reduxToken[blockchain][chainId], symbol);
if (token) return token;
}

if (blockchainTokens[symbol]) {
return blockchainTokens[symbol];
const blockchainToken = pickInsensitiveKey(blockchainTokens, symbol);
if (blockchainToken) {
return blockchainToken;
}
};

Expand Down