Skip to content

Commit

Permalink
Add removeDepositData method to our TBTC class
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
michalsmiarowski committed Nov 13, 2023
1 parent 1ce6350 commit f3512f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/hooks/tbtc/useRemoveDepositData.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { useCallback } from "react"
import { useThreshold } from "../../contexts/ThresholdContext"
import { useTbtcState } from "../useTbtcState"
import { useTBTCDepositDataFromLocalStorage } from "./useTBTCDepositDataFromLocalStorage"

export const useRemoveDepositData = () => {
const { resetDepositData } = useTbtcState()
const { removeDepositDataFromLocalStorage } =
useTBTCDepositDataFromLocalStorage()
const threshold = useThreshold()

return useCallback(() => {
removeDepositDataFromLocalStorage()
resetDepositData()
}, [resetDepositData, removeDepositDataFromLocalStorage])
threshold.tbtc.removeDepositData()
}, [resetDepositData, removeDepositDataFromLocalStorage, threshold])
}
12 changes: 10 additions & 2 deletions src/threshold-ts/tbtc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ export interface ITBTC {
*/
initiateDeposit(btcRecoveryAddress: string): Promise<Deposit>

/**
* 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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -567,6 +570,10 @@ export class TBTC implements ITBTC {
return this._deposit
}

removeDepositData = (): void => {
this._deposit = undefined
}

initiateDepositFromReceipt = async (
depositReceipt: DepositReceipt
): Promise<Deposit> => {
Expand Down Expand Up @@ -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()
}
Expand Down

0 comments on commit f3512f9

Please sign in to comment.