| 1 | import 'package:cw_core/transaction_priority.dart'; |
| 2 | import 'package:flutter/foundation.dart'; |
| 3 | |
| 4 | class EVMChainTransactionPriority extends TransactionPriority { |
| 5 | final int tip; |
| 6 | |
| 7 | const EVMChainTransactionPriority({required String title, required int raw, required this.tip}) |
| 8 | : super(title: title, raw: raw); |
| 9 | |
| 10 | static const List<EVMChainTransactionPriority> all = [fast, medium, slow]; |
| 11 | static const EVMChainTransactionPriority slow = |
| 12 | EVMChainTransactionPriority(title: 'Slow', raw: 0, tip: 1); |
| 13 | static const EVMChainTransactionPriority medium = |
| 14 | EVMChainTransactionPriority(title: 'Medium', raw: 1, tip: 2); |
| 15 | static const EVMChainTransactionPriority fast = |
| 16 | EVMChainTransactionPriority(title: 'Fast', raw: 2, tip: 4); |
| 17 | |
| 18 | static EVMChainTransactionPriority deserialize({required int raw}) { |
| 19 | switch (raw) { |
| 20 | case 0: |
| 21 | return slow; |
| 22 | case 1: |
| 23 | return medium; |
| 24 | case 2: |
| 25 | return fast; |
| 26 | default: |
| 27 | if (kDebugMode) { |
| 28 | throw Exception('Unexpected token: $raw for EVMChainTransactionPriority deserialize'); |
| 29 | } |
| 30 | return medium; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | String get units => 'gas'; |
| 35 | |
| 36 | @override |
| 37 | String toString() { |
| 38 | var label = ''; |
| 39 | |
| 40 | switch (this) { |
| 41 | case EVMChainTransactionPriority.slow: |
| 42 | label = 'Slow'; |
| 43 | break; |
| 44 | case EVMChainTransactionPriority.medium: |
| 45 | label = 'Medium'; |
| 46 | break; |
| 47 | case EVMChainTransactionPriority.fast: |
| 48 | label = 'Fast'; |
| 49 | break; |
| 50 | default: |
| 51 | break; |
| 52 | } |
| 53 | |
| 54 | return label; |
| 55 | } |
| 56 | } |