2024-03-24 22:07:43 +01:00
|
|
|
import * as BlueElectrum from '../blue_modules/BlueElectrum';
|
2019-08-27 06:05:27 +02:00
|
|
|
|
2024-06-08 18:18:56 +02:00
|
|
|
export enum NetworkTransactionFeeType {
|
|
|
|
FAST = 'Fast',
|
|
|
|
MEDIUM = 'MEDIUM',
|
|
|
|
SLOW = 'SLOW',
|
|
|
|
CUSTOM = 'CUSTOM',
|
|
|
|
}
|
2019-08-27 06:05:27 +02:00
|
|
|
|
2018-10-20 23:10:21 +02:00
|
|
|
export class NetworkTransactionFee {
|
2019-02-01 07:19:09 +01:00
|
|
|
static StorageKey = 'NetworkTransactionFee';
|
|
|
|
|
2024-05-22 21:35:36 +02:00
|
|
|
public fastestFee: number;
|
|
|
|
public mediumFee: number;
|
|
|
|
public slowFee: number;
|
2023-09-28 21:15:40 +02:00
|
|
|
|
2023-01-01 19:18:15 +01:00
|
|
|
constructor(fastestFee = 2, mediumFee = 1, slowFee = 1) {
|
2018-10-20 23:10:21 +02:00
|
|
|
this.fastestFee = fastestFee;
|
2020-05-18 16:45:31 +02:00
|
|
|
this.mediumFee = mediumFee;
|
|
|
|
this.slowFee = slowFee;
|
2018-10-20 23:10:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class NetworkTransactionFees {
|
2023-09-28 21:29:27 +02:00
|
|
|
static async recommendedFees(): Promise<NetworkTransactionFee> {
|
|
|
|
try {
|
|
|
|
const isDisabled = await BlueElectrum.isDisabled();
|
|
|
|
if (isDisabled) {
|
|
|
|
throw new Error('Electrum is disabled. Dont attempt to fetch fees');
|
2018-10-20 23:10:21 +02:00
|
|
|
}
|
2023-09-28 21:29:27 +02:00
|
|
|
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);
|
|
|
|
}
|
2018-10-20 23:10:21 +02:00
|
|
|
}
|
|
|
|
}
|