| 1 | import 'package:cw_core/receive_page_option.dart'; |
| 2 | import 'package:cw_core/utils/print_verbose.dart'; |
| 3 | |
| 4 | enum ZcashAddressType { |
| 5 | transparent, |
| 6 | transparentRotated, |
| 7 | shieldedSapling, |
| 8 | shieldedOrchard, |
| 9 | unifiedType, |
| 10 | } |
| 11 | |
| 12 | class ZcashReceivePageOption implements ReceivePageOption { |
| 13 | factory ZcashReceivePageOption.fromType(final ZcashAddressType type) { |
| 14 | switch (type) { |
| 15 | case ZcashAddressType.transparent: |
| 16 | return transparent; |
| 17 | case ZcashAddressType.transparentRotated: |
| 18 | return transparentRotated; |
| 19 | case ZcashAddressType.shieldedSapling: |
| 20 | return shieldedSapling; |
| 21 | case ZcashAddressType.shieldedOrchard: |
| 22 | return shieldedOrchard(); |
| 23 | case ZcashAddressType.unifiedType: |
| 24 | return unified; |
| 25 | } |
| 26 | } |
| 27 | const ZcashReceivePageOption._( |
| 28 | this.type, |
| 29 | this.value, { |
| 30 | this.iconPath, |
| 31 | this.description, |
| 32 | this.isCommon = false, |
| 33 | }); |
| 34 | |
| 35 | final String value; |
| 36 | final String? iconPath; |
| 37 | final String? description; |
| 38 | final bool isCommon; |
| 39 | final bool addAddressWord = false; |
| 40 | |
| 41 | static const transparent = ZcashReceivePageOption._( |
| 42 | ZcashAddressType.transparent, |
| 43 | "Public", |
| 44 | description: "Static & Transparent", |
| 45 | iconPath: "assets/new-ui/address-type-picker-icons/zec/public.svg", |
| 46 | ); |
| 47 | static const transparentRotated = ZcashReceivePageOption._( |
| 48 | ZcashAddressType.transparentRotated, |
| 49 | "Transparent", |
| 50 | description: "Disposable", |
| 51 | iconPath: "assets/new-ui/address-type-picker-icons/zec/transparent.svg", |
| 52 | isCommon: true, |
| 53 | ); |
| 54 | static const shieldedSapling = ZcashReceivePageOption._( |
| 55 | ZcashAddressType.shieldedSapling, |
| 56 | "Legacy Shielded", |
| 57 | description: "Sapling", |
| 58 | iconPath: "assets/new-ui/address-type-picker-icons/zec/sapling.svg", |
| 59 | ); |
| 60 | static const _shieldedOrchardIcon = |
| 61 | "assets/new-ui/address-type-picker-icons/zec/shielded.svg"; |
| 62 | |
| 63 | static ZcashReceivePageOption shieldedOrchard({final bool ironwood = false}) { |
| 64 | return ZcashReceivePageOption._( |
| 65 | ZcashAddressType.shieldedOrchard, |
| 66 | "Shielded", |
| 67 | description: ironwood ? "Default (Ironwood)" : "Default (Orchard)", |
| 68 | iconPath: _shieldedOrchardIcon, |
| 69 | isCommon: true, |
| 70 | ); |
| 71 | } |
| 72 | static const unified = ZcashReceivePageOption._( |
| 73 | ZcashAddressType.unifiedType, |
| 74 | "Unified", |
| 75 | description: "Compatible Shielded", |
| 76 | iconPath: "assets/new-ui/address-type-picker-icons/zec/unified.svg", |
| 77 | isCommon: true, |
| 78 | ); |
| 79 | |
| 80 | final ZcashAddressType type; |
| 81 | |
| 82 | String toString() { |
| 83 | return value; |
| 84 | } |
| 85 | |
| 86 | static List<ZcashReceivePageOption> allOptionsFor({final bool ironwood = false}) => [ |
| 87 | shieldedOrchard(ironwood: ironwood), |
| 88 | shieldedSapling, |
| 89 | unified, |
| 90 | transparentRotated, |
| 91 | transparent, |
| 92 | ]; |
| 93 | |
| 94 | static List<ZcashReceivePageOption> get allOptions => allOptionsFor(); |
| 95 | |
| 96 | ZcashAddressType toType() { |
| 97 | return type; |
| 98 | } |
| 99 | |
| 100 | static ZcashAddressType typeFromString(final String str) { |
| 101 | for (int i = 0; i < ZcashAddressType.values.length; i++) { |
| 102 | if (str == ZcashAddressType.values[i].toString()) { |
| 103 | return ZcashAddressType.values[i]; |
| 104 | } |
| 105 | } |
| 106 | printV("Not found for: $str"); |
| 107 | return ZcashAddressType.shieldedOrchard; |
| 108 | } |
| 109 | } |