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
fbd78a5a
Commit
fbd78a5a
authored
Mar 15, 2018
by
Hayden Adams
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rename web to web3Store, remove getBlock interval
parent
37d82f97
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
101 additions
and
86 deletions
+101
-86
App.js
src/App.js
+63
-60
web3-actions.js
src/actions/web3-actions.js
+12
-6
constants.js
src/constants.js
+7
-4
index.js
src/reducers/index.js
+3
-3
web3-reducer.js
src/reducers/web3-reducer.js
+8
-5
initial-state.js
src/store/initial-state.js
+8
-8
No files found.
src/App.js
View file @
fbd78a5a
...
...
@@ -27,7 +27,8 @@ import {
factoryContractReady
,
setNetworkMessage
,
setBlockTimestamp
,
setExchangeType
setExchangeType
,
putWeb3InStore
}
from
'
./actions/web3-actions
'
;
import
{
...
...
@@ -95,17 +96,15 @@ class App extends Component {
})
this
.
getInfoFirstTime
();
this
.
checkNetwork
();
this
.
getBlock
();
}
}
componentDidMount
(){
componentDidMount
(){
if
(
localweb3
===
'
undefined
'
)
{
this
.
props
.
web3ConnectionUnsuccessful
();
console
.
log
(
'
props here
'
,
this
.
props
)
}
else
if
(
this
.
props
.
web3
.
connected
===
true
)
{
console
.
log
(
'
successfully connected to metamask
'
)
setInterval
(
this
.
getBlock
,
10000
);
this
.
props
.
putWeb3InStore
(
localweb3
);
}
else
if
(
this
.
props
.
web3Store
.
connected
===
true
)
{
console
.
log
(
'
successfully connected to metamask
'
);
setInterval
(
this
.
getMarketInfo
,
15000
);
setInterval
(
this
.
getAccountInfo
,
15000
);
setInterval
(
this
.
getUserAddress
,
10000
);
...
...
@@ -120,7 +119,7 @@ class App extends Component {
// getInfoFirstTime = async () => {
// await this.getUserAddress();
// if(this.props.web3.currentMaskAddress !== '') {
// if(this.props.web3
Store
.currentMaskAddress !== '') {
// await this.getContracts();
// this.getMarketInfo();
// this.getAccountInfo();
...
...
@@ -165,23 +164,23 @@ class App extends Component {
}
getContracts
=
async
()
=>
{
const
uniExchangeAddress
=
this
.
props
.
web3
.
exchangeAddresses
.
UNI
;
const
uniExchangeAddress
=
this
.
props
.
web3
Store
.
exchangeAddresses
.
UNI
;
const
uniExchangeContract
=
new
localweb3
.
eth
.
Contract
(
exchangeABI
,
uniExchangeAddress
);
this
.
props
.
uniExchangeContractReady
(
uniExchangeContract
);
const
swapExchangeAddress
=
this
.
props
.
web3
.
exchangeAddresses
.
SWT
;
const
swapExchangeAddress
=
this
.
props
.
web3
Store
.
exchangeAddresses
.
SWT
;
const
swapExchangeContract
=
new
localweb3
.
eth
.
Contract
(
exchangeABI
,
swapExchangeAddress
);
this
.
props
.
swtExchangeContractReady
(
swapExchangeContract
);
const
uniTokenAddress
=
this
.
props
.
web3
.
tokenAddresses
.
UNI
;
const
uniTokenAddress
=
this
.
props
.
web3
Store
.
tokenAddresses
.
UNI
;
const
uniTokenContract
=
new
localweb3
.
eth
.
Contract
(
tokenABI
,
uniTokenAddress
);
this
.
props
.
uniTokenContractReady
(
uniTokenContract
);
const
swapTokenAddress
=
this
.
props
.
web3
.
tokenAddresses
.
SWT
;
const
swapTokenAddress
=
this
.
props
.
web3
Store
.
tokenAddresses
.
SWT
;
const
swapTokenContract
=
new
localweb3
.
eth
.
Contract
(
tokenABI
,
swapTokenAddress
);
this
.
props
.
swtTokenContractReady
(
swapTokenContract
);
const
factoryAddress
=
this
.
props
.
web3
.
factoryAddress
;
const
factoryAddress
=
this
.
props
.
web3
Store
.
factoryAddress
;
const
factoryContract
=
new
localweb3
.
eth
.
Contract
(
factoryABI
,
factoryAddress
);
this
.
props
.
factoryContractReady
(
factoryContract
);
...
...
@@ -234,9 +233,9 @@ class App extends Component {
symbolToTokenAddress
=
(
symbol
)
=>
{
if
(
symbol
===
'
UNI
'
)
{
return
this
.
props
.
web3
.
exchangeAddresses
.
UNI
;
return
this
.
props
.
web3
Store
.
exchangeAddresses
.
UNI
;
}
else
if
(
symbol
===
'
SWAP
'
)
{
return
this
.
props
.
web3
.
exchangeAddresses
.
SWT
;
return
this
.
props
.
web3
Store
.
exchangeAddresses
.
SWT
;
}
}
...
...
@@ -250,9 +249,9 @@ class App extends Component {
symbolToExchangeAddress
=
(
symbol
)
=>
{
if
(
symbol
===
'
UNI
'
)
{
return
this
.
props
.
web3
.
exchangeAddresses
.
UNI
;
return
this
.
props
.
web3
Store
.
exchangeAddresses
.
UNI
;
}
else
if
(
symbol
===
'
SWAP
'
)
{
return
this
.
props
.
web3
.
exchangeAddresses
.
SWT
;
return
this
.
props
.
web3
Store
.
exchangeAddresses
.
SWT
;
}
}
...
...
@@ -265,7 +264,7 @@ class App extends Component {
}
getMarketInfo
=
()
=>
{
switch
(
this
.
props
.
web3
.
exchangeType
)
{
switch
(
this
.
props
.
web3
Store
.
exchangeType
)
{
case
'
ETH to Token
'
:
this
.
getExchangeState
(
'
output
'
);
break
;
...
...
@@ -281,7 +280,7 @@ class App extends Component {
}
getAccountInfo
=
()
=>
{
switch
(
this
.
props
.
web3
.
exchangeType
)
{
switch
(
this
.
props
.
web3
Store
.
exchangeType
)
{
case
'
ETH to Token
'
:
this
.
getEthBalance
(
'
input
'
);
this
.
getTokenBalance
(
'
output
'
);
...
...
@@ -341,12 +340,12 @@ class App extends Component {
getEthBalance
=
(
type
)
=>
{
if
(
type
===
'
input
'
)
{
localweb3
.
eth
.
getBalance
(
this
.
props
.
web3
.
currentMaskAddress
,
(
error
,
balance
)
=>
{
localweb3
.
eth
.
getBalance
(
this
.
props
.
web3
Store
.
currentMaskAddress
,
(
error
,
balance
)
=>
{
this
.
props
.
setInputBalance
(
balance
);
// console.log('ETH Balance: ' + balance);
});
}
else
if
(
type
===
'
output
'
)
{
localweb3
.
eth
.
getBalance
(
this
.
props
.
web3
.
currentMaskAddress
,
(
error
,
balance
)
=>
{
localweb3
.
eth
.
getBalance
(
this
.
props
.
web3
Store
.
currentMaskAddress
,
(
error
,
balance
)
=>
{
this
.
props
.
setOutputBalance
(
balance
);
// console.log('ETH Balance: ' + balance);
});
...
...
@@ -357,13 +356,13 @@ class App extends Component {
var
token
;
if
(
type
===
'
input
'
)
{
token
=
this
.
symbolToTokenContract
(
this
.
props
.
exchange
.
inputToken
.
value
);
token
.
methods
.
balanceOf
(
this
.
props
.
web3
.
currentMaskAddress
).
call
((
error
,
balance
)
=>
{
token
.
methods
.
balanceOf
(
this
.
props
.
web3
Store
.
currentMaskAddress
).
call
((
error
,
balance
)
=>
{
this
.
props
.
setInputBalance
(
balance
);
// console.log(this.props.exchange.inputToken.value + ' Balance: ' + balance);
});
}
else
if
(
type
===
'
output
'
)
{
token
=
this
.
symbolToTokenContract
(
this
.
props
.
exchange
.
outputToken
.
value
);
token
.
methods
.
balanceOf
(
this
.
props
.
web3
.
currentMaskAddress
).
call
((
error
,
balance
)
=>
{
token
.
methods
.
balanceOf
(
this
.
props
.
web3
Store
.
currentMaskAddress
).
call
((
error
,
balance
)
=>
{
this
.
props
.
setOutputBalance
(
balance
);
// console.log(this.props.exchange.outputToken.value + ' Balance: ' + balance);
});
...
...
@@ -371,12 +370,12 @@ class App extends Component {
}
getAllowance
=
()
=>
{
var
type
=
this
.
props
.
web3
.
exchangeType
;
var
type
=
this
.
props
.
web3
Store
.
exchangeType
;
if
(
type
===
'
Token to ETH
'
||
type
===
'
Token to Token
'
)
{
var
token
=
this
.
symbolToTokenContract
(
this
.
props
.
exchange
.
inputToken
.
value
);
var
exchangeAddress
=
this
.
symbolToExchangeAddress
(
this
.
props
.
exchange
.
inputToken
.
value
);
token
.
methods
.
allowance
(
this
.
props
.
web3
.
currentMaskAddress
,
exchangeAddress
).
call
().
then
((
result
,
error
)
=>
{
token
.
methods
.
allowance
(
this
.
props
.
web3
Store
.
currentMaskAddress
,
exchangeAddress
).
call
().
then
((
result
,
error
)
=>
{
console
.
log
(
this
.
props
.
exchange
.
inputToken
.
value
+
'
allowance:
'
+
result
);
if
(
result
===
'
0
'
){
this
.
props
.
setAllowanceApprovalState
(
false
)
...
...
@@ -387,13 +386,13 @@ class App extends Component {
}
approveAllowance
=
()
=>
{
var
type
=
this
.
props
.
web3
.
exchangeType
;
var
type
=
this
.
props
.
web3
Store
.
exchangeType
;
if
(
type
===
'
Token to ETH
'
||
type
===
'
Token to Token
'
)
{
var
token
=
this
.
symbolToTokenContract
(
this
.
props
.
exchange
.
inputToken
.
value
);
var
exchangeAddress
=
this
.
symbolToExchangeAddress
(
this
.
props
.
exchange
.
inputToken
.
value
);
var
amount
=
localweb3
.
utils
.
toWei
(
'
100000
'
);
token
.
methods
.
approve
(
exchangeAddress
,
amount
).
send
({
from
:
this
.
props
.
web3
.
currentMaskAddress
})
token
.
methods
.
approve
(
exchangeAddress
,
amount
).
send
({
from
:
this
.
props
.
web3
Store
.
currentMaskAddress
})
.
on
(
'
transactionHash
'
,
console
.
log
(
'
Transaction Hash created
'
))
.
on
(
'
receipt
'
,
(
receipt
)
=>
{
console
.
log
(
receipt
)
...
...
@@ -406,7 +405,7 @@ class App extends Component {
// TODO: stuff
tokenToExchangeFactoryLookup
=
(
tokenAddress
)
=>
{
this
.
props
.
web3
.
factoryContract
.
methods
.
tokenToExchangeLookup
(
tokenAddress
).
call
((
error
,
exchangeAddress
)
=>
{
this
.
props
.
web3
Store
.
factoryContract
.
methods
.
tokenToExchangeLookup
(
tokenAddress
).
call
((
error
,
exchangeAddress
)
=>
{
console
.
log
(
exchangeAddress
)
});
}
...
...
@@ -457,7 +456,7 @@ class App extends Component {
setExchangeOutput
=
()
=>
{
var
inputValue
=
this
.
props
.
exchange
.
inputValue
;
if
(
this
.
props
.
web3
.
exchangeType
===
'
Invalid
'
){
if
(
this
.
props
.
web3
Store
.
exchangeType
===
'
Invalid
'
){
this
.
props
.
setExchangeOutputValue
(
0
);
this
.
props
.
setInteractionState
(
'
error1
'
);
}
else
if
(
inputValue
&&
inputValue
!==
0
&&
inputValue
!==
'
0
'
){
...
...
@@ -470,24 +469,24 @@ class App extends Component {
}
getExchangeRate
=
(
input
)
=>
{
if
(
this
.
props
.
web3
.
exchangeType
===
'
ETH to Token
'
)
{
if
(
this
.
props
.
web3
Store
.
exchangeType
===
'
ETH to Token
'
)
{
console
.
log
(
'
Getting Rate: ETH to
'
+
this
.
props
.
exchange
.
outputToken
.
value
);
this
.
ethToTokenRate
(
input
);
}
else
if
(
this
.
props
.
web3
.
exchangeType
===
'
Token to ETH
'
)
{
}
else
if
(
this
.
props
.
web3
Store
.
exchangeType
===
'
Token to ETH
'
)
{
console
.
log
(
'
Getting Rate:
'
+
this
.
props
.
exchange
.
inputToken
.
value
+
'
to ETH
'
);
this
.
tokenToEthRate
(
input
);
}
else
if
(
this
.
props
.
web3
.
exchangeType
===
'
Token to Token
'
)
{
}
else
if
(
this
.
props
.
web3
Store
.
exchangeType
===
'
Token to Token
'
)
{
console
.
log
(
'
Getting Rate:
'
+
this
.
props
.
exchange
.
inputToken
.
value
+
'
to
'
+
this
.
props
.
exchange
.
outputToken
.
value
);
this
.
tokenToTokenRate
(
input
);
}
}
purchaseTokens
=
()
=>
{
if
(
this
.
props
.
web3
.
exchangeType
===
'
ETH to Token
'
)
{
if
(
this
.
props
.
web3
Store
.
exchangeType
===
'
ETH to Token
'
)
{
this
.
ethToTokenPurchase
();
}
else
if
(
this
.
props
.
web3
.
exchangeType
===
'
Token to ETH
'
)
{
}
else
if
(
this
.
props
.
web3
Store
.
exchangeType
===
'
Token to ETH
'
)
{
this
.
tokenToEthPurchase
();
}
else
if
(
this
.
props
.
web3
.
exchangeType
===
'
Token to Token
'
)
{
}
else
if
(
this
.
props
.
web3
Store
.
exchangeType
===
'
Token to Token
'
)
{
this
.
tokenToTokenPurchase
();
}
}
...
...
@@ -554,16 +553,17 @@ class App extends Component {
}
// YOU ARE HERE NOW
ethToTokenPurchase
=
()
=>
{
ethToTokenPurchase
=
async
()
=>
{
await
this
.
getBlock
();
var
exchange
=
this
.
symbolToExchangeContract
(
this
.
props
.
exchange
.
outputToken
.
value
);
var
minTokens
=
(
this
.
props
.
exchange
.
outputValue
/
10
**
18
).
toString
();
var
minTokensInt
=
localweb3
.
utils
.
toWei
(
minTokens
);
var
ethSold
=
this
.
props
.
exchange
.
inputValue
;
var
weiSold
=
localweb3
.
utils
.
toWei
(
ethSold
);
var
timeout
=
this
.
props
.
web3
.
blockTimestamp
+
300
;
//current block time + 5mins
var
timeout
=
this
.
props
.
web3
Store
.
blockTimestamp
+
300
;
//current block time + 5mins
console
.
log
(
minTokensInt
,
weiSold
,
timeout
);
exchange
.
methods
.
ethToTokenSwap
(
minTokensInt
,
timeout
).
send
({
from
:
this
.
props
.
web3
.
currentMaskAddress
,
value
:
weiSold
})
exchange
.
methods
.
ethToTokenSwap
(
minTokensInt
,
timeout
).
send
({
from
:
this
.
props
.
web3
Store
.
currentMaskAddress
,
value
:
weiSold
})
.
on
(
'
transactionHash
'
,
(
result
)
=>
{
console
.
log
(
'
Transaction Hash created
'
)
let
transactions
=
this
.
state
.
transactions
...
...
@@ -590,15 +590,16 @@ class App extends Component {
// tokenToEth and EthToToken purchase functions are very similar structurally
// maybe we can make this more DRY in refactor
tokenToEthPurchase
=
()
=>
{
tokenToEthPurchase
=
async
()
=>
{
await
this
.
getBlock
();
var
exchange
=
this
.
symbolToExchangeContract
(
this
.
props
.
exchange
.
inputToken
.
value
);
var
minEth
=
(
this
.
props
.
exchange
.
outputValue
/
10
**
18
).
toString
();
var
minEthInt
=
localweb3
.
utils
.
toWei
(
minEth
);
var
tokensSold
=
this
.
props
.
exchange
.
inputValue
;
var
tokensSoldInt
=
localweb3
.
utils
.
toWei
(
tokensSold
);
var
timeout
=
this
.
props
.
web3
.
blockTimestamp
+
300
;
//current block time + 5mins
var
timeout
=
this
.
props
.
web3
Store
.
blockTimestamp
+
300
;
//current block time + 5mins
exchange
.
methods
.
tokenToEthSwap
(
tokensSoldInt
,
minEthInt
,
timeout
).
send
({
from
:
this
.
props
.
web3
.
currentMaskAddress
})
exchange
.
methods
.
tokenToEthSwap
(
tokensSoldInt
,
minEthInt
,
timeout
).
send
({
from
:
this
.
props
.
web3
Store
.
currentMaskAddress
})
.
on
(
'
transactionHash
'
,
(
result
)
=>
{
console
.
log
(
'
Transaction Hash created
'
)
let
transactions
=
this
.
state
.
transactions
...
...
@@ -614,16 +615,17 @@ class App extends Component {
.
on
(
'
error
'
,
console
.
error
);
}
tokenToTokenPurchase
=
()
=>
{
tokenToTokenPurchase
=
async
()
=>
{
await
this
.
getBlock
();
var
exchange
=
this
.
symbolToExchangeContract
(
this
.
props
.
exchange
.
inputToken
.
value
);
var
tokenOutAddress
=
this
.
symbolToTokenAddress
(
this
.
props
.
exchange
.
outputToken
.
value
);
var
minTokens
=
(
this
.
props
.
exchange
.
outputValue
/
10
**
18
).
toString
();
var
minTokensInt
=
localweb3
.
utils
.
toWei
(
minTokens
);
var
tokensSold
=
this
.
props
.
exchange
.
inputValue
;
var
tokensSoldInt
=
localweb3
.
utils
.
toWei
(
tokensSold
);
var
timeout
=
this
.
props
.
web3
.
blockTimestamp
+
300
;
//current block time + 5mins
var
timeout
=
this
.
props
.
web3
Store
.
blockTimestamp
+
300
;
//current block time + 5mins
exchange
.
methods
.
tokenToTokenSwap
(
tokenOutAddress
,
tokensSoldInt
,
minTokensInt
,
timeout
).
send
({
from
:
this
.
props
.
web3
.
currentMaskAddress
})
exchange
.
methods
.
tokenToTokenSwap
(
tokenOutAddress
,
tokensSoldInt
,
minTokensInt
,
timeout
).
send
({
from
:
this
.
props
.
web3
Store
.
currentMaskAddress
})
.
on
(
'
transactionHash
'
,
(
result
)
=>
{
console
.
log
(
'
Transaction Hash created
'
)
let
transactions
=
this
.
state
.
transactions
...
...
@@ -664,32 +666,32 @@ class App extends Component {
render
()
{
return
(
<
div
className
=
{
this
.
props
.
web3
.
connected
&&
!
this
.
props
.
web3
.
metamaskLocked
&&
this
.
props
.
web3
.
interaction
!==
'
disconnected
'
?
"
App
"
:
"
App dim
"
}
>
<
div
className
=
{
this
.
props
.
web3
Store
.
connected
&&
!
this
.
props
.
web3Store
.
metamaskLocked
&&
this
.
props
.
web3Store
.
interaction
!==
'
disconnected
'
?
"
App
"
:
"
App dim
"
}
>
<
Head
/>
<
section
className
=
"
title
"
>
<
div
className
=
"
logo border pa2
"
>
<
span
role
=
"
img
"
aria
-
label
=
"
Unicorn
"
>
🦄
<
/span
>
<
/div
>
<
NetworkStatus
network
=
{
this
.
props
.
web3
.
networkMessage
}
connected
=
{
this
.
props
.
web3
.
connected
}
network
=
{
this
.
props
.
web3
Store
.
networkMessage
}
connected
=
{
this
.
props
.
web3
Store
.
connected
}
metamask
=
{
this
.
props
.
metamask
}
interaction
=
{
this
.
props
.
web3
.
interaction
}
address
=
{
this
.
props
.
web3
.
currentMaskAddress
}
locked
=
{
this
.
props
.
web3
.
metamaskLocked
}
interaction
=
{
this
.
props
.
web3
Store
.
interaction
}
address
=
{
this
.
props
.
web3
Store
.
currentMaskAddress
}
locked
=
{
this
.
props
.
web3
Store
.
metamaskLocked
}
balance
=
{
this
.
props
.
exchange
.
inputBalance
}
/
>
<
/section
>
<
ConnectionHelper
network
=
{
this
.
props
.
web3
.
networkMessage
}
connected
=
{
this
.
props
.
web3
.
connected
}
network
=
{
this
.
props
.
web3
Store
.
networkMessage
}
connected
=
{
this
.
props
.
web3
Store
.
connected
}
metamask
=
{
this
.
props
.
metamask
}
address
=
{
this
.
props
.
web3
.
currentMaskAddress
}
locked
=
{
this
.
props
.
web3
.
metamaskLocked
}
address
=
{
this
.
props
.
web3
Store
.
currentMaskAddress
}
locked
=
{
this
.
props
.
web3
Store
.
metamaskLocked
}
approved
=
{
this
.
props
.
exchange
.
allowanceApproved
}
tokenAdded
=
{
this
.
state
.
tokenAdded
}
approveAllowance
=
{
this
.
approveAllowance
}
interaction
=
{
this
.
props
.
web3
.
interaction
}
exchangeType
=
{
this
.
props
.
web3
.
exchangeType
}
interaction
=
{
this
.
props
.
web3
Store
.
interaction
}
exchangeType
=
{
this
.
props
.
web3
Store
.
exchangeType
}
firstRun
=
{
this
.
state
.
firstRun
}
uniAdded
=
{
this
.
state
.
uniAdded
}
swapAdded
=
{
this
.
state
.
swapAdded
}
...
...
@@ -727,7 +729,7 @@ class App extends Component {
<
/span
>
<
/section
>
{
this
.
props
.
web3
.
interaction
===
'
input
'
?
{
this
.
props
.
web3
Store
.
interaction
===
'
input
'
?
<
a
className
=
"
swap border pa2
"
role
=
"
button
"
onClick
=
{()
=>
{
this
.
purchaseTokens
()}}
>
<
b
>
{
"
I want to swap
"
+
this
.
props
.
exchange
.
inputValue
+
"
"
+
this
.
props
.
exchange
.
inputToken
.
value
+
"
for
"
+
this
.
props
.
exchange
.
outputValue
/
10
**
18
+
"
"
+
this
.
props
.
exchange
.
outputToken
.
value
}
<
/b
>
...
...
@@ -763,7 +765,7 @@ class App extends Component {
<
/a
>
<
/section
>
{
this
.
state
.
transactions
.
length
>
0
&&
this
.
props
.
web3
.
interaction
!==
'
disconnected
'
?
{
this
.
state
.
transactions
.
length
>
0
&&
this
.
props
.
web3
Store
.
interaction
!==
'
disconnected
'
?
<
section
className
=
"
transaction border pa2
"
>
<
p
className
=
"
underline
"
>
Past
Transactions
:
<
/p
>
<
Transactions
transactions
=
{
this
.
state
.
transactions
}
/
>
...
...
@@ -775,7 +777,7 @@ class App extends Component {
}
const
mapStateToProps
=
state
=>
({
web3
:
state
.
web3
,
web3
Store
:
state
.
web3Store
,
exchangeContracts
:
state
.
exchangeContracts
,
tokenContracts
:
state
.
tokenContracts
,
exchange
:
state
.
exchange
...
...
@@ -811,7 +813,8 @@ const mapDispatchToProps = (dispatch) => {
setExchangeInputValue
,
setExchangeOutputValue
,
setExchangeRate
,
setExchangeFee
setExchangeFee
,
putWeb3InStore
},
dispatch
)
}
...
...
src/actions/web3-actions.js
View file @
fbd78a5a
...
...
@@ -8,7 +8,8 @@ import {
FACTORY_CONTRACT_READY
,
SET_NETWORK_MESSAGE
,
SET_BLOCK_TIMESTAMP
,
SET_EXCHANGE_TYPE
SET_EXCHANGE_TYPE
,
PUT_WEB3_IN_STORE
}
from
'
../constants
'
;
// this actions folder is actually full of action creators
...
...
@@ -63,3 +64,8 @@ export const setExchangeType = (exchangeType) => ({
type
:
SET_EXCHANGE_TYPE
,
exchangeType
});
export
const
putWeb3InStore
=
(
globalWeb3
)
=>
({
type
:
PUT_WEB3_IN_STORE
,
globalWeb3
})
src/constants.js
View file @
fbd78a5a
...
...
@@ -42,3 +42,6 @@ export const SET_EXCHANGE_INPUT_VALUE = 'SET_EXCHANGE_INPUT_VALUE';
export
const
SET_EXCHANGE_OUTPUT_VALUE
=
'
SET_EXCHANGE_OUTPUT_VALUE
'
;
export
const
SET_EXCHANGE_RATE
=
'
SET_EXCHANGE_RATE
'
;
export
const
SET_EXCHANGE_FEE
=
'
SET_EXCHANGE_FEE
'
;
// test setInteractionState
export
const
PUT_WEB3_IN_STORE
=
'
PUT_WEB3_IN_STORE
'
;
src/reducers/index.js
View file @
fbd78a5a
import
{
combineReducers
}
from
'
redux
'
;
import
web3
from
'
./web3-reducer
'
;
import
web3
Store
from
'
./web3-reducer
'
;
import
exchangeContracts
from
'
./exchangeContract-reducer
'
;
import
tokenContracts
from
'
./tokenContract-reducer
'
;
import
exchange
from
'
./exchange-reducer
'
;
export
default
combineReducers
({
web3
,
web3
Store
,
exchangeContracts
,
tokenContracts
,
exchange
...
...
src/reducers/web3-reducer.js
View file @
fbd78a5a
...
...
@@ -9,11 +9,12 @@ import {
FACTORY_CONTRACT_READY
,
SET_NETWORK_MESSAGE
,
SET_BLOCK_TIMESTAMP
,
SET_EXCHANGE_TYPE
SET_EXCHANGE_TYPE
,
PUT_WEB3_IN_STORE
}
from
'
../constants
'
;
export
default
(
state
=
{},
action
)
=>
{
const
{
connected
,
currentMaskAddress
,
metamaskLocked
,
interaction
,
factoryContract
,
networkMessage
,
timestamp
,
exchangeType
}
=
action
const
{
connected
,
currentMaskAddress
,
metamaskLocked
,
interaction
,
factoryContract
,
networkMessage
,
timestamp
,
exchangeType
,
globalWeb3
}
=
action
switch
(
action
.
type
)
{
case
WEB3_CONNECTION_SUCCESSFUL
:
return
Object
.
assign
({},
state
,
{
connected
:
connected
});
...
...
@@ -35,6 +36,8 @@ export default (state = {}, action) => {
return
Object
.
assign
({},
state
,
{
blockTimestamp
:
timestamp
});
case
SET_EXCHANGE_TYPE
:
return
Object
.
assign
({},
state
,
{
exchangeType
:
exchangeType
});
case
PUT_WEB3_IN_STORE
:
return
Object
.
assign
({},
state
,
{
globalWeb3
:
globalWeb3
});
default
:
return
state
;
}
}
src/store/initial-state.js
View file @
fbd78a5a
...
...
@@ -11,7 +11,7 @@ export default {
// lets check if metamask is installed
// also, lets assume that we're disconnected initially
// we're going to need to include a seperate nest for exchange actions
web3
:
{
web3
Store
:
{
connected
:
false
,
currentMaskAddress
:
''
,
metamaskLocked
:
true
,
...
...
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