1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-07-01 06:11:43 +02:00

fix buy fre (#458)

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>
This commit is contained in:
mihaisc 2021-03-26 10:48:27 +02:00 committed by GitHub
parent 59b571e984
commit 6190737f08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,6 +44,7 @@ const freQuery = gql`
query FrePrice($datatoken: String) { query FrePrice($datatoken: String) {
fixedRateExchanges(orderBy: id, where: { datatoken: $datatoken }) { fixedRateExchanges(orderBy: id, where: { datatoken: $datatoken }) {
rate rate
id
} }
} }
` `
@ -77,7 +78,7 @@ function AssetProvider({
data: frePrice data: frePrice
} = useQuery<FrePrice>(freQuery, { } = useQuery<FrePrice>(freQuery, {
variables, variables,
skip: true skip: false
}) })
const { const {
refetch: refetchPool, refetch: refetchPool,
@ -85,31 +86,43 @@ function AssetProvider({
data: poolPrice data: poolPrice
} = useQuery<PoolPrice>(poolQuery, { } = useQuery<PoolPrice>(poolQuery, {
variables, variables,
skip: true skip: false
}) })
useEffect(() => { // this is not working as expected, thus we need to fetch both pool and fre
if (!ddo || !variables) return // useEffect(() => {
if (ddo.price.type === 'exchange') { // if (!ddo || !variables || variables === '') return
refetchFre(variables)
startPollingFre(refreshInterval) // if (ddo.price.type === 'exchange') {
} else { // refetchFre(variables)
refetchPool(variables) // startPollingFre(refreshInterval)
startPollingPool(refreshInterval) // } else {
} // refetchPool(variables)
}, [ddo, variables]) // startPollingPool(refreshInterval)
// }
// }, [ddo, variables])
useEffect(() => { useEffect(() => {
if (!frePrice || frePrice.fixedRateExchanges.length === 0) return if (
price.value = frePrice.fixedRateExchanges[0].rate !frePrice ||
setPrice(price) frePrice.fixedRateExchanges.length === 0 ||
price.type !== 'exchange'
)
return
setPrice((prevState) => ({
...prevState,
value: frePrice.fixedRateExchanges[0].rate,
address: frePrice.fixedRateExchanges[0].id
}))
}, [frePrice]) }, [frePrice])
useEffect(() => { useEffect(() => {
if (!poolPrice || poolPrice.pools.length === 0) return if (!poolPrice || poolPrice.pools.length === 0 || price.type !== 'pool')
price.value = poolPrice.pools[0].spotPrice return
price.value = 3222222 setPrice((prevState) => ({
setPrice(price) ...prevState,
value: poolPrice.pools[0].spotPrice
}))
}, [poolPrice]) }, [poolPrice])
const fetchDdo = async (token?: CancelToken) => { const fetchDdo = async (token?: CancelToken) => {