Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update pull to refresh functionality on wallet and home tabs #6255

Merged
merged 1 commit into from
Nov 25, 2024

Conversation

kathaypacific
Copy link
Collaborator

Description

As the title:

  1. on the Wallet tab, pull to refresh refreshes balances. the loader is also displayed for any background refreshes.
  2. on the Home tab, pull to refresh refreshes only the transaction items. the loader is not displayed for background refreshes.

Test plan

Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-11-21.at.16.17.30.mp4

Related issues

Backwards compatibility

Y

Network scalability

If a new NetworkId and/or Network are added in the future, the changes in this PR will:

  • Continue to work without code changes, OR trigger a compilation error (guaranteeing we find it when a new network is added)

Copy link

codecov bot commented Nov 21, 2024

Codecov Report

Attention: Patch coverage is 73.33333% with 4 lines in your changes missing coverage. Please review.

Project coverage is 88.92%. Comparing base (66bd6d0) to head (49b4ac7).
Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
src/transactions/feed/TransactionFeedV2.tsx 66.66% 3 Missing ⚠️
src/tokens/AssetList.tsx 83.33% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##             main    #6255    +/-   ##
========================================
  Coverage   88.92%   88.92%            
========================================
  Files         737      737            
  Lines       31431    31436     +5     
  Branches     5837     5835     -2     
========================================
+ Hits        27950    27955     +5     
+ Misses       3437     3282   -155     
- Partials       44      199   +155     
Files with missing lines Coverage Δ
src/tokens/AssetList.tsx 97.91% <83.33%> (-0.65%) ⬇️
src/transactions/feed/TransactionFeedV2.tsx 88.18% <66.66%> (ø)

... and 67 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 66bd6d0...49b4ac7. Read the comment docs.

---- 🚨 Try these New Features:

@@ -499,13 +505,11 @@ export default function TransactionFeedV2() {
scrollEventThrottle={16}
refreshControl={
<RefreshControl
refreshing={isRefreshingBalances}
onRefresh={onRefresh}
refreshing={status === 'loading'}
Copy link
Contributor

@sviderock sviderock Nov 25, 2024

Choose a reason for hiding this comment

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

@kathaypacific we already have isFetching that signalizes that the feed is refreshing. What do you think of renaming the loading status to loadingBalances and modifying the check to status === 'loadingBalances' && isFetching? It might be a bit more verbose but it will make it more clear why we don't just use isFetching as a source of truth for this check (cause we also need to wait for the balance fetch).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oh but the loading state for this screen doesn't depend on the balances - we only want to show the loader if the user has pulled to refresh their transaction feed...the main reason for using status === 'loading rather than isFetching is that isFetching is true once every POLL_INTERVAL which causes the screen to be shifted down to show the spinner, which feels very unexpected. i tried to rename the isFetching return variable from the hook that is responsible for the poll to separate the loading state between the poll hook and the fetch next page hook, but it doesn't seem to work 😅

Copy link
Contributor

Choose a reason for hiding this comment

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

@kathaypacific gotcha! I haven't thought about the constant layout shift, this makes sense now!

Comment on lines 421 to 423
if (('hasAfterCursor' in error && error.hasAfterCursor) || feedFirstPage.length === 0) {
setShowError(true)
setStatus('error')
}
Copy link
Contributor

@sviderock sviderock Nov 25, 2024

Choose a reason for hiding this comment

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

@kathaypacific what do you think of moving this to a derived state? It seems like the only scenario when we use this error status is the same as it was in the previous revision with showError variable. It might also reduce the complexity of the new status field.

const showRefetchError = useMemo(() =>  {
  if (error === undefined) return false;
  return ( 'hasAfterCursor' in error && error.hasAfterCursor) || feedFirstPage.length === 0
}, [error, feedFirstPage])

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the main reason i wanted to have this enum value for status rather than have independent states for error and loading is to prevent both states from being true at the same time (and to avoid needing to put in extra logic to sync these 2 statuses) - the behaviour i want is when there is a fetch error, the user pulls to refresh, the loader should be displayed and the error is hidden (since at this point, the error is outdated + it's more clear that there is a new error if the error is first dismissed during loading). the status enum is this is a pattern we use in a few places, like the positions slice.

Copy link
Contributor

@sviderock sviderock left a comment

Choose a reason for hiding this comment

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

Thanks for explanation, this all makes sense to me now! 🚀

@kathaypacific kathaypacific added this pull request to the merge queue Nov 25, 2024
Merged via the queue into main with commit 7714ddf Nov 25, 2024
15 checks passed
@kathaypacific kathaypacific deleted the kathy/refresh-apinners branch November 25, 2024 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants