swap-ui
swap-ui copied to clipboard
Idiomatically update state after fetching orderbook data
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
- 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. - The bid and ask data is fetched again using a
useAsynchook
This should be resolved by the mentioned solution.