Skip to content

Commit

Permalink
Rename from minDepositAmount to minStakeAmount
Browse files Browse the repository at this point in the history
  • Loading branch information
kkosiorowska committed Apr 9, 2024
1 parent 904ddcf commit 3766428
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import TokenAmountForm from "#/components/shared/TokenAmountForm"
import { TokenAmountFormValues } from "#/components/shared/TokenAmountForm/TokenAmountFormBase"
import { useAppSelector, useWalletContext } from "#/hooks"
import { FormSubmitButton } from "#/components/shared/Form"
import { selectMinDepositAmount } from "#/store/btc"
import { selectMinStakeAmount } from "#/store/btc"
import StakeDetails from "./StakeDetails"

function StakeFormModal({
onSubmitForm,
}: {
onSubmitForm: (values: TokenAmountFormValues) => void
}) {
const minDepositAmount = useAppSelector(selectMinDepositAmount)
const minStakeAmount = useAppSelector(selectMinStakeAmount)
const { btcAccount } = useWalletContext()
const tokenBalance = btcAccount?.balance.toString() ?? "0"

Expand All @@ -20,12 +20,12 @@ function StakeFormModal({
tokenBalanceInputPlaceholder="BTC"
currency="bitcoin"
tokenBalance={tokenBalance}
minTokenAmount={minDepositAmount}
minTokenAmount={minStakeAmount}
onSubmitForm={onSubmitForm}
>
<StakeDetails
currency="bitcoin"
minTokenAmount={minDepositAmount}
minTokenAmount={minStakeAmount}
maxTokenAmount={BigInt(tokenBalance)}
/>
<FormSubmitButton mt={4}>Stake</FormSubmitButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { TextMd, TextSm } from "#/components/shared/Typography"
import Spinner from "#/components/shared/Spinner"
import { FormSubmitButton } from "#/components/shared/Form"
import { useAppSelector } from "#/hooks"
import { selectMinDepositAmount } from "#/store/btc"
import { selectMinStakeAmount } from "#/store/btc"
import UnstakeDetails from "./UnstakeDetails"

// TODO: Use a position amount
Expand All @@ -17,14 +17,14 @@ function UnstakeFormModal({
}: {
onSubmitForm: (values: TokenAmountFormValues) => void
}) {
const minDepositAmount = useAppSelector(selectMinDepositAmount)
const minStakeAmount = useAppSelector(selectMinStakeAmount)

return (
<TokenAmountForm
tokenBalanceInputPlaceholder="BTC"
currency="bitcoin"
tokenBalance={MOCK_POSITION_AMOUNT}
minTokenAmount={minDepositAmount}
minTokenAmount={minStakeAmount}
onSubmitForm={onSubmitForm}
>
<Flex flexDirection="column" gap={10}>
Expand Down
2 changes: 1 addition & 1 deletion dapp/src/hooks/sdk/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./useInitializeAcreSdk"
export * from "./useFetchMinDepositAmount"
export * from "./useFetchMinStakeAmount"
export * from "./useFetchSdkData"
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { useEffect } from "react"
import { setMinDepositAmount } from "#/store/btc"
import { setMinStakeAmount } from "#/store/btc"
import { logPromiseFailure } from "#/utils"
import { useAcreContext } from "#/acre-react/hooks"
import { useAppDispatch } from "../store/useAppDispatch"

export function useFetchMinDepositAmount() {
export function useFetchMinStakeAmount() {
const { acre, isInitialized } = useAcreContext()
const dispatch = useAppDispatch()

useEffect(() => {
if (!isInitialized || !acre) return

const fetchMinDepositAmount = async () => {
const fetchMinStakeAmount = async () => {
// TODO: Use function from SDK
const minDepositAmount = await new Promise<bigint>((resolve) => {
const minStakeAmount = await new Promise<bigint>((resolve) => {
resolve(BigInt(String(1e4))) // 0.0001 BTC
})

dispatch(setMinDepositAmount(minDepositAmount))
dispatch(setMinStakeAmount(minStakeAmount))
}

logPromiseFailure(fetchMinDepositAmount())
logPromiseFailure(fetchMinStakeAmount())
}, [acre, dispatch, isInitialized])
}
4 changes: 2 additions & 2 deletions dapp/src/hooks/sdk/useFetchSdkData.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useFetchMinDepositAmount } from "./useFetchMinDepositAmount"
import { useFetchMinStakeAmount } from "./useFetchMinStakeAmount"

export function useFetchSdkData() {
useFetchMinDepositAmount()
useFetchMinStakeAmount()
}
4 changes: 2 additions & 2 deletions dapp/src/store/btc/btcSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export const selectSharesBalance = (state: RootState): bigint =>
export const selectBtcUsdPrice = (state: RootState): number =>
state.btc.usdPrice

export const selectMinDepositAmount = (state: RootState) =>
state.btc.minDepositAmount
export const selectMinStakeAmount = (state: RootState) =>
state.btc.minStakeAmount
10 changes: 5 additions & 5 deletions dapp/src/store/btc/btcSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ type BtcState = {
sharesBalance: bigint
isLoadingPriceUSD: boolean
usdPrice: number
minDepositAmount: bigint
minStakeAmount: bigint
}

const initialState: BtcState = {
estimatedBtcBalance: 0n,
sharesBalance: 0n,
isLoadingPriceUSD: false,
usdPrice: 0,
minDepositAmount: 0n,
minStakeAmount: 0n,
}

// Store Bitcoin data such as balance, balance in usd and other related data to Bitcoin chain.
Expand All @@ -28,8 +28,8 @@ export const btcSlice = createSlice({
setEstimatedBtcBalance(state, action: PayloadAction<bigint>) {
state.estimatedBtcBalance = action.payload
},
setMinDepositAmount(state, action: PayloadAction<bigint>) {
state.minDepositAmount = action.payload
setMinStakeAmount(state, action: PayloadAction<bigint>) {
state.minStakeAmount = action.payload
},
},
extraReducers: (builder) => {
Expand All @@ -49,5 +49,5 @@ export const btcSlice = createSlice({
},
})

export const { setSharesBalance, setEstimatedBtcBalance, setMinDepositAmount } =
export const { setSharesBalance, setEstimatedBtcBalance, setMinStakeAmount } =
btcSlice.actions

0 comments on commit 3766428

Please sign in to comment.