Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/weak-beds-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@reservoir0x/relay-kit-ui': patch
---

Improve ui when no route are available
5 changes: 4 additions & 1 deletion packages/ui/src/components/widgets/FeeBreakdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type Props = Pick<
fromChainWalletVMSupported?: boolean
isAutoSlippage: boolean
slippageInputBps?: string
error?: any
}

const formatSwapRate = (rate: number) => {
Expand All @@ -62,7 +63,8 @@ const FeeBreakdown: FC<Props> = ({
isSingleChainLocked,
fromChainWalletVMSupported,
isAutoSlippage,
slippageInputBps
slippageInputBps,
error
}) => {
const [isOpen, setIsOpen] = useState(false)
const swapRate = quote?.details?.rate
Expand Down Expand Up @@ -218,6 +220,7 @@ const FeeBreakdown: FC<Props> = ({
setUseExternalLiquidity(selected)
}}
canonicalTimeEstimate={canonicalTimeEstimate?.formattedTime}
error={error}
trigger={
<Button color="ghost" size="none">
<Flex css={{ gap: '2', alignItems: 'center' }}>
Expand Down
38 changes: 28 additions & 10 deletions packages/ui/src/components/widgets/SwapRouteSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Box, Button, Flex, Text } from '../primitives/index.js'
import { Dropdown, DropdownMenuItem } from '../primitives/Dropdown.js'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { ASSETS_RELAY_API, type RelayChain } from '@reservoir0x/relay-sdk'
import { faChevronRight } from '@fortawesome/free-solid-svg-icons'
import { faChevronRight, faRoute } from '@fortawesome/free-solid-svg-icons'

type Props = {
supportsExternalLiquidity: boolean
Expand All @@ -12,6 +12,7 @@ type Props = {
chain?: RelayChain
canonicalTimeEstimate?: string
trigger?: ReactNode
error?: any
}

const SwapRouteSelector: FC<Props> = ({
Expand All @@ -20,9 +21,15 @@ const SwapRouteSelector: FC<Props> = ({
onExternalLiquidityChange,
chain,
canonicalTimeEstimate,
trigger
trigger,
error
}) => {
const [open, setOpen] = useState(false)

const isNoAvailableRoutesError =
error?.response?.data?.errorCode === 'NO_SWAP_ROUTES_FOUND' ||
error?.response?.data?.errorCode === 'UNSUPPORTED_ROUTE'

return (
<Dropdown
open={open}
Expand Down Expand Up @@ -72,14 +79,25 @@ const SwapRouteSelector: FC<Props> = ({
>
<Text style="subtitle2">Route</Text>
<Flex css={{ gap: '2', alignItems: 'center' }}>
<Text style="subtitle2">
{externalLiquidtySelected ? 'Native' : 'Relay'}
</Text>
{supportsExternalLiquidity || externalLiquidtySelected ? (
<Box css={{ color: 'gray11', width: 14, flexShrink: 0 }}>
<FontAwesomeIcon icon={faChevronRight} width={14} />
</Box>
) : null}
{isNoAvailableRoutesError ? (
<>
<Text style="subtitle2">No available routes</Text>
<Box css={{ color: 'gray11', width: 14, flexShrink: 0 }}>
<FontAwesomeIcon icon={faRoute} width={14} />
</Box>
</>
) : (
<>
<Text style="subtitle2">
{externalLiquidtySelected ? 'Native' : 'Relay'}
</Text>
{supportsExternalLiquidity || externalLiquidtySelected ? (
<Box css={{ color: 'gray11', width: 14, flexShrink: 0 }}>
<FontAwesomeIcon icon={faChevronRight} width={14} />
</Box>
) : null}
</>
)}
</Flex>
</Button>
)
Expand Down
2 changes: 2 additions & 0 deletions packages/ui/src/components/widgets/SwapWidget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,7 @@ const SwapWidget: FC<SwapWidgetProps> = ({
onExternalLiquidityChange={(selected) => {
setUseExternalLiquidity(selected)
}}
error={error}
/>
</Box>
) : null}
Expand Down Expand Up @@ -1588,6 +1589,7 @@ const SwapWidget: FC<SwapWidgetProps> = ({
canonicalTimeEstimate={canonicalTimeEstimate}
isSingleChainLocked={isSingleChainLocked}
fromChainWalletVMSupported={fromChainWalletVMSupported}
error={error}
/>
<WidgetErrorWell
hasInsufficientBalance={hasInsufficientBalance}
Expand Down
5 changes: 4 additions & 1 deletion packages/ui/src/components/widgets/WidgetErrorWell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ export const WidgetErrorWell: FC<Props> = ({
quote?.details?.currencyOut &&
(quote?.details?.currencyOut?.amountUsd === undefined ||
quote?.details?.currencyOut?.amountUsd === '0')
const isNoAvailableRoutesError =
error?.response?.data?.errorCode === 'NO_SWAP_ROUTES_FOUND' ||
error?.response?.data?.errorCode === 'UNSUPPORTED_ROUTE'

if (isInsufficientLiquidityError) {
if (isInsufficientLiquidityError || isNoAvailableRoutesError) {
return null
}

Expand Down