Skip to content

Commit

Permalink
address pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
abcrane123 committed Jun 12, 2024
1 parent 0f76402 commit 15aa579
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/swap/components/Swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function Swap({ account, children, onError, onSuccess }: SwapReact) {
onSuccess?.(response);
}
} catch (error) {
console.log({ error });
onError?.(error as SwapError);
}
}
}, [account, fromAmount, fromToken, toToken]);
Expand All @@ -53,7 +53,7 @@ export function Swap({ account, children, onError, onSuccess }: SwapReact) {
setToAmount(response?.toAmount);
}
} catch (error) {
console.log({ error });
onError?.(error as SwapError);
}
}
}, [fromAmount, fromToken, toToken]);
Expand Down
16 changes: 4 additions & 12 deletions src/swap/components/SwapButton.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
import { useCallback, useContext } from 'react';
import { cn } from '../../lib/utils';
import { SwapContext } from '../context';
import type { SwapButtonReact } from '../types';

export function SwapButton({ onSubmit }: SwapButtonReact) {
const {
onSubmit: onSubmitSwap,
fromAmount,
fromToken,
toAmount,
toToken,
} = useContext(SwapContext);
export function SwapButton() {
const { onSubmit, fromAmount, fromToken, toAmount, toToken } = useContext(SwapContext);

const handleSubmit = useCallback(() => {
onSubmitSwap();
onSubmit?.();
}, [onSubmit, onSubmitSwap]);
onSubmit();
}, [onSubmit]);

return (
<div className="w-full p-4">
Expand Down
6 changes: 1 addition & 5 deletions src/swap/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ export type SwapAPIResponse = {
tx: RawTransactionData; // The trade transaction
};

export type SwapButtonReact = {
onSubmit?: (params?: SwapParams) => void;
};

export type SwapContextType = {
fromAmount: string;
fromToken?: Token;
Expand All @@ -123,7 +119,7 @@ export type SwapContextType = {

export type SwapParams = {
amount: string;
fromAddress: `0x${string}`;
fromAddress: Address;
from: Token;
to: Token;
};
Expand Down

0 comments on commit 15aa579

Please sign in to comment.