1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

refresh price and pool info (#164)

* refresh price and pool info

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>

* lib update

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>

* remove unused dependencies

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>

* remove console.log

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>
This commit is contained in:
mihaisc 2020-10-29 16:53:27 +02:00 committed by GitHub
parent 0065d7b3da
commit d8dfe88e2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 2 deletions

19
package-lock.json generated
View File

@ -3876,6 +3876,25 @@
"decimal.js": "^10.2.1", "decimal.js": "^10.2.1",
"web3": "^1.3.0", "web3": "^1.3.0",
"web3modal": "^1.9.1" "web3modal": "^1.9.1"
},
"dependencies": {
"@oceanprotocol/lib": {
"version": "0.9.8",
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-0.9.8.tgz",
"integrity": "sha512-jV7lobTXskqqmv23Vl3iQ4SZk+0FVFxLSVkXniOKOOFP0pJ0vllSNnM+wHkG4inF3HWHHyeh8AyFNTSxOUuirA==",
"requires": {
"@ethereum-navigator/navigator": "^0.5.0",
"@oceanprotocol/contracts": "^0.5.7",
"decimal.js": "^10.2.0",
"fs": "0.0.1-security",
"lzma": "^2.3.2",
"node-fetch": "^2.6.1",
"save-file": "^2.3.1",
"uuid": "^8.3.0",
"web3": "^1.3.0",
"web3-eth-contract": "^1.3.0"
}
}
} }
}, },
"@oceanprotocol/typographies": { "@oceanprotocol/typographies": {

View File

@ -43,6 +43,7 @@ const initialValues: FormAddLiquidity = {
export default function Add({ export default function Add({
setShowAdd, setShowAdd,
refreshInfo,
poolAddress, poolAddress,
totalPoolTokens, totalPoolTokens,
totalBalance, totalBalance,
@ -51,6 +52,7 @@ export default function Add({
dtAddress dtAddress
}: { }: {
setShowAdd: (show: boolean) => void setShowAdd: (show: boolean) => void
refreshInfo: () => void
poolAddress: string poolAddress: string
totalPoolTokens: string totalPoolTokens: string
totalBalance: Balance totalBalance: Balance
@ -127,6 +129,7 @@ export default function Add({
setTxId(result?.transactionHash) setTxId(result?.transactionHash)
resetForm() resetForm()
refreshInfo()
} catch (error) { } catch (error) {
console.error(error.message) console.error(error.message)
toast.error(error.message) toast.error(error.message)

View File

@ -46,11 +46,13 @@ const contentQuery = graphql`
export default function Remove({ export default function Remove({
setShowRemove, setShowRemove,
refreshInfo,
poolAddress, poolAddress,
poolTokens, poolTokens,
dtSymbol dtSymbol
}: { }: {
setShowRemove: (show: boolean) => void setShowRemove: (show: boolean) => void
refreshInfo: () => void
poolAddress: string poolAddress: string
poolTokens: string poolTokens: string
dtSymbol: string dtSymbol: string
@ -87,6 +89,7 @@ export default function Remove({
) )
setTxId(result?.transactionHash) setTxId(result?.transactionHash)
refreshInfo()
} catch (error) { } catch (error) {
Logger.error(error.message) Logger.error(error.message)
toast.error(error.message) toast.error(error.message)

View File

@ -43,7 +43,7 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement {
const content = data.content.edges[0].node.childContentJson.pool const content = data.content.edges[0].node.childContentJson.pool
const { ocean, accountId, networkId } = useOcean() const { ocean, accountId, networkId } = useOcean()
const { price } = useMetadata(ddo) const { price, refreshPrice } = useMetadata(ddo)
const { dtSymbol } = usePricing(ddo) const { dtSymbol } = usePricing(ddo)
const [poolTokens, setPoolTokens] = useState<string>() const [poolTokens, setPoolTokens] = useState<string>()
@ -54,6 +54,8 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement {
const [showAdd, setShowAdd] = useState(false) const [showAdd, setShowAdd] = useState(false)
const [showRemove, setShowRemove] = useState(false) const [showRemove, setShowRemove] = useState(false)
// the purpose of the value is just to trigger the effect
const [refreshPool, setRefreshPool] = useState(false)
// TODO: put all these variables behind some useEffect // TODO: put all these variables behind some useEffect
// to prevent unneccessary updating on every render // to prevent unneccessary updating on every render
const hasAddedLiquidity = const hasAddedLiquidity =
@ -115,13 +117,18 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement {
} }
} }
init() init()
}, [ocean, accountId, price, ddo.dataToken]) }, [ocean, accountId, price, ddo.dataToken, refreshPool])
const refreshInfo = async () => {
setRefreshPool(!refreshPool)
await refreshPrice()
}
return ( return (
<> <>
{showAdd ? ( {showAdd ? (
<Add <Add
setShowAdd={setShowAdd} setShowAdd={setShowAdd}
refreshInfo={refreshInfo}
poolAddress={price.address} poolAddress={price.address}
totalPoolTokens={totalPoolTokens} totalPoolTokens={totalPoolTokens}
totalBalance={{ ocean: price.ocean, datatoken: price.datatoken }} totalBalance={{ ocean: price.ocean, datatoken: price.datatoken }}
@ -132,6 +139,7 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement {
) : showRemove ? ( ) : showRemove ? (
<Remove <Remove
setShowRemove={setShowRemove} setShowRemove={setShowRemove}
refreshInfo={refreshInfo}
poolAddress={price.address} poolAddress={price.address}
poolTokens={poolTokens} poolTokens={poolTokens}
dtSymbol={dtSymbol} dtSymbol={dtSymbol}