Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
tetogomez committed Oct 7, 2020
1 parent abc8913 commit 5044af5
Showing 1 changed file with 127 additions and 66 deletions.
193 changes: 127 additions & 66 deletions src/routes/Evodex/BackLayer/Exchange/ExchangeBackLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,24 +191,72 @@ const ExchangeBackLayer = ({
const [, setLastInterval] = useState('')

const handleOnChange = (key) => (value) => {
console.log({ value })

/**
* step 1
* - Validate if pairs of tokens was selected in order to get
*/

let set

switch (key) {
case 'youGive':
set = setYouGive
{
setYouGive((prevState) => ({
...prevState,
...value
}))

if (pair) {
console.log({ pair })

const assets = evolutiondex.getExchangeAssets(
youGive.inputValue,
pair
)

console.log({assets})

setAssets(assets)
setYouReceive((prevState) => ({
...prevState,
inputValue: assets.assetToReceive.toString().split(' ')[0]
}))
}
}
break
case 'youReceive':
set = setYouReceive
{
setYouReceive((prevState) => ({
...prevState,
...value
}))

if (pair) {
const assets = evolutiondex.getExchangeAssetsFromToken2(
youReceive.inputValue,
pair
)

setAssets(assets)
setYouGive((prevState) => ({
...prevState,
inputValue: assets.assetToGive.toString().split(' ')[0]
}))
}
}
break
default:
set = () => {}
}

set((prevState) => ({
...prevState,
...value
}))
setUserChangeInput(key)
// set((prevState) => ({
// ...prevState,
// ...value
// }))

// setUserChangeInput(key)
}

const handleIsValueAllowed = ({ floatValue, value }) => {
Expand Down Expand Up @@ -321,6 +369,9 @@ const ExchangeBackLayer = ({
}

useEffect(() => {
console.log({ youGive, youReceive })


setOptions((prevState) => ({
...prevState,
youGive: evolutiondex
Expand All @@ -330,6 +381,7 @@ const ExchangeBackLayer = ({
.getTokensFor(youGive.selectValue, exchangeState)
.map((token) => ({ label: token, value: token }))
}))

setPair(
evolutiondex.getPair(
youGive.selectValue,
Expand All @@ -345,75 +397,84 @@ const ExchangeBackLayer = ({
youReceive.selectValue
])

useEffect(() => {
if (userChangeInput !== 'youGive') {
return
}

if (!pair || !youGive.inputValue) {
setYouReceive((prevState) => ({
...prevState,
inputValue: ''
}))
setAssets(null)

return
}

const assets = evolutiondex.getExchangeAssets(youGive.inputValue, pair)
setAssets(assets)
setYouReceive((prevState) => ({
...prevState,
inputValue: assets.assetToReceive.toString().split(' ')[0]
}))
}, [userChangeInput, pair, youGive.inputValue])
// useEffect(() => {
// console.log('change pair and youGive --> Adriel fix')

// if (userChangeInput !== 'youGive') {
// return
// }

// if (!pair || !youGive.inputValue) {
// setYouReceive((prevState) => ({
// ...prevState,
// inputValue: ''
// }))
// setAssets(null)

// return
// }

// const assets = evolutiondex.getExchangeAssets(youGive.inputValue, pair)
// setAssets(assets)
// setYouReceive((prevState) => ({
// ...prevState,
// inputValue: assets.assetToReceive.toString().split(' ')[0]
// }))
// }, [userChangeInput, pair, youGive.inputValue])

// useEffect(() => {
// console.log('change pair and youReceive --> Adriel fix')

// if (userChangeInput !== 'youReceive') {
// return
// }

// setLastInterval((lastValue) => {
// clearInterval(lastValue)

// return null
// })

// if (!pair || !youReceive.inputValue) {
// setYouGive((prevState) => ({
// ...prevState,
// inputValue: ''
// }))
// setAssets(null)

// return
// }

// const assets = evolutiondex.getExchangeAssetsFromToken2(
// youReceive.inputValue,
// pair
// )

// setAssets(assets)
// setYouGive((prevState) => ({
// ...prevState,
// inputValue: assets.assetToGive.toString().split(' ')[0]
// }))
// setLastInterval(
// setTimeout(() => {
// setUserChangeInput('youGive')
// }, 2000)
// )
// }, [userChangeInput, pair, youReceive.inputValue])

// EVERYTHING IS GOOD HERE!

useEffect(() => {
if (userChangeInput !== 'youReceive') {
return
}

setLastInterval((lastValue) => {
clearInterval(lastValue)

return null
})

if (!pair || !youReceive.inputValue) {
setYouGive((prevState) => ({
...prevState,
inputValue: ''
}))
setAssets(null)
console.log('change pair --> Adriel fix')

return
}

const assets = evolutiondex.getExchangeAssetsFromToken2(
youReceive.inputValue,
pair
)

setAssets(assets)
setYouGive((prevState) => ({
...prevState,
inputValue: assets.assetToGive.toString().split(' ')[0]
}))
setLastInterval(
setTimeout(() => {
setUserChangeInput('youGive')
}, 2000)
)
}, [userChangeInput, pair, youReceive.inputValue])

useEffect(() => {
if (!pair) return

getCurrencyBalance(pair)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [pair])

useEffect(() => {
console.log('current pair --> teto fix')
if (!exchangeState.currentPair) return

setPair(exchangeState.currentPair)
Expand Down

0 comments on commit 5044af5

Please sign in to comment.