Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
denis-orbs committed Dec 4, 2024
1 parent 5bdc8ee commit 50ee56c
Show file tree
Hide file tree
Showing 6 changed files with 1,828 additions and 4,913 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"dependencies": {
"@ethersproject/hash": "^5.7.0",
"@orbs-network/liquidity-hub-sdk": "^1.0.44",
"@orbs-network/liquidity-hub-sdk": "^1.0.46",
"@orbs-network/swap-ui": "^0.0.14",
"@orbs-network/twap-sdk": "^2.0.40",
"@paraswap/sdk": "^6.10.0",
Expand Down
2 changes: 1 addition & 1 deletion src/components/tokens/token-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function getTextSize(amountLength: number) {
export type TokenCardProps = {
label: string;
amount: string;
amountUsd?: string;
amountUsd?: any;
selectedToken: Token | null;
onSelectToken: (token: Token) => void;
isAmountEditable?: boolean;
Expand Down
16 changes: 13 additions & 3 deletions src/components/tokens/token-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ import {
useSortedTokens,
useTokenBalance,
} from "@/lib";
import { useToExactAmount } from "@/trade/hooks";
import { useToExactAmount, useToken } from "@/trade/hooks";
import { Skeleton } from "../ui/skeleton";
import { Virtuoso } from "react-virtuoso";
import BN from "bignumber.js";



type TokenSelectProps = {
selectedToken: Token | undefined;
onSelectToken: (token: Token) => void;
Expand All @@ -37,17 +39,25 @@ export function TokenSelect({
const [open, setOpen] = useState(false);
const tokens = useSortedTokens();
const [filterInput, setFilterInput] = useState("");
const token = useToken(filterInput)


const filteredTokens = useMemo(() => {
if (!filterInput) return tokens || [];
return (
const res = (
tokens?.filter(
(t) =>
eqIgnoreCase(t.address, filterInput) ||
t.symbol.toLowerCase().includes(filterInput.toLowerCase())
) || []
);
}, [tokens, filterInput]);

return !token ? res : [...res, token]


}, [tokens, filterInput, token]);



return (
<Dialog modal={true} open={open} onOpenChange={(o) => setOpen(o)}>
Expand Down
38 changes: 37 additions & 1 deletion src/trade/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { getNetwork, toExactAmount, toRawAmount } from "@/lib";
import { Token } from "@/types";
import { useMemo } from "react";
import { useChainId } from "wagmi";
import { erc20Abi } from "viem";
import { useChainId, useReadContracts } from "wagmi";

export const useToExactAmount = (amount?: string, decimals?: number) => {
return useMemo(() => toExactAmount(amount, decimals), [amount, decimals]);
Expand All @@ -24,3 +26,37 @@ export const useExplorer = () => {

return network?.explorer;
};

export const useToken = (address?: any) => {
const {data: token} = useReadContracts({
allowFailure: false,
contracts: [
{
address,
abi: erc20Abi,
functionName: "decimals",
},
{
address,
abi: erc20Abi,
functionName: "name",
},
{
address,
abi: erc20Abi,
functionName: "symbol",
},
],
});

return useMemo((): Token | undefined => {
if (!token || !address) return;
return {
symbol: token[2],
decimals: token[0],
address,
name: token[1],
logoUrl: "",
};
}, [token, address]);
};
4 changes: 3 additions & 1 deletion src/trade/liquidity-hub/useIsLiquidityHubTrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export const useIsLiquidityHubTrade = () => {
}
if (liquidityHubDisabled) return false;

return BN(liquidityHubQuote?.minAmountOut || 0).gt(paraswapMinAmountOut || 0);
return BN(liquidityHubQuote?.userMinOutAmountWithGas || 0).gt(
paraswapMinAmountOut || 0
);
}, [
forceLiquidityHub,
liquidityHubDisabled,
Expand Down
Loading

0 comments on commit 50ee56c

Please sign in to comment.