Skip to content

Commit

Permalink
fetchWalletBalancesOnStepChains.ts fixed, getButtonType.ts low balanc…
Browse files Browse the repository at this point in the history
…e state fixed
  • Loading branch information
lufaque committed Dec 15, 2023
1 parent d6b2042 commit e9ea309
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/components/buttons/SwapButton/getButtonType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { SwapState } from '../../cards/SwapCard/swapReducer/types'
import { ButtonType } from './constants'
import { isInsufficientFee } from './isInsufficientFee'
import { Fees } from '../../../types/StandardRoute'
import { config } from '../../../constants/config'

export function getButtonType(swapState: SwapState, isConnected: boolean): ButtonType {
const { from, to, routes, isLoading, balance, isNoRoutes, selectedRoute } = swapState
Expand All @@ -22,8 +23,13 @@ export function getButtonType(swapState: SwapState, isConnected: boolean): Butto
return ButtonType.ENTER_AMOUNT
}

const fromGasAmount =
selectedRoute?.cost.total_fee.find((fee: Fees) => fee.asset.chainId === from.chain.id && fee.asset.address?.toLowerCase() === from.token.address.toLowerCase())?.amount ?? 0
let fromGasAmount: string | 0 = 0

if (selectedRoute?.from.token.address === config.NULL_ADDRESS) {
fromGasAmount =
selectedRoute.cost.total_fee.find((fee: Fees) => fee.asset.chainId === from.chain.id && fee.asset.address?.toLowerCase() === from.token.address.toLowerCase())?.amount ?? 0
}

const fullAmount = Number(from.amount) + Number(fromGasAmount)
const balanceNumber = Number(balance.split(' ')[0] ?? 0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { SwapAction, SwapActionType } from '../swapReducer/types'
import { fetchBalancesByChainIds } from '../../../../api/concero/fetchBalancesByChainIds'

export async function fetchWalletBalancesOnStepChains(routes: StandardRoute[], swapDispatch: Dispatch<SwapAction>, walletAddress: string): Promise<void> {
if (!routes.length) return

let chainIds: string[] = []

routes.forEach((route: StandardRoute) => {
Expand Down

0 comments on commit e9ea309

Please sign in to comment.