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

tBTC minting redesign - Phase I - part 1/4 #651

Merged
merged 58 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
d1b9846
Remove tBTC balance widget
kpyszkowski Oct 10, 2023
30b722e
Redesign MintingTimeline component
kpyszkowski Oct 12, 2023
a5e22de
Update copy in 1st step of Minting timeline
kpyszkowski Oct 12, 2023
0689817
Adjust MintingTimeline styles and remove badge
kpyszkowski Oct 12, 2023
7caaafd
Add deposit receipt download agreement checkbox
kpyszkowski Oct 12, 2023
c54486d
Implement useToast hook
kpyszkowski Oct 17, 2023
2dd3dc7
Implement DurationTiers component
kpyszkowski Oct 18, 2023
7071b42
Apply minor UI improvements for Step 2
kpyszkowski Oct 18, 2023
1227a9f
Add 'Deposit received' toast, improve toasts hook
kpyszkowski Oct 19, 2023
e9b8082
Refactor useToast hook
kpyszkowski Oct 19, 2023
6b1b082
Implement DurationWidget component
kpyszkowski Oct 19, 2023
4956411
Apply minor import/export improvements
kpyszkowski Oct 19, 2023
5d1aa55
Redesign Step 3
kpyszkowski Oct 20, 2023
56f3a83
Remove Toast UI animations
kpyszkowski Oct 24, 2023
76db73c
Merge branch 'main' into tbtc-minting-redesign
kpyszkowski Oct 24, 2023
732d101
Merge branch 'main' into tbtc-minting-redesign
kpyszkowski Nov 21, 2023
1962cc0
Refactor `DurationTiers` component declaration
kpyszkowski Dec 6, 2023
2533802
Refactor tBTC utility functions
kpyszkowski Dec 6, 2023
6b4bafb
Remove `getNumberOfConfirmationsByAmount` function
kpyszkowski Dec 6, 2023
4cb092e
Remove value correction
kpyszkowski Dec 6, 2023
52e291f
Fix amount parsing errors in components
kpyszkowski Dec 6, 2023
5d36e5f
Add responsive styles for `DurationTiers` component
kpyszkowski Dec 6, 2023
8f7468f
Rename components
kpyszkowski Dec 6, 2023
18772b9
Refactor `MintDurationWidget` component
kpyszkowski Dec 6, 2023
826eacf
Make approximation sign fixed
kpyszkowski Dec 6, 2023
ccf1079
Refactor redundant `sx` props into style props.
kpyszkowski Dec 6, 2023
16ef5a7
Update label
kpyszkowski Dec 6, 2023
93ee6d1
Update `MintingTimeline` wrapper component
kpyszkowski Dec 6, 2023
edce2a8
Revert `TbtcBalanceCard` component removal
kpyszkowski Dec 6, 2023
7760b19
Use `Toast` component instead of `useToast` hook
kpyszkowski Dec 7, 2023
cbb00fd
Remove types file for `MintDurationTiers` component
kpyszkowski Dec 8, 2023
3bbb8cc
Fix typo
kpyszkowski Dec 8, 2023
8252677
Fix missing container in `BridgeProcessResource`
kpyszkowski Dec 8, 2023
6bc8eaf
Update button label
kpyszkowski Dec 8, 2023
d95ca7a
Remove Minting confirmation modal
kpyszkowski Dec 8, 2023
7ce166f
Wrap token values with Skeltons
kpyszkowski Dec 8, 2023
0de7e18
Add spacing under InfoBox heading
kpyszkowski Dec 8, 2023
d196e23
Use Threshold lib hook instead of helper function
kpyszkowski Dec 9, 2023
050f1c0
Move types to component file
kpyszkowski Dec 9, 2023
f970330
Revert dotenv changes
kpyszkowski Dec 11, 2023
fca3a60
Remove export directive
kpyszkowski Dec 11, 2023
84ac12c
Revert mock bitcoin client changes
kpyszkowski Dec 11, 2023
53bfca0
Fix resume file contents
kpyszkowski Dec 11, 2023
7d4c515
Remove `TbtcRecoveryFileModal` component
kpyszkowski Dec 11, 2023
88caaf0
Enable 'Resume Deposit' page
kpyszkowski Dec 11, 2023
b4a5465
Fix deposit resume flow
kpyszkowski Dec 12, 2023
73aabfb
Remove redundant text
kpyszkowski Dec 12, 2023
075f94a
Get mint value from state
kpyszkowski Dec 12, 2023
8d79591
Remove redundant margin
kpyszkowski Dec 12, 2023
cfec90e
Wrap `MintDurationWidget` value with `Skelton`
kpyszkowski Dec 12, 2023
f06041c
Add half an hour precision to duration tiers
kpyszkowski Dec 12, 2023
7f8e235
Fix comment line width to fit 80 characters
kpyszkowski Dec 12, 2023
3b07562
Fix `MintDurationWidget` bugs
kpyszkowski Dec 12, 2023
f572798
Refactor `MintDurationWidget` component
kpyszkowski Dec 12, 2023
a415561
Remove unused imports
kpyszkowski Dec 12, 2023
eb3232a
Remove redundant useEffect hook
kpyszkowski Dec 12, 2023
507c500
Improve `mintingStep` state change
kpyszkowski Dec 12, 2023
0188805
Merge branch 'main' into tbtc-minting-redesign
michalsmiarowski Dec 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env
michalsmiarowski marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ REACT_APP_ELECTRUM_HOST=$ELECTRUM_HOST
REACT_APP_ELECTRUM_PORT=$ELECTRUM_PORT
REACT_APP_MOCK_BITCOIN_CLIENT=true

