Closed netindicium closed 3 years ago
Hrm it works for me when I run it locally. Have you added the event plugin and the Cloud Function trigger in your Moralis Server? These are located in the cloud-functions.js
file. If so, is there data in the DaiWethSwapVolume60
collection? If not the stats query might not be returning any data.
Swap(address,uint256,uint256,uint256,uint256,address)
event plugin populates the data in the DaiWethSwaps
collectionMoralis.Cloud.afterSave
trigger adds the stats each time a new swap is saved to that tableThis is line 175: https://github.com/MoralisWeb3/demo-apps/blob/74ca6a8c26da0ddd6e6f8e25a1f2b686a4db3741/swap-monitor/index.js#L175
The renderStats()
function is called from 2 places:
updateStats()
on line 141handleStatsUpdate()
on line 166Hope that helps.
EDIT: It occurrs to me the stats query will probably be empty the very first time it's run with a brand new server if there have been no swaps yet since the event plugin was added. After a couple minutes that would sort itself out though as the DAI/wETH pair is pretty active.
I have added the Plugin and the Cloud Function as stated on the readme.
I can see the data on the dashboard and on index.html, but no the aggregated stats.
Any idea what might be ? Thanks.
My bad! Thanks for posting the screenshots. This is the problem:
const pipeline = [ /* code omitted */ ];
Note the /* code omitted */
comment. I forgot to mention the code for Cloud Functions was supposed to be copied from the cloud-functions.js
file... not the README. I will update the README to make this clear.
The pipeline
object is what defines the things to be aggregated. It's a little long to be copying into the docs directly, but if what it's doing is confusing I can add additional explanations to the README. The complexity comes from converting the string values in the table into numbers, which is rather awkward in the MongoDB syntax the queries use.
Is this better? https://github.com/MoralisWeb3/demo-apps/blob/9-bug-swap-trigger-docs/swap-monitor/README.md
I can clarify further if needed.
That fixed it, thanks a lot. I did had to start a new instance, for some reason the last one would not respond.
Could you point me in the right direction if I wanted to to tray another token, for example WBTC ?
Thanks again.
Cool. I'll close this issue then.
If you wanted to track another swap pair you'd need to:
Hello there,
I'm following the instructions on the Swap Monitor, and I was able to get it working, but the daily cumulative stats are not working and this is the error on the console, any idea on what would it be ?
Thank you, A2