Skip to content
This repository was archived by the owner on Apr 4, 2022. It is now read-only.

1046 load from api orderstable #611

Merged
merged 11 commits into from
Sep 20, 2021
Merged

Conversation

henrypalacios
Copy link
Contributor

@henrypalacios henrypalacios commented Aug 26, 2021

Closes gnosis/cowswap#1046

Load orders from a wallet address.

🗒️ Summary:

  • Get the API to fetch data.
  • Refresh orders every 30s on the background.
  • Filter by time ago to save on calls.
  • Orders Loader

To Test

  1. Go to https://pr611--gpui.review.gnosisdev.com/rinkeby/address/0xb6BAd41ae76A11D10f7b0E664C5007b908bC77C9/
  2. No orders. https://pr611--gpui.review.gnosisdev.com/address/0xb6BAd41ae76A11D10f7b0E664C5007b908bC77C9/

@henrypalacios henrypalacios force-pushed the 1046-load-from-api-orderstable branch from 2da3f7c to 164bfc2 Compare August 26, 2021 18:41
@github-actions
Copy link

@henrypalacios
Copy link
Contributor Author

henrypalacios commented Aug 26, 2021

I would like to clarify some doubts @alfetopito:

  1. I have not been able to get the /getOrders endpoint to work, or at least how I think it works. I have done a few orders so I would expect them to show as filled but I always get []. I have tried these base_url with this query_string:

  2. Should I use operatorApi/getOrders for this purpose? if so, I guess I should add default parameters here, e.g. what date (timestamp) should I use?

  3. Since useNetworkId() could return null, should it not render if it is null?

@alfetopito
Copy link
Contributor

I would like to clarify some doubts @alfetopito:

  1. I have not been able to get the /getOrders endpoint to work, or at least how I think it works. I have done a few orders so I would expect them to show as filled but I always get []. I have tried these base_url with this query_string:

    * https://protocol-rinkeby.dev.gnosisdev.com/api/v1/orders point_left The one using by **explorer app**.
    * https://protocol-rinkeby.gnosis.io/api/v1/orders
    * https://protocol-mainnet.dev.gnosisdev.com/api/v1/orders point_left The one from **swagger**
    

How did you place the orders?

I believe your issue is that you are placing orders against PROD backend endpoint and trying to fetch them against STAGING (dev) backend endpoint.
They are different databases, so you won't see orders placed in one in the other.

There are settings in both CowSwap and the Explorer to synchronize the environments used.
A brief summary:

  1. PROD backend:
    1. PROD CowSwap & PROD Explorer
    2. STAGING CowSwap & STAGING Explorer
  2. STAGING backend:
    1. LOCAL, DEV and BARN CowSwap & LOCAL and DEV Explorer

There are a few ways to solve this:

  1. Run cowswap locally, or from a PR or from dev endpoint (cowswap.dev.gnosisdev.com/) and place orders using it
  2. Place orders using prod version as you already did and start the Explorer locally with env vars pointing to PROD backend:
$ OPERATOR_URL_STAGING_MAINNET=https://protocol-mainnet.gnosis.io/api OPERATOR_URL_STAGING_RINKEBY=https://protocol-rinkeby.gnosis.io/api OPERATOR_URL_STAGING_XDAI=https://protocol-xdai.gnosis.io/api yarn start:explorer
  1. Should I use operatorApi/getOrders for this purpose? if so, I guess I should add default parameters here, e.g. what date (timestamp) should I use?

Yep. Although the filters implemented might not all be relevant for our frontend filters https://protocol-rinkeby.dev.gnosisdev.com/api/#/default/get_api_v1_orders
Probably only includeFullyExecuted=false to exclude filled orders and includeInvalidated=false to exclude cancelled orders.
Keep in mind these filters where not added with frontend in mind, we need to work on aligning them to our requirements.

  1. Since useNetworkId() could return null, should it not render if it is null?

Correct. When network is null there's no data to show anyway.

@henrypalacios henrypalacios added the Protofire task to the protofire team label Aug 31, 2021
@henrypalacios
Copy link
Contributor Author

henrypalacios commented Aug 31, 2021

@alfetopito The problem I had with the API is that I need to extend the back date.
Selection_323

Also when when I was testing in Swagger-Rinkeby this was using was mainnet.
Selection_324

I would like to know, when you mentioned:

Probably only includeFullyExecuted=false to exclude filled orders and includeInvalidated=false to exclude cancelled orders.

  1. I'm not sure what query strings to will be used to display orders in OrdersTable by default, because as I imagined it was to show the past orders including the executed.
    (I used default values for show data like a oneYearAgo).

  2. I had to go looking for the token contracts for the orders, How about using a context here in OrdersTableWidget to hold the multiple ERC20 contracts used in OrdersTable as TradesTable?

@alfetopito
Copy link
Contributor

