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
20538d34
Commit
20538d34
authored
Mar 23, 2018
by
Uciel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
renamed web3 reducer
parent
fe19f9ea
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
54 additions
and
36 deletions
+54
-36
App.js
src/App.js
+10
-8
web3-actions.js
src/actions/web3-actions.js
+8
-1
NetworkStatus.js
src/components/NetworkStatus.js
+15
-5
Purchase.js
src/components/Purchase.js
+7
-7
global-reducer.js
src/reducers/global-reducer.js
+9
-9
index.js
src/reducers/index.js
+1
-2
web3-reducer.js
src/reducers/web3-reducer.js
+3
-3
initial-state.js
src/store/initial-state.js
+1
-1
No files found.
src/App.js
View file @
20538d34
...
@@ -14,16 +14,16 @@ import Purchase from './components/Purchase';
...
@@ -14,16 +14,16 @@ import Purchase from './components/Purchase';
import
About
from
'
./components/About
'
;
import
About
from
'
./components/About
'
;
import
Links
from
'
./components/Links
'
;
import
Links
from
'
./components/Links
'
;
import
Transactions
from
'
./components/Transactions
'
;
import
Transactions
from
'
./components/Transactions
'
;
import
SelectToken
from
'
./components/SelectToken
'
//
import SelectToken from './components/SelectToken'
// enter redux
// enter redux
import
{
bindActionCreators
}
from
'
redux
'
import
{
bindActionCreators
}
from
'
redux
'
import
{
connect
}
from
'
react-redux
'
;
import
{
connect
}
from
'
react-redux
'
;
import
{
subscribe
}
from
'
redux-subscriber
'
;
import
{
subscribe
}
from
'
redux-subscriber
'
;
// redux actions
// redux actions
import
{
initializeGlobalWeb3
}
from
'
./actions/global-actions
'
;
//
import { initializeGlobalWeb3 } from './actions/global-actions';
import
{
uniExchangeContractReady
,
swtExchangeContractReady
}
from
'
./actions/exchangeContract-actions
'
;
import
{
uniExchangeContractReady
,
swtExchangeContractReady
}
from
'
./actions/exchangeContract-actions
'
;
import
{
uniTokenContractReady
,
swtTokenContractReady
}
from
'
./actions/tokenContract-actions
'
;
import
{
uniTokenContractReady
,
swtTokenContractReady
}
from
'
./actions/tokenContract-actions
'
;
import
{
setWeb3ConnectionStatus
,
setCurrentMaskAddress
,
metamaskLocked
,
metamaskUnlocked
,
setInteractionState
,
factoryContractReady
,
toggleAbout
}
from
'
./actions/web3-actions
'
;
import
{
initializeGlobalWeb3
,
setWeb3ConnectionStatus
,
setCurrentMaskAddress
,
metamaskLocked
,
metamaskUnlocked
,
setInteractionState
,
factoryContractReady
,
toggleAbout
}
from
'
./actions/web3-actions
'
;
import
{
setInputBalance
,
setOutputBalance
,
setInvariant1
,
setInvariant2
,
setMarketEth1
,
setMarketEth2
,
setMarketTokens1
,
setMarketTokens2
,
setAllowanceApprovalState
}
from
'
./actions/exchange-actions
'
;
import
{
setInputBalance
,
setOutputBalance
,
setInvariant1
,
setInvariant2
,
setMarketEth1
,
setMarketEth2
,
setMarketTokens1
,
setMarketTokens2
,
setAllowanceApprovalState
}
from
'
./actions/exchange-actions
'
;
// enter d3 & misc. tools
// enter d3 & misc. tools
import
'
./App.css
'
;
import
'
./App.css
'
;
...
@@ -75,11 +75,11 @@ class App extends Component {
...
@@ -75,11 +75,11 @@ class App extends Component {
if
(
state
.
web3Store
.
connected
===
true
&&
!
state
.
web3Store
.
metamaskLocked
)
{
if
(
state
.
web3Store
.
connected
===
true
&&
!
state
.
web3Store
.
metamaskLocked
)
{
console
.
log
(
'
successfully connected to metamask
'
,
state
.
web3Store
.
currentMaskAddress
);
console
.
log
(
'
successfully connected to metamask
'
,
state
.
web3Store
.
currentMaskAddress
);
setInterval
(
this
.
getMarketInfo
,
15000
);
setInterval
(
this
.
getMarketInfo
,
15000
);
//
setInterval(this.getAccountInfo, 15000);
setInterval
(
this
.
getAccountInfo
,
15000
);
//
setInterval(this.getUserAddress, 10000);
setInterval
(
this
.
getUserAddress
,
10000
);
}
else
{
}
else
{
console
.
log
(
'
web3 not connected, getting user address
'
)
console
.
log
(
'
web3 not connected, getting user address
'
)
//
setInterval(this.getUserAddress, 500);
setInterval
(
this
.
getUserAddress
,
500
);
}
}
})
})
}
}
...
@@ -107,11 +107,13 @@ class App extends Component {
...
@@ -107,11 +107,13 @@ class App extends Component {
getUserAddress
=
()
=>
{
getUserAddress
=
()
=>
{
localweb3
.
eth
.
getAccounts
((
error
,
result
)
=>
{
localweb3
.
eth
.
getAccounts
((
error
,
result
)
=>
{
if
(
result
.
length
>
0
)
{
if
(
result
.
length
>
0
)
{
console
.
log
(
'
getUserAddress metamask unlocked
'
)
this
.
props
.
setCurrentMaskAddress
(
result
[
0
]);
this
.
props
.
setCurrentMaskAddress
(
result
[
0
]);
this
.
props
.
metamaskUnlocked
();
this
.
props
.
metamaskUnlocked
();
this
.
props
.
setWeb3ConnectionStatus
(
true
);
this
.
props
.
setWeb3ConnectionStatus
(
true
);
}
}
else
{
else
{
console
.
log
(
'
getUserAddress metamask Locked
'
)
this
.
props
.
metamaskLocked
();
this
.
props
.
metamaskLocked
();
this
.
props
.
setWeb3ConnectionStatus
(
false
);
this
.
props
.
setWeb3ConnectionStatus
(
false
);
this
.
props
.
setInteractionState
(
'
locked
'
);
this
.
props
.
setInteractionState
(
'
locked
'
);
...
@@ -375,8 +377,8 @@ class App extends Component {
...
@@ -375,8 +377,8 @@ class App extends Component {
inputTokenValue
=
{
this
.
props
.
exchange
.
inputToken
.
value
}
inputTokenValue
=
{
this
.
props
.
exchange
.
inputToken
.
value
}
exchangeFee
=
{
this
.
props
.
exchange
.
fee
}
exchangeFee
=
{
this
.
props
.
exchange
.
fee
}
/
>
/
>
<
Purchase
<
Purchase
symbolToExchangeContract
=
{
this
.
symbolToExchangeContract
}
symbolToExchangeContract
=
{
this
.
symbolToExchangeContract
}
symbolToTokenAddress
=
{
this
.
symbolToTokenAddress
}
symbolToTokenAddress
=
{
this
.
symbolToTokenAddress
}
/>
/>
<
About
toggleAbout
=
{
this
.
toggleAbout
}
location
=
{
this
}
/
>
<
About
toggleAbout
=
{
this
.
toggleAbout
}
location
=
{
this
}
/
>
...
...
src/actions/web3-actions.js
View file @
20538d34
import
{
import
{
INITIALIZE_GLOBAL_WEB3
,
SET_WEB3_CONNECTION_STATUS
,
SET_WEB3_CONNECTION_STATUS
,
SET_CURRENT_MASK_ADDRESS
,
SET_CURRENT_MASK_ADDRESS
,
METAMASK_LOCKED
,
METAMASK_LOCKED
,
...
@@ -94,4 +95,10 @@ export const setExchangeType = (exchangeType) => ({
...
@@ -94,4 +95,10 @@ export const setExchangeType = (exchangeType) => ({
export
const
toggleAbout
=
(
toggle
)
=>
({
export
const
toggleAbout
=
(
toggle
)
=>
({
type
:
TOGGLE_ABOUT
,
type
:
TOGGLE_ABOUT
,
aboutToggle
:
toggle
aboutToggle
:
toggle
})
});
\ No newline at end of file
export
const
initializeGlobalWeb3
=
(
web3
)
=>
({
type
:
INITIALIZE_GLOBAL_WEB3
,
web3
});
\ No newline at end of file
src/components/NetworkStatus.js
View file @
20538d34
import
React
,
{
Component
}
from
'
react
'
;
import
React
,
{
Component
}
from
'
react
'
;
import
{
bindActionCreators
}
from
'
redux
'
import
{
bindActionCreators
}
from
'
redux
'
import
{
connect
}
from
'
react-redux
'
import
{
connect
}
from
'
react-redux
'
import
{
setWeb3ConnectionStatus
,
setInteractionState
,
setNetworkMessage
}
from
'
../actions/web3-actions
'
;
import
{
subscribe
}
from
'
redux-subscriber
'
;
import
{
setWeb3ConnectionStatus
,
setInteractionState
,
setNetworkMessage
,
metamaskLocked
}
from
'
../actions/web3-actions
'
;
class
NetworkStatus
extends
Component
{
class
NetworkStatus
extends
Component
{
componentDidMount
(){
componentDidMount
(){
if
(
this
.
props
.
global
.
web3
!==
undefined
){
const
interactionStateSubscriber
=
subscribe
(
'
web3Store.metamaskLocked
'
,
state
=>
{
this
.
checkNetwork
();
if
(
state
.
web3Store
.
metamaskLocked
!==
true
)
{
}
console
.
log
(
'
metamask is unlocked
'
)
this
.
checkNetwork
();
}
else
{
console
.
log
(
'
metamask is locked
'
)
}
})
// if (this.props.web3Store.web3 !== undefined){
// this.checkNetwork();
// }
}
}
checkNetwork
=
()
=>
{
checkNetwork
=
()
=>
{
this
.
props
.
global
.
web3
.
eth
.
net
.
getNetworkType
((
err
,
networkId
)
=>
{
this
.
props
.
web3Store
.
web3
.
eth
.
net
.
getNetworkType
((
err
,
networkId
)
=>
{
console
.
log
(
"
Connected to
"
+
networkId
)
console
.
log
(
"
Connected to
"
+
networkId
)
let
interactionState
=
networkId
===
'
rinkeby
'
?
'
connected
'
:
'
disconnected
'
;
let
interactionState
=
networkId
===
'
rinkeby
'
?
'
connected
'
:
'
disconnected
'
;
let
connectionStatus
=
networkId
===
'
rinkeby
'
?
true
:
false
;
let
connectionStatus
=
networkId
===
'
rinkeby
'
?
true
:
false
;
...
@@ -64,6 +73,7 @@ const mapDispatchToProps = (dispatch) => {
...
@@ -64,6 +73,7 @@ const mapDispatchToProps = (dispatch) => {
setWeb3ConnectionStatus
,
setWeb3ConnectionStatus
,
setInteractionState
,
setInteractionState
,
setNetworkMessage
,
setNetworkMessage
,
metamaskLocked
},
dispatch
)
},
dispatch
)
}
}
...
...
src/components/Purchase.js
View file @
20538d34
...
@@ -6,7 +6,7 @@ import { setExchangeInputValue, setExchangeOutputValue } from '../actions/exchan
...
@@ -6,7 +6,7 @@ import { setExchangeInputValue, setExchangeOutputValue } from '../actions/exchan
class
Purchase
extends
Component
{
class
Purchase
extends
Component
{
purchaseTokens
=
async
()
=>
{
purchaseTokens
=
async
()
=>
{
await
this
.
props
.
setBlockTimestamp
(
this
.
props
.
global
.
web3
);
await
this
.
props
.
setBlockTimestamp
(
this
.
props
.
web3Store
.
web3
);
if
(
this
.
props
.
web3Store
.
exchangeType
===
'
ETH to Token
'
)
{
if
(
this
.
props
.
web3Store
.
exchangeType
===
'
ETH to Token
'
)
{
this
.
ethToTokenPurchase
();
this
.
ethToTokenPurchase
();
}
else
if
(
this
.
props
.
web3Store
.
exchangeType
===
'
Token to ETH
'
)
{
}
else
if
(
this
.
props
.
web3Store
.
exchangeType
===
'
Token to ETH
'
)
{
...
@@ -19,9 +19,9 @@ class Purchase extends Component {
...
@@ -19,9 +19,9 @@ class Purchase extends Component {
ethToTokenPurchase
=
()
=>
{
ethToTokenPurchase
=
()
=>
{
var
exchange
=
this
.
props
.
symbolToExchangeContract
(
this
.
props
.
exchange
.
outputToken
.
value
);
var
exchange
=
this
.
props
.
symbolToExchangeContract
(
this
.
props
.
exchange
.
outputToken
.
value
);
var
minTokens
=
(
this
.
props
.
exchange
.
outputValue
/
10
**
18
).
toString
();
var
minTokens
=
(
this
.
props
.
exchange
.
outputValue
/
10
**
18
).
toString
();
var
minTokensInt
=
this
.
props
.
global
.
web3
.
utils
.
toWei
(
minTokens
);
var
minTokensInt
=
this
.
props
.
web3Store
.
web3
.
utils
.
toWei
(
minTokens
);
var
ethSold
=
this
.
props
.
exchange
.
inputValue
;
var
ethSold
=
this
.
props
.
exchange
.
inputValue
;
var
weiSold
=
this
.
props
.
global
.
web3
.
utils
.
toWei
(
ethSold
);
var
weiSold
=
this
.
props
.
web3Store
.
web3
.
utils
.
toWei
(
ethSold
);
var
timeout
=
this
.
props
.
web3Store
.
blockTimestamp
+
300
;
//current block time + 5mins
var
timeout
=
this
.
props
.
web3Store
.
blockTimestamp
+
300
;
//current block time + 5mins
// console.log(minTokensInt, weiSold, timeout);
// console.log(minTokensInt, weiSold, timeout);
...
@@ -53,9 +53,9 @@ class Purchase extends Component {
...
@@ -53,9 +53,9 @@ class Purchase extends Component {
tokenToEthPurchase
=
()
=>
{
tokenToEthPurchase
=
()
=>
{
var
exchange
=
this
.
props
.
symbolToExchangeContract
(
this
.
props
.
exchange
.
inputToken
.
value
);
var
exchange
=
this
.
props
.
symbolToExchangeContract
(
this
.
props
.
exchange
.
inputToken
.
value
);
var
minEth
=
(
this
.
props
.
exchange
.
outputValue
/
10
**
18
).
toString
();
var
minEth
=
(
this
.
props
.
exchange
.
outputValue
/
10
**
18
).
toString
();
var
minEthInt
=
this
.
props
.
global
.
web3
.
utils
.
toWei
(
minEth
);
var
minEthInt
=
this
.
props
.
web3Store
.
web3
.
utils
.
toWei
(
minEth
);
var
tokensSold
=
this
.
props
.
exchange
.
inputValue
;
var
tokensSold
=
this
.
props
.
exchange
.
inputValue
;
var
tokensSoldInt
=
this
.
props
.
global
.
web3
.
utils
.
toWei
(
tokensSold
);
var
tokensSoldInt
=
this
.
props
.
web3Store
.
web3
.
utils
.
toWei
(
tokensSold
);
var
timeout
=
this
.
props
.
web3Store
.
blockTimestamp
+
300
;
//current block time + 5mins
var
timeout
=
this
.
props
.
web3Store
.
blockTimestamp
+
300
;
//current block time + 5mins
exchange
.
methods
.
tokenToEthSwap
(
tokensSoldInt
,
minEthInt
,
timeout
).
send
({
from
:
this
.
props
.
web3Store
.
currentMaskAddress
})
exchange
.
methods
.
tokenToEthSwap
(
tokensSoldInt
,
minEthInt
,
timeout
).
send
({
from
:
this
.
props
.
web3Store
.
currentMaskAddress
})
...
@@ -78,9 +78,9 @@ class Purchase extends Component {
...
@@ -78,9 +78,9 @@ class Purchase extends Component {
var
exchange
=
this
.
props
.
symbolToExchangeContract
(
this
.
props
.
exchange
.
inputToken
.
value
);
var
exchange
=
this
.
props
.
symbolToExchangeContract
(
this
.
props
.
exchange
.
inputToken
.
value
);
var
tokenOutAddress
=
this
.
props
.
symbolToTokenAddress
(
this
.
props
.
exchange
.
outputToken
.
value
);
var
tokenOutAddress
=
this
.
props
.
symbolToTokenAddress
(
this
.
props
.
exchange
.
outputToken
.
value
);
var
minTokens
=
(
this
.
props
.
exchange
.
outputValue
/
10
**
18
).
toString
();
var
minTokens
=
(
this
.
props
.
exchange
.
outputValue
/
10
**
18
).
toString
();
var
minTokensInt
=
this
.
props
.
global
.
web3
.
utils
.
toWei
(
minTokens
);
var
minTokensInt
=
this
.
props
.
web3Store
.
web3
.
utils
.
toWei
(
minTokens
);
var
tokensSold
=
this
.
props
.
exchange
.
inputValue
;
var
tokensSold
=
this
.
props
.
exchange
.
inputValue
;
var
tokensSoldInt
=
this
.
props
.
global
.
web3
.
utils
.
toWei
(
tokensSold
);
var
tokensSoldInt
=
this
.
props
.
web3Store
.
web3
.
utils
.
toWei
(
tokensSold
);
var
timeout
=
this
.
props
.
web3Store
.
blockTimestamp
+
300
;
//current block time + 5mins
var
timeout
=
this
.
props
.
web3Store
.
blockTimestamp
+
300
;
//current block time + 5mins
console
.
log
(
'
tokenOutAddress
'
,
tokenOutAddress
);
console
.
log
(
'
tokenOutAddress
'
,
tokenOutAddress
);
console
.
log
(
'
minTokensInt
'
,
minTokensInt
);
console
.
log
(
'
minTokensInt
'
,
minTokensInt
);
...
...
src/reducers/global-reducer.js
View file @
20538d34
import
{
INITIALIZE_GLOBAL_WEB3
}
from
'
../constants
'
;
//
import { INITIALIZE_GLOBAL_WEB3 } from '../constants';
export
default
(
state
=
{},
action
)
=>
{
// export default (state = {}, action) => {
const
{
globalWeb3
}
=
action
;
// const { globalWeb3 } = action;
switch
(
action
.
type
)
{
// switch(action.type) {
case
INITIALIZE_GLOBAL_WEB3
:
// case INITIALIZE_GLOBAL_WEB3:
return
Object
.
assign
({},
state
,
{
web3
:
globalWeb3
});
// return Object.assign({}, state, { web3: globalWeb3 });
default
:
return
state
// default: return state
}
// }
}
// }
\ No newline at end of file
\ No newline at end of file
src/reducers/index.js
View file @
20538d34
import
{
combineReducers
}
from
'
redux
'
;
import
{
combineReducers
}
from
'
redux
'
;
import
global
from
'
./global-reducer
'
;
//
import global from './global-reducer';
import
web3Store
from
'
./web3-reducer
'
;
import
web3Store
from
'
./web3-reducer
'
;
import
exchangeContracts
from
'
./exchangeContract-reducer
'
;
import
exchangeContracts
from
'
./exchangeContract-reducer
'
;
import
tokenContracts
from
'
./tokenContract-reducer
'
;
import
tokenContracts
from
'
./tokenContract-reducer
'
;
import
exchange
from
'
./exchange-reducer
'
;
import
exchange
from
'
./exchange-reducer
'
;
export
default
combineReducers
({
export
default
combineReducers
({
global
,
web3Store
,
web3Store
,
exchangeContracts
,
exchangeContracts
,
tokenContracts
,
tokenContracts
,
...
...
src/reducers/web3-reducer.js
View file @
20538d34
...
@@ -14,8 +14,10 @@ import {
...
@@ -14,8 +14,10 @@ import {
}
from
'
../constants
'
;
}
from
'
../constants
'
;
export
default
(
state
=
{},
action
)
=>
{
export
default
(
state
=
{},
action
)
=>
{
const
{
connected
,
currentMaskAddress
,
metamaskLocked
,
interaction
,
factoryContract
,
networkMessage
,
timestamp
,
exchangeType
,
globalW
eb3
,
aboutToggle
}
=
action
const
{
connected
,
currentMaskAddress
,
metamaskLocked
,
interaction
,
factoryContract
,
networkMessage
,
timestamp
,
exchangeType
,
w
eb3
,
aboutToggle
}
=
action
switch
(
action
.
type
)
{
switch
(
action
.
type
)
{
case
INITIALIZE_GLOBAL_WEB3
:
return
Object
.
assign
({},
state
,
{
web3
:
web3
});
case
SET_WEB3_CONNECTION_STATUS
:
case
SET_WEB3_CONNECTION_STATUS
:
return
Object
.
assign
({},
state
,
{
connected
:
connected
});
return
Object
.
assign
({},
state
,
{
connected
:
connected
});
case
SET_CURRENT_MASK_ADDRESS
:
case
SET_CURRENT_MASK_ADDRESS
:
...
@@ -34,8 +36,6 @@ export default (state = {}, action) => {
...
@@ -34,8 +36,6 @@ export default (state = {}, action) => {
return
Object
.
assign
({},
state
,
{
blockTimestamp
:
timestamp
});
return
Object
.
assign
({},
state
,
{
blockTimestamp
:
timestamp
});
case
SET_EXCHANGE_TYPE
:
case
SET_EXCHANGE_TYPE
:
return
Object
.
assign
({},
state
,
{
exchangeType
:
exchangeType
});
return
Object
.
assign
({},
state
,
{
exchangeType
:
exchangeType
});
case
INITIALIZE_GLOBAL_WEB3
:
return
Object
.
assign
({},
state
,
{
globalWeb3
:
globalWeb3
});
case
TOGGLE_ABOUT
:
case
TOGGLE_ABOUT
:
return
Object
.
assign
({},
state
,
{
aboutToggle
:
aboutToggle
})
return
Object
.
assign
({},
state
,
{
aboutToggle
:
aboutToggle
})
default
:
return
state
;
default
:
return
state
;
...
...
src/store/initial-state.js
View file @
20538d34
export
default
{
export
default
{
global
:
{},
web3Store
:
{
web3Store
:
{
web3
:
{},
connected
:
false
,
connected
:
false
,
aboutToggle
:
false
,
aboutToggle
:
false
,
globalWeb3
:
{},
globalWeb3
:
{},
...
...
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