Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deposits on non-ETH gas token pools #1536

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import DepositButton from './DepositButton'
import { txErrorHandler } from '@/utils/txErrorHandler'
import { fetchPoolUserData } from '@/slices/poolUserDataSlice'
import { swapPoolCalculateAddLiquidity } from '@/actions/swapPoolCalculateAddLiquidity'
import { zeroAddress } from 'viem'

export const DEFAULT_DEPOSIT_QUOTE = {
priceImpact: 0n,
Expand Down Expand Up @@ -208,6 +209,7 @@ const Deposit = ({
<SerializedDepositInput
key={i}
tokenObj={tokenObj}
pool={pool}
address={address}
chainId={chainId}
inputValue={inputValue}
Expand All @@ -234,14 +236,15 @@ const Deposit = ({
}

const SerializedDepositInput = ({
pool,
tokenObj,
address,
chainId,
inputValue,
onChangeInputValue,
}) => {
const [serializedToken, setSerializedToken] = useState(undefined)
const balanceToken = correctToken(tokenObj.token)
const balanceToken = getBalanceToken(tokenObj.token, pool)

useEffect(() => {
const fetchSerializedData = async () => {
Expand Down Expand Up @@ -281,12 +284,11 @@ const SerializedDepositInput = ({
)
}

const correctToken = (token: Token) => {
const getBalanceToken = (token: Token, pool: Token) => {
let balanceToken: Token | undefined
if (token.symbol == WETH.symbol) {
if (token.symbol == WETH.symbol && !pool.nativeTokens.includes(WETH)) {
balanceToken = ETH
} else if (token.symbol == AVWETH.symbol) {
// token = WETHE
balanceToken = WETHE
} else {
balanceToken = token
Expand All @@ -302,7 +304,7 @@ const serializeToken = async (
) => {
let fetchedBalance

if (balanceToken === ETH) {
if (balanceToken.addresses[chainId] === zeroAddress) {
fetchedBalance = await fetchBalance({
address: address as Address,
chainId,
Expand Down
Loading