From 660c789a605af1681b2f893189a6f825d66c1b31 Mon Sep 17 00:00:00 2001 From: Rafal Czajkowski Date: Wed, 15 May 2024 18:05:10 +0200 Subject: [PATCH 01/24] Make the `tbtcApi` public in `Tbtc` module We are going to use the `tbtcApi` in other modules. --- sdk/src/modules/tbtc/Tbtc.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/src/modules/tbtc/Tbtc.ts b/sdk/src/modules/tbtc/Tbtc.ts index 6e0782c79..a96de07a5 100644 --- a/sdk/src/modules/tbtc/Tbtc.ts +++ b/sdk/src/modules/tbtc/Tbtc.ts @@ -11,7 +11,7 @@ import { IEthereumSignerCompatibleWithEthersV5 as EthereumSignerCompatibleWithEt * Represents the tBTC module. */ export default class Tbtc { - readonly #tbtcApi: TbtcApi + public readonly tbtcApi: TbtcApi readonly #tbtcSdk: TbtcSdk @@ -22,7 +22,7 @@ export default class Tbtc { tbtcSdk: TbtcSdk, bitcoinDepositor: BitcoinDepositor, ) { - this.#tbtcApi = tbtcApi + this.tbtcApi = tbtcApi this.#tbtcSdk = tbtcSdk this.#bitcoinDepositor = bitcoinDepositor } @@ -105,10 +105,10 @@ export default class Tbtc { application: "acre", } - const revealSaved: boolean = await this.#tbtcApi.saveReveal(revealData) + const revealSaved: boolean = await this.tbtcApi.saveReveal(revealData) if (!revealSaved) throw new Error("Reveal not saved properly in the database") - return new Deposit(this.#tbtcApi, tbtcDeposit, revealData) + return new Deposit(this.tbtcApi, tbtcDeposit, revealData) } } From 12857dc605f1b58075fd57b0c323c02ec7b98993 Mon Sep 17 00:00:00 2001 From: Rafal Czajkowski Date: Wed, 15 May 2024 18:10:08 +0200 Subject: [PATCH 02/24] Create `AcreSubgraphApi` And expose the `getDepositsByOwner` function that returns all deposits for a given depositor. --- sdk/src/lib/api/AcreSubgraphApi.ts | 79 ++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 sdk/src/lib/api/AcreSubgraphApi.ts diff --git a/sdk/src/lib/api/AcreSubgraphApi.ts b/sdk/src/lib/api/AcreSubgraphApi.ts new file mode 100644 index 000000000..ad67f9aae --- /dev/null +++ b/sdk/src/lib/api/AcreSubgraphApi.ts @@ -0,0 +1,79 @@ +import { ChainIdentifier } from "@keep-network/tbtc-v2.ts" +import HttpApi from "./HttpApi" +import { DepositStatus } from "./TbtcApi" + +type DepositDataResponse = { + data: { + deposits: { + id: string + bitcoinTransactionId: string + amountToDeposit: string + initialDepositAmount: string + events: { type: "Initialized" | "Finalized" }[] + }[] + } +} + +type Deposit = { + depositKey: string + txHash: string + amount: bigint + status: DepositStatus +} + +export default class AcreSubgraphApi extends HttpApi { + async getDepositsByOwner( + depositOwnerId: ChainIdentifier, + ): Promise { + const query = ` + query { + deposits( + where: {depositOwner_: {id: "0x${depositOwnerId.identifierHex}"}} + ) { + id + bitcoinTransactionId + initialDepositAmount + events { + type + } + amountToDeposit + } + }` + const response = await this.postRequest( + "", + { query }, + { credentials: undefined }, + ) + + if (!response.ok) { + throw new Error( + `Could not get deposits by deposit owner: ${response.status}`, + ) + } + + const responseData = (await response.json()) as DepositDataResponse + + return responseData.data.deposits.map((deposit) => { + const { + bitcoinTransactionId: txHash, + amountToDeposit, + initialDepositAmount, + events, + id, + } = deposit + + // The subgraph indexes only initialized or finalized deposits. + const status = events.some(({ type }) => type === "Finalized") + ? DepositStatus.Finalized + : DepositStatus.Initialized + + return { + depositKey: id, + txHash, + amount: BigInt(amountToDeposit ?? initialDepositAmount), + type: "deposit", + status, + } + }) + } +} From 4aab552b0e4954f6b2c6730464dc4d9e41f4b052 Mon Sep 17 00:00:00 2001 From: Rafal Czajkowski Date: Wed, 15 May 2024 18:11:01 +0200 Subject: [PATCH 03/24] Update the `TbtcApi` class Expose the `getDepositsByOwner` function that returns all deposits for a given deposit. The main difference between this function and from `AcreSubgraphApi` class is that tbtc api stores queued deposits - this means they have not yet been initialized or finalized. Subgraph only indexes initialized or finalized deposits. --- sdk/src/lib/api/TbtcApi.ts | 52 +++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/sdk/src/lib/api/TbtcApi.ts b/sdk/src/lib/api/TbtcApi.ts index a64c3b9fa..54579dcf0 100644 --- a/sdk/src/lib/api/TbtcApi.ts +++ b/sdk/src/lib/api/TbtcApi.ts @@ -1,5 +1,31 @@ -import { BitcoinTxHash, BitcoinTxOutpoint } from "@keep-network/tbtc-v2.ts" +import { + BitcoinTxHash, + BitcoinTxOutpoint, + ChainIdentifier, +} from "@keep-network/tbtc-v2.ts" +import { ethers } from "ethers" import HttpApi from "./HttpApi" +import { Hex } from "../utils" + +type Deposit = { + id: string + depositKey: string + createdAt: number + outputIndex: number + owner: string + receipt: { + blindingFactor: string + depositor: string + extraData: string + refundLocktime: string + refundPublicKeyHash: string + walletPublicKeyHash: string + } + referral: number + status: DepositStatus + txHash: string + initialAmount: NumberType +} /** * Represents a class for integration with tBTC API. @@ -51,6 +77,30 @@ export default class TbtcApi extends HttpApi { }, } } + + async getDepositsByOwner( + depositOwner: ChainIdentifier, + ): Promise[]> { + const response = await this.getRequest( + `deposits/${depositOwner.identifierHex}`, + ) + if (!response.ok) + throw new Error(`Failed to fetch deposits: ${response.status}`) + + const responseData = (await response.json()) as Deposit[] + + return responseData.map((deposit) => ({ + ...deposit, + initialAmount: BigInt(deposit.initialAmount), + depositKey: ethers.solidityPackedKeccak256( + ["bytes32", "uint32"], + [ + Hex.from(deposit.txHash).reverse().toPrefixedString(), + deposit.outputIndex, + ], + ), + })) + } } /** From 7a261daafb1d23fb43bdee1c5bd09b9f0084bbbe Mon Sep 17 00:00:00 2001 From: Rafal Czajkowski Date: Wed, 15 May 2024 18:15:34 +0200 Subject: [PATCH 04/24] Add `getDeposits` to staking module Add function that returns all deposits - `queued`, `initialized` and `finalized` for a given depositor. Depositor address is created besed on the bitcoin address returned by `BitcoinProvider`. --- sdk/src/modules/staking/index.ts | 48 ++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/sdk/src/modules/staking/index.ts b/sdk/src/modules/staking/index.ts index 1ecead708..62d081e5e 100644 --- a/sdk/src/modules/staking/index.ts +++ b/sdk/src/modules/staking/index.ts @@ -5,6 +5,8 @@ import { StakeInitialization } from "./stake-initialization" import { fromSatoshi, toSatoshi } from "../../lib/utils" import Tbtc from "../tbtc" import { BitcoinProvider } from "../../lib/bitcoin/providers" +import AcreSubgraphApi from "../../lib/api/AcreSubgraphApi" +import { DepositStatus } from "../../lib/api/TbtcApi" export { DepositReceipt } from "../tbtc" @@ -41,16 +43,20 @@ class StakingModule { */ readonly #orangeKit: OrangeKitSdk + readonly #acreSubgraphApi: AcreSubgraphApi + constructor( _contracts: AcreContracts, _bitcoinProvider: BitcoinProvider, _orangeKit: OrangeKitSdk, _tbtc: Tbtc, + acreSubgraphApi: AcreSubgraphApi, ) { this.#contracts = _contracts this.#bitcoinProvider = _bitcoinProvider this.#tbtc = _tbtc this.#orangeKit = _orangeKit + this.#acreSubgraphApi = acreSubgraphApi } /** @@ -156,6 +162,48 @@ class StakingModule { const value = await this.#contracts.bitcoinDepositor.minDepositAmount() return toSatoshi(value) } + + async getDeposits(): Promise< + { + id: string + txHash: string + amount: bigint + status: DepositStatus + }[] + > { + const bitcoinAddress = await this.#bitcoinProvider.getAddress() + + const depositOwnerEvmAddress = EthereumAddress.from( + await this.#orangeKit.predictAddress(bitcoinAddress), + ) + + const subgraphData = await this.#acreSubgraphApi.getDepositsByOwner( + depositOwnerEvmAddress, + ) + + const initializedOrFinalizedDepositsMap = new Map( + subgraphData.map((data) => [data.depositKey, data]), + ) + + const tbtcData = await this.#tbtc.tbtcApi.getDepositsByOwner( + depositOwnerEvmAddress, + ) + + return tbtcData.map((deposit) => { + const depositFromSubgraph = initializedOrFinalizedDepositsMap.get( + deposit.depositKey, + ) + + const amount = depositFromSubgraph?.amount ?? deposit.initialAmount + + return { + id: deposit.depositKey, + txHash: deposit.txHash, + amount, + status: deposit.status, + } + }) + } } export { StakingModule, StakeInitialization } From 3e712129bd875c8c6cbaf559418040adb1485aeb Mon Sep 17 00:00:00 2001 From: Rafal Czajkowski Date: Wed, 15 May 2024 18:18:39 +0200 Subject: [PATCH 05/24] Update the Acre SDK constructor Add Acre subgraph api - used to fetch deposits data. --- sdk/src/acre.ts | 12 +++++++++++- sdk/src/index.ts | 1 + sdk/test/modules/staking.test.ts | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/sdk/src/acre.ts b/sdk/src/acre.ts index 0d1057fab..e586c34cd 100644 --- a/sdk/src/acre.ts +++ b/sdk/src/acre.ts @@ -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 @@ -19,21 +20,26 @@ class Acre { public readonly staking: StakingModule + readonly #acreSubgraph: AcreSubgraphApi + 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, ) } @@ -99,8 +105,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) } } diff --git a/sdk/src/index.ts b/sdk/src/index.ts index aa6eb58a0..526aa4936 100644 --- a/sdk/src/index.ts +++ b/sdk/src/index.ts @@ -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" diff --git a/sdk/test/modules/staking.test.ts b/sdk/test/modules/staking.test.ts index e70a42be0..c58148928 100644 --- a/sdk/test/modules/staking.test.ts +++ b/sdk/test/modules/staking.test.ts @@ -15,6 +15,7 @@ import { MockOrangeKitSdk } from "../utils/mock-orangekit" import { MockTbtc } from "../utils/mock-tbtc" import { DepositReceipt } from "../../src/modules/tbtc" import { MockBitcoinProvider } from "../utils/mock-bitcoin-provider" +import AcreSubgraphApi from "../../src/lib/api/AcreSubgraphApi" const stakingModuleData: { initializeDeposit: { @@ -118,6 +119,7 @@ describe("Staking", () => { // 'MockOrangeKitSdk' but required in type 'OrangeKitSdk'. orangeKit, tbtc, + {} as AcreSubgraphApi, ) describe("initializeStake", () => { From 0d50f6df5cf454e28bcfbda1a08daf86ff45967c Mon Sep 17 00:00:00 2001 From: Rafal Czajkowski Date: Wed, 15 May 2024 18:28:18 +0200 Subject: [PATCH 06/24] Use `getDeposits` fn from Acre SDK To fetch deposit activities for a given user. --- dapp/src/hooks/index.ts | 1 - dapp/src/hooks/sdk/index.ts | 1 + dapp/src/hooks/sdk/useFetchDeposits.ts | 17 +++++++++++++ dapp/src/hooks/sdk/useInitDataFromSdk.ts | 13 ++++++++++ dapp/src/hooks/subgraph/index.ts | 2 -- dapp/src/hooks/subgraph/useFetchActivities.ts | 24 ------------------- .../hooks/subgraph/useInitDataFromSubgraph.ts | 15 ------------ dapp/src/hooks/useInitApp.ts | 2 -- dapp/src/types/activity.ts | 4 ++-- dapp/src/types/index.ts | 1 - dapp/src/types/subgraphAPI.ts | 6 ----- 11 files changed, 33 insertions(+), 53 deletions(-) create mode 100644 dapp/src/hooks/sdk/useFetchDeposits.ts delete mode 100644 dapp/src/hooks/subgraph/index.ts delete mode 100644 dapp/src/hooks/subgraph/useFetchActivities.ts delete mode 100644 dapp/src/hooks/subgraph/useInitDataFromSubgraph.ts delete mode 100644 dapp/src/types/subgraphAPI.ts diff --git a/dapp/src/hooks/index.ts b/dapp/src/hooks/index.ts index 1c76c1c40..07fdc9e97 100644 --- a/dapp/src/hooks/index.ts +++ b/dapp/src/hooks/index.ts @@ -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" diff --git a/dapp/src/hooks/sdk/index.ts b/dapp/src/hooks/sdk/index.ts index 8d103f71e..19ff52a00 100644 --- a/dapp/src/hooks/sdk/index.ts +++ b/dapp/src/hooks/sdk/index.ts @@ -2,3 +2,4 @@ export * from "./useInitializeAcreSdk" export * from "./useFetchMinDepositAmount" export * from "./useInitDataFromSdk" export * from "./useFetchBTCBalance" +export * from "./useFetchDeposits" diff --git a/dapp/src/hooks/sdk/useFetchDeposits.ts b/dapp/src/hooks/sdk/useFetchDeposits.ts new file mode 100644 index 000000000..cbb5c8d89 --- /dev/null +++ b/dapp/src/hooks/sdk/useFetchDeposits.ts @@ -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]) +} diff --git a/dapp/src/hooks/sdk/useInitDataFromSdk.ts b/dapp/src/hooks/sdk/useInitDataFromSdk.ts index 56ade2b6a..ce82aeda7 100644 --- a/dapp/src/hooks/sdk/useInitDataFromSdk.ts +++ b/dapp/src/hooks/sdk/useInitDataFromSdk.ts @@ -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]) } diff --git a/dapp/src/hooks/subgraph/index.ts b/dapp/src/hooks/subgraph/index.ts deleted file mode 100644 index 5c9d3646c..000000000 --- a/dapp/src/hooks/subgraph/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./useInitDataFromSubgraph" -export * from "./useFetchActivities" diff --git a/dapp/src/hooks/subgraph/useFetchActivities.ts b/dapp/src/hooks/subgraph/useFetchActivities.ts deleted file mode 100644 index 055099c01..000000000 --- a/dapp/src/hooks/subgraph/useFetchActivities.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { useCallback } from "react" -import { subgraphAPI } from "#/utils" -import { setActivities } from "#/store/wallet" -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) => - "0x4c9e39e5ff458a811708c03aea21b8327118cf13" - -export function useFetchActivities() { - const dispatch = useAppDispatch() - const { btcAccount } = useWalletContext() - - return useCallback(async () => { - if (!btcAccount) return - - const ethAddress = calculateEthAddress(btcAccount.address) - const result = await subgraphAPI.fetchActivityData(ethAddress) - - dispatch(setActivities(result)) - }, [btcAccount, dispatch]) -} diff --git a/dapp/src/hooks/subgraph/useInitDataFromSubgraph.ts b/dapp/src/hooks/subgraph/useInitDataFromSubgraph.ts deleted file mode 100644 index 8272b6fa7..000000000 --- a/dapp/src/hooks/subgraph/useInitDataFromSubgraph.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { useEffect } from "react" -import { logPromiseFailure } from "#/utils" -import { useFetchActivities } from "./useFetchActivities" -import { useWalletContext } from "../useWalletContext" - -export function useInitDataFromSubgraph() { - const { btcAccount } = useWalletContext() - const fetchActivities = useFetchActivities() - - useEffect(() => { - if (btcAccount) { - logPromiseFailure(fetchActivities()) - } - }, [btcAccount, fetchActivities]) -} diff --git a/dapp/src/hooks/useInitApp.ts b/dapp/src/hooks/useInitApp.ts index bfae3073c..0aa050d5f 100644 --- a/dapp/src/hooks/useInitApp.ts +++ b/dapp/src/hooks/useInitApp.ts @@ -1,7 +1,6 @@ import { useInitDataFromSdk, useInitializeAcreSdk } from "./sdk" import { useSentry } from "./sentry" import { useFetchBTCPriceUSD } from "./useFetchBTCPriceUSD" -import { useInitDataFromSubgraph } from "./subgraph" export function useInitApp() { // TODO: Let's uncomment when dark mode is ready @@ -13,5 +12,4 @@ export function useInitApp() { // useInitGlobalToasts() useInitDataFromSdk() - useInitDataFromSubgraph() } diff --git a/dapp/src/types/activity.ts b/dapp/src/types/activity.ts index 20899dacc..e6fc1b8c9 100644 --- a/dapp/src/types/activity.ts +++ b/dapp/src/types/activity.ts @@ -1,3 +1,4 @@ +import { DepositStatus } from "@acre-btc/sdk" import { CurrencyType } from "./currency" // TODO: Update type when subgraph's ready @@ -16,6 +17,5 @@ export type ActivityInfo = { export type Activity = { txHash: string amount: bigint - type: "deposit" | "withdraw" - status: "completed" | "pending" + status: DepositStatus } diff --git a/dapp/src/types/index.ts b/dapp/src/types/index.ts index 3e2a9719f..78494ddc4 100644 --- a/dapp/src/types/index.ts +++ b/dapp/src/types/index.ts @@ -17,5 +17,4 @@ export * from "./core" export * from "./fee" export * from "./modal" export * from "./navigation" -export * from "./subgraphAPI" export * from "./form" diff --git a/dapp/src/types/subgraphAPI.ts b/dapp/src/types/subgraphAPI.ts deleted file mode 100644 index 508d879d3..000000000 --- a/dapp/src/types/subgraphAPI.ts +++ /dev/null @@ -1,6 +0,0 @@ -export type ActivityDataResponse = { - id: string - bitcoinTransactionId: string - amountToDeposit: string - events: { type: "Initialized" | "Finalized" }[] -} From 80e7ea4efee0657a1dcf654ddffdc2ae6ef0a97d Mon Sep 17 00:00:00 2001 From: Rafal Czajkowski Date: Wed, 15 May 2024 18:57:28 +0200 Subject: [PATCH 07/24] Remove unnecessary subgraph imports --- dapp/src/utils/index.ts | 1 - dapp/src/utils/subgraphAPI.ts | 58 ----------------------------------- 2 files changed, 59 deletions(-) delete mode 100644 dapp/src/utils/subgraphAPI.ts diff --git a/dapp/src/utils/index.ts b/dapp/src/utils/index.ts index 2209a949f..36f75497e 100644 --- a/dapp/src/utils/index.ts +++ b/dapp/src/utils/index.ts @@ -9,4 +9,3 @@ export * from "./promise" export * from "./exchangeApi" export * from "./verifyDepositAddress" export * from "./json" -export * from "./subgraphAPI" diff --git a/dapp/src/utils/subgraphAPI.ts b/dapp/src/utils/subgraphAPI.ts deleted file mode 100644 index 3737b02e4..000000000 --- a/dapp/src/utils/subgraphAPI.ts +++ /dev/null @@ -1,58 +0,0 @@ -import axios from "axios" -import { Activity, ActivityDataResponse } from "#/types" - -const ACRE_SUBGRAPH_URL = import.meta.env.VITE_ACRE_SUBGRAPH_URL - -const mapToActivity = (activityData: ActivityDataResponse): Activity => { - const { bitcoinTransactionId: txHash, amountToDeposit, events } = activityData - - const status = events.some(({ type }) => type === "Finalized") - ? "completed" - : "pending" - - return { - txHash, - amount: BigInt(amountToDeposit), - type: "deposit", - status, - } -} - -// TODO: Fetch transactions for withdrawals -/** - * Returns the activities for a given account. - * @param account The Ethereum address for which the activities will be fetched. - */ -async function fetchActivityData(account: string): Promise { - const response = await axios.post<{ - errors?: unknown - data: { activityDatas: ActivityDataResponse[] } - }>(ACRE_SUBGRAPH_URL, { - query: `query { - activityDatas( - where: {depositOwner_: {id: "${account}"}} - ) { - id - bitcoinTransactionId - events { - type - } - ... on Deposit { - amountToDeposit - } - } - }`, - }) - - if (response.data && response.data.errors) { - const errorMsg = "Failed to fetch data from Acre subgraph API." - console.error(errorMsg, response.data.errors) - throw new Error(errorMsg) - } - - return response.data.data.activityDatas.map(mapToActivity) -} - -export const subgraphAPI = { - fetchActivityData, -} From 088062fee98f52686ce3bab611b7b4b160ff82ee Mon Sep 17 00:00:00 2001 From: Rafal Czajkowski Date: Wed, 15 May 2024 19:02:42 +0200 Subject: [PATCH 08/24] Update `getDeposits` fn in staking module Return amount in satoshi precision. --- sdk/src/modules/staking/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sdk/src/modules/staking/index.ts b/sdk/src/modules/staking/index.ts index 62d081e5e..ac0f95797 100644 --- a/sdk/src/modules/staking/index.ts +++ b/sdk/src/modules/staking/index.ts @@ -194,7 +194,9 @@ class StakingModule { deposit.depositKey, ) - const amount = depositFromSubgraph?.amount ?? deposit.initialAmount + const amount = toSatoshi( + depositFromSubgraph?.amount ?? deposit.initialAmount, + ) return { id: deposit.depositKey, From dc23faef0e88eb273d2922e46fff0affa44d3b53 Mon Sep 17 00:00:00 2001 From: Rafal Czajkowski Date: Wed, 15 May 2024 19:03:21 +0200 Subject: [PATCH 09/24] Fix displaying activity items --- .../components/shared/ActivitiesList/ActivitiesList.tsx | 2 +- .../shared/ActivitiesList/ActivitiesListItem.tsx | 9 ++++++--- dapp/src/types/activity.ts | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/dapp/src/components/shared/ActivitiesList/ActivitiesList.tsx b/dapp/src/components/shared/ActivitiesList/ActivitiesList.tsx index 755d2857f..79b2ef852 100644 --- a/dapp/src/components/shared/ActivitiesList/ActivitiesList.tsx +++ b/dapp/src/components/shared/ActivitiesList/ActivitiesList.tsx @@ -26,7 +26,7 @@ function ActivitiesList(props: ListProps) { return activities.length > 0 ? ( {activities.map((item) => ( - + {!dismissedActivities.includes(item.txHash) && ( & function ActivitiesListItem(props: ActivitiesListItemProps) { const { amount, status, txHash, type, handleDismiss, ...restProps } = props + const isCompleted = status === DepositStatus.Finalized + return ( - {status === "completed" + {isCompleted ? `${type === "withdraw" ? "Unstaking" : "Staking"} completed` : `${type === "withdraw" ? "Unstaking" : "Staking"}...`} @@ -43,7 +46,7 @@ function ActivitiesListItem(props: ActivitiesListItemProps) { - {status === "completed" ? ( + {isCompleted ? (