|
1 | 1 | import { AddressZero } from '@ethersproject/constants'; |
2 | 2 | import { Contract } from '@ethersproject/contracts'; |
3 | | -import { BtcScope, SolScope } from '@metamask/keyring-api'; |
| 3 | +import { BtcScope, SolScope, TrxScope } from '@metamask/keyring-api'; |
4 | 4 | import { abiERC20 } from '@metamask/metamask-eth-abis'; |
5 | 5 | import type { CaipAssetType, CaipChainId } from '@metamask/utils'; |
6 | 6 | import { isCaipChainId, isStrictHexString, type Hex } from '@metamask/utils'; |
@@ -192,22 +192,33 @@ export const isBitcoinChainId = ( |
192 | 192 | return chainId.toString() === ChainId.BTC.toString(); |
193 | 193 | }; |
194 | 194 |
|
| 195 | +export const isTronChainId = (chainId: Hex | number | CaipChainId | string) => { |
| 196 | + if (isCaipChainId(chainId)) { |
| 197 | + return chainId === TrxScope.Mainnet.toString(); |
| 198 | + } |
| 199 | + return chainId.toString() === ChainId.TRON.toString(); |
| 200 | +}; |
| 201 | + |
195 | 202 | /** |
196 | 203 | * Checks if a chain ID represents a non-EVM blockchain supported by swaps |
197 | | - * Currently supports Solana and Bitcoin |
| 204 | + * Currently supports Solana, Bitcoin and Tron |
198 | 205 | * |
199 | 206 | * @param chainId - The chain ID to check |
200 | 207 | * @returns True if the chain is a supported non-EVM chain, false otherwise |
201 | 208 | */ |
202 | 209 | export const isNonEvmChainId = ( |
203 | 210 | chainId: GenericQuoteRequest['srcChainId'], |
204 | 211 | ): boolean => { |
205 | | - return isSolanaChainId(chainId) || isBitcoinChainId(chainId); |
| 212 | + return ( |
| 213 | + isSolanaChainId(chainId) || |
| 214 | + isBitcoinChainId(chainId) || |
| 215 | + isTronChainId(chainId) |
| 216 | + ); |
206 | 217 | }; |
207 | 218 |
|
208 | 219 | export const isEvmQuoteResponse = ( |
209 | 220 | quoteResponse: QuoteResponse, |
210 | | -): quoteResponse is QuoteResponse<TxData> => { |
| 221 | +): quoteResponse is QuoteResponse<TxData, TxData> => { |
211 | 222 | return !isNonEvmChainId(quoteResponse.quote.srcChainId); |
212 | 223 | }; |
213 | 224 |
|
|
0 commit comments