Skip to content

Commit 662c11e

Browse files
authored
Merge pull request #729 from reservoirprotocol/ted/fe-7596-add-a-less-intimidating-ui-state-when-there-is-no-available
Improve UI state when there are no available routes
2 parents 0c31164 + 8d56e30 commit 662c11e

File tree

5 files changed

+43
-12
lines changed

5 files changed

+43
-12
lines changed

.changeset/weak-beds-cheer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@reservoir0x/relay-kit-ui': patch
3+
---
4+
5+
Improve ui when no route are available

packages/ui/src/components/widgets/FeeBreakdown.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type Props = Pick<
4141
fromChainWalletVMSupported?: boolean
4242
isAutoSlippage: boolean
4343
slippageInputBps?: string
44+
error?: any
4445
}
4546

4647
const formatSwapRate = (rate: number) => {
@@ -62,7 +63,8 @@ const FeeBreakdown: FC<Props> = ({
6263
isSingleChainLocked,
6364
fromChainWalletVMSupported,
6465
isAutoSlippage,
65-
slippageInputBps
66+
slippageInputBps,
67+
error
6668
}) => {
6769
const [isOpen, setIsOpen] = useState(false)
6870
const swapRate = quote?.details?.rate
@@ -218,6 +220,7 @@ const FeeBreakdown: FC<Props> = ({
218220
setUseExternalLiquidity(selected)
219221
}}
220222
canonicalTimeEstimate={canonicalTimeEstimate?.formattedTime}
223+
error={error}
221224
trigger={
222225
<Button color="ghost" size="none">
223226
<Flex css={{ gap: '2', alignItems: 'center' }}>

packages/ui/src/components/widgets/SwapRouteSelector.tsx

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Box, Button, Flex, Text } from '../primitives/index.js'
33
import { Dropdown, DropdownMenuItem } from '../primitives/Dropdown.js'
44
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
55
import { ASSETS_RELAY_API, type RelayChain } from '@reservoir0x/relay-sdk'
6-
import { faChevronRight } from '@fortawesome/free-solid-svg-icons'
6+
import { faChevronRight, faRoute } from '@fortawesome/free-solid-svg-icons'
77

88
type Props = {
99
supportsExternalLiquidity: boolean
@@ -12,6 +12,7 @@ type Props = {
1212
chain?: RelayChain
1313
canonicalTimeEstimate?: string
1414
trigger?: ReactNode
15+
error?: any
1516
}
1617

1718
const SwapRouteSelector: FC<Props> = ({
@@ -20,9 +21,15 @@ const SwapRouteSelector: FC<Props> = ({
2021
onExternalLiquidityChange,
2122
chain,
2223
canonicalTimeEstimate,
23-
trigger
24+
trigger,
25+
error
2426
}) => {
2527
const [open, setOpen] = useState(false)
28+
29+
const isNoAvailableRoutesError =
30+
error?.response?.data?.errorCode === 'NO_SWAP_ROUTES_FOUND' ||
31+
error?.response?.data?.errorCode === 'UNSUPPORTED_ROUTE'
32+
2633
return (
2734
<Dropdown
2835
open={open}
@@ -72,14 +79,25 @@ const SwapRouteSelector: FC<Props> = ({
7279
>
7380
<Text style="subtitle2">Route</Text>
7481
<Flex css={{ gap: '2', alignItems: 'center' }}>
75-
<Text style="subtitle2">
76-
{externalLiquidtySelected ? 'Native' : 'Relay'}
77-
</Text>
78-
{supportsExternalLiquidity || externalLiquidtySelected ? (
79-
<Box css={{ color: 'gray11', width: 14, flexShrink: 0 }}>
80-
<FontAwesomeIcon icon={faChevronRight} width={14} />
81-
</Box>
82-
) : null}
82+
{isNoAvailableRoutesError ? (
83+
<>
84+
<Text style="subtitle2">No available routes</Text>
85+
<Box css={{ color: 'gray11', width: 14, flexShrink: 0 }}>
86+
<FontAwesomeIcon icon={faRoute} width={14} />
87+
</Box>
88+
</>
89+
) : (
90+
<>
91+
<Text style="subtitle2">
92+
{externalLiquidtySelected ? 'Native' : 'Relay'}
93+
</Text>
94+
{supportsExternalLiquidity || externalLiquidtySelected ? (
95+
<Box css={{ color: 'gray11', width: 14, flexShrink: 0 }}>
96+
<FontAwesomeIcon icon={faChevronRight} width={14} />
97+
</Box>
98+
) : null}
99+
</>
100+
)}
83101
</Flex>
84102
</Button>
85103
)

packages/ui/src/components/widgets/SwapWidget/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,6 +1565,7 @@ const SwapWidget: FC<SwapWidgetProps> = ({
15651565
onExternalLiquidityChange={(selected) => {
15661566
setUseExternalLiquidity(selected)
15671567
}}
1568+
error={error}
15681569
/>
15691570
</Box>
15701571
) : null}
@@ -1605,6 +1606,7 @@ const SwapWidget: FC<SwapWidgetProps> = ({
16051606
canonicalTimeEstimate={canonicalTimeEstimate}
16061607
isSingleChainLocked={isSingleChainLocked}
16071608
fromChainWalletVMSupported={fromChainWalletVMSupported}
1609+
error={error}
16081610
/>
16091611
<WidgetErrorWell
16101612
hasInsufficientBalance={hasInsufficientBalance}

packages/ui/src/components/widgets/WidgetErrorWell.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ export const WidgetErrorWell: FC<Props> = ({
6464
quote?.details?.currencyOut &&
6565
(quote?.details?.currencyOut?.amountUsd === undefined ||
6666
quote?.details?.currencyOut?.amountUsd === '0')
67+
const isNoAvailableRoutesError =
68+
error?.response?.data?.errorCode === 'NO_SWAP_ROUTES_FOUND' ||
69+
error?.response?.data?.errorCode === 'UNSUPPORTED_ROUTE'
6770

68-
if (isInsufficientLiquidityError) {
71+
if (isInsufficientLiquidityError || isNoAvailableRoutesError) {
6972
return null
7073
}
7174

0 commit comments

Comments
 (0)