From f3512f9205a3cf7c00700c7accb659c75e6344a3 Mon Sep 17 00:00:00 2001 From: michalsmiarowski Date: Mon, 13 Nov 2023 10:04:31 +0100 Subject: [PATCH] Add `removeDepositData` method to our `TBTC` class Adds `removeDepositData` method to our `TBTC` class. This method just removes deposit data form our `this._deposit` property. We will use it just after the reveal and in `useRemoveDepositData` hook. --- src/hooks/tbtc/useRemoveDepositData.ts | 5 ++++- src/threshold-ts/tbtc/index.ts | 12 ++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/hooks/tbtc/useRemoveDepositData.ts b/src/hooks/tbtc/useRemoveDepositData.ts index f12861f15..9c041f306 100644 --- a/src/hooks/tbtc/useRemoveDepositData.ts +++ b/src/hooks/tbtc/useRemoveDepositData.ts @@ -1,4 +1,5 @@ import { useCallback } from "react" +import { useThreshold } from "../../contexts/ThresholdContext" import { useTbtcState } from "../useTbtcState" import { useTBTCDepositDataFromLocalStorage } from "./useTBTCDepositDataFromLocalStorage" @@ -6,9 +7,11 @@ export const useRemoveDepositData = () => { const { resetDepositData } = useTbtcState() const { removeDepositDataFromLocalStorage } = useTBTCDepositDataFromLocalStorage() + const threshold = useThreshold() return useCallback(() => { removeDepositDataFromLocalStorage() resetDepositData() - }, [resetDepositData, removeDepositDataFromLocalStorage]) + threshold.tbtc.removeDepositData() + }, [resetDepositData, removeDepositDataFromLocalStorage, threshold]) } diff --git a/src/threshold-ts/tbtc/index.ts b/src/threshold-ts/tbtc/index.ts index d19f69f01..25ad75b50 100644 --- a/src/threshold-ts/tbtc/index.ts +++ b/src/threshold-ts/tbtc/index.ts @@ -205,6 +205,11 @@ export interface ITBTC { */ initiateDeposit(btcRecoveryAddress: string): Promise + /** + * Removes the deposit data assigned to `this._deposit` property. + */ + removeDepositData(): void + /** * Initiates a deposit object from DepositReceipt object. This will be used * to either initiate deposit object from JSON file or form local storage. @@ -474,8 +479,6 @@ export class TBTC implements ITBTC { this._bitcoinConfig = bitcoinConfig } - // TODO: Remove arguments from this function and just get those values from - // this._ethereumConfig async initializeSdk( providerOrSigner: providers.Provider | Signer, account?: string @@ -567,6 +570,10 @@ export class TBTC implements ITBTC { return this._deposit } + removeDepositData = (): void => { + this._deposit = undefined + } + initiateDepositFromReceipt = async ( depositReceipt: DepositReceipt ): Promise => { @@ -675,6 +682,7 @@ export class TBTC implements ITBTC { const { value, ...transactionOutpoint } = utxo if (!this._deposit) throw new EmptyDepositObjectError() const chainHash = await this._deposit.initiateMinting(transactionOutpoint) + this.removeDepositData() return chainHash.toPrefixedString() }