Skip to content

Commit c9ce311

Browse files
committed
Replace convertCurrencyFromExchangeRates with convertCurrency
1 parent afe9bf9 commit c9ce311

16 files changed

+63
-91
lines changed

src/actions/WalletActions.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
} from '../constants/WalletAndCurrencyConstants'
3030
import { lstrings } from '../locales/strings'
3131
import { selectDisplayDenomByCurrencyCode } from '../selectors/DenominationSelectors'
32+
import { convertCurrency } from '../selectors/WalletSelectors'
3233
import type { ThunkAction } from '../types/reduxTypes'
3334
import type { NavigationBase } from '../types/routerTypes'
3435
import type { MapObject } from '../types/types'
@@ -39,7 +40,6 @@ import {
3940
} from '../util/CurrencyInfoHelpers'
4041
import { getWalletName } from '../util/CurrencyWalletHelpers'
4142
import { fetchInfo } from '../util/network'
42-
import { convertCurrencyFromExchangeRates } from '../util/utils'
4343

4444
export interface SelectWalletTokenParams {
4545
navigation: NavigationBase
@@ -274,7 +274,7 @@ export function activateWalletTokens(
274274
feeDenom.multiplier,
275275
log10(feeDenom.multiplier)
276276
)
277-
let fiatFee = convertCurrencyFromExchangeRates(
277+
let fiatFee = convertCurrency(
278278
state.exchangeRates,
279279
pluginId,
280280
feeTokenId,

src/components/scenes/Fio/FioStakingChangeScene.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
} from '../../../locales/intl'
2323
import { lstrings } from '../../../locales/strings'
2424
import { getExchangeDenom } from '../../../selectors/DenominationSelectors'
25+
import { convertCurrency } from '../../../selectors/WalletSelectors'
2526
import { useDispatch, useSelector } from '../../../types/reactRedux'
2627
import type { EdgeAppSceneProps } from '../../../types/routerTypes'
2728
import {
@@ -32,10 +33,7 @@ import {
3233
type FioStakingBalanceType,
3334
getFioStakingBalances
3435
} from '../../../util/stakeUtils'
35-
import {
36-
convertCurrencyFromExchangeRates,
37-
convertNativeToDenomination
38-
} from '../../../util/utils'
36+
import { convertNativeToDenomination } from '../../../util/utils'
3937
import { AlertCardUi4 } from '../../cards/AlertCard'
4038
import { EdgeCard } from '../../cards/EdgeCard'
4139
import { SceneWrapper } from '../../common/SceneWrapper'
@@ -139,7 +137,7 @@ export const FioStakingChangeScene = withWallet((props: Props) => {
139137
const stakingDefaultCryptoAmount = convertNativeToDenomination(
140138
defaultDenomination.multiplier
141139
)(stakingNativeAmount)
142-
const stakingFiatBalance = convertCurrencyFromExchangeRates(
140+
const stakingFiatBalance = convertCurrency(
143141
exchangeRates,
144142
pluginId,
145143
tokenId,

src/components/scenes/Fio/FioStakingOverviewScene.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ export const FioStakingOverviewScene = connect<
258258
defaultDenomination.multiplier
259259
)(stakedNativeAmount ?? '0')
260260
const stakingFiatBalance = convertCurrency(
261-
state,
261+
state.exchangeRates,
262262
currencyWallet.currencyInfo.pluginId,
263263
tokenId,
264264
defaultIsoFiat,

src/components/scenes/Loans/LoanCreateConfirmationScene.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export const LoanCreateConfirmationScene = (props: Props) => {
106106
const borrowPluginCurrencyPluginId = borrowPlugin.borrowInfo.currencyPluginId
107107
const minFeeSwapAmount = useSelector(state => {
108108
const polygonPrice = convertCurrency(
109-
state,
109+
state.exchangeRates,
110110
'polygon',
111111
null,
112112
'iso:USD',
@@ -294,7 +294,7 @@ export const LoanCreateConfirmationScene = (props: Props) => {
294294
DECIMAL_PRECISION
295295
)
296296
return convertCurrency(
297-
state,
297+
state.exchangeRates,
298298
srcWallet.currencyInfo.pluginId,
299299
srcTokenId,
300300
srcIsoFiatCurrencyCode,
@@ -308,7 +308,7 @@ export const LoanCreateConfirmationScene = (props: Props) => {
308308
DECIMAL_PRECISION
309309
)
310310
return convertCurrency(
311-
state,
311+
state.exchangeRates,
312312
srcWallet.currencyInfo.pluginId,
313313
srcTokenId,
314314
srcIsoFiatCurrencyCode,
@@ -322,7 +322,7 @@ export const LoanCreateConfirmationScene = (props: Props) => {
322322
DECIMAL_PRECISION
323323
)
324324
return convertCurrency(
325-
state,
325+
state.exchangeRates,
326326
borrowEngineWallet.currencyInfo.pluginId,
327327
null,
328328
feeIsoFiatCurrencyCode,

src/components/scenes/Loans/LoanCreateScene.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,13 +320,13 @@ export const LoanCreateScene = (props: Props) => {
320320
if (srcWallet == null) return '1'
321321

322322
const sourceRate = convertCurrency(
323-
state,
323+
state.exchangeRates,
324324
srcWallet.currencyInfo.pluginId,
325325
srcTokenId,
326326
defaultIsoFiat
327327
)
328328
const hardCollateralRate = convertCurrency(
329-
state,
329+
state.exchangeRates,
330330
borrowEnginePluginId,
331331
'1bfd67037b42cf73acf2047067bd4f2c47d9bfd6', // WETH
332332
defaultIsoFiat
@@ -344,7 +344,7 @@ export const LoanCreateScene = (props: Props) => {
344344
const minSwapInputNativeAmount = useSelector(state => {
345345
if (srcWallet == null) return '0'
346346
const rate = convertCurrency(
347-
state,
347+
state.exchangeRates,
348348
srcWallet.currencyInfo.pluginId,
349349
srcTokenId,
350350
'iso:USD'

src/components/scenes/SwapConfirmationScene.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@ import { CryptoAmount } from '../../util/CryptoAmount'
2727
import { getCurrencyCodeMultiplier } from '../../util/CurrencyInfoHelpers'
2828
import { logActivity } from '../../util/logger'
2929
import { logEvent } from '../../util/tracking'
30-
import {
31-
convertCurrencyFromExchangeRates,
32-
convertNativeToExchange,
33-
DECIMAL_PRECISION
34-
} from '../../util/utils'
30+
import { convertNativeToExchange, DECIMAL_PRECISION } from '../../util/utils'
3531
import { AlertCardUi4 } from '../cards/AlertCard'
3632
import { EdgeCard } from '../cards/EdgeCard'
3733
import { PoweredByCard } from '../cards/PoweredByCard'
@@ -84,7 +80,7 @@ export const SwapConfirmationScene: React.FC<Props> = (props: Props) => {
8480
const feeFiat = useSelector(state =>
8581
selectedQuote == null
8682
? '0'
87-
: convertCurrencyFromExchangeRates(
83+
: convertCurrency(
8884
state.exchangeRates,
8985
selectedQuote.pluginId,
9086
selectedQuote.networkFee.tokenId,
@@ -507,7 +503,7 @@ const getSwapInfo = (
507503
)(quote.fromNativeAmount)
508504
const fromBalanceInFiatRaw = parseFloat(
509505
convertCurrency(
510-
state,
506+
state.exchangeRates,
511507
fromWallet.currencyInfo.pluginId,
512508
fromTokenId,
513509
defaultIsoFiat,
@@ -542,7 +538,7 @@ const getSwapInfo = (
542538
)
543539
const feeFiatAmountRaw = parseFloat(
544540
convertCurrency(
545-
state,
541+
state.exchangeRates,
546542
request.fromWallet.currencyInfo.pluginId,
547543
quote.networkFee.tokenId,
548544
defaultIsoFiat,
@@ -582,7 +578,7 @@ const getSwapInfo = (
582578
)(quote.toNativeAmount)
583579
const toBalanceInFiatRaw = parseFloat(
584580
convertCurrency(
585-
state,
581+
state.exchangeRates,
586582
toWallet.currencyInfo.pluginId,
587583
toTokenId,
588584
defaultIsoFiat,

src/components/scenes/TransactionDetailsScene.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ import { useWatch } from '../../hooks/useWatch'
3131
import { toPercentString } from '../../locales/intl'
3232
import { lstrings } from '../../locales/strings'
3333
import { getExchangeDenom } from '../../selectors/DenominationSelectors'
34+
import { convertCurrency } from '../../selectors/WalletSelectors'
3435
import { useSelector } from '../../types/reactRedux'
3536
import type { EdgeAppSceneProps } from '../../types/routerTypes'
3637
import { getCurrencyCodeWithAccount } from '../../util/CurrencyInfoHelpers'
3738
import { matchJson } from '../../util/matchJson'
3839
import { getMemoTitle } from '../../util/memoUtils'
3940
import {
40-
convertCurrencyFromExchangeRates,
4141
convertNativeToExchange,
4242
darkenHexColor,
4343
removeIsoPrefix
@@ -133,7 +133,7 @@ const TransactionDetailsComponent = (props: Props) => {
133133
)
134134
const currentFiat = useSelector(state =>
135135
parseFloat(
136-
convertCurrencyFromExchangeRates(
136+
convertCurrency(
137137
state.exchangeRates,
138138
currencyInfo.pluginId,
139139
tokenId,

src/components/services/AccountCallbackManager.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,11 @@ import { useAsyncEffect } from '../../hooks/useAsyncEffect'
1919
import { useWalletsSubscriber } from '../../hooks/useWalletsSubscriber'
2020
import { stakeMetadataCache } from '../../plugins/stake-plugins/metadataCache'
2121
import { getExchangeDenom } from '../../selectors/DenominationSelectors'
22+
import { convertCurrency } from '../../selectors/WalletSelectors'
2223
import { useDispatch, useSelector } from '../../types/reactRedux'
2324
import type { NavigationBase } from '../../types/routerTypes'
2425
import { makePeriodicTask } from '../../util/PeriodicTask'
25-
import {
26-
convertCurrencyFromExchangeRates,
27-
convertNativeToExchange,
28-
datelog,
29-
snooze
30-
} from '../../util/utils'
26+
import { convertNativeToExchange, datelog, snooze } from '../../util/utils'
3127
import { Airship, showDevError } from './AirshipInstance'
3228

3329
const REFRESH_RATES_MS = 30000
@@ -156,7 +152,7 @@ export function AccountCallbackManager(props: Props) {
156152
)
157153
)
158154
const usdAmount = parseFloat(
159-
convertCurrencyFromExchangeRates(
155+
convertCurrency(
160156
exchangeRates,
161157
wallet.currencyInfo.pluginId,
162158
tx.tokenId,

src/components/themed/ExchangeQuoteComponent.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export const ExchangeQuote = (props: Props) => {
7373
DECIMAL_PRECISION
7474
)
7575
return convertCurrency(
76-
state,
76+
state.exchangeRates,
7777
fromWallet.currencyInfo.pluginId,
7878
networkFee.tokenId,
7979
isoFiatCurrencyCode,
@@ -88,7 +88,7 @@ export const ExchangeQuote = (props: Props) => {
8888
DECIMAL_PRECISION
8989
)
9090
return convertCurrency(
91-
state,
91+
state.exchangeRates,
9292
fromWallet.currencyInfo.pluginId,
9393
fromTokenId,
9494
isoFiatCurrencyCode,

src/components/themed/ExchangedFlipInput2.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import { useDisplayDenom } from '../../hooks/useDisplayDenom'
88
import { useHandler } from '../../hooks/useHandler'
99
import { lstrings } from '../../locales/strings'
1010
import { getExchangeDenom } from '../../selectors/DenominationSelectors'
11-
import { getExchangeRate } from '../../selectors/WalletSelectors'
11+
import {
12+
convertCurrency,
13+
getExchangeRate
14+
} from '../../selectors/WalletSelectors'
1215
import { useSelector } from '../../types/reactRedux'
1316
import { getCurrencyCode } from '../../util/CurrencyInfoHelpers'
1417
import {
15-
convertCurrencyFromExchangeRates,
1618
DECIMAL_PRECISION,
1719
getDenomFromIsoCode,
1820
maxPrimaryCurrencyConversionDecimals,
@@ -132,14 +134,14 @@ const ExchangedFlipInput2Component = React.forwardRef<
132134
}
133135
]
134136

135-
const convertCurrency = useHandler(
137+
const convertCurrencyHandler = useHandler(
136138
(
137139
amount: string,
138140
pluginId: string,
139141
tokenId: EdgeTokenId,
140142
isoFiatCode: string
141143
): string => {
142-
return convertCurrencyFromExchangeRates(
144+
return convertCurrency(
143145
exchangeRates,
144146
pluginId,
145147
tokenId,
@@ -162,7 +164,7 @@ const ExchangedFlipInput2Component = React.forwardRef<
162164
cryptoDisplayDenom.multiplier,
163165
DECIMAL_PRECISION
164166
)
165-
const fiatAmountLong = convertCurrency(
167+
const fiatAmountLong = convertCurrencyHandler(
166168
exchangeAmount,
167169
pluginId,
168170
tokenId,
@@ -258,7 +260,7 @@ const ExchangedFlipInput2Component = React.forwardRef<
258260
const { exchangeAmount, displayAmount } = convertFromCryptoNative(
259261
startNativeAmount ?? ''
260262
)
261-
const initFiat = convertCurrency(
263+
const initFiat = convertCurrencyHandler(
262264
exchangeAmount,
263265
pluginId,
264266
tokenId,
@@ -267,7 +269,7 @@ const ExchangedFlipInput2Component = React.forwardRef<
267269
setRenderDisplayAmount(displayAmount)
268270
setRenderFiatAmount(initFiat)
269271
}, [
270-
convertCurrency,
272+
convertCurrencyHandler,
271273
convertFromCryptoNative,
272274
cryptoCurrencyCode,
273275
defaultIsoFiat,
@@ -296,10 +298,10 @@ const ExchangedFlipInput2Component = React.forwardRef<
296298
*/
297299
const overrideForceField = useMemo(
298300
() =>
299-
convertCurrency('100', pluginId, tokenId, defaultIsoFiat) === '0'
301+
convertCurrencyHandler('100', pluginId, tokenId, defaultIsoFiat) === '0'
300302
? 'crypto'
301303
: forceField,
302-
[convertCurrency, defaultIsoFiat, forceField, pluginId, tokenId]
304+
[convertCurrencyHandler, defaultIsoFiat, forceField, pluginId, tokenId]
303305
)
304306

305307
const pluginInfo = getSpecialCurrencyInfo(pluginId)

0 commit comments

Comments
 (0)