-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Depends on: #371 This PR adds support for fetching the deposits in SDK. We must fetch data from both sources tbtc API and Acre subgraph because the tbtc API includes additional `queued` deposits - this means they have not yet been initialized or finalized. The subgraph only indexes initialized and finalized deposits, so we need to combine them.
- Loading branch information
Showing
25 changed files
with
758 additions
and
144 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
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,27 +1,26 @@ | ||
import { useCallback } from "react" | ||
import { setActivities } from "#/store/wallet" | ||
import { logPromiseFailure, subgraphAPI } from "#/utils" | ||
import { useAcreContext } from "#/acre-react/hooks" | ||
import { Activity } from "#/types" | ||
import { DepositStatus } from "@acre-btc/sdk" | ||
import { useAppDispatch } from "../store/useAppDispatch" | ||
import { useWalletContext } from "../useWalletContext" | ||
|
||
// TODO: Use the correct function from SDK | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const calculateEthAddress = (btcAddress: string) => | ||
"0x45e2e415989477ea5450e440405f6ac858019e6b" | ||
|
||
export function useFetchDeposits() { | ||
const dispatch = useAppDispatch() | ||
const { btcAccount } = useWalletContext() | ||
const { acre } = useAcreContext() | ||
|
||
const fetchDeposits = useCallback(async () => { | ||
if (!btcAccount) return | ||
return useCallback(async () => { | ||
if (!acre) return | ||
|
||
// TODO: Use function from the SDK. | ||
const ethAddress = calculateEthAddress(btcAccount.address) | ||
const result = await subgraphAPI.fetchActivityData(ethAddress) | ||
const result: Activity[] = (await acre.staking.getDeposits()).map( | ||
(deposit) => ({ | ||
...deposit, | ||
status: | ||
deposit.status === DepositStatus.Finalized ? "completed" : "pending", | ||
type: "deposit", | ||
}), | ||
) | ||
|
||
dispatch(setActivities(result)) | ||
}, [btcAccount, dispatch]) | ||
|
||
return useCallback(() => logPromiseFailure(fetchDeposits()), [fetchDeposits]) | ||
}, [acre, 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
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 was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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.