Skip to content

Commit

Permalink
no routes button fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
lufaque committed Nov 26, 2023
1 parent b0fd9c6 commit d52cdca
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/components/buttons/SwapButton/getButtonType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ import { ButtonType } from './constants'
import { isInsufficientFee } from './isInsufficientFee'

export function getButtonType(swapState: SwapState, isConnected: boolean): ButtonType {
const { from, to, routes, isLoading, balance } = swapState
const { from, to, routes, isLoading, balance, isNoRoutes } = swapState

if (isLoading) {
return ButtonType.LOADING
}

if (isNoRoutes) {
return ButtonType.NO_ROUTES
}

if (!isConnected) {
return ButtonType.CONNECT_WALLET
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export async function fetchWalletBalancesOnStepChains(routes: StandardRoute[], s
})
})

if (!chainIds.length) return

const walletBalances = await fetchBalancesByChainIds(chainIds, walletAddress as string)
swapDispatch({ type: SwapActionType.SET_WALLET_BALANCES, balances: walletBalances })
}
5 changes: 5 additions & 0 deletions src/components/cards/SwapCard/getRoutes/getRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export const getRoutes = async (from: SwapStateDirection, to: SwapStateDirection

try {
await Promise.all([getLifiRoutes({ routes, from, to, settings, swapDispatch }), getRangoRoutes({ routes, from, to, settings, swapDispatch })])

if (!routes.length) {
swapDispatch({ type: 'SET_IS_NO_ROUTES', status: true })
}

await fetchWalletBalancesOnStepChains(routes, swapDispatch, from.address)
} catch (error) {
console.error(error)
Expand Down
1 change: 1 addition & 0 deletions src/components/cards/SwapCard/handlers/handleRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export const clearRoutes = (typingTimeoutRef: MutableRefObject<number | undefine
if (typingTimeoutRef.current) clearTimeout(typingTimeoutRef.current)
swapDispatch({ type: 'CLEAR_ROUTES' })
swapDispatch({ type: 'RESET_AMOUNTS', direction: 'to' })
swapDispatch({ type: 'SET_IS_NO_ROUTES', status: false })
}
1 change: 1 addition & 0 deletions src/components/cards/SwapCard/swapReducer/swapActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export const swapActions: SwapAction = {
// }
// },
SET_WALLET_BALANCES: (state: SwapState, action: SwapAction) => ({ ...state, walletBalances: action.balances }),
SET_IS_NO_ROUTES: (state: SwapState, action: SwapAction) => ({ ...state, isNoRoutes: action.status }),
}

function updateLastSwapState(state: SwapState): SwapState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const swapInitialState = (selection): SwapState => ({
},
balance: null,
routes: [],
isNoRoutes: false,
isLoading: false,
selectedRoute: null,
typingTimeout: 0,
Expand Down
2 changes: 2 additions & 0 deletions src/components/cards/SwapCard/swapReducer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface SwapState {
from: SwapStateDirection
to: SwapStateDirection
routes: StandardRoute[]
isNoRoutes: boolean
isLoading: boolean
selectedRoute: StandardRoute | null
typingTimeout: number
Expand Down Expand Up @@ -111,3 +112,4 @@ export type SwapAction =
| { type: 'UPDATE_LAST_SWAP_STEP' }
| { type: 'UPDATE_PREV_RANGO_STEPS'; currentTransactionStatus: TransactionStatus }
| { type: SwapActionType.SET_WALLET_BALANCES; balances: ConceroBalanceResponse | null }
| { type: 'SET_IS_NO_ROUTES'; status: boolean }

0 comments on commit d52cdca

Please sign in to comment.