Skip to content

Commit ab2bc69

Browse files
committed
fixup! Refactor ExchangeQuote Component
1 parent 91dabba commit ab2bc69

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

src/actions/CryptoExchangeActions.tsx

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { sprintf } from 'sprintf-js'
1717
import { trackConversion } from '../actions/TrackingActions'
1818
import { InsufficientFeesModal } from '../components/modals/InsufficientFeesModal'
1919
import { Airship, showError } from '../components/services/AirshipInstance'
20-
import { formatFiatString } from '../hooks/useFiatText'
2120
import { formatNumber } from '../locales/intl'
2221
import { lstrings } from '../locales/strings'
2322
import { getDisplayDenomination, getExchangeDenomination } from '../selectors/DenominationSelectors'
@@ -159,7 +158,7 @@ async function fetchSwapQuotes(state: RootState, request: EdgeSwapRequest): Prom
159158
}
160159

161160
// 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> => {
163162
// Currency conversion tools:
164163
// Both fromCurrencyCode and toCurrencyCode will exist, since we set them:
165164
const { request } = quote
@@ -183,20 +182,11 @@ export const getSwapInfo = (state: RootState, quote: EdgeSwapQuote): GuiSwapInfo
183182
const feeDisplayAmount = toFixed(feeTempAmount, 0, 6)
184183

185184
// 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 })
196188
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 })
200190

201191
// Format to amount:
202192
const toPrimaryInfo = state.cryptoExchange.toWalletPrimaryInfo
@@ -306,7 +296,7 @@ export function shiftCryptoCurrency(navigation: NavigationBase, quote: EdgeSwapQ
306296
const { account } = state.core
307297
dispatch({ type: 'START_SHIFT_TRANSACTION' })
308298

309-
const { fromDisplayAmount, fee, fromFiat, fromTotalFiat, toDisplayAmount, toFiat } = getSwapInfo(state, quote)
299+
const { fromDisplayAmount, fee, fromFiat, fromTotalFiat, toDisplayAmount, toFiat } = await getSwapInfo(state, quote)
310300
const { isEstimate, fromNativeAmount, toNativeAmount, networkFee, pluginId, expirationDate, request } = quote
311301
// Both fromCurrencyCode and toCurrencyCode will exist, since we set them:
312302
const { toWallet, fromCurrencyCode = '', toCurrencyCode = '' } = request

0 commit comments

Comments
 (0)