BlueWallet/models/networkTransactionFees.ts

39 lines
1.0 KiB
TypeScript
Raw Normal View History

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
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;
constructor(fastestFee = 2, mediumFee = 1, slowFee = 1) {
this.fastestFee = fastestFee;
2020-05-18 16:45:31 +02:00
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);
}
}
}