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
e77330ec
Commit
e77330ec
authored
Oct 09, 2018
by
Chi Kei Chan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Watch for ETH balance update
parent
eb18ec2d
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
119 additions
and
20 deletions
+119
-20
index.js
src/components/CurrencyInputPanel/index.js
+31
-5
index.js
src/components/Watcher/index.js
+65
-0
web3.js
src/ducks/web3.js
+6
-2
App.js
src/pages/App.js
+17
-13
No files found.
src/components/CurrencyInputPanel/index.js
View file @
e77330ec
...
@@ -32,6 +32,7 @@ class CurrencyInputPanel extends Component {
...
@@ -32,6 +32,7 @@ class CurrencyInputPanel extends Component {
title
:
PropTypes
.
string
,
title
:
PropTypes
.
string
,
description
:
PropTypes
.
string
,
description
:
PropTypes
.
string
,
extraText
:
PropTypes
.
string
,
extraText
:
PropTypes
.
string
,
web3
:
PropTypes
.
object
.
isRequired
,
};
};
state
=
{
state
=
{
...
@@ -40,12 +41,33 @@ class CurrencyInputPanel extends Component {
...
@@ -40,12 +41,33 @@ class CurrencyInputPanel extends Component {
selectedTokenAddress
:
''
,
selectedTokenAddress
:
''
,
};
};
getBalance
()
{
const
{
balance
,
web3
,
}
=
this
.
props
;
const
{
selectedTokenAddress
}
=
this
.
state
;
if
(
!
selectedTokenAddress
)
{
return
''
;
}
const
bn
=
balance
[
selectedTokenAddress
];
if
(
!
bn
)
{
return
''
;
}
return
`Balance:
${
web3
.
utils
.
fromWei
(
bn
,
'
ether
'
)}
`
;
}
createTokenList
=
()
=>
{
createTokenList
=
()
=>
{
let
tokens
=
this
.
props
.
tokenAddresses
.
addresses
;
let
tokens
=
this
.
props
.
tokenAddresses
.
addresses
;
let
tokenList
=
[
{
value
:
'
ETH
'
,
label
:
'
ETH
'
,
address
:
'
ETH
'
,
clearableValue
:
false
}
];
let
tokenList
=
[
{
value
:
'
ETH
'
,
label
:
'
ETH
'
,
address
:
'
ETH
'
}
];
for
(
let
i
=
0
;
i
<
tokens
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
tokens
.
length
;
i
++
)
{
let
entry
=
{
value
:
''
,
label
:
''
,
clearableValue
:
false
}
let
entry
=
{
value
:
''
,
label
:
''
}
entry
.
value
=
tokens
[
i
][
0
];
entry
.
value
=
tokens
[
i
][
0
];
entry
.
label
=
tokens
[
i
][
0
];
entry
.
label
=
tokens
[
i
][
0
];
entry
.
address
=
tokens
[
i
][
1
];
entry
.
address
=
tokens
[
i
][
1
];
...
@@ -54,7 +76,7 @@ class CurrencyInputPanel extends Component {
...
@@ -54,7 +76,7 @@ class CurrencyInputPanel extends Component {
}
}
return
tokenList
;
return
tokenList
;
}
}
;
renderTokenList
()
{
renderTokenList
()
{
const
tokens
=
this
.
createTokenList
();
const
tokens
=
this
.
createTokenList
();
...
@@ -125,7 +147,8 @@ class CurrencyInputPanel extends Component {
...
@@ -125,7 +147,8 @@ class CurrencyInputPanel extends Component {
const
{
const
{
title
,
title
,
description
,
description
,
extraText
,
balance
,
web3
,
}
=
this
.
props
;
}
=
this
.
props
;
const
{
selectedTokenAddress
}
=
this
.
state
;
const
{
selectedTokenAddress
}
=
this
.
state
;
...
@@ -138,7 +161,9 @@ class CurrencyInputPanel extends Component {
...
@@ -138,7 +161,9 @@ class CurrencyInputPanel extends Component {
<
span
className
=
"
currency-input-panel__label
"
>
{
title
}
<
/span
>
<
span
className
=
"
currency-input-panel__label
"
>
{
title
}
<
/span
>
<
span
className
=
"
currency-input-panel__label-description
"
>
{
description
}
<
/span
>
<
span
className
=
"
currency-input-panel__label-description
"
>
{
description
}
<
/span
>
<
/div
>
<
/div
>
<
span
className
=
"
currency-input-panel__extra-text
"
>
{
extraText
}
<
/span
>
<
span
className
=
"
currency-input-panel__extra-text
"
>
{
this
.
getBalance
()}
<
/span
>
<
/div
>
<
/div
>
<
div
className
=
"
currency-input-panel__input-row
"
>
<
div
className
=
"
currency-input-panel__input-row
"
>
<
input
<
input
...
@@ -180,6 +205,7 @@ export default connect(
...
@@ -180,6 +205,7 @@ export default connect(
state
=>
({
state
=>
({
tokenAddresses
:
state
.
web3
.
tokenAddresses
,
tokenAddresses
:
state
.
web3
.
tokenAddresses
,
balance
:
state
.
web3
.
balance
,
balance
:
state
.
web3
.
balance
,
web3
:
state
.
web3
.
web3
,
}),
}),
dispatch
=>
({
dispatch
=>
({
updateField
:
(
name
,
value
)
=>
dispatch
(
updateField
({
name
,
value
})),
updateField
:
(
name
,
value
)
=>
dispatch
(
updateField
({
name
,
value
})),
...
...
src/components/Watcher/index.js
0 → 100644
View file @
e77330ec
import
React
,
{
Component
}
from
'
react
'
;
import
{
connect
}
from
'
react-redux
'
;
import
PropTypes
from
'
prop-types
'
;
import
{
updateBalance
}
from
'
../../ducks/web3
'
;
class
Watcher
extends
Component
{
state
=
{
watchlist
:
{},
};
componentWillMount
()
{
this
.
startWatching
();
}
componentWillUnmount
()
{
}
add
(
address
)
{
const
{
watchlist
}
=
this
.
state
;
this
.
setState
({
...
watchlist
,
[
address
]:
true
,
});
}
remove
(
address
)
{
const
{
watchlist
}
=
this
.
state
;
this
.
setState
({
...
watchlist
,
[
address
]:
false
,
});
}
startWatching
()
{
if
(
this
.
interval
)
{
clearInterval
(
this
.
interval
);
return
;
}
this
.
interval
=
setInterval
(()
=>
{
this
.
props
.
updateBalance
();
Object
.
keys
(
this
.
state
.
watchlist
).
forEach
(
address
=>
{
});
},
15000
);
}
stopWatching
()
{
if
(
this
.
interval
)
{
clearInterval
(
this
.
interval
);
}
}
render
()
{
return
<
noscript
/>
;
}
}
export
default
connect
(
null
,
dispatch
=>
({
updateBalance
:
()
=>
dispatch
(
updateBalance
()),
}),
)(
Watcher
);
src/ducks/web3.js
View file @
e77330ec
...
@@ -36,6 +36,8 @@ export const initialize = () => dispatch => {
...
@@ -36,6 +36,8 @@ export const initialize = () => dispatch => {
payload
:
web3
,
payload
:
web3
,
});
});
dispatch
(
updateCurrentAddress
());
dispatch
(
updateCurrentAddress
());
setInterval
(()
=>
dispatch
(
updateBalance
()),
15000
)
}
}
};
};
...
@@ -55,7 +57,9 @@ export const updateCurrentAddress = () => (dispatch, getState) => {
...
@@ -55,7 +57,9 @@ export const updateCurrentAddress = () => (dispatch, getState) => {
type
:
UPDATE_CURRENT_ADDRESS
,
type
:
UPDATE_CURRENT_ADDRESS
,
payload
:
accounts
[
0
],
payload
:
accounts
[
0
],
});
});
})
dispatch
(
updateBalance
());
});
};
};
export
const
updateBalance
=
()
=>
(
dispatch
,
getState
)
=>
{
export
const
updateBalance
=
()
=>
(
dispatch
,
getState
)
=>
{
...
@@ -76,7 +80,7 @@ export const updateBalance = () => (dispatch, getState) => {
...
@@ -76,7 +80,7 @@ export const updateBalance = () => (dispatch, getState) => {
address
:
'
ETH
'
,
address
:
'
ETH
'
,
balance
:
data
,
balance
:
data
,
}
}
})
})
;
});
});
};
};
...
...
src/pages/App.js
View file @
e77330ec
...
@@ -3,6 +3,7 @@ import { connect } from 'react-redux';
...
@@ -3,6 +3,7 @@ import { connect } from 'react-redux';
import
{
BrowserRouter
,
Switch
,
Route
}
from
'
react-router-dom
'
;
import
{
BrowserRouter
,
Switch
,
Route
}
from
'
react-router-dom
'
;
import
{
AnimatedSwitch
}
from
'
react-router-transition
'
;
import
{
AnimatedSwitch
}
from
'
react-router-transition
'
;
import
{
initialize
}
from
'
../ducks/web3
'
import
{
initialize
}
from
'
../ducks/web3
'
import
Watcher
from
'
../components/Watcher
'
;
import
Swap
from
'
./Swap
'
;
import
Swap
from
'
./Swap
'
;
import
Send
from
'
./Send
'
;
import
Send
from
'
./Send
'
;
import
Pool
from
'
./Pool
'
;
import
Pool
from
'
./Pool
'
;
...
@@ -16,6 +17,8 @@ class App extends Component {
...
@@ -16,6 +17,8 @@ class App extends Component {
render
()
{
render
()
{
return
(
return
(
<
div
style
=
{{
width
:
'
100%
'
,
height
:
'
100%
'
}}
>
<
Watcher
/>
<
BrowserRouter
>
<
BrowserRouter
>
<
AnimatedSwitch
<
AnimatedSwitch
atEnter
=
{{
opacity
:
0
}}
atEnter
=
{{
opacity
:
0
}}
...
@@ -29,6 +32,7 @@ class App extends Component {
...
@@ -29,6 +32,7 @@ class App extends Component {
<
Route
component
=
{
Swap
}
/
>
<
Route
component
=
{
Swap
}
/
>
<
/AnimatedSwitch
>
<
/AnimatedSwitch
>
<
/BrowserRouter
>
<
/BrowserRouter
>
<
/div
>
);
);
}
}
}
}
...
...
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