-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #594 from threshold-network/redemption-details-imp…
…rovements Improve UX in redemption details page Redirect a user to a success step automatically when the redemption is complete. Here we subscribe to the RedemptionsCompleted event and check if this event is related to a given redemption request by checking the wallet public key hash. If yes, we are looking for a Bitcoin transfer to a given redeemer output script in a given bitcoin tx hash (we can get this transaction hash from the RedemptionsCompleted event). If we are able to find that transfer it means this RedemptionsCompleted event is related to a given redemption request and we should redirect user to a success step and update the bridge activity list.
- Loading branch information
Showing
6 changed files
with
201 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { useCallback } from "react" | ||
import { useThreshold } from "../../contexts/ThresholdContext" | ||
import { | ||
createAddressFromOutputScript, | ||
prependScriptPubKeyByLength, | ||
} from "../../threshold-ts/utils" | ||
import { useGetBlock } from "../../web3/hooks" | ||
|
||
export const useFindRedemptionInBitcoinTx = () => { | ||
const threshold = useThreshold() | ||
const getBlock = useGetBlock() | ||
|
||
return useCallback( | ||
async ( | ||
redemptionBitcoinTxHash: string, | ||
redemptionCompletedBlockNumber: number, | ||
redeemerOutputScript: string | ||
) => { | ||
const { outputs } = await threshold.tbtc.getBitcoinTransaction( | ||
redemptionBitcoinTxHash | ||
) | ||
|
||
for (const { scriptPubKey, value } of outputs) { | ||
if ( | ||
prependScriptPubKeyByLength(scriptPubKey.toString()) !== | ||
redeemerOutputScript | ||
) | ||
continue | ||
|
||
const { timestamp: redemptionCompletedTimestamp } = await getBlock( | ||
redemptionCompletedBlockNumber | ||
) | ||
|
||
return { | ||
btcAddress: createAddressFromOutputScript( | ||
scriptPubKey, | ||
threshold.tbtc.bitcoinNetwork | ||
), | ||
receivedAmount: value.toString(), | ||
bitcoinTxHash: redemptionBitcoinTxHash, | ||
redemptionCompletedTimestamp, | ||
} | ||
} | ||
}, | ||
[threshold, getBlock] | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Hex } from "@keep-network/tbtc-v2.ts" | ||
import { Event } from "ethers" | ||
import { useSubscribeToContractEvent } from "../../web3/hooks" | ||
import { useBridgeContract } from "./useBridgeContract" | ||
|
||
type RedemptionsCompletedEventCallback = ( | ||
walletPublicKeyHash: string, | ||
redemptionTxHash: string, | ||
event: Event | ||
) => void | ||
|
||
export const useSubscribeToRedemptionsCompletedEventBase = ( | ||
callback: RedemptionsCompletedEventCallback, | ||
filterParams?: any[], | ||
shouldSubscribeIfUserNotConnected: boolean = false | ||
) => { | ||
const tBTCBridgeContract = useBridgeContract() | ||
|
||
useSubscribeToContractEvent( | ||
tBTCBridgeContract, | ||
"RedemptionsCompleted", | ||
//@ts-ignore | ||
(walletPublicKeyHash, redemptionTxHash, event) => { | ||
callback( | ||
walletPublicKeyHash, | ||
Hex.from(redemptionTxHash).reverse().toString(), | ||
event | ||
) | ||
}, | ||
filterParams, | ||
shouldSubscribeIfUserNotConnected | ||
) | ||
} |
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