Skip to content

Commit

Permalink
Fees popover in transaction modal
Browse files Browse the repository at this point in the history
  • Loading branch information
ioay committed Mar 17, 2024
1 parent 5dcfc76 commit 6f64499
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 9 deletions.
3 changes: 3 additions & 0 deletions dapp/src/components/GlobalStyles/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export default function GlobalStyles() {
font-weight: 900;
font-style: normal;
}
.chakra-popover__content:focus-visible {
box-shadow: none !important;
}
`}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react"
import { List } from "@chakra-ui/react"
import TransactionDetailsAmountItem from "#/components/shared/TransactionDetails/AmountItem"
import { useTokenAmountFormValue } from "#/components/shared/TokenAmountForm/TokenAmountFormBase"
import { FeesPopover } from "#/components/TransactionModal/FeesPopover"
import { useTransactionDetails } from "#/hooks"
import { CurrencyType } from "#/types"

Expand Down Expand Up @@ -34,7 +35,9 @@ function StakeDetails({
}}
/>
<TransactionDetailsAmountItem
label="Protocol fee (0.01%)"
label="Fees"
sublabel="How are fees calculated?"
popover={<FeesPopover />}
from={{
currency,
amount: details?.protocolFee,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react"
import { List } from "@chakra-ui/react"
import TransactionDetailsAmountItem from "#/components/shared/TransactionDetails/AmountItem"
import { useTokenAmountFormValue } from "#/components/shared/TokenAmountForm/TokenAmountFormBase"
import { FeesPopover } from "#/components/TransactionModal/FeesPopover"
import { useTransactionDetails } from "#/hooks"
import { CurrencyType } from "#/types"

Expand All @@ -22,7 +23,9 @@ function UnstakeDetails({ currency }: { currency: CurrencyType }) {
}}
/>
<TransactionDetailsAmountItem
label="Protocol fee (0.01%)"
label="Fees"
sublabel="How are fees calculated?"
popover={<FeesPopover />}
from={{
currency,
amount: details?.protocolFee,
Expand Down
54 changes: 54 additions & 0 deletions dapp/src/components/TransactionModal/FeesPopover/FeesPopover.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from "react"
import { Info } from "#/assets/icons"
import {
Popover,
PopoverTrigger,
PopoverContent,
PopoverArrow,
PopoverBody,
Icon,
VStack,
} from "@chakra-ui/react"
import { FeesItemType, FeesPopoverItem } from "./FeesPopoverItem"

const fees: Array<FeesItemType> = [
{
label: "Acre protocol fees",
amount: "100000",
currency: "bitcoin",
},
{
label: "tBTC bridge fees",
amount: "240000",
currency: "bitcoin",
},
{
label: "Bitcoin network fees",
amount: "200000",
currency: "bitcoin",
},
]

export function FeesPopover() {
return (
<Popover isLazy placement="right">
<PopoverTrigger>
<Icon as={Info} ml={2} boxSize={5} cursor="pointer" color="grey.400" />
</PopoverTrigger>
<PopoverContent color="white" bg="grey.700" p={3} borderRadius="xl">
<PopoverArrow bg="grey.700" />
<PopoverBody>
<VStack gap={0.5}>
{fees.map((fee) => (
<FeesPopoverItem
label={fee.label}
amount={fee.amount}
currency={fee.currency}
/>
))}
</VStack>
</PopoverBody>
</PopoverContent>
</Popover>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from "react"
import { HStack } from "@chakra-ui/react"
import {
CurrencyBalance,
CurrencyBalanceProps,
} from "#/components/shared/CurrencyBalance"
import { TextSm } from "#/components/shared/Typography"

export type FeesItemType = CurrencyBalanceProps & {
label: string
}

export function FeesPopoverItem({ label, amount, ...props }: FeesItemType) {
return (
<HStack w="100%" justifyContent="space-between">
<TextSm color="white">{label}</TextSm>
<CurrencyBalance
size="sm"
amount={amount}
color="gold.400"
balanceFontWeight="semibold"
symbolFontWeight="semibold"
{...props}
/>
</HStack>
)
}
1 change: 1 addition & 0 deletions dapp/src/components/TransactionModal/FeesPopover/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./FeesPopover"
11 changes: 9 additions & 2 deletions dapp/src/components/shared/TransactionDetails/AmountItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@ import { CurrencyBalanceWithConversion } from "../CurrencyBalanceWithConversion"
type TransactionDetailsAmountItemProps = ComponentProps<
typeof CurrencyBalanceWithConversion
> &
Pick<TransactionDetailsItemProps, "label">
Pick<TransactionDetailsItemProps, "label" | "sublabel" | "popover">

function TransactionDetailsAmountItem({
label,
sublabel,
popover,
from,
to,
}: TransactionDetailsAmountItemProps) {
return (
<TransactionDetailsItem label={label} alignItems="start">
<TransactionDetailsItem
label={label}
sublabel={sublabel}
popover={popover}
alignItems="start"
>
<Flex flexDirection="column" alignItems="end">
<CurrencyBalanceWithConversion
from={{
Expand Down
18 changes: 13 additions & 5 deletions dapp/src/components/shared/TransactionDetails/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import React from "react"
import { ListItem, ListItemProps } from "@chakra-ui/react"
import { TextMd } from "../Typography"
import { ListItem, ListItemProps, VStack } from "@chakra-ui/react"
import { TextMd, TextSm } from "../Typography"

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

function TransactionDetailsItem({
label,
sublabel,
popover,
value,
children,
...listItemProps
Expand All @@ -21,9 +25,13 @@ function TransactionDetailsItem({
alignItems="center"
{...listItemProps}
>
<TextMd fontWeight="semibold" color="grey.700">
{label}
</TextMd>
<VStack alignItems="start" gap={0}>
<TextMd fontWeight="semibold" color="grey.700">
{label}
{popover}
</TextMd>
{sublabel && <TextSm color="grey.400">{sublabel}</TextSm>}
</VStack>
{value ? <TextMd color="grey.700">{value}</TextMd> : children}
</ListItem>
)
Expand Down

0 comments on commit 6f64499

Please sign in to comment.