-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dashboard/dashboard-card
- Loading branch information
Showing
30 changed files
with
1,191 additions
and
1,380 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
dapp/src/components/TransactionModal/FeesTooltip/FeesTooltip.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from "react" | ||
import { Info } from "#/assets/icons" | ||
import { Icon, Tooltip, List } from "@chakra-ui/react" | ||
import { FeesTooltipItem } from "./FeesTooltipItem" | ||
|
||
type Fee = { [key: string]: bigint } | ||
|
||
type Props<F extends Fee> = { | ||
fees: F | ||
mapFeeToLabel: (feeName: keyof F) => string | ||
} | ||
|
||
export function FeesTooltip<F extends Fee>({ fees, mapFeeToLabel }: Props<F>) { | ||
return ( | ||
<Tooltip | ||
placement="right" | ||
label={ | ||
<List spacing={0.5} minW={60}> | ||
{Object.entries(fees).map(([feeKey, feeValue]) => ( | ||
<FeesTooltipItem | ||
key={feeKey} | ||
label={mapFeeToLabel(feeKey)} | ||
amount={feeValue} | ||
currency="bitcoin" | ||
/> | ||
))} | ||
</List> | ||
} | ||
> | ||
<Icon as={Info} ml={2} boxSize={4} cursor="pointer" color="grey.400" /> | ||
</Tooltip> | ||
) | ||
} |
27 changes: 27 additions & 0 deletions
27
dapp/src/components/TransactionModal/FeesTooltip/FeesTooltipItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from "react" | ||
import { ListItem } 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 FeesTooltipItem({ label, amount, ...props }: FeesItemType) { | ||
return ( | ||
<ListItem display="flex" justifyContent="space-between"> | ||
<TextSm color="white">{label}</TextSm> | ||
<CurrencyBalance | ||
size="sm" | ||
amount={amount} | ||
color="gold.300" | ||
balanceFontWeight="semibold" | ||
symbolFontWeight="semibold" | ||
{...props} | ||
/> | ||
</ListItem> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./FeesTooltip" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React, { ComponentProps } from "react" | ||
import { Flex } from "@chakra-ui/react" | ||
import FeesDetailsItem, { FeesDetailsItemProps } from "." | ||
import { CurrencyBalanceWithConversion } from "../CurrencyBalanceWithConversion" | ||
|
||
type FeesDetailsItemAmountItemProps = ComponentProps< | ||
typeof CurrencyBalanceWithConversion | ||
> & | ||
Pick<FeesDetailsItemProps, "label" | "sublabel" | "tooltip"> | ||
|
||
function FeesDetailsAmountItem({ | ||
label, | ||
sublabel, | ||
tooltip, | ||
from, | ||
to, | ||
}: FeesDetailsItemAmountItemProps) { | ||
return ( | ||
<FeesDetailsItem | ||
label={label} | ||
sublabel={sublabel} | ||
tooltip={tooltip} | ||
alignItems="start" | ||
> | ||
<Flex flexDirection="column" alignItems="end"> | ||
<CurrencyBalanceWithConversion | ||
from={{ | ||
size: "md", | ||
...from, | ||
}} | ||
to={{ | ||
size: "sm", | ||
fontWeight: "medium", | ||
color: "grey.500", | ||
...to, | ||
}} | ||
/> | ||
</Flex> | ||
</FeesDetailsItem> | ||
) | ||
} | ||
|
||
export default FeesDetailsAmountItem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React from "react" | ||
import { ListItem, ListItemProps, VStack } from "@chakra-ui/react" | ||
import { TextMd, TextSm } from "../Typography" | ||
|
||
export type FeesDetailsItemProps = { | ||
label: string | ||
sublabel: string | ||
value?: string | ||
tooltip: React.ReactElement | ||
children?: React.ReactNode | ||
} & ListItemProps | ||
|
||
function FeesDetailsItem({ | ||
label, | ||
sublabel, | ||
tooltip, | ||
value, | ||
children, | ||
...listItemProps | ||
}: FeesDetailsItemProps) { | ||
return ( | ||
<ListItem | ||
display="flex" | ||
justifyContent="space-between" | ||
alignItems="center" | ||
{...listItemProps} | ||
> | ||
<VStack alignItems="start" gap={0}> | ||
<TextMd | ||
display="flex" | ||
alignItems="center" | ||
fontWeight="semibold" | ||
color="grey.700" | ||
> | ||
{label} | ||
{tooltip} | ||
</TextMd> | ||
{sublabel && <TextSm color="grey.400">{sublabel}</TextSm>} | ||
</VStack> | ||
{value ? <TextMd color="grey.700">{value}</TextMd> : children} | ||
</ListItem> | ||
) | ||
} | ||
|
||
export default FeesDetailsItem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { useAcreContext } from "#/acre-react/hooks" | ||
import { logPromiseFailure } from "#/utils" | ||
import { useEffect, useState } from "react" | ||
import { DepositFee } from "#/types" | ||
import { useAppDispatch } from "./store" | ||
|
||
const initialDepositFee = { | ||
tbtc: 0n, | ||
acre: 0n, | ||
total: 0n, | ||
} | ||
|
||
export function useTransactionFee(amount?: bigint) { | ||
const [depositFee, setDepositFee] = useState<DepositFee>(initialDepositFee) | ||
const { acre } = useAcreContext() | ||
const dispatch = useAppDispatch() | ||
|
||
useEffect(() => { | ||
if (!amount) { | ||
setDepositFee(initialDepositFee) | ||
} else { | ||
const getEstimatedDepositFee = async () => { | ||
if (!acre) return | ||
const fee = await acre.staking.estimateDepositFee(amount) | ||
|
||
setDepositFee(fee) | ||
} | ||
logPromiseFailure(getEstimatedDepositFee()) | ||
} | ||
}, [acre, dispatch, amount]) | ||
|
||
return depositFee | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export type DepositFee = { | ||
tbtc: bigint | ||
acre: bigint | ||
total: bigint | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.