Skip to content

Commit

Permalink
prevent swapping a token with itself
Browse files Browse the repository at this point in the history
  • Loading branch information
eli-d committed Jul 1, 2024
1 parent 3a9c561 commit 244f6ec
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions web/src/app/swap/explore/_AllAssetsTable/AllAssetsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function AllAssetsTable<TData, TValue>({
getFilteredRowModel: getFilteredRowModel(),
});

const { setToken1, setToken0 } = useSwapStore();
const { token0, token1, setToken1, setToken0 } = useSwapStore();

const router = useRouter();

Expand Down Expand Up @@ -140,9 +140,9 @@ export function AllAssetsTable<TData, TValue>({
{header.isPlaceholder
? null
: flexRender(
header.column.columnDef.header,
header.getContext(),
)}
header.column.columnDef.header,
header.getContext(),
)}
</TableHead>
);
})}
Expand All @@ -157,10 +157,12 @@ export function AllAssetsTable<TData, TValue>({
data-state={row.getIsSelected() && "selected"}
className=" cursor-pointer border-b-0 text-[10px] hover:bg-black md:text-xs"
onClick={() => {
if ((token === "0")) {
setToken0(row.original.token);
} else {
setToken1(row.original.token);
const { original: { token: rowToken } } = row
const { address } = rowToken
if (token === "0" && address !== token1.address) {
setToken0(rowToken);
} else if (token === "1" && address !== token0.address) {
setToken1(rowToken);
}
router.back();
}}
Expand Down

0 comments on commit 244f6ec

Please sign in to comment.