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

[4] feat(balances): update balances for priority tokens #3417

Merged
merged 30 commits into from
Dec 6, 2023

Conversation

shoom3301
Copy link
Collaborator

@shoom3301 shoom3301 commented Nov 19, 2023

Summary

Fixes: #3430, #3429, #3426, #3423, #3428

Since the regular balances+allowances updating polling happens only every ~30 seconds, it might be annoying if you order was just filled and you don't see balances updater. Or you just approved your token spending and still see "Approve token" state.

To fix that, I've created PriorityTokensUpdater that is almost the same as BalancesAndAllowancesUpdater.
The only difference is that the priority updater updates only assets from the current trade state + from pending orders. And it does it quite often - every ~10 seconds.

To Test

  1. Create an order
  2. Wait until it is filled
  • traded assets balances should be updated within ~10 seconds
  1. Approve some token
  • the "Approve token" state should disappear within ~10 seconds

Copy link

vercel bot commented Nov 19, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
cosmos ✅ Ready (Inspect) Visit Preview Dec 6, 2023 1:04pm
swap-dev ✅ Ready (Inspect) Visit Preview Dec 6, 2023 1:04pm
widget-configurator ✅ Ready (Inspect) Visit Preview Dec 6, 2023 1:04pm

setLoadingState?: boolean
}

export function usePersistBalancesAndAllowances(params: PersistBalancesAndAllowancesParams) {
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 code is actually just extracted from BalancesAndAllowancesUpdater

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense that you refactored this logic so you can use it in the 2 updaters. I wonder if we should even have a sigle updater, and just pass the refresh (so any lib can tell this updater the refresh interval).

If we do that, we might want to extract the native into its own updater, which sounds like a good idea, as its completly separated logic and clients of this lib could use it in isolation.

@shoom3301 shoom3301 force-pushed the feat/priority-tokens-updater branch from a645cce to e34ce1e Compare November 21, 2023 09:23
@shoom3301 shoom3301 self-assigned this Nov 21, 2023
@shoom3301 shoom3301 requested a review from a team November 21, 2023 09:26
@shoom3301 shoom3301 changed the title feat(balances): update balances for priority tokens [4] feat(balances): update balances for priority tokens Nov 21, 2023
@shoom3301 shoom3301 marked this pull request as ready for review November 21, 2023 09:26
Copy link
Contributor

@anxolin anxolin 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! And is enough to get the problem solved!

One small thing though, is that, the selected token and any other tokens in the prioty queue will be queried twice. Also, it's a bit rigid in case we want finer control.

Anyways, no need to address these things, lets not overoptimise. This is already a great improvement. Let's see what are the new bottlenecks and potential improvements instead.

Really good work these 4 PRs. Thanks!!!

@anxolin
Copy link
Contributor

anxolin commented Nov 21, 2023

I think we are showing 0 balance for not-connected wallets when we don't know.

image

In prod doesn't show the balance:
image

@anxolin
Copy link
Contributor

anxolin commented Nov 21, 2023

@shoom3301 Do you think is possible to trigger eagerly the refresh of a token in some situations?

For example:

  • A Swap just happened: Update FROM_TOKEN, TO_TOKEN
  • Wrap Ether or Unwrap: Native, WETH
  • Eth Flow: Native, TO_TOKEN

@@ -175,8 +175,14 @@ export function OrderRow({

const showCancellationModal = orderActions.getShowCancellationModal(order)

/**
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@alfetopito please, take a look on the fix, I'm not sure if it's correct

Copy link
Collaborator

Choose a reason for hiding this comment

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

The idea here - like with hasEnoughAllowance - is to only set the warning if we know there's no valid permit.
hasValidPendingPermit can be undefined, when we don't know/can't tell.

Was that causing any issues?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see now that this has been reverted on #3487

… feat/priority-tokens-updater

# Conflicts:
#	apps/cowswap-frontend/src/legacy/hooks/useTokenAllowance.ts
#	apps/cowswap-frontend/src/modules/ordersTable/pure/OrdersTableContainer/utils/getOrderParams.test.ts
#	apps/cowswap-frontend/src/modules/ordersTable/pure/OrdersTableContainer/utils/getOrderParams.ts
#	apps/cowswap-frontend/src/modules/tokensList/pure/TokenListItem/index.tsx
#	libs/balances-and-allowances/src/hooks/useNativeTokenBalance.ts
#	libs/balances-and-allowances/src/index.ts
#	libs/balances-and-allowances/src/state/allowancesAtom.ts
#	libs/balances-and-allowances/src/state/balancesAtom.ts
#	libs/balances-and-allowances/src/updaters/BalancesAndAllowancesUpdater.ts
@shoom3301 shoom3301 merged commit 1d1458c into develop Dec 6, 2023
6 of 7 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Dec 6, 2023
@alfetopito alfetopito deleted the feat/priority-tokens-updater branch December 11, 2023 16:10
Comment on lines 63 to 71
const { data, isLoading } = useSWR(['useCowFromLockedGnoBalances', account, allocated, tokenDistro], async () => {
if (account && tokenDistro && allocated.greaterThan(0)) {
return tokenDistro.balances(account)
}

return null
})

const claimed = useMemo(() => CurrencyAmount.fromRawAmount(_COW, data ? data.claimed.toString() : 0), [data])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Has this been tested?

(Not saying this is wrong, just thinking out loud)

@@ -175,8 +175,14 @@ export function OrderRow({

const showCancellationModal = orderActions.getShowCancellationModal(order)

/**
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see now that this has been reverted on #3487

Copy link
Collaborator

Choose a reason for hiding this comment

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

@shoom3301 is it intentional to have multicall and multiCall?

image

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

Successfully merging this pull request may close these issues.

[v1.50.0] No 'Unfillable' state for a limit order (allowance/balance)
4 participants