[skip ci] add transaction priority

This commit is contained in:
Serhii 2023-08-14 19:00:38 +03:00
parent afcfab9796
commit af58c45190
5 changed files with 57 additions and 8 deletions

View file

@ -1,9 +1,52 @@
import 'package:cw_core/transaction_priority.dart'; import 'package:cw_core/transaction_priority.dart';
class BitcoinCashTransactionPriority extends TransactionPriority{ class BitcoinCashTransactionPriority extends TransactionPriority {
BitcoinCashTransactionPriority({required super.title, required super.raw}); const BitcoinCashTransactionPriority({required String title, required int raw})
: super(title: title, raw: raw);
static BitcoinCashTransactionPriority deserialize ({required int raw}) { static const List<BitcoinCashTransactionPriority> all = [fast, medium, slow];
throw UnimplementedError('BitcoinCashTransactionPriority.deserialize() is not implemented'); static const BitcoinCashTransactionPriority slow =
BitcoinCashTransactionPriority(title: 'Slow', raw: 0);
static const BitcoinCashTransactionPriority medium =
BitcoinCashTransactionPriority(title: 'Medium', raw: 1);
static const BitcoinCashTransactionPriority fast =
BitcoinCashTransactionPriority(title: 'Fast', raw: 2);
static BitcoinCashTransactionPriority deserialize({required int raw}) {
switch (raw) {
case 0:
return slow;
case 1:
return medium;
case 2:
return fast;
default:
throw Exception('Unexpected token: $raw for BitcoinTransactionPriority deserialize');
}
} }
}
String get units => 'sat';
@override
String toString() {
var label = '';
switch (this) {
case BitcoinCashTransactionPriority.slow:
label = 'Slow ~24hrs'; // '${S.current.transaction_priority_slow} ~24hrs';
break;
case BitcoinCashTransactionPriority.medium:
label = 'Medium'; // S.current.transaction_priority_medium;
break;
case BitcoinCashTransactionPriority.fast:
label = 'Fast'; // S.current.transaction_priority_fast;
break;
default:
break;
}
return label;
}
String labelWithRate(int rate) => '${toString()} ($rate ${units}/byte)';
}

View file

@ -31,6 +31,8 @@ class CWBitcoinCash extends BitcoinCash {
BitcoinCashTransactionPriority.deserialize(raw: raw); BitcoinCashTransactionPriority.deserialize(raw: raw);
@override @override
TransactionPriority getDefaultTransactionPriority() => TransactionPriority getDefaultTransactionPriority() => BitcoinCashTransactionPriority.medium;
throw UnimplementedError('getDefaultTransactionPriority');
@override
List<TransactionPriority> getTransactionPriorities() => BitcoinCashTransactionPriority.all;
} }

View file

@ -1,4 +1,5 @@
import 'package:cake_wallet/bitcoin/bitcoin.dart'; import 'package:cake_wallet/bitcoin/bitcoin.dart';
import 'package:cake_wallet/bitcoin_cash/bitcoin_cash.dart';
import 'package:cake_wallet/ethereum/ethereum.dart'; import 'package:cake_wallet/ethereum/ethereum.dart';
import 'package:cake_wallet/haven/haven.dart'; import 'package:cake_wallet/haven/haven.dart';
import 'package:cake_wallet/monero/monero.dart'; import 'package:cake_wallet/monero/monero.dart';
@ -17,6 +18,8 @@ List<TransactionPriority> priorityForWalletType(WalletType type) {
return haven!.getTransactionPriorities(); return haven!.getTransactionPriorities();
case WalletType.ethereum: case WalletType.ethereum:
return ethereum!.getTransactionPriorities(); return ethereum!.getTransactionPriorities();
case WalletType.bitcoinCash:
return bitcoinCash!.getTransactionPriorities();
default: default:
return []; return [];
} }

View file

@ -51,7 +51,6 @@ class WalletListBodyState extends State<WalletListBody> {
} }
final path = walletTypeToCryptoCurrency(type).iconPath ?? nonWalletTypeIconPath; final path = walletTypeToCryptoCurrency(type).iconPath ?? nonWalletTypeIconPath;
print('path: $path type: $type');
return Image.asset(path, height: 24, width: 24); return Image.asset(path, height: 24, width: 24);
} }

View file

@ -594,6 +594,8 @@ abstract class BitcoinCash {
TransactionPriority deserializeBitcoinCashTransactionPriority(int raw); TransactionPriority deserializeBitcoinCashTransactionPriority(int raw);
TransactionPriority getDefaultTransactionPriority(); TransactionPriority getDefaultTransactionPriority();
List<TransactionPriority> getTransactionPriorities();
} }
"""; """;