dev
dart 115 lines 4.26 KB
Raw
1 import 'package:bitcoin_base/bitcoin_base.dart';
2 import 'package:cw_bitcoin/lightning/lightning_addres_type.dart';
3 import 'package:cw_core/receive_page_option.dart';
4
5 class BitcoinReceivePageOption implements ReceivePageOption {
6 static const p2wpkh = BitcoinReceivePageOption._('Standard',
7 description: "Default (P2WPKH)",
8 iconPath: "assets/new-ui/address-type-picker-icons/btc_standard.svg",
9 isCommon: true,
10 addAddressWord: true);
11 static const p2sh = BitcoinReceivePageOption._('Segwit-Compatible',
12 description: "P2SH", iconPath: "assets/new-ui/address-type-picker-icons/segwit.svg");
13 static const p2tr = BitcoinReceivePageOption._('Taproot',
14 description: "P2TR", iconPath: "assets/new-ui/address-type-picker-icons/taproot.svg");
15 static const p2wsh = BitcoinReceivePageOption._('Segwit',
16 description: "P2WSH", iconPath: "assets/new-ui/address-type-picker-icons/segwit.svg");
17 static const p2pkh = BitcoinReceivePageOption._('Legacy',
18 description: "P2PKH", iconPath: "assets/new-ui/address-type-picker-icons/legacy.svg");
19 static const mweb = BitcoinReceivePageOption._('Private',
20 description: "MWEB",
21 iconPath: "assets/new-ui/address-type-picker-icons/mweb.svg",
22 isCommon: true,
23 addAddressWord: true);
24
25 static const silent_payments = BitcoinReceivePageOption._('Silent Payments',
26 description: "Privacy-preserving static address",
27 iconPath: "assets/new-ui/address-type-picker-icons/silent.svg",
28 isCommon: true);
29 static const lightning = BitcoinReceivePageOption._('Lightning',
30 description: "Instant, low fee payments",
31 iconPath: "assets/new-ui/address-type-picker-icons/btc_lightning.svg",
32 isCommon: true);
33
34 const BitcoinReceivePageOption._(this.value,
35 {this.iconPath, this.description, this.isCommon = false, this.addAddressWord = false});
36
37 final String value;
38 final String? iconPath;
39 final String? description;
40 final bool isCommon;
41 final bool addAddressWord;
42
43 String toString() {
44 return value;
45 }
46
47 static const all = [
48 BitcoinReceivePageOption.lightning,
49 BitcoinReceivePageOption.silent_payments,
50 BitcoinReceivePageOption.p2wpkh,
51 BitcoinReceivePageOption.p2tr,
52 BitcoinReceivePageOption.p2wsh,
53 BitcoinReceivePageOption.p2sh,
54 BitcoinReceivePageOption.p2pkh
55 ];
56
57 static const allViewOnly = [
58 BitcoinReceivePageOption.p2wpkh,
59 // TODO: uncomment this after we properly derive keys and not use m/84 for
60 // all of them (as this breaks cupcake)
61 // BitcoinReceivePageOption.p2tr,
62 // BitcoinReceivePageOption.p2wsh,
63 // BitcoinReceivePageOption.p2sh,
64 // BitcoinReceivePageOption.p2pkh
65 ];
66
67 static const allLitecoin = [
68 BitcoinReceivePageOption.p2wpkh,
69 BitcoinReceivePageOption.mweb,
70 ];
71
72 BitcoinAddressType toType() {
73 switch (this) {
74 case BitcoinReceivePageOption.p2tr:
75 return SegwitAddresType.p2tr;
76 case BitcoinReceivePageOption.p2wsh:
77 return SegwitAddresType.p2wsh;
78 case BitcoinReceivePageOption.p2pkh:
79 return P2pkhAddressType.p2pkh;
80 case BitcoinReceivePageOption.p2sh:
81 return P2shAddressType.p2wpkhInP2sh;
82 case BitcoinReceivePageOption.silent_payments:
83 return SilentPaymentsAddresType.p2sp;
84 case BitcoinReceivePageOption.lightning:
85 return LightningAddressType.p2l;
86 case BitcoinReceivePageOption.mweb:
87 return SegwitAddresType.mweb;
88 case BitcoinReceivePageOption.p2wpkh:
89 default:
90 return SegwitAddresType.p2wpkh;
91 }
92 }
93
94 factory BitcoinReceivePageOption.fromType(BitcoinAddressType type) {
95 switch (type) {
96 case SegwitAddresType.p2tr:
97 return BitcoinReceivePageOption.p2tr;
98 case SegwitAddresType.p2wsh:
99 return BitcoinReceivePageOption.p2wsh;
100 case SegwitAddresType.mweb:
101 return BitcoinReceivePageOption.mweb;
102 case P2pkhAddressType.p2pkh:
103 return BitcoinReceivePageOption.p2pkh;
104 case P2shAddressType.p2wpkhInP2sh:
105 return BitcoinReceivePageOption.p2sh;
106 case SilentPaymentsAddresType.p2sp:
107 return BitcoinReceivePageOption.silent_payments;
108 case LightningAddressType.p2l:
109 return BitcoinReceivePageOption.lightning;
110 case SegwitAddresType.p2wpkh:
111 default:
112 return BitcoinReceivePageOption.p2wpkh;
113 }
114 }
115 }