+
Admin Controls
Force V3
dispatch(setForceV3Routing(!forceV3Routing))}
+ onChange={() => {
+ dispatch(setForceV3Routing(!forceV3Routing));
+ dispatch(setForceV2Routing(false));
+ }}
+ />
+
+
+ Force V2
+ {
+ dispatch(setForceV2Routing(!forceV2Routing));
+ dispatch(setForceV3Routing(false));
+ }}
/>
diff --git a/src/elements/trade/useTradeWidget.ts b/src/elements/trade/useTradeWidget.ts
index 3e8d28916..58bf54d90 100644
--- a/src/elements/trade/useTradeWidget.ts
+++ b/src/elements/trade/useTradeWidget.ts
@@ -42,6 +42,7 @@ export const useTradeWidget = ({
const account = useAppSelector((state) => state.user.account);
const isFiat = useAppSelector((state) => state.user.usdToggle);
const forceV3Routing = useAppSelector((state) => state.user.forceV3Routing);
+ const forceV2Routing = useAppSelector((state) => state.user.forceV2Routing);
const [fromInputTkn, setFromInputTkn] = useState('');
const [fromInputFiat, setFromInputFiat] = useState('');
@@ -141,13 +142,14 @@ export const useTradeWidget = ({
fromToken,
toToken,
val,
- forceV3Routing
+ forceV3Routing,
+ forceV2Routing
);
}
return { rate: '', priceImpact: '', isV3: true };
},
- [forceV3Routing, isExternal]
+ [forceV3Routing, forceV2Routing, isExternal]
);
const onFromDebounce = useCallback(
diff --git a/src/services/web3/swap/market.ts b/src/services/web3/swap/market.ts
index 7212e9fe4..db38e3386 100644
--- a/src/services/web3/swap/market.ts
+++ b/src/services/web3/swap/market.ts
@@ -27,7 +27,8 @@ export const getRateAndPriceImapct = async (
fromToken: TokenMinimal,
toToken: TokenMinimal,
amount: string,
- forceV3Routing: boolean
+ forceV3Routing: boolean,
+ forceV2Routing: boolean
) => {
try {
const networkContractAddress = await bancorNetwork$
@@ -82,7 +83,8 @@ export const getRateAndPriceImapct = async (
: new BigNumber(0);
const v3PriceImpact = isNaN(v3PI.toNumber()) ? '0.0000' : v3PI.toFixed(4);
- const isV3 = forceV3Routing || Number(v3Rate) >= Number(v2Rate);
+ const isV3 =
+ (forceV3Routing || Number(v3Rate) >= Number(v2Rate)) && !forceV2Routing;
console.log('V2 Rate', v2Rate);
console.log('V3 Rate', v3Rate);
diff --git a/src/store/user/user.ts b/src/store/user/user.ts
index f8955ba5b..b1449b0f3 100644
--- a/src/store/user/user.ts
+++ b/src/store/user/user.ts
@@ -2,8 +2,10 @@ import { createSelector, createSlice, PayloadAction } from '@reduxjs/toolkit';
import { RootState } from 'store';
import {
getForceV3LS,
- setDarkModeLS,
setForceV3LS,
+ getForceV2LS,
+ setForceV2LS,
+ setDarkModeLS,
setSlippageToleranceLS,
setUsdToggleLS,
} from 'utils/localStorage';
@@ -24,6 +26,7 @@ export interface UserState {
locale: LocaleType;
loadingBalances: boolean;
forceV3Routing: boolean;
+ forceV2Routing: boolean;
}
export const initialState: UserState = {
@@ -35,6 +38,7 @@ export const initialState: UserState = {
locale: 'en',
loadingBalances: false,
forceV3Routing: getForceV3LS(),
+ forceV2Routing: getForceV2LS(),
};
const userSlice = createSlice({
@@ -70,6 +74,10 @@ const userSlice = createSlice({
state.forceV3Routing = action.payload;
setForceV3LS(action.payload);
},
+ setForceV2Routing: (state, action) => {
+ state.forceV2Routing = action.payload;
+ setForceV2LS(action.payload);
+ },
},
});
@@ -104,6 +112,7 @@ export const {
setUsdToggle,
setLoadingBalances,
setForceV3Routing,
+ setForceV2Routing,
} = userSlice.actions;
export const user = userSlice.reducer;
diff --git a/src/utils/localStorage.ts b/src/utils/localStorage.ts
index 3223e3914..019c78a1a 100644
--- a/src/utils/localStorage.ts
+++ b/src/utils/localStorage.ts
@@ -13,6 +13,7 @@ const tenderlyRpcUrl = 'tenderlyRpcUrl';
const v3ApiUrl = 'v3ApiUrl';
const v2ApiUrl = 'v2ApiUrl';
const forceV3 = 'forceV3';
+const forceV2 = 'forceV2';
const enableDeposit = 'enableDeposit';
const pageRows = 'pageRows';
const migrationDisabled = 'migrationDisabledV2';
@@ -148,6 +149,7 @@ export const setMigrationDisabledLS = (user?: string | null) => {
export const resetTenderly = () => {
localStorage.removeItem(tenderlyRpcUrl);
localStorage.removeItem(forceV3);
+ localStorage.removeItem(forceV2);
localStorage.removeItem(enableDeposit);
};
@@ -170,3 +172,12 @@ export const getForceV3LS = (): boolean => {
export const setForceV3LS = (flag: boolean) => {
localStorage.setItem(forceV3, JSON.stringify(flag));
};
+
+export const getForceV2LS = (): boolean => {
+ const force = localStorage.getItem(forceV2);
+ return force && JSON.parse(force);
+};
+
+export const setForceV2LS = (flag: boolean) => {
+ localStorage.setItem(forceV2, JSON.stringify(flag));
+};
From 8d657b283dd8f02817c0b91c23b7a0023d28a474 Mon Sep 17 00:00:00 2001
From: Ran Cohen
Date: Tue, 22 Nov 2022 14:52:51 +0200
Subject: [PATCH 9/9] updated text
---
src/App.tsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/App.tsx b/src/App.tsx
index 4c31e6978..8e2f67803 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -125,7 +125,7 @@ export const App = () => {