Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deposit history #427

Merged
merged 26 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
660c789
Make the `tbtcApi` public in `Tbtc` module
r-czajkowski May 15, 2024
12857dc
Create `AcreSubgraphApi`
r-czajkowski May 15, 2024
4aab552
Update the `TbtcApi` class
r-czajkowski May 15, 2024
7a261da
Add `getDeposits` to staking module
r-czajkowski May 15, 2024
3e71212
Update the Acre SDK constructor
r-czajkowski May 15, 2024
0d50f6d
Use `getDeposits` fn from Acre SDK
r-czajkowski May 15, 2024
80e7ea4
Remove unnecessary subgraph imports
r-czajkowski May 15, 2024
088062f
Update `getDeposits` fn in staking module
r-czajkowski May 15, 2024
dc23fae
Fix displaying activity items
r-czajkowski May 15, 2024
3e4774a
Update `stake` fn
r-czajkowski May 15, 2024
e5ab117
Add permissions to get XPub
nkuba May 15, 2024
8bf01e0
Update the `Tbtc` module
r-czajkowski May 16, 2024
652ba67
Add unit test for Acre Subgraph API component
r-czajkowski May 22, 2024
f4d3958
Add unit tests for `getDepositsByOwner`
r-czajkowski May 22, 2024
c2518f3
Update unit tests for `Tbtc` module
r-czajkowski May 22, 2024
1c159b7
Add unit tests for `getDeposits`
r-czajkowski May 22, 2024
0677948
Add docs
r-czajkowski May 23, 2024
7e4bd75
Merge branch 'bitcoin-native-experience' into deposit-history
r-czajkowski May 29, 2024
002b241
Update `getDeposits` fn
r-czajkowski May 29, 2024
b0516df
Extract query to a separate function
r-czajkowski May 29, 2024
d3d5413
Remove unused env variable
r-czajkowski May 29, 2024
adf9c36
Update `Activity` type
r-czajkowski May 29, 2024
c92b9f5
Fix linting errors
r-czajkowski May 29, 2024
2820180
Fix `ActivitiesListItem` component
r-czajkowski May 29, 2024
c8c8bbb
Fetch the deposits in interval
r-czajkowski May 29, 2024
ff637eb
Merge branch 'main' into deposit-history
r-czajkowski May 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions dapp/.env
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,5 @@ VITE_REFERRAL=123
# TODO: Pass this value as an environment variable during the build process.
VITE_DEFENDER_RELAYER_WEBHOOK_URL="https://api.defender.openzeppelin.com/actions/a0d6d2e2-ce9c-4619-aa2b-6c874fe97af7/runs/webhook/b1f17c89-8230-46e3-866f-a3213887974c/Sbddsy54cJ6sPg2bLPyuHJ"

VITE_ACRE_SUBGRAPH_URL="https://api.studio.thegraph.com/query/73600/acre/version/latest"

# TODO: Set this env variable in CI.
VITE_TBTC_API_ENDPOINT=""
3 changes: 2 additions & 1 deletion dapp/ledger-manifest-testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"account.list",
"message.sign",
"transaction.sign",
"transaction.signAndBroadcast"
"transaction.signAndBroadcast",
"bitcoin.getXPub"
],
"domains": ["http://*"],
"type": "walletApp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function DepositBTCModal() {
const fetchDeposits = useFetchDeposits()