REACT_APP_WALLET_CONNECT_PROJECT_ID=$WALLET_CONNECT_PROJECT_ID
REACT_APP_WALLET_CONNECT_PROJECT_ID=$WALLET_CONNECT_PROJECT_ID
116 changes: 116 additions & 0 deletions src/components/MintDurationTiers/MintDurationTiers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import { BodyXs, Flex, H5, Stack, VStack } from "@threshold-network/components"
import { FC } from "react"
import { getRangeSign } from "../../utils/getRangeSign"
import { getDurationByNumberOfConfirmations } from "../../utils/tBTC"
import { StackProps } from "@threshold-network/components"
import { ComponentPropsWithoutRef } from "react"
import { RangeOperatorType, CurrencyType } from "../../types"
import { useThreshold } from "../../contexts/ThresholdContext"

type BaseProps = ComponentPropsWithoutRef<"li"> & StackProps
type MintDurationTiersItemProps = {
amount: number
currency: CurrencyType
rangeOperator: RangeOperatorType
}

interface MintDurationTiersProps extends BaseProps {
items: MintDurationTiersItemProps[]
}

const MintDurationTiers: FC<MintDurationTiersProps> = ({
items,
...restProps
}) => {
const {
tbtc: {
minimumNumberOfConfirmationsNeeded: getNumberOfConfirmationsByAmount,
},
} = useThreshold()

return (
<Stack
direction={{
base: "column",
sm: "row",
}}
spacing={{
base: 3,
md: 6,
}}
{...restProps}
>
{items.map(({ amount, rangeOperator, currency }, index) => {
const correctedAmount =
amount + (rangeOperator.includes("greater") ? 0.01 : -0.01)
// The amount is corrected by adding or subtracting 0.01 to the given
// amount depending on the range operator. This is done to avoid
// floating-point errors when comparing BigNumber values.
const safeAmount = Number.isSafeInteger(correctedAmount)
? correctedAmount
: Math.floor((correctedAmount as number) * 1e8)
michalsmiarowski marked this conversation as resolved.
Show resolved Hide resolved
// Only safe integers (not floating-point numbers) can be transformed to
// BigNumber. Converting the given amount to a safe integer if it is not
// already a safe integer. If the amount is already a safe integer, it
// is returned as is.
const confirmations = getNumberOfConfirmationsByAmount(safeAmount)
const durationInMinutes =
getDurationByNumberOfConfirmations(confirmations)
// Round up the minutes to the nearest half-hour
const hours = (Math.round(durationInMinutes / 30) * 30) / 60
const formattedAmount = amount.toFixed(2)

const hoursSuffix = hours === 1 ? "hour" : "hours"
const confirmationsSuffix =
confirmations === 1 ? "confirmation" : "confirmations"
const rangeSign = getRangeSign(rangeOperator)
return (
<Flex
key={index}
flexFlow={{ sm: "column" }}
flex="1"
rounded="md"
boxShadow="md"
>
<Flex
flexFlow="column"
justifyContent="center"
textAlign="center"
bg="purple.50"
w="full"
px="3"
py="2"
>
<H5 color="purple.700">
{hours} {hoursSuffix}
</H5>
<BodyXs color="purple.700" whiteSpace="nowrap">
+ {confirmations} {confirmationsSuffix}
</BodyXs>
</Flex>
<VStack
px={{
base: 4,
sm: 4,
md: 8,
}}
py="5"
w="full"
mt="0"
spacing="0"
>
<H5 alignSelf="start" color="gray.500" whiteSpace="nowrap">
{rangeSign} {formattedAmount}
</H5>
<BodyXs alignSelf="end" color="gray.500">
{currency}
</BodyXs>
</VStack>
</Flex>
)
})}
</Stack>
)
}

