mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-02-21 14:34:55 +01:00
REF: estimates
This commit is contained in:
parent
1ab763ffeb
commit
b0dd59f269
3 changed files with 25 additions and 0 deletions
|
@ -3,6 +3,7 @@ import { AppStorage } from './class';
|
|||
const ElectrumClient = require('electrum-client');
|
||||
let bitcoin = require('bitcoinjs-lib');
|
||||
let reverse = require('buffer-reverse');
|
||||
let BigNumber = require('bignumber.js');
|
||||
|
||||
const storageKey = 'ELECTRUM_PEERS';
|
||||
const defaultPeer = { host: 'electrum1.bluewallet.io', tcp: '50001' };
|
||||
|
@ -351,6 +352,25 @@ module.exports.estimateFees = async function() {
|
|||
return { fast, medium, slow };
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the estimated transaction fee to be confirmed within a certain number of blocks
|
||||
*
|
||||
* @param numberOfBlocks {number} The number of blocks to target for confirmation
|
||||
* @returns {Promise<number>} Satoshis per byte
|
||||
*/
|
||||
module.exports.estimateFee = async function(numberOfBlocks) {
|
||||
if (!mainClient) throw new Error('Electrum client is not connected');
|
||||
numberOfBlocks = numberOfBlocks || 1;
|
||||
let coinUnitsPerKilobyte = await mainClient.blockchainEstimatefee(numberOfBlocks);
|
||||
if (coinUnitsPerKilobyte === -1) return 1;
|
||||
return Math.round(
|
||||
new BigNumber(coinUnitsPerKilobyte)
|
||||
.dividedBy(1024)
|
||||
.multipliedBy(100000000)
|
||||
.toNumber(),
|
||||
);
|
||||
};
|
||||
|
||||
module.exports.broadcast = async function(hex) {
|
||||
if (!mainClient) throw new Error('Electrum client is not connected');
|
||||
try {
|
||||
|
|
|
@ -143,6 +143,7 @@ export default class SendDetails extends Component {
|
|||
};
|
||||
|
||||
async componentDidMount() {
|
||||
console.log('send/details - componentDidMount');
|
||||
StatusBar.setBarStyle('dark-content');
|
||||
this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this._keyboardDidShow);
|
||||
this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', this._keyboardDidHide);
|
||||
|
|
|
@ -27,6 +27,10 @@ describe('Electrum', () => {
|
|||
assert.ok(await BlueElectrum.testConnection('electrum1.bluewallet.io', '50001'));
|
||||
});
|
||||
|
||||
it('ElectrumClient can estimate fees', async () => {
|
||||
assert.ok((await BlueElectrum.estimateFee(1)) > 1);
|
||||
});
|
||||
|
||||
it('ElectrumClient can connect and query', async () => {
|
||||
const ElectrumClient = require('electrum-client');
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue