-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: brc-20 token balances as fiat, #4408
- Loading branch information
Showing
27 changed files
with
224 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,17 @@ | ||
import { useCallback, useMemo } from 'react'; | ||
import { useCallback } from 'react'; | ||
|
||
import { CryptoCurrencies } from '@shared/models/currencies.model'; | ||
import { createMarketData, createMarketPair } from '@shared/models/market.model'; | ||
import type { Money } from '@shared/models/money.model'; | ||
import { type Money } from '@shared/models/money.model'; | ||
|
||
import { useCryptoCurrencyMarketData } from '@app/query/common/market-data/market-data.hooks'; | ||
import { useCryptoCurrencyMarketDataMeanAverage } from '@app/query/common/market-data/market-data.hooks'; | ||
|
||
import { baseCurrencyAmountInQuote } from '../money/calculate-money'; | ||
|
||
export function useConvertCryptoCurrencyToFiatAmount(currency: CryptoCurrencies) { | ||
const cryptoCurrencyMarketData = useCryptoCurrencyMarketData(currency); | ||
const cryptoCurrencyMarketData = useCryptoCurrencyMarketDataMeanAverage(currency); | ||
|
||
return useCallback( | ||
(value: Money) => baseCurrencyAmountInQuote(value, cryptoCurrencyMarketData), | ||
[cryptoCurrencyMarketData] | ||
); | ||
} | ||
|
||
export function useConvertAlexSdkCurrencyToFiatAmount(currency: CryptoCurrencies, price: Money) { | ||
const alexCurrencyMarketData = useMemo( | ||
() => createMarketData(createMarketPair(currency, 'USD'), price), | ||
[currency, price] | ||
); | ||
|
||
return useCallback( | ||
(value: Money) => baseCurrencyAmountInQuote(value, alexCurrencyMarketData), | ||
[alexCurrencyMarketData] | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import type { CryptoCurrencies } from '@shared/models/currencies.model'; | ||
import { createMarketData, createMarketPair } from '@shared/models/market.model'; | ||
import { type Money, createMoney } from '@shared/models/money.model'; | ||
import { isUndefined } from '@shared/utils'; | ||
|
||
import { baseCurrencyAmountInQuote } from './calculate-money'; | ||
import { unitToFractionalUnit } from './unit-conversion'; | ||
|
||
export function checkIsMoneyAmountValidToDisplay(money: Money) { | ||
return !(money.amount.isNaN() || money.amount.isZero()); | ||
} | ||
|
||
export function convertCryptoCurrencyMoneyToFiat( | ||
currency: CryptoCurrencies, | ||
price: Money, | ||
money: Money | ||
) { | ||
const cryptoCurrencyMarketData = createMarketData(createMarketPair(currency, 'USD'), price); | ||
return baseCurrencyAmountInQuote(money, cryptoCurrencyMarketData); | ||
} | ||
|
||
export function convertCryptoCurrencyValueToFiat(balance: Money, price: Money, value: string) { | ||
if (isUndefined(balance) || isUndefined(price) || isUndefined(value)) return; | ||
|
||
const cryptoCurrencyMarketData = createMarketData(createMarketPair(balance.symbol, 'USD'), price); | ||
|
||
const valueAsMoney = createMoney( | ||
unitToFractionalUnit(balance.decimals)(value), | ||
balance.symbol, | ||
balance.decimals | ||
); | ||
return baseCurrencyAmountInQuote(valueAsMoney, cryptoCurrencyMarketData); | ||
} | ||
|
||
// Used in swaps for amount input fiat conversion while typing | ||
// export function useFormattedFractionalUnitAsFiat(balance?: Money, price?: Money, value?: string) { | ||
// const convertCurrencyToUsd = useConvertCryptoCurrencyToUsdAmount( | ||
// balance?.symbol ?? '', | ||
// price ?? createMoney(0, 'USD') | ||
// ); | ||
|
||
// if (isUndefined(balance) || isUndefined(price) || isUndefined(value)) return; | ||
|
||
// const convertedAmountAsMoney = convertCurrencyToUsd( | ||
// createMoney(unitToFractionalUnit(balance.decimals)(value), balance.symbol, balance.decimals) | ||
// ); | ||
|
||
// if (convertedAmountAsMoney.amount.isNaN()) return; | ||
// return i18nFormatCurrency(convertedAmountAsMoney); | ||
// } | ||
|
||
// export function convertCryptoCurrencyToFractionalUnitAsFiat( | ||
// balance: Money, | ||
// price: Money, | ||
// value: string | ||
// ) { | ||
// const valueAsMoney = createMoney( | ||
// unitToFractionalUnit(balance.decimals)(value), | ||
// balance.symbol, | ||
// balance.decimals | ||
// ); | ||
// const convertCurrencyToFiatAmount = convertCryptoCurrencyMoneyToFiat( | ||
// balance.symbol, | ||
// price, | ||
// valueAsMoney | ||
// ); | ||
|
||
// return convertCurrencyToFiatAmount; | ||
// } | ||
|
||
// Used in asset list and swaps to show ft fiat balances | ||
// export function useFormattedBaseUnitAsFiat(balance: Money, price?: Money | null) { | ||
// const convertCurrencyToUsd = useConvertCryptoCurrencyToUsdAmount( | ||
// balance.symbol, | ||
// price ?? createMoney(0, 'USD') | ||
// ); | ||
|
||
// if (isUndefined(balance) || isUndefined(price)) return; | ||
|
||
// const convertedBalanceAsMoney = convertCurrencyToUsd( | ||
// createMoney(balance.amount, balance.symbol, balance.decimals) | ||
// ); | ||
|
||
// if (convertedBalanceAsMoney.amount.isNaN() || convertedBalanceAsMoney.amount.isEqualTo(0)) return; | ||
// return i18nFormatCurrency(convertedBalanceAsMoney); | ||
// } | ||
|
||
// export function convertCryptoCurrencyBalanceToFiatAmount(balance: Money, price: Money) { | ||
// const convertCurrencyToFiatAmount = convertCryptoCurrencyMoneyToFiat( | ||
// balance.symbol, | ||
// price, | ||
// valueAsMoney | ||
// ); | ||
|
||
// return convertCurrencyToFiatAmount; | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.