Skip to content

Commit

Permalink
Merge branch 'main' into update-success-Modal
Browse files Browse the repository at this point in the history
  • Loading branch information
kpyszkowski authored Oct 31, 2024
2 parents 38f31be + f05d840 commit 26b00b3
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 45 deletions.
25 changes: 25 additions & 0 deletions dapp/src/components/TransactionModal/ActionDurationEstimation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from "react"
import { ActivityType } from "#/types"
import { getEstimatedDuration } from "#/utils"
import { useFormField } from "#/hooks"
import { TextMd } from "../shared/Typography"
import { TOKEN_AMOUNT_FIELD_NAME } from "../shared/TokenAmountForm/TokenAmountFormBase"

export default function ActionDurationEstimation({
type,
}: {
type: ActivityType
}) {
const { value: amount = 0n } = useFormField<bigint | undefined>(
TOKEN_AMOUNT_FIELD_NAME,
)

return (
<TextMd mt={4} color="grey.400">
Estimated duration&nbsp;
<TextMd as="span" color="grey.500">
~ {getEstimatedDuration(amount, type)}
</TextMd>
</TextMd>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ function StakeDetails({ currency }: { currency: CurrencyType }) {

return (
<List spacing={3} mt={10}>
<TransactionDetailsAmountItem
label="Amount to be deposited"
from={{
currency,
amount: details.amount,
}}
to={{
currency: "usd",
}}
/>
<FeesDetailsAmountItem
label="Fees"
// TODO: Add `Bitcoin Network fee` (funding transaction fee selected by
Expand All @@ -48,15 +38,13 @@ function StakeDetails({ currency }: { currency: CurrencyType }) {
currency: "usd",
}}
/>

<TransactionDetailsAmountItem
label="Approximate staked tokens"
label="You will deposit"
from={{
currency,
amount: details.estimatedAmount,
}}
to={{
currency: "usd",
}}
/>
</List>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { fixedPointNumberToString, getCurrencyByType } from "#/utils"
import { featureFlags } from "#/constants"
import StakeDetails from "./StakeDetails"
import AcrePointsRewardEstimation from "./AcrePointsRewardEstimation"
import ActionDurationEstimation from "../../ActionDurationEstimation"

function StakeFormModal({
onSubmitForm,
Expand Down Expand Up @@ -35,6 +36,7 @@ function StakeFormModal({
)}
<StakeDetails currency="bitcoin" />
<FormSubmitButton mt={10}>Deposit</FormSubmitButton>
<ActionDurationEstimation type="deposit" />
</TokenAmountForm>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,11 @@ function UnstakeDetails({
const { total, ...restFees } = details.transactionFee

return (
<Flex flexDirection="column" gap={10} mt={4}>
<Flex flexDirection="column" gap={10} mt={10}>
{featureFlags.GAMIFICATION_ENABLED && (
<WithdrawWarning balance={balance} currency={currency} />
)}
<List spacing={3}>
<TransactionDetailsAmountItem
label="Withdraw from pool"
from={{
currency,
amount: details.amount,
}}
to={{
currency: "usd",
}}
/>

<FeesDetailsAmountItem
label="Fees"
// TODO: Add `Bitcoin Network fee` (funding transaction fee selected by
Expand All @@ -67,9 +56,6 @@ function UnstakeDetails({
currency,
amount: details.estimatedAmount,
}}
to={{
currency: "usd",
}}
/>
</List>
</Flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from "#/hooks"
import { fixedPointNumberToString, getCurrencyByType } from "#/utils"
import UnstakeDetails from "./UnstakeDetails"
import ActionDurationEstimation from "../../ActionDurationEstimation"

function UnstakeFormModal({
onSubmitForm,
Expand Down Expand Up @@ -38,7 +39,8 @@ function UnstakeFormModal({
defaultAmount={defaultAmount}
>
<UnstakeDetails balance={balance} currency="bitcoin" />
<FormSubmitButton mt={10}>Withdraw</FormSubmitButton>
<FormSubmitButton mt={8}>Withdraw</FormSubmitButton>
<ActionDurationEstimation type="withdraw" />
</TokenAmountForm>
)
}
Expand Down
2 changes: 1 addition & 1 deletion dapp/src/components/shared/TokenAmountForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const TokenAmountForm = withFormik<TokenAmountFormProps, TokenAmountFormValues>(
handleSubmit: (values, { props }) => {
props.onSubmitForm(values)
},
validateOnBlur: false,
validateOnBlur: true,
validateOnChange: false,
},
)(TokenAmountFormBase)
Expand Down
33 changes: 19 additions & 14 deletions dapp/src/components/shared/TransactionDetails/AmountItem.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import React, { ComponentProps } from "react"
import { Flex } from "@chakra-ui/react"
import { Optional } from "#/types"
import TransactionDetailsItem, { TransactionDetailsItemProps } from "."
import { CurrencyBalanceWithConversion } from "../CurrencyBalanceWithConversion"
import { CurrencyBalance } from "../CurrencyBalance"

type TransactionDetailsAmountItemProps = ComponentProps<
typeof CurrencyBalanceWithConversion
type TransactionDetailsAmountItemProps = Optional<
ComponentProps<typeof CurrencyBalanceWithConversion>,
"to"
> &
Pick<TransactionDetailsItemProps, "label">

Expand All @@ -13,21 +16,23 @@ function TransactionDetailsAmountItem({
from,
to,
}: TransactionDetailsAmountItemProps) {
const fromProps: TransactionDetailsAmountItemProps["from"] = {
size: "md",
...from,
}

const toProps: TransactionDetailsAmountItemProps["to"] = to
? { size: "sm", fontWeight: "medium", color: "grey.500", ...to }
: undefined

return (
<TransactionDetailsItem label={label} alignItems="start">
<Flex flexDirection="column" alignItems="end">
<CurrencyBalanceWithConversion
from={{
size: "md",
...from,
}}
to={{
size: "sm",
fontWeight: "medium",
color: "grey.500",
...to,
}}
/>
{toProps ? (
<CurrencyBalanceWithConversion from={fromProps} to={toProps} />
) : (
<CurrencyBalance {...fromProps} />
)}
</Flex>
</TransactionDetailsItem>
)
Expand Down
2 changes: 2 additions & 0 deletions dapp/src/types/core.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export type Tuple<T> = [T, T]

export type WithRequired<T, K extends keyof T> = T & { [P in K]-?: T[P] }

export type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>

0 comments on commit 26b00b3

Please sign in to comment.