1
- import { isStrictHexString , type Hex } from '@metamask/utils' ;
1
+ import { type CaipChainId , isStrictHexString , type Hex } from '@metamask/utils' ;
2
2
import { BigNumber } from 'bignumber.js' ;
3
3
import type { ContractMarketData } from '@metamask/assets-controllers' ;
4
4
import {
@@ -8,9 +8,11 @@ import {
8
8
import { toChecksumAddress } from 'ethereumjs-util' ;
9
9
import { decGWEIToHexWEI } from '../../../shared/modules/conversion.utils' ;
10
10
import { Numeric } from '../../../shared/modules/Numeric' ;
11
- import { type TxData } from '../../../shared/types/bridge' ;
11
+ import { ChainId , type TxData } from '../../../shared/types/bridge' ;
12
12
import { getTransaction1559GasFeeEstimates } from '../../pages/swaps/swaps.util' ;
13
13
import { fetchTokenExchangeRates as fetchTokenExchangeRatesUtil } from '../../helpers/utils/util' ;
14
+ import { formatChainIdToHex } from '../../../shared/modules/bridge-utils/caip-formatters' ;
15
+ import { MultichainNetworks } from '../../../shared/constants/multichain/networks' ;
14
16
15
17
type GasFeeEstimate = {
16
18
suggestedMaxPriorityFeePerGas : string ;
@@ -73,14 +75,19 @@ export const getTxGasEstimates = async ({
73
75
} ;
74
76
75
77
const fetchTokenExchangeRates = async (
76
- chainId : string ,
78
+ chainId : Hex | CaipChainId | ChainId ,
77
79
currency : string ,
78
80
...tokenAddresses : string [ ]
79
81
) => {
82
+ // TODO fetch exchange rates for solana
83
+ if ( chainId === MultichainNetworks . SOLANA ) {
84
+ return { } ;
85
+ }
86
+
80
87
const exchangeRates = await fetchTokenExchangeRatesUtil (
81
88
currency ,
82
89
tokenAddresses ,
83
- chainId ,
90
+ formatChainIdToHex ( chainId ) ,
84
91
) ;
85
92
return Object . keys ( exchangeRates ) . reduce (
86
93
( acc : Record < string , number | undefined > , address ) => {
@@ -95,7 +102,7 @@ const fetchTokenExchangeRates = async (
95
102
// rate is not available in the TokenRatesController, which happens when the selected token has not been
96
103
// imported into the wallet
97
104
export const getTokenExchangeRate = async ( request : {
98
- chainId : Hex ;
105
+ chainId : Hex | CaipChainId | ChainId ;
99
106
tokenAddress : string ;
100
107
currency : string ;
101
108
} ) => {
@@ -115,11 +122,12 @@ export const getTokenExchangeRate = async (request: {
115
122
// This extracts a token's exchange rate from the marketData state object
116
123
// These exchange rates are against the native asset of the chain
117
124
export const exchangeRateFromMarketData = (
118
- chainId : string ,
125
+ chainId : Hex | ChainId ,
119
126
tokenAddress : string ,
120
127
marketData ?: Record < string , ContractMarketData > ,
128
+ // TODO get market data for solana
121
129
) =>
122
- isStrictHexString ( tokenAddress )
130
+ isStrictHexString ( tokenAddress ) && isStrictHexString ( chainId )
123
131
? marketData ?. [ chainId ] ?. [ tokenAddress ] ?. price
124
132
: undefined ;
125
133
0 commit comments