add tx_description to notes field

Godwin Asuquo committed Jan 18, 2022 at 08:46 UTC 46afd43884e9a6be8456cde2436d5fb0d3763e2e
4 files changed +39 -14
lib/entities/openalias_record.dart
+19 -2
@@ -3,10 +3,15 @@ import 'package:cw_core/wallet_type.dart';
3 import 'package:flutter/material.dart';
4
5 class OpenaliasRecord {
6 - OpenaliasRecord({this.address, this.name});
6 + OpenaliasRecord({
7 + this.address,
8 + this.name,
9 + this.description,
10 + });
11
12 final String name;
13 final String address;
14 + final String description;
15
16 static String formatDomainName(String name) {
17 String formattedName = name;
@@ -24,6 +29,7 @@ class OpenaliasRecord {
29 }) async {
30 String address = formattedName;
31 String name = formattedName;
32 + String note = '';
33
34 if (formattedName.contains(".")) {
35 try {
@@ -60,6 +66,17 @@ class OpenaliasRecord {
66 name = recipientName.replaceAll("recipient_name=", "");
67 }
68
69 + final description = dataList
70 + .where((item) => (item.contains("tx_description")))
71 + .toString()
72 + .replaceAll("(", "")
73 + .replaceAll(")", "")
74 + .trim();
75 +
76 + if (description.isNotEmpty) {
77 + note = description.replaceAll("tx_description=", "");
78 + }
79 +
80 break;
81 }
82 }
@@ -69,6 +86,6 @@ class OpenaliasRecord {
86 }
87 }
88
72 - return OpenaliasRecord(address: address, name: name);
89 + return OpenaliasRecord(address: address, name: name, description: note);
90 }
91 }
lib/entities/parse_address_from_domain.dart
+1
@@ -63,6 +63,7 @@ Future<ParsedAddress> parseAddressFromDomain(
63 return ParsedAddress(
64 addresses: [record.address],
65 name: record.name,
66 + description: record.description,
67 parseFrom: ParseFrom.openAlias);
68 } catch (e) {
69 print(e.toString());
lib/entities/parsed_address.dart
+6 -3
@@ -1,12 +1,15 @@
1 -enum ParseFrom {unstoppableDomains, openAlias, yatRecord, notParsed}
1 +enum ParseFrom { unstoppableDomains, openAlias, yatRecord, notParsed }
2
3 class ParsedAddress {
4 ParsedAddress({
5 this.addresses,
6 this.name = '',
7 - this.parseFrom = ParseFrom.notParsed});
7 + this.description = '',
8 + this.parseFrom = ParseFrom.notParsed,
9 + });
10
11 final List<String> addresses;
12 final String name;
13 + final String description;
14 final ParseFrom parseFrom;
12 -}
\ No newline at end of file
15 +}
lib/view_model/send/output.dart
+13 -9
@@ -22,7 +22,7 @@ class Output = OutputBase with _$Output;
22
23 abstract class OutputBase with Store {
24 OutputBase(this._wallet, this._settingsStore, this._fiatConversationStore)
25 - :_cryptoNumberFormat = NumberFormat(cryptoNumberPattern) {
25 + : _cryptoNumberFormat = NumberFormat(cryptoNumberPattern) {
26 reset();
27 _setCryptoNumMaximumFractionDigits();
28 key = UniqueKey();
@@ -52,8 +52,9 @@ abstract class OutputBase with Store {
52 String extractedAddress;
53
54 @computed
55 - bool get isParsedAddress => parsedAddress.parseFrom != ParseFrom.notParsed
56 - && parsedAddress.name.isNotEmpty;
55 + bool get isParsedAddress =>
56 + parsedAddress.parseFrom != ParseFrom.notParsed &&
57 + parsedAddress.name.isNotEmpty;
58
59 @computed
60 int get formattedCryptoAmount {
@@ -68,10 +69,12 @@ abstract class OutputBase with Store {
69 _amount = monero.formatterMoneroParseAmount(amount: _cryptoAmount);
70 break;
71 case WalletType.bitcoin:
71 - _amount = bitcoin.formatterStringDoubleToBitcoinAmount(_cryptoAmount);
72 + _amount =
73 + bitcoin.formatterStringDoubleToBitcoinAmount(_cryptoAmount);
74 break;
75 case WalletType.litecoin:
74 - _amount = bitcoin.formatterStringDoubleToBitcoinAmount(_cryptoAmount);
76 + _amount =
77 + bitcoin.formatterStringDoubleToBitcoinAmount(_cryptoAmount);
78 break;
79 default:
80 break;
@@ -81,7 +84,7 @@ abstract class OutputBase with Store {
84 amount = _amount;
85 }
86 }
84 - } catch(e) {
87 + } catch (e) {
88 amount = 0;
89 }
90
@@ -94,8 +97,8 @@ abstract class OutputBase with Store {
97 final fee = _wallet.calculateEstimatedFee(
98 _settingsStore.priority[_wallet.type], formattedCryptoAmount);
99
97 - if (_wallet.type == WalletType.bitcoin
98 - || _wallet.type == WalletType.litecoin) {
100 + if (_wallet.type == WalletType.bitcoin ||
101 + _wallet.type == WalletType.litecoin) {
102 return bitcoin.formatterBitcoinAmountToDouble(amount: fee);
103 }
104
@@ -215,5 +218,6 @@ abstract class OutputBase with Store {
218 final ticker = _wallet.currency.title.toLowerCase();
219 parsedAddress = await parseAddressFromDomain(domain, ticker);
220 extractedAddress = await extractAddressFromParsed(context, parsedAddress);
221 + note = parsedAddress.description;
222 }
219 -}
\ No newline at end of file
223 +}