Skip to content

Commit

Permalink
✨ select tokens both side
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin Burg committed Sep 8, 2023
1 parent b00afdb commit a9515a6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
23 changes: 13 additions & 10 deletions batcher-ui/src/components/Exchange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ const Exchange = () => {
</Form.Label>
</div>
<div className="flex">
<SelectPair />
<SelectPair isFrom />
<Form.Control asChild>
<input
className="box-border w-full bg-white shadow-black inline-flex h-[35px] items-center justify-center rounded-[4px] px-[10px] text-[15px] leading-none text-black outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"
Expand Down Expand Up @@ -339,15 +339,18 @@ const Exchange = () => {
</p>
</Form.Label>
</div>
<Form.Control asChild>
<input
className="box-border w-full cursor-not-allowed bg-white shadow-black inline-flex h-[35px] items-center justify-center rounded-[4px] px-[10px] text-[15px] leading-none text-black outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"
type="number"
min={0}
disabled
required
/>
</Form.Control>
<div className="flex">
<SelectPair isFrom={false} />
<Form.Control asChild>
<input
className="box-border w-full cursor-not-allowed bg-white shadow-black inline-flex h-[35px] items-center justify-center rounded-[4px] px-[10px] text-[15px] leading-none text-black outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"
type="number"
min={0}
disabled
required
/>
</Form.Control>
</div>
</Form.Field>

<Form.Submit asChild>
Expand Down
23 changes: 17 additions & 6 deletions batcher-ui/src/components/SelectPair.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { useCallback, useEffect, useState } from 'react';
import * as Select from '@radix-ui/react-select';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import {
Expand All @@ -13,12 +13,24 @@ import { changePair } from 'src/actions';
import { getTokensMetadata } from 'src/utils/utils';
import Image from 'next/image';

const SelectPair = () => {
interface SelectPairProps {
isFrom: boolean;
}

const SelectPair = ({ isFrom }: SelectPairProps) => {
const { swap, isReverse } = useSelector(currentSwapSelector);
const dispatch = useDispatch();

const [availableTokens, setAvailableTokens] = useState<any[]>([]);

const displayValue = useCallback(() => {
if (isReverse && isFrom) return swap.to.name;
if (isReverse && !isFrom) return swap.from.token.name;
if (!isReverse && isFrom) return swap.from.token.name;
if (!isReverse && !isFrom) return swap.to.name;
return swap.from.token.name;
}, [isReverse, isFrom, swap]);

useEffect(() => {
getTokensMetadata().then(
(tokens: { name: string; address: string; icon: string | undefined }[]) =>
Expand All @@ -28,14 +40,13 @@ const SelectPair = () => {

return (
<Select.Root
// value={availableTokens[1].name}
value={isReverse ? swap.to.name : swap.from.token.name}
value={displayValue()}
onValueChange={value => {
//TODO: change this when we had more pair
// const parsedValue = value === 'USDt'
const pair =
value === 'tzBTC' ? `tzBTC/${swap.to.name}` : `tzBTC/${value}`;
const reversed = value !== 'tzBTC';
const reversed =
(!isFrom && value === 'tzBTC') || (isFrom && value !== 'tzBTC');
dispatch(changePair(pair, reversed));
}}>
<Select.Trigger className="flex items-center text-dark w-[150px] justify-center rounded px-2 mr-1 text-base gap-2 bg-white hover:bg-hovergray outline-none">
Expand Down

0 comments on commit a9515a6

Please sign in to comment.