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
9f2d5ee9
Commit
9f2d5ee9
authored
Mar 15, 2018
by
Uciel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
globalWeb3 redux logic ready
parent
fbd78a5a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
27 deletions
+28
-27
App.js
src/App.js
+17
-23
web3-actions.js
src/actions/web3-actions.js
+11
-4
No files found.
src/App.js
View file @
9f2d5ee9
...
@@ -84,6 +84,7 @@ class App extends Component {
...
@@ -84,6 +84,7 @@ class App extends Component {
// lets start with what's in the componentDidMount
// lets start with what's in the componentDidMount
componentWillMount
(){
componentWillMount
(){
this
.
props
.
putWeb3InStore
(
localweb3
);
console
.
log
(
'
props
'
,
this
.
props
)
console
.
log
(
'
props
'
,
this
.
props
)
if
(
localweb3
===
'
undefined
'
)
{
if
(
localweb3
===
'
undefined
'
)
{
this
.
props
.
web3ConnectionUnsuccessful
();
this
.
props
.
web3ConnectionUnsuccessful
();
...
@@ -225,12 +226,6 @@ class App extends Component {
...
@@ -225,12 +226,6 @@ class App extends Component {
})
})
}
}
getBlock
=
()
=>
{
localweb3
.
eth
.
getBlock
(
'
latest
'
,
(
error
,
blockInfo
)
=>
{
this
.
props
.
setBlockTimestamp
(
blockInfo
.
timestamp
);
});
}
symbolToTokenAddress
=
(
symbol
)
=>
{
symbolToTokenAddress
=
(
symbol
)
=>
{
if
(
symbol
===
'
UNI
'
)
{
if
(
symbol
===
'
UNI
'
)
{
return
this
.
props
.
web3Store
.
exchangeAddresses
.
UNI
;
return
this
.
props
.
web3Store
.
exchangeAddresses
.
UNI
;
...
@@ -469,6 +464,7 @@ class App extends Component {
...
@@ -469,6 +464,7 @@ class App extends Component {
}
}
getExchangeRate
=
(
input
)
=>
{
getExchangeRate
=
(
input
)
=>
{
console
.
log
(
this
.
props
.
web3Store
.
globalWeb3
,
'
this better be defined
'
)
if
(
this
.
props
.
web3Store
.
exchangeType
===
'
ETH to Token
'
)
{
if
(
this
.
props
.
web3Store
.
exchangeType
===
'
ETH to Token
'
)
{
console
.
log
(
'
Getting Rate: ETH to
'
+
this
.
props
.
exchange
.
outputToken
.
value
);
console
.
log
(
'
Getting Rate: ETH to
'
+
this
.
props
.
exchange
.
outputToken
.
value
);
this
.
ethToTokenRate
(
input
);
this
.
ethToTokenRate
(
input
);
...
@@ -481,16 +477,6 @@ class App extends Component {
...
@@ -481,16 +477,6 @@ class App extends Component {
}
}
}
}
purchaseTokens
=
()
=>
{
if
(
this
.
props
.
web3Store
.
exchangeType
===
'
ETH to Token
'
)
{
this
.
ethToTokenPurchase
();
}
else
if
(
this
.
props
.
web3Store
.
exchangeType
===
'
Token to ETH
'
)
{
this
.
tokenToEthPurchase
();
}
else
if
(
this
.
props
.
web3Store
.
exchangeType
===
'
Token to Token
'
)
{
this
.
tokenToTokenPurchase
();
}
}
ethToTokenRate
=
(
ethInput
)
=>
{
ethToTokenRate
=
(
ethInput
)
=>
{
var
ethInMarket
=
+
this
.
props
.
exchange
.
marketEth2
;
var
ethInMarket
=
+
this
.
props
.
exchange
.
marketEth2
;
var
tokensInMarket
=
+
this
.
props
.
exchange
.
marketTokens2
;
var
tokensInMarket
=
+
this
.
props
.
exchange
.
marketTokens2
;
...
@@ -552,16 +538,26 @@ class App extends Component {
...
@@ -552,16 +538,26 @@ class App extends Component {
this
.
props
.
setExchangeOutputValue
(
adjustedTokensOut
);
this
.
props
.
setExchangeOutputValue
(
adjustedTokensOut
);
}
}
purchaseTokens
=
async
()
=>
{
await
this
.
props
.
setBlockTimestamp
(
this
.
props
.
web3Store
.
globalWeb3
);
if
(
this
.
props
.
web3Store
.
exchangeType
===
'
ETH to Token
'
)
{
this
.
ethToTokenPurchase
();
}
else
if
(
this
.
props
.
web3Store
.
exchangeType
===
'
Token to ETH
'
)
{
this
.
tokenToEthPurchase
();
}
else
if
(
this
.
props
.
web3Store
.
exchangeType
===
'
Token to Token
'
)
{
this
.
tokenToTokenPurchase
();
}
}
// YOU ARE HERE NOW
// YOU ARE HERE NOW
ethToTokenPurchase
=
async
()
=>
{
ethToTokenPurchase
=
()
=>
{
await
this
.
getBlock
();
var
exchange
=
this
.
symbolToExchangeContract
(
this
.
props
.
exchange
.
outputToken
.
value
);
var
exchange
=
this
.
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
=
localweb3
.
utils
.
toWei
(
minTokens
);
var
minTokensInt
=
localweb3
.
utils
.
toWei
(
minTokens
);
var
ethSold
=
this
.
props
.
exchange
.
inputValue
;
var
ethSold
=
this
.
props
.
exchange
.
inputValue
;
var
weiSold
=
localweb3
.
utils
.
toWei
(
ethSold
);
var
weiSold
=
localweb3
.
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);
exchange
.
methods
.
ethToTokenSwap
(
minTokensInt
,
timeout
).
send
({
from
:
this
.
props
.
web3Store
.
currentMaskAddress
,
value
:
weiSold
})
exchange
.
methods
.
ethToTokenSwap
(
minTokensInt
,
timeout
).
send
({
from
:
this
.
props
.
web3Store
.
currentMaskAddress
,
value
:
weiSold
})
.
on
(
'
transactionHash
'
,
(
result
)
=>
{
.
on
(
'
transactionHash
'
,
(
result
)
=>
{
...
@@ -590,8 +586,7 @@ class App extends Component {
...
@@ -590,8 +586,7 @@ class App extends Component {
// tokenToEth and EthToToken purchase functions are very similar structurally
// tokenToEth and EthToToken purchase functions are very similar structurally
// maybe we can make this more DRY in refactor
// maybe we can make this more DRY in refactor
tokenToEthPurchase
=
async
()
=>
{
tokenToEthPurchase
=
()
=>
{
await
this
.
getBlock
();
var
exchange
=
this
.
symbolToExchangeContract
(
this
.
props
.
exchange
.
inputToken
.
value
);
var
exchange
=
this
.
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
=
localweb3
.
utils
.
toWei
(
minEth
);
var
minEthInt
=
localweb3
.
utils
.
toWei
(
minEth
);
...
@@ -615,8 +610,7 @@ class App extends Component {
...
@@ -615,8 +610,7 @@ class App extends Component {
.
on
(
'
error
'
,
console
.
error
);
.
on
(
'
error
'
,
console
.
error
);
}
}
tokenToTokenPurchase
=
async
()
=>
{
tokenToTokenPurchase
=
()
=>
{
await
this
.
getBlock
();
var
exchange
=
this
.
symbolToExchangeContract
(
this
.
props
.
exchange
.
inputToken
.
value
);
var
exchange
=
this
.
symbolToExchangeContract
(
this
.
props
.
exchange
.
inputToken
.
value
);
var
tokenOutAddress
=
this
.
symbolToTokenAddress
(
this
.
props
.
exchange
.
outputToken
.
value
);
var
tokenOutAddress
=
this
.
symbolToTokenAddress
(
this
.
props
.
exchange
.
outputToken
.
value
);
var
minTokens
=
(
this
.
props
.
exchange
.
outputValue
/
10
**
18
).
toString
();
var
minTokens
=
(
this
.
props
.
exchange
.
outputValue
/
10
**
18
).
toString
();
...
...
src/actions/web3-actions.js
View file @
9f2d5ee9
...
@@ -55,10 +55,17 @@ export const setNetworkMessage = (networkMessage) => ({
...
@@ -55,10 +55,17 @@ export const setNetworkMessage = (networkMessage) => ({
networkMessage
networkMessage
});
});
export
const
setBlockTimestamp
=
(
timestamp
)
=>
({
export
const
setBlockTimestamp
=
(
globalWeb3
)
=>
{
type
:
SET_BLOCK_TIMESTAMP
,
return
async
(
dispatch
,
getState
)
=>
{
timestamp
await
globalWeb3
.
eth
.
getBlock
(
'
latest
'
,
(
error
,
blockInfo
)
=>
{
});
console
.
log
(
blockInfo
.
timestamp
,
'
BLOCKTIMESTAMP
'
);
dispatch
({
type
:
SET_BLOCK_TIMESTAMP
,
timestamp
:
blockInfo
.
timestamp
})
});
}
}
export
const
setExchangeType
=
(
exchangeType
)
=>
({
export
const
setExchangeType
=
(
exchangeType
)
=>
({
type
:
SET_EXCHANGE_TYPE
,
type
:
SET_EXCHANGE_TYPE
,
...
...
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