Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
interface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LuckySwap
interface
Commits
0a31428d
Unverified
Commit
0a31428d
authored
Sep 22, 2023
by
eddie
Committed by
GitHub
Sep 22, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: uniswapX opt-out update (#7368)
parent
fbc7e640
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
32 additions
and
8 deletions
+32
-8
index.tsx
src/components/Settings/RouterPreferenceSettings/index.tsx
+11
-6
useRoutingAPIArguments.ts
src/lib/hooks/routing/useRoutingAPIArguments.ts
+4
-1
reducerTypeTest.ts
src/state/reducerTypeTest.ts
+1
-0
slice.ts
src/state/routing/slice.ts
+2
-1
types.ts
src/state/routing/types.ts
+3
-0
hooks.tsx
src/state/user/hooks.tsx
+4
-0
reducer.ts
src/state/user/reducer.ts
+7
-0
No files found.
src/components/Settings/RouterPreferenceSettings/index.tsx
View file @
0a31428d
...
@@ -8,8 +8,8 @@ import { isUniswapXSupportedChain } from 'constants/chains'
...
@@ -8,8 +8,8 @@ import { isUniswapXSupportedChain } from 'constants/chains'
import
{
useUniswapXDefaultEnabled
}
from
'
featureFlags/flags/uniswapXDefault
'
import
{
useUniswapXDefaultEnabled
}
from
'
featureFlags/flags/uniswapXDefault
'
import
{
useAppDispatch
}
from
'
state/hooks
'
import
{
useAppDispatch
}
from
'
state/hooks
'
import
{
RouterPreference
}
from
'
state/routing/types
'
import
{
RouterPreference
}
from
'
state/routing/types
'
import
{
useRouterPreference
,
useUser
Disabled
UniswapX
}
from
'
state/user/hooks
'
import
{
useRouterPreference
,
useUser
OptedOutOf
UniswapX
}
from
'
state/user/hooks
'
import
{
updateDisabledUniswapX
}
from
'
state/user/reducer
'
import
{
updateDisabledUniswapX
,
updateOptedOutOfUniswapX
}
from
'
state/user/reducer
'
import
styled
from
'
styled-components
'
import
styled
from
'
styled-components
'
import
{
Divider
,
ExternalLink
,
ThemedText
}
from
'
theme/components
'
import
{
Divider
,
ExternalLink
,
ThemedText
}
from
'
theme/components
'
...
@@ -27,9 +27,9 @@ export default function RouterPreferenceSettings() {
...
@@ -27,9 +27,9 @@ export default function RouterPreferenceSettings() {
const
[
routerPreference
,
setRouterPreference
]
=
useRouterPreference
()
const
[
routerPreference
,
setRouterPreference
]
=
useRouterPreference
()
const
uniswapXEnabled
=
chainId
&&
isUniswapXSupportedChain
(
chainId
)
const
uniswapXEnabled
=
chainId
&&
isUniswapXSupportedChain
(
chainId
)
const
dispatch
=
useAppDispatch
()
const
dispatch
=
useAppDispatch
()
const
user
DisabledUniswapX
=
useUserDisabled
UniswapX
()
const
user
OptedOutOfUniswapX
=
useUserOptedOutOf
UniswapX
()
const
isUniswapXDefaultEnabled
=
useUniswapXDefaultEnabled
()
const
isUniswapXDefaultEnabled
=
useUniswapXDefaultEnabled
()
const
isUniswapXOverrideEnabled
=
isUniswapXDefaultEnabled
&&
!
user
Disabled
UniswapX
const
isUniswapXOverrideEnabled
=
isUniswapXDefaultEnabled
&&
!
user
OptedOutOf
UniswapX
const
uniswapXInEffect
=
const
uniswapXInEffect
=
routerPreference
===
RouterPreference
.
X
||
routerPreference
===
RouterPreference
.
X
||
...
@@ -61,8 +61,13 @@ export default function RouterPreferenceSettings() {
...
@@ -61,8 +61,13 @@ export default function RouterPreferenceSettings() {
isActive=
{
uniswapXInEffect
}
isActive=
{
uniswapXInEffect
}
toggle=
{
()
=>
{
toggle=
{
()
=>
{
if
(
uniswapXInEffect
)
{
if
(
uniswapXInEffect
)
{
// We need to remember if a user disables Uniswap X, so we don't show the opt-in flow again.
if
(
isUniswapXDefaultEnabled
)
{
dispatch
(
updateDisabledUniswapX
({
disabledUniswapX
:
true
}))
// We need to remember if a opts out of UniswapX, so we don't request UniswapX quotes.
dispatch
(
updateOptedOutOfUniswapX
({
optedOutOfUniswapX
:
true
}))
}
else
{
// We need to remember if a user disables Uniswap X, so we don't show the opt-in flow again.
dispatch
(
updateDisabledUniswapX
({
disabledUniswapX
:
true
}))
}
}
}
setRouterPreference
(
uniswapXInEffect
?
RouterPreference
.
API
:
RouterPreference
.
X
)
setRouterPreference
(
uniswapXInEffect
?
RouterPreference
.
API
:
RouterPreference
.
X
)
}
}
}
}
...
...
src/lib/hooks/routing/useRoutingAPIArguments.ts
View file @
0a31428d
...
@@ -7,7 +7,7 @@ import { useUniswapXSyntheticQuoteEnabled } from 'featureFlags/flags/uniswapXUse
...
@@ -7,7 +7,7 @@ import { useUniswapXSyntheticQuoteEnabled } from 'featureFlags/flags/uniswapXUse
import
{
useMemo
}
from
'
react
'
import
{
useMemo
}
from
'
react
'
import
{
GetQuoteArgs
,
INTERNAL_ROUTER_PREFERENCE_PRICE
,
RouterPreference
}
from
'
state/routing/types
'
import
{
GetQuoteArgs
,
INTERNAL_ROUTER_PREFERENCE_PRICE
,
RouterPreference
}
from
'
state/routing/types
'
import
{
currencyAddressForSwapQuote
}
from
'
state/routing/utils
'
import
{
currencyAddressForSwapQuote
}
from
'
state/routing/utils
'
import
{
useUserDisabledUniswapX
}
from
'
state/user/hooks
'
import
{
useUserDisabledUniswapX
,
useUserOptedOutOfUniswapX
}
from
'
state/user/hooks
'
/**
/**
* Returns query arguments for the Routing API query or undefined if the
* Returns query arguments for the Routing API query or undefined if the
...
@@ -35,6 +35,7 @@ export function useRoutingAPIArguments({
...
@@ -35,6 +35,7 @@ export function useRoutingAPIArguments({
}):
GetQuoteArgs
|
SkipToken
{
}):
GetQuoteArgs
|
SkipToken
{
const
uniswapXForceSyntheticQuotes
=
useUniswapXSyntheticQuoteEnabled
()
const
uniswapXForceSyntheticQuotes
=
useUniswapXSyntheticQuoteEnabled
()
const
userDisabledUniswapX
=
useUserDisabledUniswapX
()
const
userDisabledUniswapX
=
useUserDisabledUniswapX
()
const
userOptedOutOfUniswapX
=
useUserOptedOutOfUniswapX
()
const
uniswapXEthOutputEnabled
=
useUniswapXEthOutputEnabled
()
const
uniswapXEthOutputEnabled
=
useUniswapXEthOutputEnabled
()
const
uniswapXExactOutputEnabled
=
useUniswapXExactOutputEnabled
()
const
uniswapXExactOutputEnabled
=
useUniswapXExactOutputEnabled
()
const
isUniswapXDefaultEnabled
=
useUniswapXDefaultEnabled
()
const
isUniswapXDefaultEnabled
=
useUniswapXDefaultEnabled
()
...
@@ -59,6 +60,7 @@ export function useRoutingAPIArguments({
...
@@ -59,6 +60,7 @@ export function useRoutingAPIArguments({
needsWrapIfUniswapX
:
tokenIn
.
isNative
,
needsWrapIfUniswapX
:
tokenIn
.
isNative
,
uniswapXForceSyntheticQuotes
,
uniswapXForceSyntheticQuotes
,
userDisabledUniswapX
,
userDisabledUniswapX
,
userOptedOutOfUniswapX
,
uniswapXEthOutputEnabled
,
uniswapXEthOutputEnabled
,
uniswapXExactOutputEnabled
,
uniswapXExactOutputEnabled
,
isUniswapXDefaultEnabled
,
isUniswapXDefaultEnabled
,
...
@@ -75,6 +77,7 @@ export function useRoutingAPIArguments({
...
@@ -75,6 +77,7 @@ export function useRoutingAPIArguments({
uniswapXExactOutputEnabled
,
uniswapXExactOutputEnabled
,
uniswapXForceSyntheticQuotes
,
uniswapXForceSyntheticQuotes
,
userDisabledUniswapX
,
userDisabledUniswapX
,
userOptedOutOfUniswapX
,
uniswapXEthOutputEnabled
,
uniswapXEthOutputEnabled
,
isUniswapXDefaultEnabled
,
isUniswapXDefaultEnabled
,
inputTax
,
inputTax
,
...
...
src/state/reducerTypeTest.ts
View file @
0a31428d
...
@@ -88,6 +88,7 @@ interface ExpectedUserState {
...
@@ -88,6 +88,7 @@ interface ExpectedUserState {
hideBaseWalletBanner
:
boolean
hideBaseWalletBanner
:
boolean
showSurveyPopup
?:
boolean
showSurveyPopup
?:
boolean
disabledUniswapX
?:
boolean
disabledUniswapX
?:
boolean
optedOutOfUniswapX
?:
boolean
}
}
assert
<
Equals
<
UserState
,
ExpectedUserState
>>
()
assert
<
Equals
<
UserState
,
ExpectedUserState
>>
()
...
...
src/state/routing/slice.ts
View file @
0a31428d
...
@@ -73,7 +73,8 @@ function getRoutingAPIConfig(args: GetQuoteArgs): RoutingConfig {
...
@@ -73,7 +73,8 @@ function getRoutingAPIConfig(args: GetQuoteArgs): RoutingConfig {
// UniswapX doesn't support native out, exact-out, or non-mainnet trades (yet),
// UniswapX doesn't support native out, exact-out, or non-mainnet trades (yet),
// so even if the user has selected UniswapX as their router preference, force them to receive a Classic quote.
// so even if the user has selected UniswapX as their router preference, force them to receive a Classic quote.
if
(
if
(
(
args
.
userDisabledUniswapX
&&
routerPreference
!==
RouterPreference
.
X
)
||
// If the user has opted out of UniswapX during the opt-out transition period, we should respect that preference and only request classic quotes.
(
args
.
userOptedOutOfUniswapX
&&
routerPreference
!==
RouterPreference
.
X
)
||
(
tokenOutIsNative
&&
!
uniswapXEthOutputEnabled
)
||
(
tokenOutIsNative
&&
!
uniswapXEthOutputEnabled
)
||
(
!
uniswapXExactOutputEnabled
&&
tradeType
===
TradeType
.
EXACT_OUTPUT
)
||
(
!
uniswapXExactOutputEnabled
&&
tradeType
===
TradeType
.
EXACT_OUTPUT
)
||
!
isUniswapXSupportedChain
(
tokenInChainId
)
||
!
isUniswapXSupportedChain
(
tokenInChainId
)
||
...
...
src/state/routing/types.ts
View file @
0a31428d
...
@@ -45,7 +45,10 @@ export interface GetQuoteArgs {
...
@@ -45,7 +45,10 @@ export interface GetQuoteArgs {
uniswapXForceSyntheticQuotes
:
boolean
uniswapXForceSyntheticQuotes
:
boolean
uniswapXEthOutputEnabled
:
boolean
uniswapXEthOutputEnabled
:
boolean
uniswapXExactOutputEnabled
:
boolean
uniswapXExactOutputEnabled
:
boolean
// legacy field indicating the user disabled UniswapX during the opt-in period, or dismissed the UniswapX opt-in modal.
userDisabledUniswapX
:
boolean
userDisabledUniswapX
:
boolean
// temporary field indicating the user disabled UniswapX during the transition to the opt-out model
userOptedOutOfUniswapX
:
boolean
isUniswapXDefaultEnabled
:
boolean
isUniswapXDefaultEnabled
:
boolean
inputTax
:
Percent
inputTax
:
Percent
outputTax
:
Percent
outputTax
:
Percent
...
...
src/state/user/hooks.tsx
View file @
0a31428d
...
@@ -221,6 +221,10 @@ export function useUserDisabledUniswapX(): boolean {
...
@@ -221,6 +221,10 @@ export function useUserDisabledUniswapX(): boolean {
return
useAppSelector
((
state
)
=>
state
.
user
.
disabledUniswapX
)
??
false
return
useAppSelector
((
state
)
=>
state
.
user
.
disabledUniswapX
)
??
false
}
}
export
function
useUserOptedOutOfUniswapX
():
boolean
{
return
useAppSelector
((
state
)
=>
state
.
user
.
optedOutOfUniswapX
)
??
false
}
/**
/**
* Given two tokens return the liquidity token that represents its liquidity shares
* Given two tokens return the liquidity token that represents its liquidity shares
* @param tokenA one of the two tokens
* @param tokenA one of the two tokens
...
...
src/state/user/reducer.ts
View file @
0a31428d
...
@@ -47,7 +47,10 @@ export interface UserState {
...
@@ -47,7 +47,10 @@ export interface UserState {
timestamp
:
number
timestamp
:
number
hideBaseWalletBanner
:
boolean
hideBaseWalletBanner
:
boolean
// legacy field indicating the user disabled UniswapX during the opt-in period, or dismissed the UniswapX opt-in modal.
disabledUniswapX
?:
boolean
disabledUniswapX
?:
boolean
// temporary field indicating the user disabled UniswapX during the transition to the opt-out model
optedOutOfUniswapX
?:
boolean
// undefined means has not gone through A/B split yet
// undefined means has not gone through A/B split yet
showSurveyPopup
?:
boolean
showSurveyPopup
?:
boolean
}
}
...
@@ -105,6 +108,9 @@ const userSlice = createSlice({
...
@@ -105,6 +108,9 @@ const userSlice = createSlice({
updateDisabledUniswapX
(
state
,
action
)
{
updateDisabledUniswapX
(
state
,
action
)
{
state
.
disabledUniswapX
=
action
.
payload
.
disabledUniswapX
state
.
disabledUniswapX
=
action
.
payload
.
disabledUniswapX
},
},
updateOptedOutOfUniswapX
(
state
,
action
)
{
state
.
optedOutOfUniswapX
=
action
.
payload
.
optedOutOfUniswapX
},
addSerializedToken
(
state
,
{
payload
:
{
serializedToken
}
})
{
addSerializedToken
(
state
,
{
payload
:
{
serializedToken
}
})
{
if
(
!
state
.
tokens
)
{
if
(
!
state
.
tokens
)
{
state
.
tokens
=
{}
state
.
tokens
=
{}
...
@@ -138,5 +144,6 @@ export const {
...
@@ -138,5 +144,6 @@ export const {
updateUserSlippageTolerance
,
updateUserSlippageTolerance
,
updateHideBaseWalletBanner
,
updateHideBaseWalletBanner
,
updateDisabledUniswapX
,
updateDisabledUniswapX
,
updateOptedOutOfUniswapX
,
}
=
userSlice
.
actions
}
=
userSlice
.
actions
export
default
userSlice
.
reducer
export
default
userSlice
.
reducer
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment