Skip to content

Commit 7d27bb2

Browse files
committed
fx qi plugin
1 parent 3795f58 commit 7d27bb2

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

packages/plugin-quick-intel/src/utils/chain-detection.ts

+24-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
const CHAIN_MAPPINGS = {
1+
type ChainMappings = {
2+
[key: string]: string[]
3+
};
4+
5+
const CHAIN_MAPPINGS: ChainMappings = {
26
eth: ['eth', 'ethereum', 'ether', 'mainnet'],
37
bsc: ['bsc', 'binance', 'bnb', 'binance smart chain', 'smartchain'],
48
polygon: ['polygon', 'matic', 'poly'],
@@ -86,13 +90,17 @@ export interface TokenInfo {
8690

8791
function normalizeChainName(chain: string): string | null {
8892
const normalizedInput = chain.toLowerCase().trim();
89-
93+
94+
// First try exact matches
9095
for (const [standardName, variations] of Object.entries(CHAIN_MAPPINGS)) {
91-
if (variations.some((v: string) => normalizedInput.includes(v))) {
96+
// Check for exact matches first
97+
if (variations.includes(normalizedInput)) {
9298
return standardName;
9399
}
94100
}
95101

102+
// If no exact match is found, return the original input
103+
// This allows for new/unknown chains to pass through
96104
return normalizedInput;
97105
}
98106

@@ -110,18 +118,20 @@ export function extractTokenInfo(message: string): TokenInfo {
110118
const prepositionPattern = /(?:on|for|in|at|chain)\s+([a-zA-Z0-9]+)/i;
111119
const prepositionMatch = cleanMessage.match(prepositionPattern);
112120

113-
// 2. Look for chain names anywhere in the message
114-
for (const [chainName, variations] of Object.entries(CHAIN_MAPPINGS)) {
115-
if (variations.some((v: string) => cleanMessage.includes(v))) {
116-
result.chain = chainName;
117-
break;
118-
}
119-
}
120-
121-
// If chain wasn't found in mappings but was found through preposition pattern,
122-
// use the exact chain name provided
123-
if (!result.chain && prepositionMatch?.[1]) {
121+
if (prepositionMatch?.[1]) {
124122
result.chain = normalizeChainName(prepositionMatch[1]);
123+
} else {
124+
// 2. Look for exact chain matches in the message
125+
for (const [chainName, variations] of Object.entries(CHAIN_MAPPINGS)) {
126+
if (variations.some(v => {
127+
// Split message into words and check for exact word matches
128+
const words = cleanMessage.split(/\s+/);
129+
return words.includes(v);
130+
})) {
131+
result.chain = chainName;
132+
break;
133+
}
134+
}
125135
}
126136

127137
// Find token address using different patterns

0 commit comments

Comments
 (0)