swap-ui icon indicating copy to clipboard operation
swap-ui copied to clipboard

Idiomatically update state after fetching orderbook data

Open secretshardul opened this issue 4 years ago • 0 comments

Currently context/Dex.ts and context/Token.ts use a hacky approach to update state.

https://github.com/project-serum/swap-ui/blob/4a92cad65a703d87afae5aebc725dc61c7e5cc2d/src/context/Dex.tsx#L227

A useState hook explicitly for refreshing is used after new values for _ORDERBOOK_CACHE are fetched via websockets. Ideally the orderbook data itself should be stored in useState(); that way updating this value will automatically refresh the UI.

Secondly there's double fetching of same data

  1. Websocket listens to changes in bid or asks, then calls setRefesh(). The fetched value is discarded, the only purpose of this was to update the UI again.
  2. The bid and ask data is fetched again using a useAsync hook

This should be resolved by the mentioned solution.

secretshardul avatar Sep 05 '21 07:09 secretshardul