From d07b1039c5b80ed2c1fe5479564b569f4eccca8d Mon Sep 17 00:00:00 2001 From: Rafal Czajkowski Date: Wed, 12 Jul 2023 16:50:10 +0200 Subject: [PATCH] Update `useFetchRedemptionDetails` hook Convert the `scriptPubKey` placed on the output of a Bitcoin trransaction to a Bitcoin address. We want to display the Bitcoin address in UI instead of the output script. --- src/hooks/tbtc/useFetchRedemptionDetails.ts | 13 +++++++++---- src/threshold-ts/utils/bitcoin.ts | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/hooks/tbtc/useFetchRedemptionDetails.ts b/src/hooks/tbtc/useFetchRedemptionDetails.ts index cc1d49ddd..fe69cb393 100644 --- a/src/hooks/tbtc/useFetchRedemptionDetails.ts +++ b/src/hooks/tbtc/useFetchRedemptionDetails.ts @@ -1,7 +1,10 @@ import { useEffect, useState } from "react" import { useThreshold } from "../../contexts/ThresholdContext" -import { prependScriptPubKeyByLength } from "../../threshold-ts/utils" -import { isValidType } from "../../threshold-ts/utils/chain" +import { + createAddressFromOutputScript, + prependScriptPubKeyByLength, + isValidType, +} from "../../threshold-ts/utils" import { useGetBlock } from "../../web3/hooks" import { isEmptyOrZeroAddress } from "../../web3/utils" @@ -206,8 +209,10 @@ export const useFetchRedemptionDetails = ( requestedAt: redemptionRequestedEventTimestamp, completedAt: redemptionCompletedTimestamp, isTimedOut: false, - // TODO: convert the `scriptPubKey` to address. - btcAddress: "2Mzs2YNphdHmBoE7SE77cGB57JBXveNGtae", + btcAddress: createAddressFromOutputScript( + scriptPubKey, + threshold.tbtc.bitcoinNetwork + ), }) return diff --git a/src/threshold-ts/utils/bitcoin.ts b/src/threshold-ts/utils/bitcoin.ts index e25e11cdd..a0bd2e61a 100644 --- a/src/threshold-ts/utils/bitcoin.ts +++ b/src/threshold-ts/utils/bitcoin.ts @@ -3,6 +3,7 @@ import { TransactionHash } from "@keep-network/tbtc-v2.ts/dist/src/bitcoin" export { computeHash160, createOutputScriptFromAddress, + createAddressFromOutputScript, } from "@keep-network/tbtc-v2.ts/dist/src/bitcoin" import { toBcoinNetwork } from "@keep-network/tbtc-v2.ts/dist/src/bitcoin-network" import {