add tx_description to notes field

This commit is contained in:
Godwin Asuquo 2022-01-18 08:46:13 +01:00
parent 0a2157e978
commit 46afd43884
4 changed files with 39 additions and 14 deletions

View file

@ -3,10 +3,15 @@ import 'package:cw_core/wallet_type.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class OpenaliasRecord { class OpenaliasRecord {
OpenaliasRecord({this.address, this.name}); OpenaliasRecord({
this.address,
this.name,
this.description,
});
final String name; final String name;
final String address; final String address;
final String description;
static String formatDomainName(String name) { static String formatDomainName(String name) {
String formattedName = name; String formattedName = name;
@ -24,6 +29,7 @@ class OpenaliasRecord {
}) async { }) async {
String address = formattedName; String address = formattedName;
String name = formattedName; String name = formattedName;
String note = '';
if (formattedName.contains(".")) { if (formattedName.contains(".")) {
try { try {
@ -60,6 +66,17 @@ class OpenaliasRecord {
name = recipientName.replaceAll("recipient_name=", ""); 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; break;
} }
} }
@ -69,6 +86,6 @@ class OpenaliasRecord {
} }
} }
return OpenaliasRecord(address: address, name: name); return OpenaliasRecord(address: address, name: name, description: note);
} }
} }

View file

@ -63,6 +63,7 @@ Future<ParsedAddress> parseAddressFromDomain(
return ParsedAddress( return ParsedAddress(
addresses: [record.address], addresses: [record.address],
name: record.name, name: record.name,
description: record.description,
parseFrom: ParseFrom.openAlias); parseFrom: ParseFrom.openAlias);
} catch (e) { } catch (e) {
print(e.toString()); print(e.toString());

View file

@ -1,12 +1,15 @@
enum ParseFrom {unstoppableDomains, openAlias, yatRecord, notParsed} enum ParseFrom { unstoppableDomains, openAlias, yatRecord, notParsed }
class ParsedAddress { class ParsedAddress {
ParsedAddress({ ParsedAddress({
this.addresses, this.addresses,
this.name = '', this.name = '',
this.parseFrom = ParseFrom.notParsed}); this.description = '',
this.parseFrom = ParseFrom.notParsed,
});
final List<String> addresses; final List<String> addresses;
final String name; final String name;
final String description;
final ParseFrom parseFrom; final ParseFrom parseFrom;
} }

View file

@ -22,7 +22,7 @@ class Output = OutputBase with _$Output;
abstract class OutputBase with Store { abstract class OutputBase with Store {
OutputBase(this._wallet, this._settingsStore, this._fiatConversationStore) OutputBase(this._wallet, this._settingsStore, this._fiatConversationStore)
:_cryptoNumberFormat = NumberFormat(cryptoNumberPattern) { : _cryptoNumberFormat = NumberFormat(cryptoNumberPattern) {
reset(); reset();
_setCryptoNumMaximumFractionDigits(); _setCryptoNumMaximumFractionDigits();
key = UniqueKey(); key = UniqueKey();
@ -52,8 +52,9 @@ abstract class OutputBase with Store {
String extractedAddress; String extractedAddress;
@computed @computed
bool get isParsedAddress => parsedAddress.parseFrom != ParseFrom.notParsed bool get isParsedAddress =>
&& parsedAddress.name.isNotEmpty; parsedAddress.parseFrom != ParseFrom.notParsed &&
parsedAddress.name.isNotEmpty;
@computed @computed
int get formattedCryptoAmount { int get formattedCryptoAmount {
@ -68,10 +69,12 @@ abstract class OutputBase with Store {
_amount = monero.formatterMoneroParseAmount(amount: _cryptoAmount); _amount = monero.formatterMoneroParseAmount(amount: _cryptoAmount);
break; break;
case WalletType.bitcoin: case WalletType.bitcoin:
_amount = bitcoin.formatterStringDoubleToBitcoinAmount(_cryptoAmount); _amount =
bitcoin.formatterStringDoubleToBitcoinAmount(_cryptoAmount);
break; break;
case WalletType.litecoin: case WalletType.litecoin:
_amount = bitcoin.formatterStringDoubleToBitcoinAmount(_cryptoAmount); _amount =
bitcoin.formatterStringDoubleToBitcoinAmount(_cryptoAmount);
break; break;
default: default:
break; break;
@ -81,7 +84,7 @@ abstract class OutputBase with Store {
amount = _amount; amount = _amount;
} }
} }
} catch(e) { } catch (e) {
amount = 0; amount = 0;
} }
@ -94,8 +97,8 @@ abstract class OutputBase with Store {
final fee = _wallet.calculateEstimatedFee( final fee = _wallet.calculateEstimatedFee(
_settingsStore.priority[_wallet.type], formattedCryptoAmount); _settingsStore.priority[_wallet.type], formattedCryptoAmount);
if (_wallet.type == WalletType.bitcoin if (_wallet.type == WalletType.bitcoin ||
|| _wallet.type == WalletType.litecoin) { _wallet.type == WalletType.litecoin) {
return bitcoin.formatterBitcoinAmountToDouble(amount: fee); return bitcoin.formatterBitcoinAmountToDouble(amount: fee);
} }
@ -215,5 +218,6 @@ abstract class OutputBase with Store {
final ticker = _wallet.currency.title.toLowerCase(); final ticker = _wallet.currency.title.toLowerCase();
parsedAddress = await parseAddressFromDomain(domain, ticker); parsedAddress = await parseAddressFromDomain(domain, ticker);
extractedAddress = await extractAddressFromParsed(context, parsedAddress); extractedAddress = await extractAddressFromParsed(context, parsedAddress);
note = parsedAddress.description;
} }
} }