export default MintDurationTiers
1 change: 1 addition & 0 deletions src/components/MintDurationTiers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as MintDurationTiers } from "./MintDurationTiers"
82 changes: 82 additions & 0 deletions src/components/MintDurationWidget/MintDurationWidget.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import {
BodyLg,
BodyXs,
Box,
Flex,
HStack,
LabelSm,
Skeleton,
} from "@threshold-network/components"
import { FC } from "react"
import { useThreshold } from "../../contexts/ThresholdContext"
import { getDurationByNumberOfConfirmations } from "../../utils/tBTC"
import { BoxProps } from "@threshold-network/components"
import { RangeOperatorType, CurrencyType } from "../../types"
import { BigNumber, BigNumberish } from "ethers"
import { InlineTokenBalance } from "../TokenBalance"

interface MintDurationWidgetProps extends BoxProps {
label?: string
amount: [RangeOperatorType, BigNumberish, CurrencyType]
}

const MintDurationWidget: FC<MintDurationWidgetProps> = ({
label = "Duration",
amount,
...restProps
}) => {
const [operator, rawValue, currency] = amount
const {
tbtc: {
minimumNumberOfConfirmationsNeeded: getNumberOfConfirmationsByAmount,
},
} = useThreshold()

const value = BigNumber.from(rawValue).toNumber()
const correctedValue = value + (operator.includes("greater") ? 0.01 : -0.01)
// The amount is corrected by adding or subtracting 0.01 to the given amount
// depending on the range operator. This is done to avoid floating-point
// errors when comparing BigNumber values.
const safeAmount = Number.isSafeInteger(correctedValue)
? value
: Math.floor(value * 1e8)
// Only safe integers (not floating-point numbers) can be transformed to
// BigNumber. Converting the given amount to a safe integer if it is not
// already a safe integer. If the amount is already a safe integer, it is
// returned as is.
const confirmations = getNumberOfConfirmationsByAmount(safeAmount)
const durationInMinutes = getDurationByNumberOfConfirmations(confirmations)
// Round up the minutes to the nearest half-hour
const hours = (Math.round(durationInMinutes / 30) * 30) / 60
const hoursSuffix = durationInMinutes === 60 ? "Hour" : "Hours"

return (
<Box {...restProps}>
<LabelSm mb="4">{label}</LabelSm>
<HStack>
<BodyXs
color="purple.700"
bg="purple.50"
rounded="sm"
pl="2"
pr="4"
py="1"
>
~ {hours} {hoursSuffix}
</BodyXs>
<Flex alignItems="end" color="gray.500">
<Skeleton isLoaded={!BigNumber.from(rawValue).isZero()}>
<BodyLg>
<InlineTokenBalance tokenAmount={value} />
</BodyLg>
</Skeleton>
<BodyXs ml="1.5" mb="0.5">
{currency}
</BodyXs>
</Flex>
</HStack>
</Box>
)
}

export default MintDurationWidget
1 change: 1 addition & 0 deletions src/components/MintDurationWidget/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as MintDurationWidget } from "./MintDurationWidget"
123 changes: 0 additions & 123 deletions src/components/Modal/TbtcMintingConfirmationModal/index.tsx

This file was deleted.

Loading
Loading