Skip to content

Commit

Permalink
Replace source and target from searchParams with useState
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagofilipenunes committed Sep 13, 2024
1 parent adedb5f commit 6e18fef
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 27 deletions.
27 changes: 4 additions & 23 deletions src/components/trade/tradeWidget/useBuySell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,15 @@ import { TradeWidgetBuySellProps } from 'components/trade/tradeWidget/TradeWidge
import { useTradeAction } from 'components/trade/tradeWidget/useTradeAction';
import { prettifyNumber } from 'utils/helpers';
import { isTouchedZero, isZero } from 'components/strategies/common/utils';
import { useNavigate, useSearch } from '@tanstack/react-router';
import { TradeMarketSearch } from 'libs/routing/routes/trade';

export const useBuySell = ({
source,
target,
sourceBalanceQuery,
buy = false,
}: TradeWidgetBuySellProps) => {
const { source: sourceInput = '', target: targetInput = '' } = useSearch({
strict: false,
}) as TradeMarketSearch;
const [sourceInput, setSourceInput] = useState('');
const [targetInput, setTargetInput] = useState('');
const { user, provider } = useWagmi();
const { openModal } = useModal();
const { selectedFiatCurrency } = useFiatCurrency();
Expand All @@ -53,22 +50,6 @@ export const useBuySell = ({
target.address
);

const navigate = useNavigate({ from: '/trade/market' });
const setSourceInput = (value: string) => {
navigate({
search: (s) => ({ ...s, source: value }),
replace: true,
resetScroll: false,
});
};
const setTargetInput = (value: string) => {
navigate({
search: (s) => ({ ...s, target: value }),
replace: true,
resetScroll: false,
});
};

const { getFiatValue: getFiatValueSource } = useFiatCurrency(source);

const clearInputs = useCallback(() => {
Expand Down Expand Up @@ -251,8 +232,8 @@ export const useBuySell = ({
target,
tradeActions,
isTradeBySource,
sourceInput: sourceInput,
targetInput: targetInput,
sourceInput,
targetInput,
});

if (approval.approvalRequired) {
Expand Down
4 changes: 0 additions & 4 deletions src/libs/routing/routes/trade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ export type SetOverlapping = (next: OverlappingSearch) => any;
// TRADE MARKET
export interface TradeMarketSearch extends TradeSearch {
direction?: StrategyDirection;
source?: string;
target?: string;
}

// ROUTES
Expand Down Expand Up @@ -87,8 +85,6 @@ const marketPage = new Route({
priceStart: validNumber,
priceEnd: validNumber,
direction: validLiteral(['buy', 'sell']),
source: validNumber,
target: validNumber,
}),
});

Expand Down

0 comments on commit 6e18fef

Please sign in to comment.