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

Dashboard: ActivitiesList component #400

Merged
merged 14 commits into from
May 14, 2024

Conversation

kpyszkowski
Copy link
Contributor

@kpyszkowski kpyszkowski commented May 7, 2024

Closes: #363

Goal:

To implement ActivitiesList component

Features:

  • multiple variants by the status property
  • dismissable with presence animation
  • unstaking variant

Designs:

image

Testing:

dashboard-page.patch

@kpyszkowski kpyszkowski requested review from r-czajkowski and kkosiorowska and removed request for r-czajkowski May 7, 2024 13:36
Copy link

netlify bot commented May 7, 2024

Deploy Preview for acre-dapp-testnet ready!

Name Link
🔨 Latest commit a48f2c3
🔍 Latest deploy log https://app.netlify.com/sites/acre-dapp-testnet/deploys/66434144b291d60008359485
😎 Deploy Preview https://deploy-preview-400--acre-dapp-testnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

dapp/src/theme/Alert.ts Outdated Show resolved Hide resolved
Comment on lines 31 to 33
const handleItemDismiss = (id: string) => {
setDismissedItemIds((prev) => [...prev, id])
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We pass this function to the child component. So let's useCallback here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Generally speaking the rule is to optimize code only when you have performance issues.

Wrapping every callback with useCallback is an anti pattern which can have the opposite effect to that intended. Memoization costs, you always need to think twice before you decide to memoize a value. Very often it's not prevention but over engineering with possible harmful results.

https://kentcdodds.com/blog/usememo-and-usecallback

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If handleItemDismiss would operate on hardly reactive data it would be reasonable to memoize this callback. But in this particular case the only value we might want to memoize is state setter which is just a function - static (not reactive) function.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's true that we shouldn't wrap everything in useCallback or useMemo. In this case, we have a list of items and we pass this function to the children. Therefore, I would be inclined to do it. Note that we will not use the setState function here in the final app version.

What is interesting is that information that setState function identity is stable has been omitted from the new documentation. That's why I have mixed feelings sometimes.

import { CurrencyBalance } from "../CurrencyBalance"
import Spinner from "../Spinner"

export type StakingActivitiesListItemType = {
Copy link
Contributor

Choose a reason for hiding this comment

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

We already have a defined type for the activity. I will be updating this type soon so I will add missing fields such as timestamp or id.

export type Activity = {
txHash: string
amount: bigint
type: "deposit" | "withdraw"
status: "completed" | "pending"
}

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 can use tx hash as id. I did so.

Copy link
Contributor

Choose a reason for hiding this comment

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

Currently, we can do it like that. We will probably have to use an id since we don't have a txHash yet when the deposit is initialized. But we can fix it later.

`StakingActivitiesList` to `ActivitiesList`
Adjusted container items alignment
Rendered `ActivitiesList` in `DashboardCard`. Refactored
`BlockExplorerLink` to make it compatible with `as` prop
@kpyszkowski kpyszkowski changed the title Dashboard: StakingActivitiesList component Dashboard: ActivitiesList component May 13, 2024
Copy link
Contributor

@kkosiorowska kkosiorowska left a comment

Choose a reason for hiding this comment

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

It looks like we are almost ready. Let's just add the missing parameter for BlockExplorerLink and we can merge it.

@kkosiorowska kkosiorowska enabled auto-merge May 14, 2024 10:47
@kkosiorowska kkosiorowska merged commit f4a9713 into main May 14, 2024
25 checks passed
@kkosiorowska kkosiorowska deleted the dashboard/staking-activities-list branch May 14, 2024 10:50
@kpyszkowski kpyszkowski mentioned this pull request Jul 2, 2024
kkosiorowska added a commit that referenced this pull request Jul 5, 2024
Closes: #505 

This PR resolves an issue with inconsistency in `Alert` components.

### Changes:
- Now styles are defined as Chakra theme only. 
- Components from `shared/alerts/...` have been removed in favor of
`shared/Alert` component.
- `ErrorAlert` component has been removed and replaced by `<Alert
status="error" />` component.
- `CardAlert` component has been removed and replaced by `<Alert
variant="elevated" />` component.
- The `process` variant has been ported from #400 

**Note:** Changes are not fully accurate with designs (especially in
color levels) because of inconsistency. It can be adjusted in the future
as the design system will be introduced.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dApp Dashboard: Activities Status - Deposit
2 participants