-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into bitcoin-redeemer-2
- Loading branch information
Showing
31 changed files
with
202 additions
and
74 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
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
File renamed without changes.
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,2 +1,4 @@ | ||
export * from "./useAppDispatch" | ||
export * from "./useAppSelector" | ||
export * from "./useEstimatedBTCBalance" | ||
export * from "./useSharesBalance" |
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 { selectEstimatedBtcBalance } from "#/store/btc" | ||
import { useAppSelector } from "./useAppSelector" | ||
|
||
export function useEstimatedBTCBalance() { | ||
return useAppSelector(selectEstimatedBtcBalance) | ||
} |
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 { selectSharesBalance } from "#/store/btc" | ||
import { useAppSelector } from "./useAppSelector" | ||
|
||
export function useSharesBalance() { | ||
return useAppSelector(selectSharesBalance) | ||
} |
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,28 @@ | ||
import { useEffect } from "react" | ||
import { EthereumAddress } from "@acre-btc/sdk" | ||
import { useAcreContext } from "#/acre-react/hooks" | ||
import { logPromiseFailure } from "#/utils" | ||
import { setEstimatedBtcBalance, setSharesBalance } from "#/store/btc" | ||
import { useWalletContext } from "./useWalletContext" | ||
import { useAppDispatch } from "./store" | ||
|
||
export function useFetchBTCBalance() { | ||
const { acre, isInitialized } = useAcreContext() | ||
const { ethAccount } = useWalletContext() | ||
const dispatch = useAppDispatch() | ||
|
||
useEffect(() => { | ||
const getBtcBalance = async () => { | ||
if (!isInitialized || !ethAccount || !acre) return | ||
|
||
const chainIdentifier = EthereumAddress.from(ethAccount.address) | ||
const sharesBalance = await acre.staking.sharesBalance(chainIdentifier) | ||
const estimatedBitcoinBalance = | ||
await acre.staking.estimatedBitcoinBalance(chainIdentifier) | ||
|
||
dispatch(setSharesBalance(sharesBalance)) | ||
dispatch(setEstimatedBtcBalance(estimatedBitcoinBalance)) | ||
} | ||
logPromiseFailure(getBtcBalance()) | ||
}, [acre, isInitialized, ethAccount, dispatch]) | ||
} |
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,13 @@ | ||
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() | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
import { RootState } from ".." | ||
|
||
export const selectBtcUsdPrice = (state: RootState) => state.btc.usdPrice | ||
export const selectEstimatedBtcBalance = (state: RootState): bigint => | ||
state.btc.estimatedBtcBalance | ||
export const selectSharesBalance = (state: RootState): bigint => | ||
state.btc.sharesBalance | ||
export const selectBtcUsdPrice = (state: RootState): number => | ||
state.btc.usdPrice |
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.