Skip to content

Commit

Permalink
feat: add check fee rate function
Browse files Browse the repository at this point in the history
  • Loading branch information
Polybius93 committed Apr 25, 2024
1 parent 8481a66 commit 985b8e8
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/app/hooks/use-bitcoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,19 @@ export function useBitcoin(): UseBitcoinReturnType {
}
}

/**
* Evaluates the fee rate from the bitcoin blockchain API.
*
* @returns The fee rate.
*/
function checkFeeRate(feeRate: number): number {
if (!feeRate || feeRate < 2) {
return 2;
} else {
return feeRate;
}
}

/**
* Fetches the fee rate from the bitcoin blockchain API.
*
Expand All @@ -173,11 +186,9 @@ export function useBitcoin(): UseBitcoinReturnType {
throw new BitcoinError(`Error parsing Bitcoin Blockchain Fee Rate Response JSON: ${error}`);
}

if (bitcoinNetworkName === 'regtest' && (!feeRates.fastestFee || feeRates.fastestFee < 2)) {
return 2;
}
const feeRate = checkFeeRate(feeRates.fastestFee);

return feeRates.fastestFee;
return feeRate;
}

/**
Expand Down

0 comments on commit 985b8e8

Please sign in to comment.