feat: show usd price with no input amount (#7328)
* feat: show usd price with no input amount * fix: snapshots * fix: make tokens undefined only - no null * fix: readability * fix: syntax improvements
This commit is contained in:
parent
4f8956f79a
commit
7cd72a706d
@ -190,7 +190,7 @@ export function useToken(tokenAddress?: string | null): Token | null | undefined
|
||||
return useTokenFromMapOrNetwork(tokens, tokenAddress)
|
||||
}
|
||||
|
||||
export function useCurrency(currencyId: Maybe<string>, chainId?: ChainId): Currency | null | undefined {
|
||||
export function useCurrency(currencyId: Maybe<string>, chainId?: ChainId): Currency | undefined {
|
||||
const { chainId: connectedChainId } = useWeb3React()
|
||||
const tokens = useDefaultActiveTokens(chainId ?? connectedChainId)
|
||||
return useCurrencyFromMap(tokens, chainId ?? connectedChainId, currencyId)
|
||||
|
@ -80,7 +80,7 @@ type TokenMap = { [address: string]: Token }
|
||||
* Returns null if token is loading or null was passed.
|
||||
* Returns undefined if tokenAddress is invalid or token does not exist.
|
||||
*/
|
||||
export function useTokenFromMapOrNetwork(tokens: TokenMap, tokenAddress?: string | null): Token | null | undefined {
|
||||
export function useTokenFromMapOrNetwork(tokens: TokenMap, tokenAddress?: string | null): Token | undefined {
|
||||
const address = isAddress(tokenAddress)
|
||||
const token: Token | undefined = address ? tokens[address] : undefined
|
||||
const tokenFromNetwork = useTokenFromActiveNetwork(token ? undefined : address ? address : undefined)
|
||||
@ -106,7 +106,7 @@ export function useCurrencyFromMap(
|
||||
tokens: TokenMap,
|
||||
chainId: ChainId | undefined,
|
||||
currencyId?: string | null
|
||||
): Currency | null | undefined {
|
||||
): Currency | undefined {
|
||||
const nativeCurrency = useNativeCurrency(chainId)
|
||||
const isNative = Boolean(nativeCurrency && currencyId?.toUpperCase() === 'ETH')
|
||||
const shorthandMatchAddress = useMemo(() => {
|
||||
@ -116,7 +116,7 @@ export function useCurrencyFromMap(
|
||||
|
||||
const token = useTokenFromMapOrNetwork(tokens, isNative ? undefined : shorthandMatchAddress ?? currencyId)
|
||||
|
||||
if (currencyId === null || currencyId === undefined || !isSupportedChain(chainId)) return null
|
||||
if (currencyId === null || currencyId === undefined || !isSupportedChain(chainId)) return
|
||||
|
||||
// this case so we use our builtin wrapped token instead of wrapped tokens on token lists
|
||||
const wrappedNative = nativeCurrency?.wrapped
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -323,10 +323,19 @@ export function Swap({
|
||||
[independentField, parsedAmount, showWrap, trade]
|
||||
)
|
||||
|
||||
const fiatValueInput = useUSDPrice(parsedAmounts[Field.INPUT], currencies[Field.INPUT] ?? undefined)
|
||||
const fiatValueOutput = useUSDPrice(parsedAmounts[Field.OUTPUT], currencies[Field.OUTPUT] ?? undefined)
|
||||
const showFiatValueInput = Boolean(parsedAmounts[Field.INPUT])
|
||||
const showFiatValueOutput = Boolean(parsedAmounts[Field.OUTPUT])
|
||||
const getSingleUnitAmount = (currency?: Currency) => {
|
||||
if (!currency) return
|
||||
return CurrencyAmount.fromRawAmount(currency, JSBI.BigInt(10 ** currency.decimals))
|
||||
}
|
||||
|
||||
const fiatValueInput = useUSDPrice(
|
||||
parsedAmounts[Field.INPUT] ?? getSingleUnitAmount(currencies[Field.INPUT]),
|
||||
currencies[Field.INPUT]
|
||||
)
|
||||
const fiatValueOutput = useUSDPrice(
|
||||
parsedAmounts[Field.OUTPUT] ?? getSingleUnitAmount(currencies[Field.OUTPUT]),
|
||||
currencies[Field.OUTPUT]
|
||||
)
|
||||
|
||||
const [routeNotFound, routeIsLoading, routeIsSyncing] = useMemo(
|
||||
() => [
|
||||
@ -632,7 +641,7 @@ export function Swap({
|
||||
currency={currencies[Field.INPUT] ?? null}
|
||||
onUserInput={handleTypeInput}
|
||||
onMax={handleMaxInput}
|
||||
fiatValue={showFiatValueInput ? fiatValueInput : undefined}
|
||||
fiatValue={fiatValueInput}
|
||||
onCurrencySelect={handleInputSelect}
|
||||
otherCurrency={currencies[Field.OUTPUT]}
|
||||
showCommonBases
|
||||
@ -673,7 +682,7 @@ export function Swap({
|
||||
label={<Trans>You receive</Trans>}
|
||||
showMaxButton={false}
|
||||
hideBalance={false}
|
||||
fiatValue={showFiatValueOutput ? fiatValueOutput : undefined}
|
||||
fiatValue={fiatValueOutput}
|
||||
priceImpact={stablecoinPriceImpact}
|
||||
currency={currencies[Field.OUTPUT] ?? null}
|
||||
onCurrencySelect={handleOutputSelect}
|
||||
|
@ -78,7 +78,7 @@ const BAD_RECIPIENT_ADDRESSES: { [address: string]: true } = {
|
||||
}
|
||||
|
||||
export type SwapInfo = {
|
||||
currencies: { [field in Field]?: Currency | null }
|
||||
currencies: { [field in Field]?: Currency }
|
||||
currencyBalances: { [field in Field]?: CurrencyAmount<Currency> }
|
||||
inputTax: Percent
|
||||
outputTax: Percent
|
||||
@ -148,7 +148,7 @@ export function useDerivedSwapInfo(state: SwapState, chainId: ChainId | undefine
|
||||
[relevantTokenBalances]
|
||||
)
|
||||
|
||||
const currencies: { [field in Field]?: Currency | null } = useMemo(
|
||||
const currencies: { [field in Field]?: Currency } = useMemo(
|
||||
() => ({
|
||||
[Field.INPUT]: inputCurrency,
|
||||
[Field.OUTPUT]: outputCurrency,
|
||||
|
Loading…
Reference in New Issue
Block a user