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
39248a0f
Unverified
Commit
39248a0f
authored
Oct 27, 2018
by
Chi Kei Chan
Committed by
GitHub
Oct 27, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle first liquidity deposit and add warning message (#88)
parent
43244fec
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
147 additions
and
26 deletions
+147
-26
plus-blue.svg
src/assets/images/plus-blue.svg
+3
-0
web3connect.js
src/ducks/web3connect.js
+1
-1
AddLiquidity.js
src/pages/Pool/AddLiquidity.js
+120
-24
pool.scss
src/pages/Pool/pool.scss
+19
-0
variables.scss
src/variables.scss
+4
-1
No files found.
src/assets/images/plus-blue.svg
0 → 100644
View file @
39248a0f
<svg
width=
"12"
height=
"12"
viewBox=
"0 0 12 12"
fill=
"none"
xmlns=
"http://www.w3.org/2000/svg"
>
<path
d=
"M1 6H6M11 6L6 6M6 1V6M6 6L6 11"
stroke=
"#2F80ED"
stroke-linecap=
"round"
/>
</svg>
src/ducks/web3connect.js
View file @
39248a0f
...
@@ -260,7 +260,7 @@ export const sync = () => async (dispatch, getState) => {
...
@@ -260,7 +260,7 @@ export const sync = () => async (dispatch, getState) => {
const
decimals
=
tokenBalance
.
decimals
||
await
contract
.
methods
.
decimals
().
call
();
const
decimals
=
tokenBalance
.
decimals
||
await
contract
.
methods
.
decimals
().
call
();
const
symbol
=
TOKEN_LABEL_FALLBACK
[
tokenAddress
]
||
tokenBalance
.
label
||
await
contract
.
methods
.
symbol
().
call
();
const
symbol
=
TOKEN_LABEL_FALLBACK
[
tokenAddress
]
||
tokenBalance
.
label
||
await
contract
.
methods
.
symbol
().
call
();
if
(
tokenBalance
.
value
.
isEqualTo
(
BN
(
balance
)))
{
if
(
tokenBalance
.
value
.
isEqualTo
(
BN
(
balance
))
&&
tokenBalance
.
label
&&
tokenBalance
.
decimals
)
{
return
;
return
;
}
}
...
...
src/pages/Pool/AddLiquidity.js
View file @
39248a0f
...
@@ -7,8 +7,8 @@ import CurrencyInputPanel from '../../components/CurrencyInputPanel';
...
@@ -7,8 +7,8 @@ import CurrencyInputPanel from '../../components/CurrencyInputPanel';
import
OversizedPanel
from
'
../../components/OversizedPanel
'
;
import
OversizedPanel
from
'
../../components/OversizedPanel
'
;
import
NavigationTabs
from
'
../../components/NavigationTabs
'
;
import
NavigationTabs
from
'
../../components/NavigationTabs
'
;
import
Modal
from
'
../../components/Modal
'
;
import
Modal
from
'
../../components/Modal
'
;
import
{
selectors
,
sync
}
from
'
../../ducks/web3connect
'
;
import
{
selectors
}
from
'
../../ducks/web3connect
'
;
import
ArrowDown
from
'
../../assets/images/
arrow-down
-blue.svg
'
;
import
ArrowDown
from
'
../../assets/images/
plus
-blue.svg
'
;
import
DropdownBlue
from
"
../../assets/images/dropdown-blue.svg
"
;
import
DropdownBlue
from
"
../../assets/images/dropdown-blue.svg
"
;
import
DropupBlue
from
"
../../assets/images/dropup-blue.svg
"
;
import
DropupBlue
from
"
../../assets/images/dropup-blue.svg
"
;
import
ModeSelector
from
'
./ModeSelector
'
;
import
ModeSelector
from
'
./ModeSelector
'
;
...
@@ -57,6 +57,41 @@ class AddLiquidity extends Component {
...
@@ -57,6 +57,41 @@ class AddLiquidity extends Component {
showSummaryModal
!==
nextState
.
showSummaryModal
;
showSummaryModal
!==
nextState
.
showSummaryModal
;
}
}
componentWillReceiveProps
()
{
this
.
recalcForm
();
}
recalcForm
=
()
=>
{
const
{
outputCurrency
,
inputValue
,
outputValue
,
lastEditedField
,
}
=
this
.
state
;
const
exchangeRate
=
this
.
getExchangeRate
();
const
append
=
{};
if
(
!
outputCurrency
||
this
.
isNewExchange
())
{
return
;
}
if
(
lastEditedField
===
INPUT
)
{
const
newOutputValue
=
exchangeRate
.
multipliedBy
(
inputValue
).
toFixed
(
7
);
if
(
newOutputValue
!==
outputValue
)
{
append
.
outputValue
=
newOutputValue
;
}
}
if
(
lastEditedField
===
OUTPUT
)
{
const
newInputValue
=
BN
(
outputValue
).
dividedBy
(
exchangeRate
).
toFixed
(
7
);
if
(
newInputValue
!==
inputValue
)
{
append
.
inputValue
=
newInputValue
;
}
}
this
.
setState
(
append
);
}
getBalance
(
currency
)
{
getBalance
(
currency
)
{
const
{
selectors
,
account
}
=
this
.
props
;
const
{
selectors
,
account
}
=
this
.
props
;
...
@@ -130,11 +165,16 @@ class AddLiquidity extends Component {
...
@@ -130,11 +165,16 @@ class AddLiquidity extends Component {
outputValue
=
BN
(
value
).
dividedBy
(
exchangeRate
).
toFixed
(
7
);
outputValue
=
BN
(
value
).
dividedBy
(
exchangeRate
).
toFixed
(
7
);
}
}
this
.
setState
({
const
append
=
{
outputValue
,
inputValue
:
value
,
inputValue
:
value
,
lastEditedField
:
INPUT
,
lastEditedField
:
INPUT
,
});
};
if
(
!
this
.
isNewExchange
())
{
append
.
outputValue
=
outputValue
;
}
this
.
setState
(
append
);
};
};
onOutputChange
=
value
=>
{
onOutputChange
=
value
=>
{
...
@@ -150,13 +190,34 @@ class AddLiquidity extends Component {
...
@@ -150,13 +190,34 @@ class AddLiquidity extends Component {
inputValue
=
exchangeRate
.
multipliedBy
(
value
).
toFixed
(
7
);
inputValue
=
exchangeRate
.
multipliedBy
(
value
).
toFixed
(
7
);
}
}
this
.
setState
({
const
append
=
{
inputValue
,
outputValue
:
value
,
outputValue
:
value
,
lastEditedField
:
OUTPUT
,
lastEditedField
:
INPUT
,
});
};
if
(
!
this
.
isNewExchange
())
{
append
.
inputValue
=
inputValue
;
}
this
.
setState
(
append
);
};
};
isNewExchange
()
{
const
{
selectors
,
exchangeAddresses
:
{
fromToken
}
}
=
this
.
props
;
const
{
inputCurrency
,
outputCurrency
}
=
this
.
state
;
const
eth
=
[
inputCurrency
,
outputCurrency
].
filter
(
currency
=>
currency
===
'
ETH
'
)[
0
];
const
token
=
[
inputCurrency
,
outputCurrency
].
filter
(
currency
=>
currency
!==
'
ETH
'
)[
0
];
if
(
!
eth
||
!
token
)
{
return
false
;
}
const
{
value
:
tokenValue
}
=
selectors
().
getBalance
(
fromToken
[
token
],
token
);
const
{
value
:
ethValue
}
=
selectors
().
getBalance
(
fromToken
[
token
],
eth
);
return
tokenValue
.
isZero
()
&&
ethValue
.
isZero
();
}
getExchangeRate
()
{
getExchangeRate
()
{
const
{
selectors
,
exchangeAddresses
:
{
fromToken
}
}
=
this
.
props
;
const
{
selectors
,
exchangeAddresses
:
{
fromToken
}
}
=
this
.
props
;
const
{
inputCurrency
,
outputCurrency
}
=
this
.
state
;
const
{
inputCurrency
,
outputCurrency
}
=
this
.
state
;
...
@@ -209,33 +270,52 @@ class AddLiquidity extends Component {
...
@@ -209,33 +270,52 @@ class AddLiquidity extends Component {
}
}
renderInfo
()
{
renderInfo
()
{
const
blank
=
(
<
div
className
=
"
pool__summary-panel
"
>
<
div
className
=
"
pool__exchange-rate-wrapper
"
>
<
span
className
=
"
pool__exchange-rate
"
>
Exchange
Rate
<
/span
>
<
span
>
-
<
/span
>
<
/div
>
<
div
className
=
"
pool__exchange-rate-wrapper
"
>
<
span
className
=
"
swap__exchange-rate
"
>
Current
Pool
Size
<
/span
>
<
span
>
-
<
/span
>
<
/div
>
<
/div
>
);
const
{
selectors
,
exchangeAddresses
:
{
fromToken
}
}
=
this
.
props
;
const
{
selectors
,
exchangeAddresses
:
{
fromToken
}
}
=
this
.
props
;
const
{
inputCurrency
,
outputCurrency
}
=
this
.
state
;
const
{
getBalance
}
=
selectors
();
const
{
inputCurrency
,
outputCurrency
,
inputValue
,
outputValue
}
=
this
.
state
;
const
eth
=
[
inputCurrency
,
outputCurrency
].
filter
(
currency
=>
currency
===
'
ETH
'
)[
0
];
const
eth
=
[
inputCurrency
,
outputCurrency
].
filter
(
currency
=>
currency
===
'
ETH
'
)[
0
];
const
token
=
[
inputCurrency
,
outputCurrency
].
filter
(
currency
=>
currency
!==
'
ETH
'
)[
0
];
const
token
=
[
inputCurrency
,
outputCurrency
].
filter
(
currency
=>
currency
!==
'
ETH
'
)[
0
];
if
(
!
eth
||
!
token
)
{
if
(
!
eth
||
!
token
)
{
return
blank
;
}
const
{
value
:
tokenValue
,
decimals
,
label
}
=
getBalance
(
fromToken
[
token
],
token
);
const
{
value
:
ethValue
}
=
getBalance
(
fromToken
[
token
]);
if
(
this
.
isNewExchange
())
{
const
rate
=
BN
(
outputValue
).
dividedBy
(
inputValue
);
const
rateText
=
rate
.
isNaN
()
?
'
---
'
:
rate
.
toFixed
(
4
);
return
(
return
(
<
div
className
=
"
pool__summary-panel
"
>
<
div
className
=
"
pool__summary-panel
"
>
<
div
className
=
"
pool__exchange-rate-wrapper
"
>
<
div
className
=
"
pool__exchange-rate-wrapper
"
>
<
span
className
=
"
pool__exchange-rate
"
>
Exchange
Rate
<
/span
>
<
span
className
=
"
pool__exchange-rate
"
>
Exchange
Rate
<
/span
>
<
span
>
-
<
/span
>
<
span
>
{
`1 ETH =
${
rateText
}
${
label
}
`
}
<
/span
>
<
/div
>
<
/div
>
<
div
className
=
"
pool__exchange-rate-wrapper
"
>
<
div
className
=
"
pool__exchange-rate-wrapper
"
>
<
span
className
=
"
swap__exchange-rate
"
>
Current
Pool
Size
<
/span
>
<
span
className
=
"
swap__exchange-rate
"
>
Current
Pool
Size
<
/span
>
<
span
>
-
<
/span
>
<
span
>
{
`
${
ethValue
.
dividedBy
(
10
**
18
).
toFixed
(
2
)}
${
eth
}
+
${
tokenValue
.
dividedBy
(
10
**
decimals
).
toFixed
(
2
)}
${
label
}
`
}
<
/span
>
<
/div
>
<
/div
>
<
/div
>
<
/div
>
)
)
}
}
const
{
if
(
tokenValue
.
dividedBy
(
ethValue
).
isNaN
())
{
value
:
tokenValue
,
return
blank
;
decimals
,
}
label
}
=
selectors
().
getTokenBalance
(
token
,
fromToken
[
token
]);
const
{
value
:
ethValue
}
=
selectors
().
getBalance
(
fromToken
[
token
]);
return
(
return
(
<
div
className
=
"
pool__summary-panel
"
>
<
div
className
=
"
pool__summary-panel
"
>
...
@@ -302,7 +382,7 @@ class AddLiquidity extends Component {
...
@@ -302,7 +382,7 @@ class AddLiquidity extends Component {
)
)
}
}
const
{
value
,
decimals
,
label
}
=
selectors
().
getTokenBalance
(
outputCurrency
,
fromToken
[
outputCurrency
]);
const
{
label
}
=
selectors
().
getTokenBalance
(
outputCurrency
,
fromToken
[
outputCurrency
]);
if
(
!
inputValue
||
!
outputValue
)
{
if
(
!
inputValue
||
!
outputValue
)
{
return
(
return
(
...
@@ -330,7 +410,6 @@ class AddLiquidity extends Component {
...
@@ -330,7 +410,6 @@ class AddLiquidity extends Component {
const
{
const
{
inputValue
,
inputValue
,
outputValue
,
outputValue
,
inputCurrency
,
outputCurrency
,
outputCurrency
,
showSummaryModal
,
showSummaryModal
,
}
=
this
.
state
;
}
=
this
.
state
;
...
@@ -381,6 +460,8 @@ class AddLiquidity extends Component {
...
@@ -381,6 +460,8 @@ class AddLiquidity extends Component {
render
()
{
render
()
{
const
{
const
{
isConnected
,
isConnected
,
exchangeAddresses
:
{
fromToken
},
selectors
,
}
=
this
.
props
;
}
=
this
.
props
;
const
{
const
{
...
@@ -388,10 +469,10 @@ class AddLiquidity extends Component {
...
@@ -388,10 +469,10 @@ class AddLiquidity extends Component {
outputValue
,
outputValue
,
inputCurrency
,
inputCurrency
,
outputCurrency
,
outputCurrency
,
lastEditedField
,
}
=
this
.
state
;
}
=
this
.
state
;
const
{
inputError
,
outputError
,
isValid
}
=
this
.
validate
();
const
{
inputError
,
outputError
,
isValid
}
=
this
.
validate
();
const
{
label
}
=
selectors
().
getTokenBalance
(
outputCurrency
,
fromToken
[
outputCurrency
]);
return
[
return
[
<
div
<
div
...
@@ -405,6 +486,20 @@ class AddLiquidity extends Component {
...
@@ -405,6 +486,20 @@ class AddLiquidity extends Component {
'
header--inactive
'
:
!
isConnected
,
'
header--inactive
'
:
!
isConnected
,
})}
})}
/
>
/
>
{
this
.
isNewExchange
()
?
(
<
div
className
=
"
pool__new-exchange-warning
"
>
<
div
className
=
"
pool__new-exchange-warning-text
"
>
You
are
the
first
person
to
add
liquidity
🚰
!
<
/div
>
<
div
className
=
"
pool__new-exchange-warning-text
"
>
{
`A new exchange rate will be set based on your deposits. Please make sure that your ETH and
${
label
}
deposits have the same fiat value.`
}
<
/div
>
<
/div
>
)
:
null
}
<
ModeSelector
/>
<
ModeSelector
/>
<
CurrencyInputPanel
<
CurrencyInputPanel
title
=
"
Deposit
"
title
=
"
Deposit
"
...
@@ -426,7 +521,9 @@ class AddLiquidity extends Component {
...
@@ -426,7 +521,9 @@ class AddLiquidity extends Component {
extraText
=
{
this
.
getBalance
(
outputCurrency
)}
extraText
=
{
this
.
getBalance
(
outputCurrency
)}
selectedTokenAddress
=
{
outputCurrency
}
selectedTokenAddress
=
{
outputCurrency
}
onCurrencySelected
=
{
currency
=>
{
onCurrencySelected
=
{
currency
=>
{
this
.
setState
({
outputCurrency
:
currency
});
this
.
setState
({
outputCurrency
:
currency
,
},
this
.
recalcForm
);
}}
}}
onValueChange
=
{
this
.
onOutputChange
}
onValueChange
=
{
this
.
onOutputChange
}
value
=
{
outputValue
}
value
=
{
outputValue
}
...
@@ -465,7 +562,6 @@ export default drizzleConnect(
...
@@ -465,7 +562,6 @@ export default drizzleConnect(
}),
}),
dispatch
=>
({
dispatch
=>
({
selectors
:
()
=>
dispatch
(
selectors
()),
selectors
:
()
=>
dispatch
(
selectors
()),
sync
:
()
=>
dispatch
(
sync
()),
})
})
)
)
...
...
src/pages/Pool/pool.scss
View file @
39248a0f
...
@@ -58,6 +58,25 @@
...
@@ -58,6 +58,25 @@
background
:
$mercury-gray
;
background
:
$mercury-gray
;
}
}
}
}
&
__new-exchange-warning
{
padding
:
1rem
;
margin-bottom
:
2rem
;
border
:
1px
solid
rgba
(
$pizazz-orange
,
.4
);
background-color
:
rgba
(
$pizazz-orange
,
.1
);
border-radius
:
1rem
;
}
&
__new-exchange-warning-text
{
font-size
:
.75rem
;
line-height
:
1rem
;
text-align
:
center
;
&
:first-child
{
padding-bottom
:
.3rem
;
font-weight
:
500
;
}
}
}
}
.pool-modal
{
.pool-modal
{
...
...
src/variables.scss
View file @
39248a0f
...
@@ -18,7 +18,10 @@ $royal-blue: #2F80ED;
...
@@ -18,7 +18,10 @@ $royal-blue: #2F80ED;
$wisteria-purple
:
#AE60B9
;
$wisteria-purple
:
#AE60B9
;
// Red
// Red
$salmon-red
:
#FF8368
;
$salmon-red
:
#FF6871
;
// Orange
$pizazz-orange
:
#FF8F05
;
%col-nowrap
{
%col-nowrap
{
display
:
flex
;
display
:
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