diff --git a/src/front/shared/pages/Exchange/QuickSwap/Footer.tsx b/src/front/shared/pages/Exchange/QuickSwap/Footer.tsx index 87382af39f..519960f13b 100644 --- a/src/front/shared/pages/Exchange/QuickSwap/Footer.tsx +++ b/src/front/shared/pages/Exchange/QuickSwap/Footer.tsx @@ -5,9 +5,8 @@ import styles from './index.scss' import utils from 'common/utils' import ADDRESSES from 'common/helpers/constants/ADDRESSES' import actions from 'redux/actions' -import { feedback, externalConfig, constants, transactions, routing, apiLooper } from 'helpers' +import { feedback, externalConfig, constants, transactions, routing } from 'helpers' import { ComponentState, BlockReasons, Actions, Direction } from './types' -import { buildApiSwapParams, estimateApiSwapData } from './swapApi' import { SWAP_API, GWEI_DECIMALS, @@ -25,12 +24,13 @@ type FooterProps = { isSourceMode: boolean sourceAction: Actions reportError: (e: IError) => void - resetSwapData: () => void - resetSpendedAmount: () => void + resetSwapData: VoidFunction + resetSpendedAmount: VoidFunction setBlockReason: (a: BlockReasons) => void isApiRequestBlocking: () => boolean setPending: (a: boolean) => void - onInputDataChange: () => void + onInputDataChange: VoidFunction + finalizeApiSwapData: () => Promise baseChainWallet: IUniversalObj } @@ -49,6 +49,7 @@ function Footer(props: FooterProps) { setPending, baseChainWallet, onInputDataChange, + finalizeApiSwapData, } = props const { blockReason, @@ -69,38 +70,13 @@ function Footer(props: FooterProps) { error, slippage, currentLiquidityPair, - serviceFee, - zeroxApiKey, } = parentState const [finalizeSwap, setFinalizeSwap] = useState(false) - const [quote, setQuote] = useState | undefined>(undefined) const startSwapReview = async () => { setFinalizeSwap(true) - - const { headers, endpoint } = buildApiSwapParams({ - route: '/quote', - slippage, - spendedAmount, - fromWallet, - toWallet, - serviceFee, - zeroxApiKey, - }) - const rawQuote: any = await apiLooper.get(SWAP_API[network.networkVersion].name, endpoint, { - headers, - sourceError: true, - reportErrors: (error: IError) => {}, - }) - const data = await estimateApiSwapData({ - data: rawQuote, - baseChainWallet, - toWallet, - gasLimit, - gasPrice, - }) - setQuote(data.swapData) + await finalizeApiSwapData() } const approve = async (direction) => { @@ -298,7 +274,7 @@ function Footer(props: FooterProps) { return (
{finalizeSwap && ( - setFinalizeSwap(false)} /> + setFinalizeSwap(false)} /> )} {needApproveA ? ( ) : sourceAction === Actions.Swap ? ( diff --git a/src/front/shared/pages/Exchange/QuickSwap/ReviewSwapModal.tsx b/src/front/shared/pages/Exchange/QuickSwap/ReviewSwapModal.tsx index 4f0ebef2ea..2182ade140 100644 --- a/src/front/shared/pages/Exchange/QuickSwap/ReviewSwapModal.tsx +++ b/src/front/shared/pages/Exchange/QuickSwap/ReviewSwapModal.tsx @@ -1,3 +1,25 @@ -export default function ReviewSwapModal() { - return
Review swap here
+import { Modal } from 'components/modal' + +interface Props { + data: any + onSwap: VoidFunction + onClose: VoidFunction +} + +export default function ReviewSwapModal(props: Props) { + const { data, onSwap, onClose } = props + + return ( +
+ + <>{JSON.stringify(data, undefined, 2)} + + +
+ ) } diff --git a/src/front/shared/pages/Exchange/QuickSwap/index.tsx b/src/front/shared/pages/Exchange/QuickSwap/index.tsx index 59b48aeb7e..f5d2501ee6 100644 --- a/src/front/shared/pages/Exchange/QuickSwap/index.tsx +++ b/src/front/shared/pages/Exchange/QuickSwap/index.tsx @@ -622,6 +622,7 @@ class QuickSwap extends PureComponent { gasPrice, onError: this.reportError, }) + console.log('SWAP PRICE response', data) this.setState(() => ({ ...data })) } else if (this.tryToSkipValidation(swap)) { const p = buildApiSwapParams({ @@ -643,6 +644,45 @@ class QuickSwap extends PureComponent { } } + finalizeApiSwapData = async () => { + const { + network, + spendedAmount, + zeroxApiKey, + slippage, + fromWallet, + toWallet, + serviceFee, + baseChainWallet, + gasLimit, + gasPrice, + } = this.state + + const { headers, endpoint } = buildApiSwapParams({ + route: '/quote', + slippage, + spendedAmount, + fromWallet, + toWallet, + serviceFee, + zeroxApiKey, + }) + const rawQuote: any = await apiLooper.get(SWAP_API[network.networkVersion].name, endpoint, { + headers, + sourceError: true, + reportErrors: this.reportError, + }) + const data = await estimateApiSwapData({ + data: rawQuote, + baseChainWallet, + toWallet, + gasLimit, + gasPrice, + }) + console.log('SWAP QUOTE response', data) + this.setState(() => ({ ...data })) + } + updateCurrentPairAddress = async () => { const { network, baseChainWallet, fromWallet, toWallet } = this.state const tokenA = fromWallet?.contractAddress || EVM_COIN_ADDRESS @@ -1201,6 +1241,7 @@ class QuickSwap extends PureComponent { insufficientBalanceB={insufficientBalanceB} setPending={this.setPending} onInputDataChange={this.onInputDataChange} + finalizeApiSwapData={this.finalizeApiSwapData} baseChainWallet={baseChainWallet} />