| 1 | import 'package:cake_wallet/core/address_validator.dart'; |
| 2 | import 'package:cw_core/crypto_currency.dart'; |
| 3 | |
| 4 | enum AddressSource { |
| 5 | twitter(label: 'X', iconPath: 'assets/new-ui/address_sources/x.svg', alias: '@username'), |
| 6 | unstoppableDomains( |
| 7 | label: 'Unstoppable Domains', |
| 8 | iconPath: 'assets/new-ui/address_sources/unstoppable.svg', |
| 9 | alias: 'domain.tld'), |
| 10 | openAlias( |
| 11 | label: 'OpenAlias', |
| 12 | iconPath: 'assets/new-ui/address_sources/openalias.svg', |
| 13 | alias: 'name.domain.tld'), |
| 14 | yatRecord(label: 'Yat', iconPath: 'assets/new-ui/address_sources/yat.svg', alias: '🎂🎂🎂'), |
| 15 | fio(label: 'FIO', iconPath: 'assets/new-ui/address_sources/fio.svg', alias: 'user@domain'), |
| 16 | ens( |
| 17 | label: 'Ethereum Name Service', |
| 18 | iconPath: 'assets/new-ui/address_sources/ens.svg', |
| 19 | alias: 'domain.eth'), |
| 20 | mastodon( |
| 21 | label: 'Mastodon', |
| 22 | iconPath: 'assets/new-ui/address_sources/mastodon.svg', |
| 23 | alias: '@username@domain.tld'), |
| 24 | nostr( |
| 25 | label: 'Nostr', |
| 26 | iconPath: 'assets/new-ui/address_sources/nostr.svg', |
| 27 | alias: 'user@domain.tld'), |
| 28 | thorChain( |
| 29 | label: 'ThorChain', |
| 30 | iconPath: 'assets/new-ui/address_sources/icon-thorchain.svg', |
| 31 | alias: 'name'), |
| 32 | wellKnown( |
| 33 | label: '.wellknown', |
| 34 | iconPath: 'assets/new-ui/address_sources/wellknown.svg', |
| 35 | alias: 'domain.tld'), |
| 36 | zanoAlias( |
| 37 | label: 'Zano Alias', iconPath: 'assets/new-ui/address_sources/zano.svg', alias: '@alias'), |
| 38 | bip353( |
| 39 | label: 'BIP353', |
| 40 | iconPath: 'assets/new-ui/address_sources/bip353.svg', |
| 41 | alias: 'user@domain.com'), |
| 42 | zcashAddress( |
| 43 | label: 'Zcash.me', |
| 44 | iconPath: 'assets/new-ui/address_sources/icon-zcash-me.svg', |
| 45 | alias: 'zcash.me/username'), |
| 46 | zcashName( |
| 47 | label: 'Zcash Names', |
| 48 | iconPath: 'assets/new-ui/address_sources/icon-zcashnames.svg', |
| 49 | alias: 'name.zec'), |
| 50 | lnurlPay( |
| 51 | label: 'LNURL Pay', |
| 52 | iconPath: 'assets/new-ui/address_sources/icon-lnurl-pay.svg', |
| 53 | alias: 'user@domain.com'), |
| 54 | contact(label: 'Contact', iconPath: ''), |
| 55 | notParsed(label: 'Unknown', iconPath: ''), |
| 56 | ; |
| 57 | |
| 58 | const AddressSource({ |
| 59 | required this.label, |
| 60 | required this.iconPath, |
| 61 | this.alias = '', |
| 62 | }); |
| 63 | |
| 64 | final String label; |
| 65 | final String iconPath; |
| 66 | final String alias; |
| 67 | } |
| 68 | |
| 69 | extension AddressSourceIndex on AddressSource { |
| 70 | int get raw => index; |
| 71 | |
| 72 | static AddressSource fromRaw(int raw) => |
| 73 | AddressSource.values[raw.clamp(0, AddressSource.values.length - 1)]; |
| 74 | } |
| 75 | |
| 76 | extension AddressSourceNameParser on AddressSource { |
| 77 | static AddressSource fromLabel(String? text) { |
| 78 | if (text == null || text.trim().isEmpty) { |
| 79 | return AddressSource.notParsed; |
| 80 | } |
| 81 | final needle = text.trim().toLowerCase(); |
| 82 | return AddressSource.values.firstWhere( |
| 83 | (src) => src.label.toLowerCase() == needle, |
| 84 | orElse: () => AddressSource.notParsed, |
| 85 | ); |
| 86 | } |
| 87 | } |