|
3 | 3 |
|
4 | 4 | import { SWError } from '@subwallet/extension-base/background/errors/SWError';
|
5 | 5 | import { _BEAR_TOKEN } from '@subwallet/extension-base/services/chain-service/constants';
|
6 |
| -import { BitcoinAddressSummaryInfo, BlockStreamBlock, BlockStreamFeeEstimates, BlockStreamTransactionDetail, BlockStreamTransactionStatus, Brc20BalanceItem, Inscription, InscriptionFetchedData, RunesInfoByAddress, RunesInfoByAddressFetchedData, RuneTxs, RuneTxsResponse, UpdateOpenBitUtxo } from '@subwallet/extension-base/services/chain-service/handler/bitcoin/strategy/BlockStream/types'; |
| 6 | +import { BitcoinAddressSummaryInfo, BlockStreamBlock, BlockStreamFeeEstimates, BlockStreamTransactionDetail, BlockStreamTransactionStatus, Brc20BalanceItem, Inscription, InscriptionFetchedData, RecommendedFeeEstimates, RunesInfoByAddress, RunesInfoByAddressFetchedData, RuneTxs, RuneTxsResponse, UpdateOpenBitUtxo } from '@subwallet/extension-base/services/chain-service/handler/bitcoin/strategy/BlockStream/types'; |
7 | 7 | import { BitcoinApiStrategy, BitcoinTransactionEventMap } from '@subwallet/extension-base/services/chain-service/handler/bitcoin/strategy/types';
|
8 | 8 | import { OBResponse } from '@subwallet/extension-base/services/chain-service/types';
|
9 | 9 | import { HiroService } from '@subwallet/extension-base/services/hiro-service';
|
@@ -150,6 +150,38 @@ export class BlockStreamRequestStrategy extends BaseApiRequestStrategy implement
|
150 | 150 | }, 0);
|
151 | 151 | }
|
152 | 152 |
|
| 153 | + getRecommendedFeeRate (): Promise<BitcoinFeeInfo> { |
| 154 | + return this.addRequest<BitcoinFeeInfo>(async (): Promise<BitcoinFeeInfo> => { |
| 155 | + const _rs = await getRequest(this.getUrl('fee-estimates/recommended'), undefined, this.headers); |
| 156 | + const rs = await _rs.json() as OBResponse<RecommendedFeeEstimates>; |
| 157 | + |
| 158 | + if (rs.status_code !== 200) { |
| 159 | + throw new SWError('BlockStreamRequestStrategy.getRecommendedFeeRate', rs.message); |
| 160 | + } |
| 161 | + |
| 162 | + const result = rs.result; |
| 163 | + |
| 164 | + const convertTimeMilisec = { |
| 165 | + fastestFee: 10 * 60000, |
| 166 | + halfHourFee: 30 * 60000, |
| 167 | + hourFee: 60 * 60000 |
| 168 | + }; |
| 169 | + |
| 170 | + const convertFee = (fee: number) => parseInt(new BigN(fee).toFixed()); |
| 171 | + |
| 172 | + return { |
| 173 | + type: 'bitcoin', |
| 174 | + busyNetwork: false, |
| 175 | + options: { |
| 176 | + slow: { feeRate: convertFee(result.hourFee), time: convertTimeMilisec.hourFee }, |
| 177 | + average: { feeRate: convertFee(result.halfHourFee), time: convertTimeMilisec.halfHourFee }, |
| 178 | + fast: { feeRate: convertFee(result.fastestFee), time: convertTimeMilisec.fastestFee }, |
| 179 | + default: 'slow' |
| 180 | + } |
| 181 | + }; |
| 182 | + }, 0); |
| 183 | + } |
| 184 | + |
153 | 185 | getUtxos (address: string): Promise<UtxoResponseItem[]> {
|
154 | 186 | return this.addRequest<UtxoResponseItem[]>(async (): Promise<UtxoResponseItem[]> => {
|
155 | 187 | const _rs = await getRequest(this.getUrl(`address/${address}/utxo`), undefined, this.headers);
|
|
0 commit comments