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
9d8c5330
Commit
9d8c5330
authored
Oct 26, 2018
by
Kenny Tran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement feedback
parent
5987095e
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
241 additions
and
60 deletions
+241
-60
address-input-panel.scss
src/components/AddressInputPanel/address-input-panel.scss
+3
-1
currency-panel.scss
src/components/CurrencyInputPanel/currency-panel.scss
+9
-0
index.js
src/components/CurrencyInputPanel/index.js
+10
-0
header.scss
src/components/Header/header.scss
+2
-2
index.js
src/components/Header/index.js
+0
-5
index.js
src/components/TokenLogo/index.js
+14
-5
web3-status.scss
src/components/Web3Status/web3-status.scss
+1
-1
AddLiquidity.js
src/pages/Pool/AddLiquidity.js
+60
-12
index.js
src/pages/Send/index.js
+65
-17
index.js
src/pages/Swap/index.js
+71
-15
swap.scss
src/pages/Swap/swap.scss
+6
-2
No files found.
src/components/AddressInputPanel/address-input-panel.scss
View file @
9d8c5330
...
@@ -4,12 +4,14 @@
...
@@ -4,12 +4,14 @@
@extend
%col-nowrap
;
@extend
%col-nowrap
;
&
__input
{
&
__input
{
font-size
:
.75
rem
;
font-size
:
1
rem
;
outline
:
none
;
outline
:
none
;
border
:
none
;
border
:
none
;
flex
:
1
1
auto
;
flex
:
1
1
auto
;
width
:
0
;
width
:
0
;
color
:
$royal-blue
;
color
:
$royal-blue
;
overflow
:
hidden
;
text-overflow
:
ellipsis
;
&
:
:
placeholder
{
&
:
:
placeholder
{
color
:
$chalice-gray
;
color
:
$chalice-gray
;
...
...
src/components/CurrencyInputPanel/currency-panel.scss
View file @
9d8c5330
...
@@ -59,6 +59,15 @@
...
@@ -59,6 +59,15 @@
&
--error
{
&
--error
{
color
:
$salmon-red
;
color
:
$salmon-red
;
}
}
&
[
type
=
'number'
]
{
-moz-appearance
:textfield
;
}
&
:
:-
webkit-outer-spin-button
,
&::-
webkit-inner-spin-button
{
-webkit-appearance
:
none
;
}
}
}
&
__extra-text
{
&
__extra-text
{
...
...
src/components/CurrencyInputPanel/index.js
View file @
9d8c5330
...
@@ -272,11 +272,21 @@ class CurrencyInputPanel extends Component {
...
@@ -272,11 +272,21 @@ class CurrencyInputPanel extends Component {
<
div
className
=
"
currency-input-panel__input-row
"
>
<
div
className
=
"
currency-input-panel__input-row
"
>
<
input
<
input
type
=
"
number
"
type
=
"
number
"
min
=
"
0
"
className
=
{
classnames
(
'
currency-input-panel__input
'
,{
className
=
{
classnames
(
'
currency-input-panel__input
'
,{
'
currency-input-panel__input--error
'
:
errorMessage
,
'
currency-input-panel__input--error
'
:
errorMessage
,
})}
})}
placeholder
=
"
0.0
"
placeholder
=
"
0.0
"
onChange
=
{
e
=>
onValueChange
(
e
.
target
.
value
)}
onChange
=
{
e
=>
onValueChange
(
e
.
target
.
value
)}
onKeyPress
=
{
e
=>
{
const
charCode
=
e
.
which
?
e
.
which
:
e
.
keyCode
;
// Prevent 'minus' character
if
(
charCode
===
45
)
{
e
.
preventDefault
();
e
.
stopPropagation
();
}
}}
value
=
{
value
}
value
=
{
value
}
/
>
/
>
{
this
.
renderUnlockButton
()
}
{
this
.
renderUnlockButton
()
}
...
...
src/components/Header/header.scss
View file @
9d8c5330
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
&
__top
{
&
__top
{
@extend
%row-nowrap
;
@extend
%row-nowrap
;
padding
:
1
.5rem
;
padding
:
1
.5rem
1
.5rem
.5rem
1
.5rem
;
align-items
:
center
;
align-items
:
center
;
}
}
...
@@ -22,7 +22,7 @@
...
@@ -22,7 +22,7 @@
}
}
&
__navigation
{
&
__navigation
{
margin
:
0
.75
rem
;
margin
-bottom
:
2
rem
;
}
}
&
--inactive
{
&
--inactive
{
...
...
src/components/Header/index.js
View file @
9d8c5330
...
@@ -121,11 +121,6 @@ function Header (props) {
...
@@ -121,11 +121,6 @@ function Header (props) {
<
/div
>
<
/div
>
<
Web3Status
isConnected
/>
<
Web3Status
isConnected
/>
<
/div
>
<
/div
>
<
NavigationTabs
className
=
{
classnames
(
'
header__navigation
'
,
{
'
header--inactive
'
:
!
props
.
isConnected
,
})}
/
>
<
/div
>
<
/div
>
)
)
}
}
...
...
src/components/TokenLogo/index.js
View file @
9d8c5330
...
@@ -3,6 +3,14 @@ import PropTypes from 'prop-types';
...
@@ -3,6 +3,14 @@ import PropTypes from 'prop-types';
import
EthereumLogo
from
'
../../assets/images/ethereum-logo.png
'
;
import
EthereumLogo
from
'
../../assets/images/ethereum-logo.png
'
;
import
GenericTokenLogo
from
'
../../assets/images/generic-token-logo.png
'
;
import
GenericTokenLogo
from
'
../../assets/images/generic-token-logo.png
'
;
const
RINKEBY_TOKEN_MAP
=
{
'
0xDA5B056Cfb861282B4b59d29c9B395bcC238D29B
'
:
'
0x0d8775f648430679a709e98d2b0cb6250d2887ef
'
,
'
0x2448eE2641d78CC42D7AD76498917359D961A783
'
:
'
0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359
'
,
'
0xF9bA5210F91D0474bd1e1DcDAeC4C58E359AaD85
'
:
'
0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2
'
,
'
0x879884c3C46A24f56089f3bBbe4d5e38dB5788C0
'
:
'
0xd26114cd6ee289accf82350c8d8487fedb8a0c07
'
,
'
0xF22e3F33768354c9805d046af3C0926f27741B43
'
:
'
0xe41d2489571d322189246dafa5ebde1f4699f498
'
,
};
const
TOKEN_ICON_API
=
'
https://raw.githubusercontent.com/TrustWallet/tokens/master/images
'
;
const
TOKEN_ICON_API
=
'
https://raw.githubusercontent.com/TrustWallet/tokens/master/images
'
;
const
BAD_IMAGES
=
{};
const
BAD_IMAGES
=
{};
export
default
class
TokenLogo
extends
Component
{
export
default
class
TokenLogo
extends
Component
{
...
@@ -14,7 +22,7 @@ export default class TokenLogo extends Component {
...
@@ -14,7 +22,7 @@ export default class TokenLogo extends Component {
static
defaultProps
=
{
static
defaultProps
=
{
address
:
''
,
address
:
''
,
size
:
'
1
.5
rem
'
,
size
:
'
1rem
'
,
className
:
''
,
className
:
''
,
};
};
...
@@ -25,13 +33,14 @@ export default class TokenLogo extends Component {
...
@@ -25,13 +33,14 @@ export default class TokenLogo extends Component {
render
()
{
render
()
{
const
{
address
,
size
,
className
}
=
this
.
props
;
const
{
address
,
size
,
className
}
=
this
.
props
;
let
path
=
GenericTokenLogo
;
let
path
=
GenericTokenLogo
;
const
mainAddress
=
RINKEBY_TOKEN_MAP
[
address
]
?
RINKEBY_TOKEN_MAP
[
address
]
:
address
;
if
(
a
ddress
===
'
ETH
'
)
{
if
(
mainA
ddress
===
'
ETH
'
)
{
path
=
EthereumLogo
;
path
=
EthereumLogo
;
}
}
if
(
!
this
.
state
.
error
&&
!
BAD_IMAGES
[
address
]
)
{
if
(
!
this
.
state
.
error
&&
!
BAD_IMAGES
[
mainAddress
]
&&
mainAddress
!==
'
ETH
'
)
{
path
=
`
${
TOKEN_ICON_API
}
/
${
a
ddress
}
.png`
;
path
=
`
${
TOKEN_ICON_API
}
/
${
mainA
ddress
}
.png`
;
}
}
return
(
return
(
...
@@ -44,7 +53,7 @@ export default class TokenLogo extends Component {
...
@@ -44,7 +53,7 @@ export default class TokenLogo extends Component {
}}
}}
onError
=
{()
=>
{
onError
=
{()
=>
{
this
.
setState
({
error
:
true
});
this
.
setState
({
error
:
true
});
BAD_IMAGES
[
a
ddress
]
=
true
;
BAD_IMAGES
[
mainA
ddress
]
=
true
;
}}
}}
/
>
/
>
);
);
...
...
src/components/Web3Status/web3-status.scss
View file @
9d8c5330
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
line-height
:
1rem
;
line-height
:
1rem
;
align-items
:
center
;
align-items
:
center
;
border
:
1px
solid
$mercury-gray
;
border
:
1px
solid
$mercury-gray
;
padding
:
.5rem
1rem
;
padding
:
.5rem
;
border-radius
:
2rem
;
border-radius
:
2rem
;
color
:
$dove-gray
;
color
:
$dove-gray
;
font-weight
:
400
;
font-weight
:
400
;
...
...
src/pages/Pool/AddLiquidity.js
View file @
9d8c5330
...
@@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
...
@@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
import
classnames
from
"
classnames
"
;
import
classnames
from
"
classnames
"
;
import
CurrencyInputPanel
from
'
../../components/CurrencyInputPanel
'
;
import
CurrencyInputPanel
from
'
../../components/CurrencyInputPanel
'
;
import
OversizedPanel
from
'
../../components/OversizedPanel
'
;
import
OversizedPanel
from
'
../../components/OversizedPanel
'
;
import
NavigationTabs
from
'
../../components/NavigationTabs
'
;
import
{
selectors
,
sync
}
from
'
../../ducks/web3connect
'
;
import
{
selectors
,
sync
}
from
'
../../ducks/web3connect
'
;
import
ArrowDown
from
'
../../assets/images/arrow-down-blue.svg
'
;
import
ArrowDown
from
'
../../assets/images/arrow-down-blue.svg
'
;
import
ModeSelector
from
'
./ModeSelector
'
;
import
ModeSelector
from
'
./ModeSelector
'
;
...
@@ -61,6 +62,27 @@ class AddLiquidity extends Component {
...
@@ -61,6 +62,27 @@ class AddLiquidity extends Component {
return
`Balance:
${
value
.
dividedBy
(
10
**
decimals
).
toFixed
(
4
)}
`
;
return
`Balance:
${
value
.
dividedBy
(
10
**
decimals
).
toFixed
(
4
)}
`
;
}
}
isUnapproved
()
{
const
{
account
,
exchangeAddresses
,
selectors
}
=
this
.
props
;
const
{
outputCurrency
}
=
this
.
state
;
if
(
!
outputCurrency
)
{
return
false
;
}
const
{
value
,
label
}
=
selectors
().
getApprovals
(
outputCurrency
,
account
,
exchangeAddresses
.
fromToken
[
outputCurrency
]
);
if
(
!
label
||
value
.
isLessThan
(
BN
(
10
**
22
)))
{
return
true
;
}
return
false
;
}
onAddLiquidity
=
async
()
=>
{
onAddLiquidity
=
async
()
=>
{
const
{
account
,
web3
,
exchangeAddresses
:
{
fromToken
},
selectors
}
=
this
.
props
;
const
{
account
,
web3
,
exchangeAddresses
:
{
fromToken
},
selectors
}
=
this
.
props
;
const
{
inputValue
,
outputValue
,
outputCurrency
}
=
this
.
state
;
const
{
inputValue
,
outputValue
,
outputCurrency
}
=
this
.
state
;
...
@@ -155,8 +177,10 @@ class AddLiquidity extends Component {
...
@@ -155,8 +177,10 @@ class AddLiquidity extends Component {
let
inputError
;
let
inputError
;
let
outputError
;
let
outputError
;
let
isValid
=
true
;
let
isValid
=
true
;
const
inputIsZero
=
BN
(
inputValue
).
isEqualTo
(
BN
(
0
));
const
outputIsZero
=
BN
(
outputValue
).
isEqualTo
(
BN
(
0
));
if
(
!
inputValue
||
!
outputValue
||
!
inputCurrency
||
!
outputCurrency
)
{
if
(
!
inputValue
||
inputIsZero
||
!
outputValue
||
outputIsZero
||
!
inputCurrency
||
!
outputCurrency
||
this
.
isUnapproved
()
)
{
isValid
=
false
;
isValid
=
false
;
}
}
...
@@ -229,10 +253,12 @@ class AddLiquidity extends Component {
...
@@ -229,10 +253,12 @@ class AddLiquidity extends Component {
inputCurrency
,
inputCurrency
,
outputCurrency
,
outputCurrency
,
}
=
this
.
state
;
}
=
this
.
state
;
const
inputIsZero
=
BN
(
inputValue
).
isEqualTo
(
BN
(
0
));
const
outputIsZero
=
BN
(
outputValue
).
isEqualTo
(
BN
(
0
));
if
(
!
inputCurrency
||
!
outputCurrency
)
{
if
(
!
inputCurrency
||
!
outputCurrency
)
{
return
(
return
(
<
div
className
=
"
swap__summary-wrapper
"
>
<
div
key
=
"
summary
"
className
=
"
swap__summary-wrapper
"
>
<
div
>
Select
a
token
to
continue
.
<
/div
>
<
div
>
Select
a
token
to
continue
.
<
/div
>
<
/div
>
<
/div
>
)
)
...
@@ -240,7 +266,7 @@ class AddLiquidity extends Component {
...
@@ -240,7 +266,7 @@ class AddLiquidity extends Component {
if
(
inputCurrency
===
outputCurrency
)
{
if
(
inputCurrency
===
outputCurrency
)
{
return
(
return
(
<
div
className
=
"
swap__summary-wrapper
"
>
<
div
key
=
"
summary
"
className
=
"
swap__summary-wrapper
"
>
<
div
>
Must
be
different
token
.
<
/div
>
<
div
>
Must
be
different
token
.
<
/div
>
<
/div
>
<
/div
>
)
)
...
@@ -248,17 +274,33 @@ class AddLiquidity extends Component {
...
@@ -248,17 +274,33 @@ class AddLiquidity extends Component {
if
(
!
[
inputCurrency
,
outputCurrency
].
includes
(
'
ETH
'
))
{
if
(
!
[
inputCurrency
,
outputCurrency
].
includes
(
'
ETH
'
))
{
return
(
return
(
<
div
className
=
"
swap__summary-wrapper
"
>
<
div
key
=
"
summary
"
className
=
"
swap__summary-wrapper
"
>
<
div
>
One
of
the
input
must
be
ETH
.
<
/div
>
<
div
>
One
of
the
input
must
be
ETH
.
<
/div
>
<
/div
>
<
/div
>
)
)
}
}
if
(
inputIsZero
||
outputIsZero
)
{
return
(
<
div
key
=
"
summary
"
className
=
"
swap__summary-wrapper
"
>
<
div
>
Amount
cannot
be
zero
.
<
/div
>
<
/div
>
)
}
if
(
this
.
isUnapproved
())
{
return
(
<
div
key
=
"
summary
"
className
=
"
swap__summary-wrapper
"
>
<
div
>
Please
unlock
token
to
continue
.
<
/div
>
<
/div
>
)
}
const
{
value
,
decimals
,
label
}
=
selectors
().
getTokenBalance
(
outputCurrency
,
fromToken
[
outputCurrency
]);
const
{
value
,
decimals
,
label
}
=
selectors
().
getTokenBalance
(
outputCurrency
,
fromToken
[
outputCurrency
]);
if
(
!
inputValue
||
!
outputValue
)
{
if
(
!
inputValue
||
!
outputValue
)
{
return
(
return
(
<
div
className
=
"
swap__summary-wrapper
"
>
<
div
key
=
"
summary
"
className
=
"
swap__summary-wrapper
"
>
<
div
>
{
`Enter a
${
inputCurrency
}
or
${
label
}
value to continue.`
}
<
/div
>
<
div
>
{
`Enter a
${
inputCurrency
}
or
${
label
}
value to continue.`
}
<
/div
>
<
/div
>
<
/div
>
)
)
...
@@ -272,10 +314,10 @@ class AddLiquidity extends Component {
...
@@ -272,10 +314,10 @@ class AddLiquidity extends Component {
const
maxPercentage
=
maxOutput
.
dividedBy
(
maxOutput
.
plus
(
tokenReserve
)).
multipliedBy
(
100
);
const
maxPercentage
=
maxOutput
.
dividedBy
(
maxOutput
.
plus
(
tokenReserve
)).
multipliedBy
(
100
);
return
(
return
(
<
div
className
=
"
swap__summary-wrapper
"
>
<
div
key
=
"
summary
"
className
=
"
swap__summary-wrapper
"
>
<
div
>
You
are
adding
between
{
b
(
`
${
minOutput
.
toFixed
(
2
)}
-
${
maxOutput
.
toFixed
(
2
)}
${
label
}
`
)}
+
{
b
(
`
${
BN
(
inputValue
).
toFixed
(
2
)}
ETH`
)}
into
the
liquidity
pool
.
<
/div
>
<
div
>
You
are
adding
between
{
b
(
`
${
minOutput
.
toFixed
(
5
)}
-
${
maxOutput
.
toFixed
(
5
)}
${
label
}
`
)}
+
{
b
(
`
${
BN
(
inputValue
).
toFixed
(
5
)}
ETH`
)}
into
the
liquidity
pool
.
<
/div
>
<
div
className
=
"
pool__last-summary-text
"
>
<
div
className
=
"
pool__last-summary-text
"
>
You
will
receive
between
{
b
(
`
${
minPercentage
.
toFixed
(
2
)}
%`
)}
and
{
b
(
`
${
maxPercentage
.
toFixed
(
2
)}
%`
)}
of
the
{
`
${
label
}
/ETH`
}
pool
tokens
.
You
will
receive
between
{
b
(
`
${
minPercentage
.
toFixed
(
5
)}
%`
)}
and
{
b
(
`
${
maxPercentage
.
toFixed
(
5
)}
%`
)}
of
the
{
`
${
label
}
/ETH`
}
pool
tokens
.
<
/div
>
<
/div
>
<
/div
>
<
/div
>
)
)
...
@@ -296,12 +338,18 @@ class AddLiquidity extends Component {
...
@@ -296,12 +338,18 @@ class AddLiquidity extends Component {
const
{
inputError
,
outputError
,
isValid
}
=
this
.
validate
();
const
{
inputError
,
outputError
,
isValid
}
=
this
.
validate
();
return
(
return
[
<
div
<
div
key
=
"
content
"
className
=
{
classnames
(
'
swap__content
'
,
{
className
=
{
classnames
(
'
swap__content
'
,
{
'
swap--inactive
'
:
!
isConnected
,
'
swap--inactive
'
:
!
isConnected
,
})}
})}
>
>
<
NavigationTabs
className
=
{
classnames
(
'
header__navigation
'
,
{
'
header--inactive
'
:
!
isConnected
,
})}
/
>
<
ModeSelector
/>
<
ModeSelector
/>
<
CurrencyInputPanel
<
CurrencyInputPanel
title
=
"
Deposit
"
title
=
"
Deposit
"
...
@@ -333,7 +381,6 @@ class AddLiquidity extends Component {
...
@@ -333,7 +381,6 @@ class AddLiquidity extends Component {
<
OversizedPanel
hideBottom
>
<
OversizedPanel
hideBottom
>
{
this
.
renderInfo
()
}
{
this
.
renderInfo
()
}
<
/OversizedPanel
>
<
/OversizedPanel
>
{
this
.
renderSummary
()
}
<
div
className
=
"
pool__cta-container
"
>
<
div
className
=
"
pool__cta-container
"
>
<
button
<
button
className
=
{
classnames
(
'
pool__cta-btn
'
,
{
className
=
{
classnames
(
'
pool__cta-btn
'
,
{
...
@@ -346,8 +393,9 @@ class AddLiquidity extends Component {
...
@@ -346,8 +393,9 @@ class AddLiquidity extends Component {
Add
Liquidity
Add
Liquidity
<
/button
>
<
/button
>
<
/div
>
<
/div
>
<
/div
>
<
/div>
,
);
this
.
renderSummary
()
];
}
}
}
}
...
...
src/pages/Send/index.js
View file @
9d8c5330
...
@@ -5,6 +5,7 @@ import classnames from 'classnames';
...
@@ -5,6 +5,7 @@ import classnames from 'classnames';
import
{
BigNumber
as
BN
}
from
"
bignumber.js
"
;
import
{
BigNumber
as
BN
}
from
"
bignumber.js
"
;
import
{
selectors
}
from
'
../../ducks/web3connect
'
;
import
{
selectors
}
from
'
../../ducks/web3connect
'
;
import
Header
from
'
../../components/Header
'
;
import
Header
from
'
../../components/Header
'
;
import
NavigationTabs
from
'
../../components/NavigationTabs
'
;
import
AddressInputPanel
from
'
../../components/AddressInputPanel
'
;
import
AddressInputPanel
from
'
../../components/AddressInputPanel
'
;
import
CurrencyInputPanel
from
'
../../components/CurrencyInputPanel
'
;
import
CurrencyInputPanel
from
'
../../components/CurrencyInputPanel
'
;
import
OversizedPanel
from
'
../../components/OversizedPanel
'
;
import
OversizedPanel
from
'
../../components/OversizedPanel
'
;
...
@@ -28,7 +29,7 @@ class Send extends Component {
...
@@ -28,7 +29,7 @@ class Send extends Component {
state
=
{
state
=
{
inputValue
:
''
,
inputValue
:
''
,
outputValue
:
''
,
outputValue
:
''
,
inputCurrency
:
''
,
inputCurrency
:
'
ETH
'
,
outputCurrency
:
''
,
outputCurrency
:
''
,
inputAmountB
:
''
,
inputAmountB
:
''
,
lastEditedField
:
''
,
lastEditedField
:
''
,
...
@@ -56,7 +57,7 @@ class Send extends Component {
...
@@ -56,7 +57,7 @@ class Send extends Component {
}
}
validate
()
{
validate
()
{
const
{
selectors
,
account
}
=
this
.
props
;
const
{
selectors
,
account
,
web3
}
=
this
.
props
;
const
{
const
{
inputValue
,
outputValue
,
inputValue
,
outputValue
,
inputCurrency
,
outputCurrency
,
inputCurrency
,
outputCurrency
,
...
@@ -66,8 +67,11 @@ class Send extends Component {
...
@@ -66,8 +67,11 @@ class Send extends Component {
let
inputError
=
''
;
let
inputError
=
''
;
let
outputError
=
''
;
let
outputError
=
''
;
let
isValid
=
true
;
let
isValid
=
true
;
const
validRecipientAddress
=
web3
&&
web3
.
utils
.
isAddress
(
recipient
);
const
inputIsZero
=
BN
(
inputValue
).
isEqualTo
(
BN
(
0
));
const
outputIsZero
=
BN
(
outputValue
).
isEqualTo
(
BN
(
0
));
if
(
!
inputValue
||
!
outputValue
||
!
inputCurrency
||
!
outputCurrency
||
!
recipient
)
{
if
(
!
inputValue
||
inputIsZero
||
!
outputValue
||
outputIsZero
||
!
inputCurrency
||
!
outputCurrency
||
!
recipient
||
this
.
isUnapproved
()
||
!
validRecipientAddress
)
{
isValid
=
false
;
isValid
=
false
;
}
}
...
@@ -88,13 +92,40 @@ class Send extends Component {
...
@@ -88,13 +92,40 @@ class Send extends Component {
};
};
}
}
isUnapproved
()
{
const
{
account
,
exchangeAddresses
,
selectors
}
=
this
.
props
;
const
{
inputCurrency
}
=
this
.
state
;
if
(
!
inputCurrency
||
inputCurrency
===
'
ETH
'
)
{
return
false
;
}
const
{
value
,
label
}
=
selectors
().
getApprovals
(
inputCurrency
,
account
,
exchangeAddresses
.
fromToken
[
inputCurrency
]
);
if
(
!
label
||
value
.
isLessThan
(
BN
(
10
**
22
)))
{
return
true
;
}
return
false
;
}
recalcForm
()
{
recalcForm
()
{
const
{
inputCurrency
,
outputCurrency
}
=
this
.
state
;
const
{
inputCurrency
,
outputCurrency
,
lastEditedField
}
=
this
.
state
;
if
(
!
inputCurrency
||
!
outputCurrency
)
{
if
(
!
inputCurrency
||
!
outputCurrency
)
{
return
;
return
;
}
}
const
editedValue
=
lastEditedField
===
INPUT
?
this
.
state
.
inputValue
:
this
.
state
.
outputValue
;
if
(
BN
(
editedValue
).
isEqualTo
(
BN
(
0
)))
{
return
;
}
if
(
inputCurrency
===
outputCurrency
)
{
if
(
inputCurrency
===
outputCurrency
)
{
this
.
setState
({
this
.
setState
({
inputValue
:
''
,
inputValue
:
''
,
...
@@ -457,10 +488,14 @@ class Send extends Component {
...
@@ -457,10 +488,14 @@ class Send extends Component {
outputError
,
outputError
,
recipient
,
recipient
,
}
=
this
.
state
;
}
=
this
.
state
;
const
{
web3
}
=
this
.
props
;
const
{
selectors
,
account
}
=
this
.
props
;
const
{
selectors
,
account
}
=
this
.
props
;
const
{
label
:
inputLabel
}
=
selectors
().
getBalance
(
account
,
inputCurrency
);
const
{
label
:
inputLabel
}
=
selectors
().
getBalance
(
account
,
inputCurrency
);
const
{
label
:
outputLabel
}
=
selectors
().
getBalance
(
account
,
outputCurrency
);
const
{
label
:
outputLabel
}
=
selectors
().
getBalance
(
account
,
outputCurrency
);
const
validRecipientAddress
=
web3
&&
web3
.
utils
.
isAddress
(
recipient
);
const
inputIsZero
=
BN
(
inputValue
).
isEqualTo
(
BN
(
0
));
const
outputIsZero
=
BN
(
outputValue
).
isEqualTo
(
BN
(
0
));
let
nextStepMessage
;
let
nextStepMessage
;
if
(
inputError
||
outputError
)
{
if
(
inputError
||
outputError
)
{
...
@@ -472,8 +507,14 @@ class Send extends Component {
...
@@ -472,8 +507,14 @@ class Send extends Component {
}
else
if
(
!
inputValue
||
!
outputValue
)
{
}
else
if
(
!
inputValue
||
!
outputValue
)
{
const
missingCurrencyValue
=
!
inputValue
?
inputLabel
:
outputLabel
;
const
missingCurrencyValue
=
!
inputValue
?
inputLabel
:
outputLabel
;
nextStepMessage
=
`Enter a
${
missingCurrencyValue
}
value to continue.`
;
nextStepMessage
=
`Enter a
${
missingCurrencyValue
}
value to continue.`
;
}
else
if
(
inputIsZero
||
outputIsZero
)
{
nextStepMessage
=
'
Amount cannot be zero.
'
;
}
else
if
(
this
.
isUnapproved
())
{
nextStepMessage
=
'
Please unlock token to continue.
'
;
}
else
if
(
!
recipient
)
{
}
else
if
(
!
recipient
)
{
nextStepMessage
=
'
Enter a wallet address to send to.
'
;
nextStepMessage
=
'
Enter a wallet address to send to.
'
;
}
else
if
(
!
validRecipientAddress
)
{
nextStepMessage
=
'
Please enter a valid wallet address recipient.
'
;
}
}
if
(
nextStepMessage
)
{
if
(
nextStepMessage
)
{
...
@@ -485,8 +526,8 @@ class Send extends Component {
...
@@ -485,8 +526,8 @@ class Send extends Component {
}
}
const
SLIPPAGE
=
0.025
;
const
SLIPPAGE
=
0.025
;
const
minOutput
=
BN
(
outputValue
).
multipliedBy
(
1
-
SLIPPAGE
).
toFixed
(
2
);
const
minOutput
=
BN
(
outputValue
).
multipliedBy
(
1
-
SLIPPAGE
).
toFixed
(
5
);
const
maxOutput
=
BN
(
outputValue
).
multipliedBy
(
1
+
SLIPPAGE
).
toFixed
(
2
);
const
maxOutput
=
BN
(
outputValue
).
multipliedBy
(
1
+
SLIPPAGE
).
toFixed
(
5
);
return
(
return
(
<
div
className
=
"
swap__summary-wrapper
"
>
<
div
className
=
"
swap__summary-wrapper
"
>
...
@@ -547,13 +588,18 @@ class Send extends Component {
...
@@ -547,13 +588,18 @@ class Send extends Component {
const
{
inputError
,
outputError
,
isValid
}
=
this
.
validate
();
const
{
inputError
,
outputError
,
isValid
}
=
this
.
validate
();
return
(
return
(
<
div
className
=
"
s
wap
"
>
<
div
className
=
"
s
end
"
>
<
Header
/>
<
Header
/>
<
div
<
div
className
=
{
classnames
(
'
swap__content
'
,
{
className
=
{
classnames
(
'
swap__content
'
,
{
'
swap--inactive
'
:
!
this
.
props
.
isConnected
,
'
swap--inactive
'
:
!
this
.
props
.
isConnected
,
})}
})}
>
>
<
NavigationTabs
className
=
{
classnames
(
'
header__navigation
'
,
{
'
header--inactive
'
:
!
this
.
props
.
isConnected
,
})}
/
>
<
CurrencyInputPanel
<
CurrencyInputPanel
title
=
"
Input
"
title
=
"
Input
"
description
=
{
lastEditedField
===
OUTPUT
?
estimatedText
:
''
}
description
=
{
lastEditedField
===
OUTPUT
?
estimatedText
:
''
}
...
@@ -598,17 +644,19 @@ class Send extends Component {
...
@@ -598,17 +644,19 @@ class Send extends Component {
onChange
=
{
address
=>
this
.
setState
({
recipient
:
address
})}
onChange
=
{
address
=>
this
.
setState
({
recipient
:
address
})}
/
>
/
>
{
this
.
renderExchangeRate
()
}
{
this
.
renderExchangeRate
()
}
{
this
.
renderSummary
()
}
<
div
className
=
"
swap__cta-container
"
>
<
button
className
=
{
classnames
(
'
swap__cta-btn
'
,
{
'
swap--inactive
'
:
!
this
.
props
.
isConnected
,
})}
disabled
=
{
!
isValid
}
onClick
=
{
this
.
onSend
}
>
Send
<
/button
>
<
/div
>
<
/div
>
<
/div
>
<
button
{
this
.
renderSummary
()
}
className
=
{
classnames
(
'
swap__cta-btn
'
,
{
'
swap--inactive
'
:
!
this
.
props
.
isConnected
,
})}
disabled
=
{
!
isValid
}
onClick
=
{
this
.
onSend
}
>
Send
<
/button
>
<
/div
>
<
/div
>
);
);
}
}
...
...
src/pages/Swap/index.js
View file @
9d8c5330
...
@@ -5,6 +5,7 @@ import classnames from 'classnames';
...
@@ -5,6 +5,7 @@ import classnames from 'classnames';
import
{
BigNumber
as
BN
}
from
"
bignumber.js
"
;
import
{
BigNumber
as
BN
}
from
"
bignumber.js
"
;
import
{
selectors
}
from
'
../../ducks/web3connect
'
;
import
{
selectors
}
from
'
../../ducks/web3connect
'
;
import
Header
from
'
../../components/Header
'
;
import
Header
from
'
../../components/Header
'
;
import
NavigationTabs
from
'
../../components/NavigationTabs
'
;
import
CurrencyInputPanel
from
'
../../components/CurrencyInputPanel
'
;
import
CurrencyInputPanel
from
'
../../components/CurrencyInputPanel
'
;
import
OversizedPanel
from
'
../../components/OversizedPanel
'
;
import
OversizedPanel
from
'
../../components/OversizedPanel
'
;
import
ArrowDown
from
'
../../assets/images/arrow-down-blue.svg
'
;
import
ArrowDown
from
'
../../assets/images/arrow-down-blue.svg
'
;
...
@@ -28,7 +29,7 @@ class Swap extends Component {
...
@@ -28,7 +29,7 @@ class Swap extends Component {
state
=
{
state
=
{
inputValue
:
''
,
inputValue
:
''
,
outputValue
:
''
,
outputValue
:
''
,
inputCurrency
:
''
,
inputCurrency
:
'
ETH
'
,
outputCurrency
:
''
,
outputCurrency
:
''
,
inputAmountB
:
''
,
inputAmountB
:
''
,
lastEditedField
:
''
,
lastEditedField
:
''
,
...
@@ -63,8 +64,11 @@ class Swap extends Component {
...
@@ -63,8 +64,11 @@ class Swap extends Component {
let
inputError
=
''
;
let
inputError
=
''
;
let
outputError
=
''
;
let
outputError
=
''
;
let
isValid
=
true
;
let
isValid
=
true
;
let
isUnapproved
=
this
.
isUnapproved
();
const
inputIsZero
=
BN
(
inputValue
).
isEqualTo
(
BN
(
0
));
const
outputIsZero
=
BN
(
outputValue
).
isEqualTo
(
BN
(
0
));
if
(
!
inputValue
||
!
outputValue
||
!
inputCurrency
||
!
outputCurrency
)
{
if
(
!
inputValue
||
inputIsZero
||
!
outputValue
||
outputIsZero
||
!
inputCurrency
||
!
outputCurrency
||
isUnapproved
)
{
isValid
=
false
;
isValid
=
false
;
}
}
...
@@ -85,13 +89,40 @@ class Swap extends Component {
...
@@ -85,13 +89,40 @@ class Swap extends Component {
};
};
}
}
isUnapproved
()
{
const
{
account
,
exchangeAddresses
,
selectors
}
=
this
.
props
;
const
{
inputCurrency
}
=
this
.
state
;
if
(
!
inputCurrency
||
inputCurrency
===
'
ETH
'
)
{
return
false
;
}
const
{
value
,
label
}
=
selectors
().
getApprovals
(
inputCurrency
,
account
,
exchangeAddresses
.
fromToken
[
inputCurrency
]
);
if
(
!
label
||
value
.
isLessThan
(
BN
(
10
**
22
)))
{
return
true
;
}
return
false
;
}
recalcForm
()
{
recalcForm
()
{
const
{
inputCurrency
,
outputCurrency
}
=
this
.
state
;
const
{
inputCurrency
,
outputCurrency
,
lastEditedField
}
=
this
.
state
;
if
(
!
inputCurrency
||
!
outputCurrency
)
{
if
(
!
inputCurrency
||
!
outputCurrency
)
{
return
;
return
;
}
}
const
editedValue
=
lastEditedField
===
INPUT
?
this
.
state
.
inputValue
:
this
.
state
.
outputValue
;
if
(
BN
(
editedValue
).
isEqualTo
(
BN
(
0
)))
{
return
;
}
if
(
inputCurrency
===
outputCurrency
)
{
if
(
inputCurrency
===
outputCurrency
)
{
this
.
setState
({
this
.
setState
({
inputValue
:
''
,
inputValue
:
''
,
...
@@ -450,8 +481,10 @@ class Swap extends Component {
...
@@ -450,8 +481,10 @@ class Swap extends Component {
const
{
label
:
inputLabel
}
=
selectors
().
getBalance
(
account
,
inputCurrency
);
const
{
label
:
inputLabel
}
=
selectors
().
getBalance
(
account
,
inputCurrency
);
const
{
label
:
outputLabel
}
=
selectors
().
getBalance
(
account
,
outputCurrency
);
const
{
label
:
outputLabel
}
=
selectors
().
getBalance
(
account
,
outputCurrency
);
const
SLIPPAGE
=
0.025
;
const
SLIPPAGE
=
0.025
;
const
minOutput
=
BN
(
outputValue
).
multipliedBy
(
1
-
SLIPPAGE
).
toFixed
(
2
);
const
minOutput
=
BN
(
outputValue
).
multipliedBy
(
1
-
SLIPPAGE
).
toFixed
(
5
);
const
maxOutput
=
BN
(
outputValue
).
multipliedBy
(
1
+
SLIPPAGE
).
toFixed
(
2
);
const
maxOutput
=
BN
(
outputValue
).
multipliedBy
(
1
+
SLIPPAGE
).
toFixed
(
5
);
const
inputIsZero
=
BN
(
inputValue
).
isEqualTo
(
BN
(
0
));
const
outputIsZero
=
BN
(
outputValue
).
isEqualTo
(
BN
(
0
));
if
(
!
inputCurrency
||
!
outputCurrency
)
{
if
(
!
inputCurrency
||
!
outputCurrency
)
{
return
(
return
(
...
@@ -469,6 +502,22 @@ class Swap extends Component {
...
@@ -469,6 +502,22 @@ class Swap extends Component {
)
)
}
}
if
(
inputIsZero
||
outputIsZero
)
{
return
(
<
div
className
=
"
swap__summary-wrapper
"
>
<
div
>
Amount
cannot
be
zero
.
<
/div
>
<
/div
>
)
}
if
(
this
.
isUnapproved
())
{
return
(
<
div
className
=
"
swap__summary-wrapper
"
>
<
div
>
Please
unlock
token
to
continue
.
<
/div
>
<
/div
>
);
}
return
(
return
(
<
div
className
=
"
swap__summary-wrapper
"
>
<
div
className
=
"
swap__summary-wrapper
"
>
<
div
>
You
are
selling
{
b
(
`
${
inputValue
}
${
inputLabel
}
`
)}
<
/div
>
<
div
>
You
are
selling
{
b
(
`
${
inputValue
}
${
inputLabel
}
`
)}
<
/div
>
...
@@ -530,6 +579,11 @@ class Swap extends Component {
...
@@ -530,6 +579,11 @@ class Swap extends Component {
'
swap--inactive
'
:
!
this
.
props
.
isConnected
,
'
swap--inactive
'
:
!
this
.
props
.
isConnected
,
})}
})}
>
>
<
NavigationTabs
className
=
{
classnames
(
'
header__navigation
'
,
{
'
header--inactive
'
:
!
this
.
props
.
isConnected
,
})}
/
>
<
CurrencyInputPanel
<
CurrencyInputPanel
title
=
"
Input
"
title
=
"
Input
"
description
=
{
lastEditedField
===
OUTPUT
?
estimatedText
:
''
}
description
=
{
lastEditedField
===
OUTPUT
?
estimatedText
:
''
}
...
@@ -565,17 +619,19 @@ class Swap extends Component {
...
@@ -565,17 +619,19 @@ class Swap extends Component {
disableUnlock
disableUnlock
/>
/>
{
this
.
renderExchangeRate
()
}
{
this
.
renderExchangeRate
()
}
{
this
.
renderSummary
()
}
<
div
className
=
"
swap__cta-container
"
>
<
button
className
=
{
classnames
(
'
swap__cta-btn
'
,
{
'
swap--inactive
'
:
!
this
.
props
.
isConnected
,
})}
disabled
=
{
!
isValid
}
onClick
=
{
this
.
onSwap
}
>
Swap
<
/button
>
<
/div
>
<
/div
>
<
/div
>
<
button
{
this
.
renderSummary
()
}
className
=
{
classnames
(
'
swap__cta-btn
'
,
{
'
swap--inactive
'
:
!
this
.
props
.
isConnected
,
})}
disabled
=
{
!
isValid
}
onClick
=
{
this
.
onSwap
}
>
Swap
<
/button
>
<
/div
>
<
/div
>
);
);
}
}
...
...
src/pages/Swap/swap.scss
View file @
9d8c5330
...
@@ -11,7 +11,6 @@
...
@@ -11,7 +11,6 @@
&
__content
{
&
__content
{
padding
:
1rem
.75rem
;
padding
:
1rem
.75rem
;
margin-top
:
1rem
;
flex
:
1
1
auto
;
flex
:
1
1
auto
;
height
:
0
;
height
:
0
;
overflow-y
:
auto
;
overflow-y
:
auto
;
...
@@ -46,7 +45,7 @@
...
@@ -46,7 +45,7 @@
}
}
&
__summary-wrapper
{
&
__summary-wrapper
{
margin
:
2rem
1rem
0
;
margin
:
2rem
1rem
;
color
:
#737373
;
color
:
#737373
;
font-size
:
.75rem
;
font-size
:
.75rem
;
text-align
:
center
;
text-align
:
center
;
...
@@ -56,6 +55,11 @@
...
@@ -56,6 +55,11 @@
color
:
$royal-blue
;
color
:
$royal-blue
;
}
}
&
__cta-container
{
display
:
flex
;
margin-top
:
1
.5rem
;
}
&
__cta-btn
{
&
__cta-btn
{
@extend
%primary-button
;
@extend
%primary-button
;
margin
:
1rem
auto
;
margin
:
1rem
auto
;
...
...
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