From 46afd43884e9a6be8456cde2436d5fb0d3763e2e Mon Sep 17 00:00:00 2001 From: Godwin Asuquo Date: Tue, 18 Jan 2022 08:46:13 +0100 Subject: [PATCH] add tx_description to notes field --- lib/entities/openalias_record.dart | 21 ++++++++++++++++++-- lib/entities/parse_address_from_domain.dart | 1 + lib/entities/parsed_address.dart | 9 ++++++--- lib/view_model/send/output.dart | 22 ++++++++++++--------- 4 files changed, 39 insertions(+), 14 deletions(-) diff --git a/lib/entities/openalias_record.dart b/lib/entities/openalias_record.dart index 073f5dbe9..0420950bd 100644 --- a/lib/entities/openalias_record.dart +++ b/lib/entities/openalias_record.dart @@ -3,10 +3,15 @@ import 'package:cw_core/wallet_type.dart'; import 'package:flutter/material.dart'; class OpenaliasRecord { - OpenaliasRecord({this.address, this.name}); + OpenaliasRecord({ + this.address, + this.name, + this.description, + }); final String name; final String address; + final String description; static String formatDomainName(String name) { String formattedName = name; @@ -24,6 +29,7 @@ class OpenaliasRecord { }) async { String address = formattedName; String name = formattedName; + String note = ''; if (formattedName.contains(".")) { try { @@ -60,6 +66,17 @@ class OpenaliasRecord { name = recipientName.replaceAll("recipient_name=", ""); } + final description = dataList + .where((item) => (item.contains("tx_description"))) + .toString() + .replaceAll("(", "") + .replaceAll(")", "") + .trim(); + + if (description.isNotEmpty) { + note = description.replaceAll("tx_description=", ""); + } + break; } } @@ -69,6 +86,6 @@ class OpenaliasRecord { } } - return OpenaliasRecord(address: address, name: name); + return OpenaliasRecord(address: address, name: name, description: note); } } diff --git a/lib/entities/parse_address_from_domain.dart b/lib/entities/parse_address_from_domain.dart index 13fa6a0ed..056658067 100644 --- a/lib/entities/parse_address_from_domain.dart +++ b/lib/entities/parse_address_from_domain.dart @@ -63,6 +63,7 @@ Future parseAddressFromDomain( return ParsedAddress( addresses: [record.address], name: record.name, + description: record.description, parseFrom: ParseFrom.openAlias); } catch (e) { print(e.toString()); diff --git a/lib/entities/parsed_address.dart b/lib/entities/parsed_address.dart index ae15ce7ea..11b87d9f5 100644 --- a/lib/entities/parsed_address.dart +++ b/lib/entities/parsed_address.dart @@ -1,12 +1,15 @@ -enum ParseFrom {unstoppableDomains, openAlias, yatRecord, notParsed} +enum ParseFrom { unstoppableDomains, openAlias, yatRecord, notParsed } class ParsedAddress { ParsedAddress({ this.addresses, this.name = '', - this.parseFrom = ParseFrom.notParsed}); + this.description = '', + this.parseFrom = ParseFrom.notParsed, + }); final List addresses; final String name; + final String description; final ParseFrom parseFrom; -} \ No newline at end of file +} diff --git a/lib/view_model/send/output.dart b/lib/view_model/send/output.dart index e2f07bdcf..eeca8fd2c 100644 --- a/lib/view_model/send/output.dart +++ b/lib/view_model/send/output.dart @@ -22,7 +22,7 @@ class Output = OutputBase with _$Output; abstract class OutputBase with Store { OutputBase(this._wallet, this._settingsStore, this._fiatConversationStore) - :_cryptoNumberFormat = NumberFormat(cryptoNumberPattern) { + : _cryptoNumberFormat = NumberFormat(cryptoNumberPattern) { reset(); _setCryptoNumMaximumFractionDigits(); key = UniqueKey(); @@ -52,8 +52,9 @@ abstract class OutputBase with Store { String extractedAddress; @computed - bool get isParsedAddress => parsedAddress.parseFrom != ParseFrom.notParsed - && parsedAddress.name.isNotEmpty; + bool get isParsedAddress => + parsedAddress.parseFrom != ParseFrom.notParsed && + parsedAddress.name.isNotEmpty; @computed int get formattedCryptoAmount { @@ -68,10 +69,12 @@ abstract class OutputBase with Store { _amount = monero.formatterMoneroParseAmount(amount: _cryptoAmount); break; case WalletType.bitcoin: - _amount = bitcoin.formatterStringDoubleToBitcoinAmount(_cryptoAmount); + _amount = + bitcoin.formatterStringDoubleToBitcoinAmount(_cryptoAmount); break; case WalletType.litecoin: - _amount = bitcoin.formatterStringDoubleToBitcoinAmount(_cryptoAmount); + _amount = + bitcoin.formatterStringDoubleToBitcoinAmount(_cryptoAmount); break; default: break; @@ -81,7 +84,7 @@ abstract class OutputBase with Store { amount = _amount; } } - } catch(e) { + } catch (e) { amount = 0; } @@ -94,8 +97,8 @@ abstract class OutputBase with Store { final fee = _wallet.calculateEstimatedFee( _settingsStore.priority[_wallet.type], formattedCryptoAmount); - if (_wallet.type == WalletType.bitcoin - || _wallet.type == WalletType.litecoin) { + if (_wallet.type == WalletType.bitcoin || + _wallet.type == WalletType.litecoin) { return bitcoin.formatterBitcoinAmountToDouble(amount: fee); } @@ -215,5 +218,6 @@ abstract class OutputBase with Store { final ticker = _wallet.currency.title.toLowerCase(); parsedAddress = await parseAddressFromDomain(domain, ticker); extractedAddress = await extractAddressFromParsed(context, parsedAddress); + note = parsedAddress.description; } -} \ No newline at end of file +}