Skip to content

Commit

Permalink
Merge branch 'dev' into marcinciarka/sc-15009/multiply-fix-price-impact
Browse files Browse the repository at this point in the history
  • Loading branch information
marcinciarka authored Mar 27, 2024
2 parents 4d6122b + bb53d2b commit ca9e4bc
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions features/omni-kit/components/sidebars/OmniInputSwap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ExpandableArrow } from 'components/dumb/ExpandableArrow'
import { TokensGroup } from 'components/TokensGroup'
import { useOmniGeneralContext, useOmniProductContext } from 'features/omni-kit/contexts'
import { formatCryptoBalance } from 'helpers/formatters/format'
import { useAccount } from 'helpers/useAccount'
import { useOutsideElementClickHandler } from 'helpers/useOutsideElementClickHandler'
import type { FC, ReactElement, ReactNode } from 'react'
import React, { useMemo, useRef, useState } from 'react'
Expand All @@ -30,7 +31,7 @@ export const OmniInputSwap: FC<OmniInputSwapProps> = ({
type,
}) => {
const {
environment: { extraTokensData, networkId, productType, settings },
environment: { extraTokensData, networkId, productType, settings, shouldSwitchNetwork },
} = useOmniGeneralContext()
const {
form: {
Expand All @@ -39,35 +40,36 @@ export const OmniInputSwap: FC<OmniInputSwapProps> = ({
},
} = useOmniProductContext(productType)

const { walletAddress } = useAccount()

const [isOpen, setIsOpen] = useState<boolean>(false)
const [selectedToken, setSelectedToken] = useState<string>(pullToken?.token ?? defaultToken)

const outsideRef = useOutsideElementClickHandler(() => setIsOpen(false))
const scrollRef = useRef<HTMLDivElement>(null)

const tokensList = useMemo(
() =>
[
{
address: defaultTokenAddress,
balance: defaultTokenBalance,
precision: defaultTokenPrecision,
price: defaultTokenPrice,
token: defaultToken,
},
...(settings[`${type}Tokens`]?.[networkId] ?? [])
.filter((token) => token !== defaultToken)
.map((token) => ({
address: getNetworkContracts(networkId).tokens[token].address,
balance: extraTokensData[token].balance,
digits: getToken(token).digits,
precision: getToken(token).precision,
price: extraTokensData[token].price,
token,
})),
]
() => [
{
address: defaultTokenAddress,
balance: defaultTokenBalance,
precision: defaultTokenPrecision,
price: defaultTokenPrice,
token: defaultToken,
},
...(settings[`${type}Tokens`]?.[networkId] ?? [])
.filter((token) => token !== defaultToken)
.map((token) => ({
address: getNetworkContracts(networkId).tokens[token].address,
balance: extraTokensData[token].balance,
digits: getToken(token).digits,
precision: getToken(token).precision,
price: extraTokensData[token].price,
token,
}))
.filter(({ balance }) => !balance.isZero())
.sort((a, b) => b.balance.times(b.price).minus(a.balance.times(a.price)).toNumber()),
],
[
defaultToken,
defaultTokenAddress,
Expand Down Expand Up @@ -190,5 +192,7 @@ export const OmniInputSwap: FC<OmniInputSwapProps> = ({
</Box>
)

return children({ ...(tokensList.length > 1 && { swapController }) })
return children({
...(walletAddress && !shouldSwitchNetwork && tokensList.length > 1 && { swapController }),
})
}

0 comments on commit ca9e4bc

Please sign in to comment.