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
f5c4468c
Unverified
Commit
f5c4468c
authored
Jun 26, 2020
by
Moody Salem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(token logo): fix persistent error state in token logo, clean up swap route code
parent
852e8f74
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
61 deletions
+62
-61
index.tsx
src/components/TokenLogo/index.tsx
+9
-13
AdvancedSwapDetails.tsx
src/components/swap/AdvancedSwapDetails.tsx
+15
-48
SwapRoute.tsx
src/components/swap/SwapRoute.tsx
+38
-0
No files found.
src/components/TokenLogo/index.tsx
View file @
f5c4468c
...
@@ -6,9 +6,9 @@ import { WETH } from '@uniswap/sdk'
...
@@ -6,9 +6,9 @@ import { WETH } from '@uniswap/sdk'
import
EthereumLogo
from
'
../../assets/images/ethereum-logo.png
'
import
EthereumLogo
from
'
../../assets/images/ethereum-logo.png
'
const
TOKEN_ICON_API
=
address
=>
const
getTokenLogoURL
=
address
=>
`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/
${
address
}
/logo.png`
`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/
${
address
}
/logo.png`
const
BAD_IMAGES
=
{}
const
NO_LOGO_ADDRESSES
:
{
[
tokenAddress
:
string
]:
true
}
=
{}
const
Image
=
styled
.
img
<
{
size
:
string
}
>
`
const
Image
=
styled
.
img
<
{
size
:
string
}
>
`
width:
${({
size
})
=>
size
}
;
width:
${({
size
})
=>
size
}
;
...
@@ -44,20 +44,16 @@ export default function TokenLogo({
...
@@ -44,20 +44,16 @@ export default function TokenLogo({
size
?:
string
size
?:
string
style
?:
React
.
CSSProperties
style
?:
React
.
CSSProperties
})
{
})
{
const
[
error
,
setError
]
=
useState
(
false
)
const
[
,
refresh
]
=
useState
<
number
>
(
0
)
const
{
chainId
}
=
useActiveWeb3React
()
const
{
chainId
}
=
useActiveWeb3React
()
// mock rinkeby DAI
if
(
chainId
===
4
&&
address
===
'
0xc7AD46e0b8a400Bb3C915120d284AafbA8fc4735
'
)
{
address
=
'
0x6B175474E89094C44Da98b954EedeAC495271d0F
'
}
let
path
=
''
let
path
=
''
const
validated
=
isAddress
(
address
)
// hard code to show ETH instead of WETH in UI
// hard code to show ETH instead of WETH in UI
if
(
address
===
WETH
[
chainId
].
address
)
{
if
(
validated
===
WETH
[
chainId
].
address
)
{
return
<
StyledEthereumLogo
src=
{
EthereumLogo
}
size=
{
size
}
{
...
rest
}
/>
return
<
StyledEthereumLogo
src=
{
EthereumLogo
}
size=
{
size
}
{
...
rest
}
/>
}
else
if
(
!
error
&&
!
BAD_IMAGES
[
address
]
&&
isAddress
(
address
)
)
{
}
else
if
(
!
NO_LOGO_ADDRESSES
[
address
]
&&
validated
)
{
path
=
TOKEN_ICON_API
(
address
)
path
=
getTokenLogoURL
(
validated
)
}
else
{
}
else
{
return
(
return
(
<
Emoji
{
...
rest
}
size=
{
size
}
>
<
Emoji
{
...
rest
}
size=
{
size
}
>
...
@@ -75,8 +71,8 @@ export default function TokenLogo({
...
@@ -75,8 +71,8 @@ export default function TokenLogo({
src=
{
path
}
src=
{
path
}
size=
{
size
}
size=
{
size
}
onError=
{
()
=>
{
onError=
{
()
=>
{
BAD_IMAG
ES
[
address
]
=
true
NO_LOGO_ADDRESS
ES
[
address
]
=
true
setError
(
true
)
refresh
(
i
=>
i
+
1
)
}
}
}
}
/>
/>
)
)
...
...
src/components/swap/AdvancedSwapDetails.tsx
View file @
f5c4468c
import
{
Trade
,
TradeType
}
from
'
@uniswap/sdk
'
import
{
Trade
,
TradeType
}
from
'
@uniswap/sdk
'
import
React
,
{
useContext
}
from
'
react
'
import
React
,
{
useContext
}
from
'
react
'
import
{
ChevronRight
}
from
'
react-feather
'
import
{
Flex
}
from
'
rebass
'
import
{
ThemeContext
}
from
'
styled-components
'
import
{
ThemeContext
}
from
'
styled-components
'
import
{
Field
}
from
'
../../state/swap/actions
'
import
{
Field
}
from
'
../../state/swap/actions
'
import
{
useUserSlippageTolerance
}
from
'
../../state/user/hooks
'
import
{
TYPE
}
from
'
../../theme
'
import
{
TYPE
}
from
'
../../theme
'
import
{
computeSlippageAdjustedAmounts
,
computeTradePriceBreakdown
}
from
'
../../utils/prices
'
import
{
computeSlippageAdjustedAmounts
,
computeTradePriceBreakdown
}
from
'
../../utils/prices
'
import
{
AutoColumn
}
from
'
../Column
'
import
{
AutoColumn
}
from
'
../Column
'
import
{
SectionBreak
}
from
'
./styleds
'
import
QuestionHelper
from
'
../QuestionHelper
'
import
QuestionHelper
from
'
../QuestionHelper
'
import
{
RowBetween
,
RowFixed
}
from
'
../Row
'
import
{
RowBetween
,
RowFixed
}
from
'
../Row
'
import
FormattedPriceImpact
from
'
./FormattedPriceImpact
'
import
FormattedPriceImpact
from
'
./FormattedPriceImpact
'
import
TokenLogo
from
'
../TokenLogo
'
import
{
SectionBreak
}
from
'
./styleds
'
import
flatMap
from
'
lodash.flatmap
'
import
SwapRoute
from
'
./SwapRoute
'
import
{
useUserSlippageTolerance
}
from
'
../../state/user/hooks
'
function
TradeSummary
({
trade
,
allowedSlippage
}:
{
trade
:
Trade
;
allowedSlippage
:
number
})
{
function
TradeSummary
({
trade
,
allowedSlippage
}:
{
trade
:
Trade
;
allowedSlippage
:
number
})
{
const
theme
=
useContext
(
ThemeContext
)
const
theme
=
useContext
(
ThemeContext
)
...
@@ -79,49 +76,19 @@ export function AdvancedSwapDetails({ trade }: AdvancedSwapDetailsProps) {
...
@@ -79,49 +76,19 @@ export function AdvancedSwapDetails({ trade }: AdvancedSwapDetailsProps) {
return
(
return
(
<
AutoColumn
gap=
"md"
>
<
AutoColumn
gap=
"md"
>
{
trade
&&
<
TradeSummary
trade=
{
trade
}
allowedSlippage=
{
allowedSlippage
}
/>
}
{
trade
&&
<
TradeSummary
trade=
{
trade
}
allowedSlippage=
{
allowedSlippage
}
/>
}
{
showRoute
&&
<
SectionBreak
/>
}
{
showRoute
&&
(
{
showRoute
&&
(
<
AutoColumn
style=
{
{
padding
:
'
0 24px
'
}
}
>
<>
<
RowFixed
>
<
SectionBreak
/>
<
TYPE
.
black
fontSize=
{
14
}
fontWeight=
{
400
}
color=
{
theme
.
text2
}
>
<
AutoColumn
style=
{
{
padding
:
'
0 24px
'
}
}
>
Route
<
RowFixed
>
</
TYPE
.
black
>
<
TYPE
.
black
fontSize=
{
14
}
fontWeight=
{
400
}
color=
{
theme
.
text2
}
>
<
QuestionHelper
text=
"Routing through these tokens resulted in the best price for your trade."
/>
Route
</
RowFixed
>
</
TYPE
.
black
>
<
Flex
<
QuestionHelper
text=
"Routing through these tokens resulted in the best price for your trade."
/>
px=
"1rem"
</
RowFixed
>
py=
"0.5rem"
<
SwapRoute
trade=
{
trade
}
/>
my=
"0.5rem"
</
AutoColumn
>
style=
{
{
border
:
`1px solid ${theme.bg3}`
,
borderRadius
:
'
1rem
'
}
}
</>
flexWrap=
"wrap"
width=
"100%"
justifyContent=
"space-evenly"
alignItems=
"center"
>
{
flatMap
(
trade
.
route
.
path
,
// add a null in-between each item
(
token
,
i
,
array
)
=>
{
const
lastItem
=
i
===
array
.
length
-
1
return
lastItem
?
[
token
]
:
[
token
,
null
]
}
).
map
((
token
,
i
)
=>
{
// use null as an indicator to insert chevrons
if
(
token
===
null
)
{
return
<
ChevronRight
key=
{
i
}
color=
{
theme
.
text2
}
/>
}
else
{
return
(
<
Flex
my=
"0.5rem"
alignItems=
"center"
key=
{
token
.
address
}
style=
{
{
flexShrink
:
0
}
}
>
<
TokenLogo
address=
{
token
.
address
}
size=
"1.5rem"
/>
<
TYPE
.
black
fontSize=
{
14
}
color=
{
theme
.
text1
}
ml=
"0.5rem"
>
{
token
.
symbol
}
</
TYPE
.
black
>
</
Flex
>
)
}
})
}
</
Flex
>
</
AutoColumn
>
)
}
)
}
</
AutoColumn
>
</
AutoColumn
>
)
)
...
...
src/components/swap/SwapRoute.tsx
0 → 100644
View file @
f5c4468c
import
{
Trade
}
from
'
@uniswap/sdk
'
import
React
,
{
Fragment
,
memo
,
useContext
}
from
'
react
'
import
{
ChevronRight
}
from
'
react-feather
'
import
{
Flex
}
from
'
rebass
'
import
{
ThemeContext
}
from
'
styled-components
'
import
{
TYPE
}
from
'
../../theme
'
import
TokenLogo
from
'
../TokenLogo
'
export
default
memo
(
function
SwapRoute
({
trade
}:
{
trade
:
Trade
})
{
const
theme
=
useContext
(
ThemeContext
)
return
(
<
Flex
px=
"1rem"
py=
"0.5rem"
my=
"0.5rem"
style=
{
{
border
:
`1px solid ${theme.bg3}`
,
borderRadius
:
'
1rem
'
}
}
flexWrap=
"wrap"
width=
"100%"
justifyContent=
"space-evenly"
alignItems=
"center"
>
{
trade
.
route
.
path
.
map
((
token
,
i
,
path
)
=>
{
const
isLastItem
:
boolean
=
i
===
path
.
length
-
1
return
(
<
Fragment
key=
{
i
}
>
<
Flex
my=
"0.5rem"
alignItems=
"center"
key=
{
token
.
address
}
style=
{
{
flexShrink
:
0
}
}
>
<
TokenLogo
address=
{
token
.
address
}
size=
"1.5rem"
/>
<
TYPE
.
black
fontSize=
{
14
}
color=
{
theme
.
text1
}
ml=
"0.5rem"
>
{
token
.
symbol
}
</
TYPE
.
black
>
</
Flex
>
{
isLastItem
?
null
:
<
ChevronRight
key=
{
i
}
color=
{
theme
.
text2
}
/>
}
</
Fragment
>
)
})
}
</
Flex
>
)
})
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