forked from BlueWallet/BlueWallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnetworkTransactionFees.ts
38 lines (33 loc) · 1.05 KB
/
networkTransactionFees.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const BlueElectrum = require('../blue_modules/BlueElectrum');
export const NetworkTransactionFeeType = Object.freeze({
FAST: 'Fast',
MEDIUM: 'MEDIUM',
SLOW: 'SLOW',
CUSTOM: 'CUSTOM',
});
export class NetworkTransactionFee {
static StorageKey = 'NetworkTransactionFee';
private fastestFee: number;
private mediumFee: number;
private slowFee: number;
constructor(fastestFee = 2, mediumFee = 1, slowFee = 1) {
this.fastestFee = fastestFee;
this.mediumFee = mediumFee;
this.slowFee = slowFee;
}
}
export default class NetworkTransactionFees {
static async recommendedFees(): Promise<NetworkTransactionFee> {
try {
const isDisabled = await BlueElectrum.isDisabled();
if (isDisabled) {
throw new Error('Electrum is disabled. Dont attempt to fetch fees');
}
const response = await BlueElectrum.estimateFees();
return new NetworkTransactionFee(response.fast + 5, response.medium + 2, response.slow);
} catch (err) {
console.warn(err);
return new NetworkTransactionFee(2, 1, 1);
}
}
}