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

Fees popover in transaction modal #317

Merged
merged 21 commits into from
Apr 30, 2024
Merged

Conversation

ioay
Copy link
Contributor

@ioay ioay commented Mar 17, 2024

Refs: #295
Depends on: ##307


Show staking fees in the dApp


What was done:

  • added FeesPopover component to TransactionModal
  • updated TransactionDetailsAmountItem to accept additional props: sublabel & popover to pass required data
  • fees item is based on mocked data

Preview:

Screenshot 2024-03-22 at 12 03 04 Screenshot 2024-03-22 at 12 03 08 Screenshot 2024-03-22 at 12 03 16 Screenshot 2024-03-22 at 12 03 21

Additional info:

Figma: https://www.figma.com/file/OUdSfHsmgV8EJpWxAzXjl5/ACRE?type=design&node-id=7398-55794&mode=design&t=3gtbEQAUkkNjhYf2-4

@ioay ioay self-assigned this Mar 17, 2024
Copy link

netlify bot commented Mar 17, 2024

Deploy Preview for acre-dapp-testnet ready!

Name Link
🔨 Latest commit 0de3011
🔍 Latest deploy log https://app.netlify.com/sites/acre-dapp-testnet/deploys/6630b8286a43980008743f04
😎 Deploy Preview https://deploy-preview-317--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.

@ioay ioay force-pushed the show-staking-fees-in-the-dApp branch from 775a3c7 to 6f64499 Compare March 17, 2024 18:42
@ioay ioay marked this pull request as ready for review March 17, 2024 18:47
@ioay ioay force-pushed the show-staking-fees-in-the-dApp branch 2 times, most recently from c0bacac to 1dd715e Compare March 17, 2024 19:40
@ioay ioay force-pushed the show-staking-fees-in-the-dApp branch from 1dd715e to 9284bfc Compare March 18, 2024 11:38
@ioay ioay requested a review from kkosiorowska March 22, 2024 10:15
dapp/src/components/GlobalStyles/index.tsx Outdated Show resolved Hide resolved
ml={2}
pb={0.5}
boxSize={5}
cursor="pointer"
Copy link
Contributor

Choose a reason for hiding this comment

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

I would like to make sure and keep some consistency. Do we need it? 🤔 In other places where we use tooltip, we do not change the cursor.

<Tooltip label="Template" placement="top">
<Icon as={Info} color="grey.700" />
</Tooltip>

@SorinQ Please confirm how the cursor should look.

Screen.Recording.2024-04-03.at.08.33.44.mov

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, this is great! Thank you @kkosiorowska

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@SorinQ Just to confirm, because I don't get it is it great as it is, or should this hand-pointer be removed on the hover info icon? I set the hand-pointer cursor in this PR, in other places we use the default arrow-cursor.

Comment on lines 28 to 34
<VStack alignItems="start" gap={0}>
<TextMd fontWeight="semibold" color="grey.700">
{label}
{popover}
</TextMd>
{sublabel && <TextSm color="grey.400">{sublabel}</TextSm>}
</VStack>
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this is the best solution for sure. What if for the next list element we want to apply another custom label? This could create a mess. What do you think about allowing label customization? I'm thinking of something like this:

label: React.ReactNode
Suggested change
<VStack alignItems="start" gap={0}>
<TextMd fontWeight="semibold" color="grey.700">
{label}
{popover}
</TextMd>
{sublabel && <TextSm color="grey.400">{sublabel}</TextSm>}
</VStack>
{typeof label === "string" ? (
<TextMd fontWeight="semibold" color="grey.700">
{label}
</TextMd>
) : (
label
)}

Then we can pass the following label:

<TransactionDetailsAmountItem
  label={
    <Flex flexDirection="column">
      <HStack>
        <TextMd fontWeight="semibold" color="grey.700">
          Fees
        </TextMd>
        <FeesPopover />
      </HStack>
      <TextSm color="grey.400">How are fees calculated?</TextSm>
    </Flex>
  }

...

/>

What do you think about this solution?

Copy link
Contributor Author

@ioay ioay Apr 3, 2024

Choose a reason for hiding this comment

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

Your solution is good in the case when we need a more complex, unique UI. My solution can be easier to implement for other cases using sublabel and popover just passing appropriate, simple props, instead of passing:

 <Flex flexDirection="column">
      <HStack>
        <TextMd fontWeight="semibold" color="grey.700">
          Fees
        </TextMd>
        <FeesPopover />
      </HStack>
      <TextSm color="grey.400">How are fees calculated?</TextSm>
    </Flex>

every time when we need a sublabel or popover.
Let's leave it as it is, and if the need arises, we will consider extending this solution.

Copy link
Contributor

Choose a reason for hiding this comment

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

hm @r-czajkowski I'm curious what you think about it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, If we stay with your approach I think we should also rename the popover to something more generic. Currently, we pass the component that is a tooltip which can be confusing.

Additionally, the icon is not centered relative to the text.

Screenshot 2024-04-04 at 11 25 58

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, it was broken after the last change(https://github.com/thesis/acre/pull/317/files/eb29f17f128688667324dbb90a289b6841e8c397#r1549007304), it has already been fixed - 37e98bc

Copy link
Contributor

Choose a reason for hiding this comment

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

At this moment looks like this component is only used in ActiveStakingStep. So I think we can even keep it in shared/TransactionModal/ActiveStakinStep/FeesTransacionItem.tsx.

Copy link
Contributor

Choose a reason for hiding this comment

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

TransactionDetails/index.ts

import React from "react"
import { ListItem, ListItemProps, VStack } from "@chakra-ui/react"
import { TextMd } from "../Typography"

export type TransactionDetailsItemProps = {
  label: string
  value?: string
  children?: React.ReactNode
} & ListItemProps

export function TransactionDetailsWrapper({
  children,
  ...listItemProps
}: ListItemProps & { children?: React.ReactNode }) {
  return (
    <ListItem
      display="flex"
      justifyContent="space-between"
      alignItems="center"
      {...listItemProps}
    >
      {children}
    </ListItem>
  )
}

export function TransactionDetailsLabel({ children }) {
  return (
    <TextMd fontWeight="semibold" color="grey.700">
      {children}
    </TextMd>
  )
}

function TransactionDetailsItem({
  label,
  value,
  children,
  ...listItemProps
}: TransactionDetailsItemProps) {
  return (
    <TransactionDetailsWrapper {...listItemProps}>
      <TransactionDetailsLabel>{label}</TransactionDetailsLabel>
      {value ? <TextMd color="grey.700">{value}</TextMd> : children}
    </TransactionDetailsWrapper>
  )
}

export default TransactionDetailsItem

New component

export function StakingFeesTransactionDetailsItem({ label }) {
  return (
    <TransactionDetailsWrapper>
      <VStack alignItems="start" gap={0}>
        <TransactionDetailsLabel>
          Fees
          <FeePopover />
        </TransactionDetailsLabel>
        <TextSm color="grey.400">How are fees calculated</TextSm>
      </VStack>
      <Flex flexDirection="column" alignItems="end">
        <CurrencyBalanceWithConversion
          from={{
            size: "md",
            ...from,
          }}
          to={{
            size: "sm",
            fontWeight: "medium",
            color: "grey.500",
            ...to,
          }}
        />
      </Flex>
    </TransactionDetailsWrapper>
  )
}

we can try to extract this part:

      <Flex flexDirection="column" alignItems="end">
        <CurrencyBalanceWithConversion
          from={{
            size: "md",
            ...from,
          }}
          to={{
            size: "sm",
            fontWeight: "medium",
            color: "grey.500",
            ...to,
          }}
        />
      </Flex>

since we repeat it in AmountItem

Copy link
Contributor Author

@ioay ioay Apr 11, 2024

Choose a reason for hiding this comment

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

Thanks for the feedback @r-czajkowski ! I am also a fan of generic components, hence my suggestion to use optional props such as sublabel/tooltip in TransactionDetailsItem. Thanks to this, we can support similar solutions in the future, not only for fees and this fees tooltip:

  <TransactionDetailsItem
       label={label}
       sublabel={sublabel}
       tooltip={tooltip}
       alignItems="start"
     >

This solution allow us to freely and easily pass any sublabel or tooltip according to design without the risk of any regression which gives us a generic approach.
The sublabel can be any text and the tooltip can be any tooltip component we want to show.

Correct me if I understood wrong, but creating the StakingFeesTransactionDetailsItem component according to your proposal is not generic, but rather very restrictive only for this Fee case:

export function StakingFeesTransactionDetailsItem({ label }) {
  return (
    <TransactionDetailsWrapper>
      <VStack alignItems="start" gap={0}>
        <TransactionDetailsLabel>
          Fees
          <FeePopover />
        </TransactionDetailsLabel>
        <TextSm color="grey.400">How are fees calculated</TextSm>
      </VStack>
      <Flex flexDirection="column" alignItems="end">
        <CurrencyBalanceWithConversion
          from={{
            size: "md",
            ...from,
          }}
          to={{
            size: "sm",
            fontWeight: "medium",
            color: "grey.500",
            ...to,
          }}
        />
      </Flex>
    </TransactionDetailsWrapper>
  )
}

Maybe let's combine our suggestions and create an independent component like TransactionDetailsTooltipItem, which will accept the tooltip and sublabel as a prop and at the same time the current component TransactionDetailsItem will remain unchanged. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

My point is that we should avoid props like tooltip, sublabel because we may end up with meaningless props like rightLabel or leftSublabel or subValue. So I propose to split the main component into smaller components that allow as to build more specific components.

Yes StakingFeesTransactionDetailsItem is not generic it is a specific component for a given case and has only one prop label instead of tooltip, sublabel etc.

This is only my suggestion and I prefer this style for creating components but ofc we can use this approach. I'm just not convinced about the flexibility of this approach. E.g. if the designer adds another element to the designs will we add another prop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okey dokey, I restored the transaction details component to its original shape and created a similar one for fees:
c16b8fc

Comment on lines 29 to 37
<VStack gap={0.5}>
{fees.map((fee) => (
<FeesPopoverItem
label={fee.label}
amount={fee.amount}
currency={fee.currency}
/>
))}
</VStack>
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 a list of items. So let's use the List component here. I have one more thought. The FeesPopoverItem component is very similar to TransactionDetailsAmountItem. I feel that we are duplicating the code unnecessarily.

We display the details of the transaction fees, so I think we can use the TransactionDetailsAmountItem component. It could look something like this:

        <List spacing={0.5} minW={60}>
          {fees.map((fee) => (
            <TransactionDetailsAmountItem
              key={fee.label}
              label={<TextSm color="white">{fee.label}</TextSm>}
              from={{
                currency: fee.currency,
                amount: fee.amount,
                size: "sm",
                color: "gold.300",
                fontWeight: "semibold",
              }}
            />
          ))}
        </List>

We would only need to update the TransactionDetailsAmountItem component to allow it to display the amount without conversion. What do you think about it?

Copy link
Contributor Author

@ioay ioay Apr 3, 2024

Choose a reason for hiding this comment

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

List instead VStack added 👍🏻 I considered this solution of reusing the existing TransactionDetailsAmountItem component and making it more generic, but I think it's better to create a separate view component with pure logic instead of updating already used in other places the view component with more complex and conditional logic. Moreover, If any detail changes, there is no risk of regression in the application.

@ioay ioay requested review from kkosiorowska and SorinQ April 3, 2024 15:53
@nkuba nkuba added the 🎨 dApp dApp label Apr 4, 2024
Comment on lines 28 to 34
<VStack alignItems="start" gap={0}>
<TextMd fontWeight="semibold" color="grey.700">
{label}
{popover}
</TextMd>
{sublabel && <TextSm color="grey.400">{sublabel}</TextSm>}
</VStack>
Copy link
Contributor

Choose a reason for hiding this comment

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

hm @r-czajkowski I'm curious what you think about it.

Comment on lines 28 to 34
<VStack alignItems="start" gap={0}>
<TextMd fontWeight="semibold" color="grey.700">
{label}
{popover}
</TextMd>
{sublabel && <TextSm color="grey.400">{sublabel}</TextSm>}
</VStack>
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, If we stay with your approach I think we should also rename the popover to something more generic. Currently, we pass the component that is a tooltip which can be confusing.

Additionally, the icon is not centered relative to the text.

Screenshot 2024-04-04 at 11 25 58

@ioay ioay requested a review from kkosiorowska April 4, 2024 19:14
@ioay ioay enabled auto-merge April 8, 2024 06:46
dapp/src/store/btc/btcSlice.ts Outdated Show resolved Hide resolved
dapp/src/store/btc/btcSlice.ts Outdated Show resolved Hide resolved
dapp/src/store/btc/btcSelector.ts Outdated Show resolved Hide resolved
dapp/src/components/shared/TransactionDetails/index.tsx Outdated Show resolved Hide resolved
@ioay ioay requested a review from r-czajkowski April 28, 2024 13:50
@r-czajkowski
Copy link
Contributor

obraz

Fees are not displayed in the tooltip.

r-czajkowski and others added 3 commits April 30, 2024 11:08
To use this component with other fees eg. unstaking not only with
deposit fees.

Fix displaying the fees in tooltip.
We want to display the `Bitcoin Netowrk fee` in tooltip as well - this
fee should point to the funding transaction fee selected by the user.
@r-czajkowski r-czajkowski disabled auto-merge April 30, 2024 09:22
@kkosiorowska kkosiorowska enabled auto-merge April 30, 2024 09:29
@kkosiorowska kkosiorowska merged commit 7cd0798 into main Apr 30, 2024
25 checks passed
@kkosiorowska kkosiorowska deleted the show-staking-fees-in-the-dApp branch April 30, 2024 09:30
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.

5 participants