-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read the min amount of BTC deposit from the SDK (#303)
Closes #234 Closes #336 This PR reads the minimum amount of BTC deposit from the SDK and saves it in the redux store. ### What has been done: - Fetch the minimum amount of BTC deposit from the SDK - Create a special hook `useFetchSdkData` to load all needed data from the SDK - Set desired decimals for Bitcoin currency manually. Previously, we determined the number of desired places based on the minimum stake amount. However, now we are not able to do it this way because the data from the SDK is loaded after connecting the accounts. - Standardization of types in the form. Use a `bigint` for `tokenBalnce`. - Extend `CurrencyBalance` to pass the amount in `bigint` One note: the contracts have not been deployed yet. Therefore, an error will appear in the console `TypeError: this.instance.minDepositAmount is not a function` However, When the contracts are re-deployed I will update the code and the error will disappear.
- Loading branch information
Showing
31 changed files
with
164 additions
and
58 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
8 changes: 5 additions & 3 deletions
8
dapp/src/components/TransactionModal/ActiveUnstakingStep/UnstakeFormModal/index.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
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
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
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 |
---|---|---|
@@ -1,11 +1 @@ | ||
import { getDesiredDecimals } from "#/utils/numbers" | ||
|
||
// TODO: Read the value from the SDK, once we expose it | ||
export const BITCOIN_MIN_AMOUNT = String(1e4) // 0.0001 BTC | ||
|
||
export const BITCOIN_DESIRED_DECIMALS = getDesiredDecimals( | ||
BITCOIN_MIN_AMOUNT, | ||
8, | ||
) | ||
|
||
export const REFERRAL = import.meta.env.VITE_REFERRAL |
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,4 @@ | ||
export * from "./useInitializeAcreSdk" | ||
export * from "./useFetchMinDepositAmount" | ||
export * from "./useInitDataFromSdk" | ||
export * from "./useFetchBTCBalance" |
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,22 @@ | ||
import { useEffect } from "react" | ||
import { setMinDepositAmount } from "#/store/btc" | ||
import { logPromiseFailure } from "#/utils" | ||
import { useAcreContext } from "#/acre-react/hooks" | ||
import { useAppDispatch } from "../store/useAppDispatch" | ||
|
||
export function useFetchMinDepositAmount() { | ||
const { acre, isInitialized } = useAcreContext() | ||
const dispatch = useAppDispatch() | ||
|
||
useEffect(() => { | ||
if (!isInitialized || !acre) return | ||
|
||
const fetchMinDepositAmount = async () => { | ||
const minDepositAmount = await acre.staking.minDepositAmount() | ||
|
||
dispatch(setMinDepositAmount(minDepositAmount)) | ||
} | ||
|
||
logPromiseFailure(fetchMinDepositAmount()) | ||
}, [acre, dispatch, isInitialized]) | ||
} |
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,7 @@ | ||
import { useFetchBTCBalance } from "./useFetchBTCBalance" | ||
import { useFetchMinDepositAmount } from "./useFetchMinDepositAmount" | ||
|
||
export function useInitDataFromSdk() { | ||
useFetchBTCBalance() | ||
useFetchMinDepositAmount() | ||
} |
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
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,6 @@ | ||
import { selectMinDepositAmount } from "#/store/btc" | ||
import { useAppSelector } from "./useAppSelector" | ||
|
||
export function useMinDepositAmount() { | ||
return useAppSelector(selectMinDepositAmount) | ||
} |
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 |
---|---|---|
@@ -1,13 +1,12 @@ | ||
import { useInitDataFromSdk, useInitializeAcreSdk } from "./sdk" | ||
import { useSentry } from "./sentry" | ||
import { useInitializeAcreSdk } from "./useInitializeAcreSdk" | ||
import { useFetchBTCPriceUSD } from "./useFetchBTCPriceUSD" | ||
import { useFetchBTCBalance } from "./useFetchBTCBalance" | ||
|
||
export function useInitApp() { | ||
// TODO: Let's uncomment when dark mode is ready | ||
// useDetectThemeMode() | ||
useSentry() | ||
useInitializeAcreSdk() | ||
useInitDataFromSdk() | ||
useFetchBTCPriceUSD() | ||
useFetchBTCBalance() | ||
} |
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
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
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
Oops, something went wrong.