@alfetopito The problem I had with the API is that I need to extend the back date.
Selection_323

Well, I was sure I used this before, but it seems I mistook /orders with /trades endpoint.
Yeah, minValidTo must be set in the past to show older orders.
By default to start with all trades we could set this to 0.
Subsequent calls we perform the same query with minValidTo set to 10 min ago or something like that, then update the existing orders.

Also, set all boolean fields to true such as https://protocol-rinkeby.dev.gnosisdev.com/api/v1/orders?owner=0x5B0ABE214aB7875562ADeE331dEfF0Fe1912FE42&includeFullyExecuted=true&includeInvalidated=true&includeInsufficientBalance=true&includePresignaturePending=true&includeUnsupportedTokens=true&minValidTo=0

We want to show everything on the explorer.

Also when when I was testing in Swagger-Rinkeby this was using was mainnet.
Selection_324

You can switch on top which endpoint you are calling. You can access all of them from the same page. I know, weird.
screenshot_2021-08-31_14-13-07

I would like to know, when you mentioned:

Probably only includeFullyExecuted=false to exclude filled orders and includeInvalidated=false to exclude cancelled orders.

  1. I'm not sure what query strings to will be used to display orders in OrdersTable by default, because as I imagined it was to show the past orders including the executed.

I've answered this on the top above. Set all flags to true and start with minValidTo=0

   (I used default values for show data like a [oneYearAgo](https://github.com/gnosis/gp-ui/blob/1046-load-from-api-orderstable/src/api/operator/operatorApi.ts#L200)).
  1. I had to go looking for the token contracts for the orders, How about using a context here in OrdersTableWidget to hold the multiple ERC20 contracts used in OrdersTable as TradesTable?

Yes, that makes a lot of sense. It'll be very handy as well for @stackseeder since trades have even less context and need the respective orders in order to build the full row of data.

The tokens are already stored on global state (once loaded). Orders and trades are not because it only makes sense to do so if viewing the user details page so your idea of a context is great for the user details page.

@elena-zh
Copy link

elena-zh commented Sep 1, 2021

Hey @henrypalacios , @alfetopito ,
I might be a bit lost, but is seems to me that we do not have 'Search', 'Filtering' and 'Pagination' components for a user's orders/trades table
search

I have an endless table for my Rinkeby account with lines overlapping the table header, that is why I raised this issue
https://pr611--gpui.review.gnosisdev.com/rinkeby/address/0xFF714b8b0e2700303eC912BD40496C3997ceEa2b/

image

@elena-zh
Copy link

elena-zh commented Sep 1, 2021

I know, that this PR is WIP, but I would like to add a suggestion

  1. to add a default sort order to tables (created desc or so)
    image

  2. to display see/buy amounts better or shorter..
    image

  3. to app a loader when order details are loaded
    https://drive.google.com/file/d/1gYDU8PymA690htXpTuf0SQg6Wz4BZLXU/view

  4. to open an order link in a new tab

  5. Can we move the \/ Copied to a new row?
    image

  6. Will we add a sorting feature to columns?

@alfetopito
Copy link
Contributor

Hey @henrypalacios , @alfetopito ,
I might be a bit lost, but is seems to me that we do not have 'Search', 'Filtering' and 'Pagination' components for a user's orders/trades table
search

We agreed to not have search, filtering and pagination on the first version.

I have an endless table for my Rinkeby account with lines overlapping the table header, that is why I raised this issue
https://pr611--gpui.review.gnosisdev.com/rinkeby/address/0xFF714b8b0e2700303eC912BD40496C3997ceEa2b/

image

Hmm, I do not see any orders when I open this link :/

@alfetopito
Copy link
Contributor

I know, that this PR is WIP, but I would like to add a suggestion

  1. to add a default sort order to tables (created desc or so)
    image

Orders are supposed to come directly from the API sorted by creation date descending.
For now, they are not. I'll have a sync with backend team tomorrow to discuss this.

  1. to display see/buy amounts better or shorter..
    image

Agree this should be improved. But I think we can do it all at once, similar to what's been done on CowSwap.
It'll involve updating how Order details are displayed as well so better to do in a separated task.

  1. to app a loader when order details are loaded
    https://drive.google.com/file/d/1gYDU8PymA690htXpTuf0SQg6Wz4BZLXU/view

👍

  1. to open an order link in a new tab

👍

5. Can we move the `\/ Copied` to a new row?
   ![image](https://user-images.githubusercontent.com/70885163/131675051-da094998-59cc-4301-8ae0-1632bbf51885.png)

Not a big deal to me right now. Maybe we could replace the text with 'copied' depending on the screen size.
But again, also another task.

6. Will we add a sorting feature to columns?

Yes, but not on the first version.

@elena-zh
Copy link

elena-zh commented Sep 2, 2021

Hmm, I do not see any orders when I open this link :/

I was not able to open this page yesterday, today I see orders again. So here is the video: https://drive.google.com/file/d/1VpDeAdbZHNziW-xyqKNVEGiTwgL37jP2/view

Btw, looks a bit weird when order list flashing when a user's order info is updated.

@elena-zh
Copy link

elena-zh commented Sep 2, 2021

I have created separate tasks for cases:

@henrypalacios
Copy link
Contributor Author

@elena-zh

I was not able to open this page yesterday

you're right, I had problems with this, I thought it was my changes, but then I realized that something had changed in the API.

Btw, looks a bit weird when order list flashing when a user's order info is updated.

I'm working on it 😅 , I just wanted to make sure the table is updated.

And thank you for your other remarks.

@henrypalacios henrypalacios marked this pull request as ready for review September 7, 2021 23:35
@@ -2,6 +2,8 @@ import { AnalyticsDimension } from 'types'

/** Explorer app constants */
export const ORDER_QUERY_INTERVAL = 10000 // in ms
export const ORDERS_QUERY_INTERVAL = 10000 // in ms
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had agreed on 30min but I have set it to 10min to test.

@alongoni
Copy link
Contributor

alongoni commented Sep 9, 2021

Looks great!
We need to add the Title: "User details"
Screenshot from 2021-09-09 11-09-06

@henrypalacios henrypalacios force-pushed the 1046-load-from-api-orderstable branch from 74fb547 to ea58455 Compare September 9, 2021 18:40
Copy link
Contributor

@alfetopito alfetopito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working quite nicely!

Left a few refactoring suggestions.

And, this isn't part of the logic but I missed when reviewing the table design.
On full screen the columns don't fill the whole table
screenshot_2021-09-09_14-26-38

try {
const ordersFetched = await getOrders({ networkId: network, owner, minValidTo: minTimeHistoryTimeStamp })
const newErc20Addresses = ordersFetched.reduce((accumulator: string[], element) => {
const updateAccumulator = (tokenAddress: string): void => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using a Set (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) for this?

const newErc20Address = new Set<string>()
ordersFetched.forEach(order => {
  newErc20Address.add(order.buyToken)
  newErc20Address.add(order.sellToken)
})

Copy link
Contributor Author

@henrypalacios henrypalacios Sep 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love the Set, it would be much more readable however but I went for the reduce for performance.
Do you think it makes up for it or should I go for the Set? https://jsben.ch/ognIg

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, no idea it had such a performance impact. Guess they make mose sense in languages where Sets are first class citizens.

I prefer sets for readability but maybe we should stick with reducer due to performance as you suggest.

@anxolin @W3stside FYI

@elena-zh
Copy link

elena-zh commented Sep 10, 2021

Hey @henrypalacios , great pr!
A new tiny issue from me: ann empty orders table is jumping when updating each 30 secs
https://drive.google.com/file/d/14c41B_FzYnQHCu4zEk6XoI9Z-tFeqB3M/view

Btw, can we change 'Canceled' status to 'Cancelled' to match Cowswap app?
I know that it is a known pending issue under the #612 task, but may be it is an easy fix?

Also, can we add validation to URL on address format? However, I'm not sure about it..
image

@elena-zh
Copy link

Hey @henrypalacios , changes you implemented look great!
But still orders table is jumping each 30 sec when it is empty:
https://drive.google.com/file/d/1bTWypM3bHfc4OHVbfUrrraXgxiL5JvQe/view
Also, it looks a bit weird when hovered state is applied to an empty table
image

Thanks!

Copy link
Contributor

@alfetopito alfetopito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it! Working great!

@henrypalacios
Copy link
Contributor Author

henrypalacios commented Sep 20, 2021

@elena-zh hover has been removed in the row when there are not orders.

@alongoni has suggested using the same size of the table when reloading so it doesn't look strange.

@alfetopito I have set the interval back to 30sec. I also think something is going wrong in the evaluation of the test coverage.

Copy link
Contributor

@alongoni alongoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@alfetopito alfetopito merged commit 1381c0a into develop Sep 20, 2021
@alfetopito alfetopito deleted the 1046-load-from-api-orderstable branch September 20, 2021 20:43
@alfetopito
Copy link
Contributor

I force merged it.
The failure is due to an outage on Coveralls https://status.coveralls.io/ unrelated to your changes

@elena-zh
Copy link

Hey @henrypalacios , great!

Just curious: why do I always see these 404 errors in the console?
image

In addition, please, don't kill me.. But still I see blinking table when it is updating each 30 seconds (see from 19 sec )
https://drive.google.com/file/d/1DFNOWTSpBvpr8hJgzFAuiIOH9OvkFxO0/view

A bit strange to see this scroll in the empty table. It is also displayed when a table has orders, but it is more logical to show it there, but not in the empty table..
image

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Protofire task to the protofire team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Explorer] Load orders from API onto OrdersTable
4 participants