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
1aea452f
Unverified
Commit
1aea452f
authored
May 18, 2020
by
Moody Salem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a test and improve our redirects
parent
e311e2fc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
4 deletions
+49
-4
App.tsx
src/pages/App.tsx
+30
-1
reducer.test.ts
src/state/swap/reducer.test.ts
+16
-0
reducer.ts
src/state/swap/reducer.ts
+3
-3
No files found.
src/pages/App.tsx
View file @
1aea452f
...
@@ -98,6 +98,34 @@ function GoogleAnalyticsReporter({ location: { pathname, search } }: RouteCompon
...
@@ -98,6 +98,34 @@ function GoogleAnalyticsReporter({ location: { pathname, search } }: RouteCompon
return
null
return
null
}
}
// Redirects to swap but only replace the pathname
function
RedirectPathToSwapOnly
({
location
}:
RouteComponentProps
)
{
return
<
Redirect
to=
{
{
...
location
,
pathname
:
'
/swap
'
}
}
/>
}
// Redirects from the /swap/:outputCurrency path to the /swap?outputCurrency=:outputCurrency format
function
RedirectToSwap
(
props
:
RouteComponentProps
<
{
outputCurrency
:
string
}
>
)
{
const
{
location
:
{
search
},
match
:
{
params
:
{
outputCurrency
}
}
}
=
props
return
(
<
Redirect
to=
{
{
...
props
.
location
,
pathname
:
'
/swap
'
,
search
:
search
&&
search
.
length
>
1
?
`${search}&outputCurrency=${outputCurrency}`
:
`?outputCurrency=${outputCurrency}`
}
}
/>
)
}
export
default
function
App
()
{
export
default
function
App
()
{
return
(
return
(
<>
<>
...
@@ -115,6 +143,7 @@ export default function App() {
...
@@ -115,6 +143,7 @@ export default function App() {
<
NavigationTabs
/>
<
NavigationTabs
/>
<
Switch
>
<
Switch
>
<
Route
exact
strict
path=
"/swap"
component=
{
Swap
}
/>
<
Route
exact
strict
path=
"/swap"
component=
{
Swap
}
/>
<
Route
exact
strict
path=
"/swap/:outputCurrency"
component=
{
RedirectToSwap
}
/>
<
Route
exact
strict
path=
"/send"
component=
{
Send
}
/>
<
Route
exact
strict
path=
"/send"
component=
{
Send
}
/>
<
Route
exact
strict
path=
"/find"
component=
{
Find
}
/>
<
Route
exact
strict
path=
"/find"
component=
{
Find
}
/>
<
Route
exact
strict
path=
"/create"
component=
{
Create
}
/>
<
Route
exact
strict
path=
"/create"
component=
{
Create
}
/>
...
@@ -153,7 +182,7 @@ export default function App() {
...
@@ -153,7 +182,7 @@ export default function App() {
}
}
}
}
}
}
/>
/>
<
R
edirect
to=
"/swap"
/>
<
R
oute
component=
{
RedirectPathToSwapOnly
}
/>
</
Switch
>
</
Switch
>
</
Body
>
</
Body
>
</
Web3ReactManager
>
</
Web3ReactManager
>
...
...
src/state/swap/reducer.test.ts
View file @
1aea452f
...
@@ -33,6 +33,22 @@ describe('swap reducer', () => {
...
@@ -33,6 +33,22 @@ describe('swap reducer', () => {
})
})
})
})
test
(
'
does not duplicate eth for invalid output token
'
,
()
=>
{
store
.
dispatch
(
setDefaultsFromURL
({
chainId
:
ChainId
.
MAINNET
,
queryString
:
'
?outputCurrency=invalid
'
})
)
expect
(
store
.
getState
()).
toEqual
({
[
Field
.
INPUT
]:
{
address
:
''
},
[
Field
.
OUTPUT
]:
{
address
:
WETH
[
ChainId
.
MAINNET
].
address
},
typedValue
:
''
,
independentField
:
Field
.
INPUT
})
})
test
(
'
output ETH only
'
,
()
=>
{
test
(
'
output ETH only
'
,
()
=>
{
store
.
dispatch
(
store
.
dispatch
(
setDefaultsFromURL
({
setDefaultsFromURL
({
...
...
src/state/swap/reducer.ts
View file @
1aea452f
...
@@ -54,10 +54,10 @@ export default createReducer<SwapState>(initialState, builder =>
...
@@ -54,10 +54,10 @@ export default createReducer<SwapState>(initialState, builder =>
let
inputCurrency
=
parseCurrencyFromURLParameter
(
parsedQs
.
inputCurrency
,
chainId
)
let
inputCurrency
=
parseCurrencyFromURLParameter
(
parsedQs
.
inputCurrency
,
chainId
)
let
outputCurrency
=
parseCurrencyFromURLParameter
(
parsedQs
.
outputCurrency
,
chainId
)
let
outputCurrency
=
parseCurrencyFromURLParameter
(
parsedQs
.
outputCurrency
,
chainId
)
if
(
inputCurrency
===
outputCurrency
)
{
if
(
inputCurrency
===
outputCurrency
)
{
if
(
typeof
parsedQs
.
inputCurrency
===
'
string
'
)
{
if
(
typeof
parsedQs
.
outputCurrency
===
'
string
'
)
{
outputCurrency
=
''
}
else
if
(
typeof
parsedQs
.
outputCurrency
===
'
string
'
)
{
inputCurrency
=
''
inputCurrency
=
''
}
else
{
outputCurrency
=
''
}
}
}
}
...
...
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