Skip to content

Commit

Permalink
feat: allow to select order of returned routes (jumperexchange#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxklenk authored May 20, 2022
1 parent 5899dc3 commit ff33ba5
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions src/components/Swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
getChainById,
getChainByKey,
isSwapStep,
Order,
Route as RouteType,
RoutesRequest,
RoutesResponse,
Expand All @@ -72,6 +73,24 @@ const TOTAL_SLIPPAGE_GUARD_MODAL = new BigNumber(0.9)

const history = createBrowserHistory()
const { Panel } = Collapse
const availableOrders = [
{
key: 'RECOMMENDED',
name: 'Recommended',
},
{
key: 'SAFEST',
name: 'Safest',
},
{
key: 'FASTEST',
name: 'Fastest',
},
{
key: 'CHEAPEST',
name: 'Cheapest',
},
]

let currentRouteCallId: string

Expand Down Expand Up @@ -164,6 +183,7 @@ const Swap = () => {
const [routeCallResult, setRouteCallResult] = useState<{ result: RoutesResponse; id: string }>()

// Options
const [optionOrder, setOptionOrder] = useState<Order>('RECOMMENDED' as Order)
const [optionSlippage, setOptionSlippage] = useState<number>(3)
const [optionInfiniteApproval, setOptionInfiniteApproval] = useState<boolean>(false)
const [optionEnabledBridges, setOptionEnabledBridges] = useState<string[] | undefined>()
Expand Down Expand Up @@ -693,6 +713,7 @@ const Swap = () => {
fromAddress: web3.account || undefined,
toAddress: web3.account || undefined,
options: {
order: optionOrder,
slippage: optionSlippage / 100,
bridges: {
allow: optionEnabledBridges,
Expand Down Expand Up @@ -724,6 +745,7 @@ const Swap = () => {
fromTokenAddress,
toChainKey,
toTokenAddress,
optionOrder,
optionSlippage,
optionEnabledBridges,
optionEnabledExchanges,
Expand Down Expand Up @@ -979,6 +1001,25 @@ const Swap = () => {
<Row justify={'center'} style={{ marginTop: 16 }}>
<Collapse ghost style={{ width: '100%' }}>
<Collapse.Panel header={`Advanced Options`} key="1">
Order
<div>
<Select
placeholder="Select Chain"
value={optionOrder}
onChange={(v) => setOptionOrder(v)}
style={{
width: '100%',
}}>
{availableOrders.map((orderOption) => (
<Select.Option
key={orderOption.key}
value={orderOption.key}
data-label={orderOption.name}>
{orderOption.name}
</Select.Option>
))}
</Select>
</div>
Slippage
<div>
<InputNumber
Expand All @@ -989,8 +1030,7 @@ const Swap = () => {
parser={(value) => parseFloat(value ? value.replace('%', '') : '')}
onChange={setOptionSlippage}
style={{
border: '1px solid rgba(0,0,0,0.25)',
borderRadius: 6,
border: '1px solid #d9d9d9',
width: '100%',
}}
/>
Expand Down

0 comments on commit ff33ba5

Please sign in to comment.