const onStakeBTCSuccess = useCallback(() => {
fetchDeposits()
logPromiseFailure(fetchDeposits())
dispatch(setStatus(PROCESS_STATUSES.SUCCEEDED))
}, [dispatch, fetchDeposits])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function StakingErrorModal() {
const [isServerError, setIsServerError] = useState(false)

const onStakeBTCSuccess = useCallback(() => {
fetchDeposits()
logPromiseFailure(fetchDeposits())
dispatch(setStatus(PROCESS_STATUSES.SUCCEEDED))
}, [dispatch, fetchDeposits])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,27 @@ type ActivitiesListItemProps = Omit<AlertProps, "status"> &
function ActivitiesListItem(props: ActivitiesListItemProps) {
const { amount, status, txHash, type, handleDismiss, ...restProps } = props

const isCompleted = status === "completed"

return (
<Alert as={HStack} variant="process" {...restProps}>
<AlertIcon
color="brand.400"
as={status === "completed" ? LoadingSpinnerSuccessIcon : Spinner}
as={isCompleted ? LoadingSpinnerSuccessIcon : Spinner}
/>

<VStack flex={1} spacing={0} align="stretch">
<HStack justify="space-between" as={AlertTitle}>
<Text as="span">
{status === "completed"
{isCompleted
? `${type === "withdraw" ? "Unstaking" : "Staking"} completed`
: `${type === "withdraw" ? "Unstaking" : "Staking"}...`}
</Text>

<CurrencyBalance amount={amount} currency="bitcoin" />
</HStack>
<HStack justify="space-between" as={AlertDescription}>
{status === "completed" ? (
{isCompleted ? (
<Button
variant="link"
fontSize="sm"
Expand Down
31 changes: 15 additions & 16 deletions dapp/src/hooks/sdk/useFetchDeposits.ts
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])
}
7 changes: 4 additions & 3 deletions dapp/src/hooks/sdk/useInitDataFromSdk.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { useEffect } from "react"
import { useInterval } from "@chakra-ui/react"
import { ONE_MINUTE_IN_SECONDS, ONE_SEC_IN_MILLISECONDS } from "#/constants"
import { logPromiseFailure } from "#/utils"
import { useWalletContext } from "../useWalletContext"
import { useFetchBTCBalance } from "./useFetchBTCBalance"
import { useFetchMinDepositAmount } from "./useFetchMinDepositAmount"
import { useFetchDeposits } from "./useFetchDeposits"
import { useWalletContext } from "../useWalletContext"

const INTERVAL_TIME = ONE_SEC_IN_MILLISECONDS * ONE_MINUTE_IN_SECONDS * 30

Expand All @@ -14,11 +15,11 @@ export function useInitDataFromSdk() {

useEffect(() => {
if (btcAccount) {
fetchDeposits()
logPromiseFailure(fetchDeposits())
}
}, [btcAccount, fetchDeposits])

useFetchBTCBalance()
useFetchMinDepositAmount()
useInterval(fetchDeposits, INTERVAL_TIME)
kkosiorowska marked this conversation as resolved.
Show resolved Hide resolved
useInterval(() => logPromiseFailure(fetchDeposits()), INTERVAL_TIME)
}
2 changes: 1 addition & 1 deletion dapp/src/types/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export type Activity = {
timestamp: number
txHash: string
amount: bigint
status: Exclude<ActivityInfoStatus, "syncing">
type: "deposit" | "withdraw"
status: "completed" | "pending"
}

export type ActivitiesByIds = {
Expand Down
1 change: 0 additions & 1 deletion dapp/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ export * from "./core"
export * from "./fee"
export * from "./modal"
export * from "./navigation"
export * from "./subgraphAPI"
export * from "./form"
6 changes: 0 additions & 6 deletions dapp/src/types/subgraphAPI.ts

This file was deleted.

1 change: 0 additions & 1 deletion dapp/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ export * from "./promise"
export * from "./exchangeApi"
export * from "./verifyDepositAddress"
export * from "./json"
export * from "./subgraphAPI"
export * from "./activities"
68 changes: 0 additions & 68 deletions dapp/src/utils/subgraphAPI.ts

This file was deleted.

1 change: 0 additions & 1 deletion dapp/src/vite-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ interface ImportMetaEnv {
readonly VITE_ETH_HOSTNAME_HTTP: string
readonly VITE_REFERRAL: number
readonly VITE_TBTC_API_ENDPOINT: string
readonly VITE_ACRE_SUBGRAPH_URL: string
readonly VITE_TBTC_API_ENDPOINT: string
}

Expand Down
12 changes: 11 additions & 1 deletion sdk/src/acre.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Tbtc from "./modules/tbtc"
import { VoidSigner } from "./lib/utils"
import { BitcoinProvider, BitcoinNetwork } from "./lib/bitcoin"
import { getChainIdByNetwork } from "./lib/ethereum/network"
import AcreSubgraphApi from "./lib/api/AcreSubgraphApi"

class Acre {
readonly #tbtc: Tbtc
Expand All @@ -19,21 +20,26 @@ class Acre {

public readonly staking: StakingModule

readonly #acreSubgraph: AcreSubgraphApi

private constructor(
contracts: AcreContracts,
bitcoinProvider: BitcoinProvider,
orangeKit: OrangeKitSdk,
tbtc: Tbtc,
acreSubgraphApi: AcreSubgraphApi,
) {
this.contracts = contracts
this.#tbtc = tbtc
this.#orangeKit = orangeKit
this.#acreSubgraph = acreSubgraphApi
this.#bitcoinProvider = bitcoinProvider
this.staking = new StakingModule(
this.contracts,
this.#bitcoinProvider,
this.#orangeKit,
this.#tbtc,
this.#acreSubgraph,
)
}

Expand Down Expand Up @@ -76,8 +82,12 @@ class Acre {
tbtcApiUrl,
contracts.bitcoinDepositor,
)
const subgraph = new AcreSubgraphApi(
// TODO: Set correct url based on the network
"https://api.studio.thegraph.com/query/73600/acre/version/latest",
)

return new Acre(contracts, bitcoinProvider, orangeKit, tbtc)
return new Acre(contracts, bitcoinProvider, orangeKit, tbtc, subgraph)
}
}

Expand Down
1 change: 1 addition & 0 deletions sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from "./lib/contracts"
export * from "./lib/eip712-signer"
export * from "./lib/ethereum"
export * from "./lib/utils"
export { DepositStatus } from "./lib/api/TbtcApi"

export * from "./modules/staking"

Expand Down
Loading
Loading