@@ -17,7 +17,6 @@ import { sprintf } from 'sprintf-js'
17
17
import { trackConversion } from '../actions/TrackingActions'
18
18
import { InsufficientFeesModal } from '../components/modals/InsufficientFeesModal'
19
19
import { Airship , showError } from '../components/services/AirshipInstance'
20
- import { formatFiatString } from '../hooks/useFiatText'
21
20
import { formatNumber } from '../locales/intl'
22
21
import { lstrings } from '../locales/strings'
23
22
import { getDisplayDenomination , getExchangeDenomination } from '../selectors/DenominationSelectors'
@@ -159,7 +158,7 @@ async function fetchSwapQuotes(state: RootState, request: EdgeSwapRequest): Prom
159
158
}
160
159
161
160
// TODO: Use new hooks and utility methods for all conversions here
162
- export const getSwapInfo = ( state : RootState , quote : EdgeSwapQuote ) : GuiSwapInfo => {
161
+ export const getSwapInfo = async ( state : RootState , quote : EdgeSwapQuote ) : Promise < GuiSwapInfo > => {
163
162
// Currency conversion tools:
164
163
// Both fromCurrencyCode and toCurrencyCode will exist, since we set them:
165
164
const { request } = quote
@@ -183,20 +182,11 @@ export const getSwapInfo = (state: RootState, quote: EdgeSwapQuote): GuiSwapInfo
183
182
const feeDisplayAmount = toFixed ( feeTempAmount , 0 , 6 )
184
183
185
184
// Format fiat fee:
186
- const feeCryptoAmount = div ( feeNativeAmount , feeDenomination . multiplier , DECIMAL_PRECISION )
187
- const fiatAmount = convertCurrency (
188
- state ,
189
- fromWallet . currencyInfo . currencyCode ,
190
- fromWallet . fiatCurrencyCode ,
191
- div ( feeCryptoAmount , fromExchangeDenomination . multiplier , DECIMAL_PRECISION )
192
- )
193
- const feeFiatAmount = formatFiatString ( {
194
- fiatAmount
195
- } )
185
+ const feeDenominatedAmount = await fromWallet . nativeToDenomination ( feeNativeAmount , request . fromWallet . currencyInfo . currencyCode )
186
+ const feeFiatAmountRaw = parseFloat ( convertCurrency ( state , request . fromWallet . currencyInfo . currencyCode , fromWallet . fiatCurrencyCode , feeDenominatedAmount ) )
187
+ const feeFiatAmount = formatNumber ( feeFiatAmountRaw || 0 , { toFixed : 2 } )
196
188
const fee = `${ feeDisplayAmount } ${ feeDenomination . name } (${ feeFiatAmount } ${ fromWallet . fiatCurrencyCode . replace ( 'iso:' , '' ) } )`
197
- const fromTotalFiat = formatNumber ( add ( fromBalanceInFiatRaw . toFixed ( DECIMAL_PRECISION ) , parseFloat ( feeFiatAmount ) . toFixed ( DECIMAL_PRECISION ) ) , {
198
- toFixed : 2
199
- } )
189
+ const fromTotalFiat = formatNumber ( add ( fromBalanceInFiatRaw . toFixed ( DECIMAL_PRECISION ) , feeFiatAmountRaw . toFixed ( DECIMAL_PRECISION ) ) , { toFixed : 2 } )
200
190
201
191
// Format to amount:
202
192
const toPrimaryInfo = state . cryptoExchange . toWalletPrimaryInfo
@@ -306,7 +296,7 @@ export function shiftCryptoCurrency(navigation: NavigationBase, quote: EdgeSwapQ
306
296
const { account } = state . core
307
297
dispatch ( { type : 'START_SHIFT_TRANSACTION' } )
308
298
309
- const { fromDisplayAmount, fee, fromFiat, fromTotalFiat, toDisplayAmount, toFiat } = getSwapInfo ( state , quote )
299
+ const { fromDisplayAmount, fee, fromFiat, fromTotalFiat, toDisplayAmount, toFiat } = await getSwapInfo ( state , quote )
310
300
const { isEstimate, fromNativeAmount, toNativeAmount, networkFee, pluginId, expirationDate, request } = quote
311
301
// Both fromCurrencyCode and toCurrencyCode will exist, since we set them:
312
302
const { toWallet, fromCurrencyCode = '' , toCurrencyCode = '' } = request
0 commit comments