| 1 | import 'package:cw_core/transaction_priority.dart'; |
| 2 | import 'package:flutter/foundation.dart'; |
| 3 | |
| 4 | class BitcoinTransactionPriority extends TransactionPriority { |
| 5 | const BitcoinTransactionPriority( |
| 6 | {required String title, required int raw, String? description, String? hint}) |
| 7 | : super(title: title, raw: raw, description: description, hint: hint); |
| 8 | |
| 9 | static const List<BitcoinTransactionPriority> all = [fast, medium, slow, custom]; |
| 10 | static const BitcoinTransactionPriority slow = |
| 11 | BitcoinTransactionPriority(title: 'Slow', description: "2 sat/byte", hint: "~ 24 h", raw: 0); |
| 12 | static const BitcoinTransactionPriority medium = |
| 13 | BitcoinTransactionPriority(title: 'Medium', description: "3 sat/byte", hint: "~ 1 h", raw: 1); |
| 14 | static const BitcoinTransactionPriority fast = BitcoinTransactionPriority( |
| 15 | title: 'Fast', description: "4 sat/byte", hint: "~ 30 min", raw: 2); |
| 16 | static const BitcoinTransactionPriority custom = |
| 17 | BitcoinTransactionPriority(title: 'Custom', raw: 3); |
| 18 | |
| 19 | static BitcoinTransactionPriority deserialize({required int raw}) { |
| 20 | switch (raw) { |
| 21 | case 0: |
| 22 | return slow; |
| 23 | case 1: |
| 24 | return medium; |
| 25 | case 2: |
| 26 | return fast; |
| 27 | case 3: |
| 28 | return custom; |
| 29 | default: |
| 30 | if (kDebugMode) { |
| 31 | throw Exception('Unexpected token: $raw for BitcoinTransactionPriority deserialize'); |
| 32 | } |
| 33 | return medium; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | String get units => 'sat'; |
| 38 | |
| 39 | @override |
| 40 | String toString() { |
| 41 | var label = ''; |
| 42 | |
| 43 | switch (this) { |
| 44 | case BitcoinTransactionPriority.slow: |
| 45 | label = 'Slow ~24hrs+'; // '${S.current.transaction_priority_slow} ~24hrs'; |
| 46 | break; |
| 47 | case BitcoinTransactionPriority.medium: |
| 48 | label = 'Medium'; // S.current.transaction_priority_medium; |
| 49 | break; |
| 50 | case BitcoinTransactionPriority.fast: |
| 51 | label = 'Fast'; |
| 52 | break; // S.current.transaction_priority_fast; |
| 53 | case BitcoinTransactionPriority.custom: |
| 54 | label = 'Custom'; |
| 55 | break; |
| 56 | default: |
| 57 | break; |
| 58 | } |
| 59 | |
| 60 | return label; |
| 61 | } |
| 62 | |
| 63 | String labelWithRate(int rate, int? customRate) { |
| 64 | final rateValue = this == custom ? customRate ??= 0 : rate; |
| 65 | return '${toString()} ($rateValue ${units}/byte)'; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | class LitecoinTransactionPriority extends BitcoinTransactionPriority { |
| 70 | const LitecoinTransactionPriority({required String title, required int raw}) |
| 71 | : super(title: title, raw: raw); |
| 72 | |
| 73 | static const List<LitecoinTransactionPriority> all = [fast, medium, slow]; |
| 74 | static const LitecoinTransactionPriority slow = |
| 75 | LitecoinTransactionPriority(title: 'Slow', raw: 0); |
| 76 | static const LitecoinTransactionPriority medium = |
| 77 | LitecoinTransactionPriority(title: 'Medium', raw: 1); |
| 78 | static const LitecoinTransactionPriority fast = |
| 79 | LitecoinTransactionPriority(title: 'Fast', raw: 2); |
| 80 | |
| 81 | static LitecoinTransactionPriority deserialize({required int raw}) { |
| 82 | switch (raw) { |
| 83 | case 0: |
| 84 | return slow; |
| 85 | case 1: |
| 86 | return medium; |
| 87 | case 2: |
| 88 | return fast; |
| 89 | default: |
| 90 | if (kDebugMode) { |
| 91 | throw Exception('Unexpected token: $raw for LitecoinTransactionPriority deserialize'); |
| 92 | } |
| 93 | return medium; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | @override |
| 98 | String get units => 'Litoshi'; |
| 99 | |
| 100 | @override |
| 101 | String toString() { |
| 102 | var label = ''; |
| 103 | |
| 104 | switch (this) { |
| 105 | case LitecoinTransactionPriority.slow: |
| 106 | label = 'Slow'; // S.current.transaction_priority_slow; |
| 107 | break; |
| 108 | case LitecoinTransactionPriority.medium: |
| 109 | label = 'Medium'; // S.current.transaction_priority_medium; |
| 110 | break; |
| 111 | case LitecoinTransactionPriority.fast: |
| 112 | label = 'Fast'; // S.current.transaction_priority_fast; |
| 113 | break; |
| 114 | default: |
| 115 | break; |
| 116 | } |
| 117 | |
| 118 | return label; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | class BitcoinCashTransactionPriority extends BitcoinTransactionPriority { |
| 123 | const BitcoinCashTransactionPriority({required String title, required int raw}) |
| 124 | : super(title: title, raw: raw); |
| 125 | |
| 126 | static const List<BitcoinCashTransactionPriority> all = [fast, medium, slow]; |
| 127 | static const BitcoinCashTransactionPriority slow = |
| 128 | BitcoinCashTransactionPriority(title: 'Slow', raw: 0); |
| 129 | static const BitcoinCashTransactionPriority medium = |
| 130 | BitcoinCashTransactionPriority(title: 'Medium', raw: 1); |
| 131 | static const BitcoinCashTransactionPriority fast = |
| 132 | BitcoinCashTransactionPriority(title: 'Fast', raw: 2); |
| 133 | |
| 134 | static BitcoinCashTransactionPriority deserialize({required int raw}) { |
| 135 | switch (raw) { |
| 136 | case 0: |
| 137 | return slow; |
| 138 | case 1: |
| 139 | return medium; |
| 140 | case 2: |
| 141 | return fast; |
| 142 | default: |
| 143 | if (kDebugMode) { |
| 144 | throw Exception('Unexpected token: $raw for BitcoinCashTransactionPriority deserialize'); |
| 145 | } |
| 146 | return medium; |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | @override |
| 151 | String get units => 'Satoshi'; |
| 152 | |
| 153 | @override |
| 154 | String toString() { |
| 155 | var label = ''; |
| 156 | |
| 157 | switch (this) { |
| 158 | case BitcoinCashTransactionPriority.slow: |
| 159 | label = 'Slow'; // S.current.transaction_priority_slow; |
| 160 | break; |
| 161 | case BitcoinCashTransactionPriority.medium: |
| 162 | label = 'Medium'; // S.current.transaction_priority_medium; |
| 163 | break; |
| 164 | case BitcoinCashTransactionPriority.fast: |
| 165 | label = 'Fast'; // S.current.transaction_priority_fast; |
| 166 | break; |
| 167 | default: |
| 168 | break; |
| 169 | } |
| 170 | |
| 171 | return label; |
| 172 | } |
| 173 | } |