Skip to content

Commit

Permalink
Use getDeposits fn from Acre SDK
Browse files Browse the repository at this point in the history
To fetch deposit activities for a given user.
  • Loading branch information
r-czajkowski committed May 15, 2024
1 parent b997cec commit ce5b260
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 53 deletions.
1 change: 0 additions & 1 deletion dapp/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export * from "./store"
export * from "./toasts"
export * from "./sdk"
export * from "./subgraph"
export * from "./useDetectThemeMode"
export * from "./useRequestBitcoinAccount"
export * from "./useWalletContext"
Expand Down
1 change: 1 addition & 0 deletions dapp/src/hooks/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from "./useInitializeAcreSdk"
export * from "./useFetchMinDepositAmount"
export * from "./useInitDataFromSdk"
export * from "./useFetchBTCBalance"
export * from "./useFetchDeposits"
17 changes: 17 additions & 0 deletions dapp/src/hooks/sdk/useFetchDeposits.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useCallback } from "react"
import { setActivities } from "#/store/wallet"
import { useAcreContext } from "#/acre-react/hooks"
import { useAppDispatch } from "../store/useAppDispatch"

export function useFetchDeposits() {
const dispatch = useAppDispatch()
const { acre } = useAcreContext()

return useCallback(async () => {
if (!acre) return

const result = await acre.staking.getDeposits()

dispatch(setActivities(result))
}, [acre, dispatch])
}
13 changes: 13 additions & 0 deletions dapp/src/hooks/sdk/useInitDataFromSdk.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import { useEffect } from "react"
import { logPromiseFailure } from "#/utils"
import { useWalletContext } from "../useWalletContext"
import { useFetchBTCBalance } from "./useFetchBTCBalance"
import { useFetchMinDepositAmount } from "./useFetchMinDepositAmount"
import { useFetchDeposits } from "./useFetchDeposits"

export function useInitDataFromSdk() {
const { btcAccount } = useWalletContext()
const fetchDeposits = useFetchDeposits()

useFetchBTCBalance()
useFetchMinDepositAmount()

useEffect(() => {
if (btcAccount) {
logPromiseFailure(fetchDeposits())
}
}, [btcAccount, fetchDeposits])
}
2 changes: 0 additions & 2 deletions dapp/src/hooks/subgraph/index.ts

This file was deleted.

24 changes: 0 additions & 24 deletions dapp/src/hooks/subgraph/useFetchActivities.ts

This file was deleted.

15 changes: 0 additions & 15 deletions dapp/src/hooks/subgraph/useInitDataFromSubgraph.ts

This file was deleted.

2 changes: 0 additions & 2 deletions dapp/src/hooks/useInitApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useInitDataFromSdk, useInitializeAcreSdk } from "./sdk"
import { useSentry } from "./sentry"
import { useFetchBTCPriceUSD } from "./useFetchBTCPriceUSD"
import { useInitGlobalToasts } from "./toasts/useInitGlobalToasts"
import { useInitDataFromSubgraph } from "./subgraph"

export function useInitApp() {
// TODO: Let's uncomment when dark mode is ready
Expand All @@ -13,5 +12,4 @@ export function useInitApp() {
useInitGlobalToasts()

useInitDataFromSdk()
useInitDataFromSubgraph()
}
4 changes: 2 additions & 2 deletions dapp/src/types/activity.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DepositStatus } from "@acre-btc/sdk"
import { CurrencyType } from "./currency"

// TODO: Update type when subgraph's ready
Expand All @@ -16,6 +17,5 @@ export type ActivityInfo = {
export type Activity = {
txHash: string
amount: bigint
type: "deposit" | "withdraw"
status: "completed" | "pending"
status: DepositStatus
}
1 change: 0 additions & 1 deletion dapp/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ export * from "./toast"
export * from "./core"
export * from "./fee"
export * from "./navigation"
export * from "./subgraphAPI"
6 changes: 0 additions & 6 deletions dapp/src/types/subgraphAPI.ts

This file was deleted.

0 comments on commit ce5b260

Please sign in to comment.