Skip to content

Commit

Permalink
cleaned up
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor committed Oct 27, 2023
1 parent f81b37d commit 09ad290
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/app/components/PairSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { useAppSelector, useAppDispatch } from "../hooks";
import { selectPairAddress } from "../redux/pairSelectorSlice";
import { useRef, useState } from "react";

interface PairInfo {
name: string;
address: string;
}
function displayName(name?: string) {
return name?.replace("/", " - ");
}
Expand All @@ -14,10 +18,8 @@ export function PairSelector() {
};
const options = pairSelector.pairsList;
const id = "pairOption";
let selectedVal = useRef<string>(
pairSelector.pairsList[0] ? pairSelector.pairsList[0].name : "Loading"
);
const handleChange = (val) => {
const handleChange = (val: PairInfo | null) => {
if (val == null) return;
selectPair(val["address"]);
};

Expand All @@ -27,10 +29,9 @@ export function PairSelector() {
const inputRef = useRef(null);
const dropdownRef = useRef(null);

const selectOption = (option) => {
const selectOption = (option: PairInfo) => {
setQuery(() => "");
handleChange(option);
selectedVal.current = option["name"];
setIsOpen((isOpen) => !isOpen);
};

Expand All @@ -40,12 +41,12 @@ export function PairSelector() {

const getDisplayValue = () => {
if (query) return displayName(query);
if (selectedVal.current) return displayName(selectedVal.current);
if (pairSelector.name) return displayName(pairSelector.name);

return "";
};

const filter = (options) => {
const filter = (options: PairInfo[]) => {
return options.filter(
(option) => option["name"].toLowerCase().indexOf(query.toLowerCase()) > -1
);
Expand Down Expand Up @@ -93,11 +94,7 @@ export function PairSelector() {
return (
<li
onClick={() => selectOption(option)}
className={
`${
option["name"] === selectedVal.current ? "selected" : ""
}` + " font-bold !pl-0"
}
className=" font-bold !pl-0"
key={`${id}-${index}`}
>
<div className="flex justify-between">
Expand All @@ -107,6 +104,17 @@ export function PairSelector() {
</li>
);
})}
<li>
<div
className={
filter(options).length == 0
? "flex justify-between"
: "flex justify-between hidden"
}
>
<span className="flex-1">No Results</span>
</div>
</li>
</ul>
</div>
</div>
Expand Down

0 comments on commit 09ad290

Please sign in to comment.