Cw 805 fix bch refund address (#1782)
* fix bch address format for exolix, stealth, thorchain, simpleswap * exclude SP and MWEB from the exchange address book * address pr review comments
Serhii committed
Nov 5, 2024 at 11:33 UTC
459f0d352d92150a3b6b96cf94106d060ebd92dd
6 files changed
+32
-18
lib/core/address_validator.dart
+1
-2
@@ -106,8 +106,7 @@ class AddressValidator extends TextValidator {
106
case CryptoCurrency.wow:
107
pattern = '[0-9a-zA-Z]+';
108
case CryptoCurrency.bch:
109
- pattern =
110
- '(?!bitcoincash:)[0-9a-zA-Z]*|(?!bitcoincash:)q|p[0-9a-zA-Z]{41}|(?!bitcoincash:)q|p[0-9a-zA-Z]{42}|bitcoincash:q|p[0-9a-zA-Z]{41}|bitcoincash:q|p[0-9a-zA-Z]{42}';
109
+ pattern = '^(bitcoincash:)?(q|p)[0-9a-zA-Z]{41,42}';
110
case CryptoCurrency.bnb:
111
pattern = '[0-9a-zA-Z]+';
112
case CryptoCurrency.hbar:
lib/exchange/provider/exolix_exchange_provider.dart
+5
-2
@@ -141,8 +141,8 @@ class ExolixExchangeProvider extends ExchangeProvider {
141
'coinTo': _normalizeCurrency(request.toCurrency),
142
'networkFrom': _networkFor(request.fromCurrency),
143
'networkTo': _networkFor(request.toCurrency),
144
- 'withdrawalAddress': request.toAddress,
145
- 'refundAddress': request.refundAddress,
144
+ 'withdrawalAddress': _normalizeAddress(request.toAddress),
145
+ 'refundAddress': _normalizeAddress(request.refundAddress),
146
'rateType': _getRateType(isFixedRateMode),
147
'apiToken': apiKey,
148
};
@@ -275,4 +275,7 @@ class ExolixExchangeProvider extends ExchangeProvider {
275
return tag;
276
}
277
}
278
+
279
+ String _normalizeAddress(String address) =>
280
+ address.startsWith('bitcoincash:') ? address.replaceFirst('bitcoincash:', '') : address;
281
}
lib/exchange/provider/simpleswap_exchange_provider.dart
+5
-2
@@ -129,8 +129,8 @@ class SimpleSwapExchangeProvider extends ExchangeProvider {
129
"currency_to": _normalizeCurrency(request.toCurrency),
130
"amount": request.fromAmount,
131
"fixed": isFixedRateMode,
132
- "user_refund_address": request.refundAddress,
133
- "address_to": request.toAddress
132
+ "user_refund_address": _normalizeAddress(request.refundAddress),
133
+ "address_to": _normalizeAddress(request.toAddress)
134
};
135
final uri = Uri.https(apiAuthority, createExchangePath, params);
136
@@ -243,4 +243,7 @@ class SimpleSwapExchangeProvider extends ExchangeProvider {
243
return currency.title.toLowerCase();
244
}
245
}
246
+
247
+ String _normalizeAddress(String address) =>
248
+ address.startsWith('bitcoincash:') ? address.replaceFirst('bitcoincash:', '') : address;
249
}
lib/exchange/provider/stealth_ex_exchange_provider.dart
+5
-2
@@ -129,8 +129,8 @@ class StealthExExchangeProvider extends ExchangeProvider {
129
if (isFixedRateMode) 'rate_id': rateId,
130
'amount':
131
isFixedRateMode ? double.parse(request.toAmount) : double.parse(request.fromAmount),
132
- 'address': request.toAddress,
133
- 'refund_address': request.refundAddress,
132
+ 'address': _normalizeAddress(request.toAddress),
133
+ 'refund_address': _normalizeAddress(request.refundAddress),
134
'additional_fee_percent': _additionalFeePercent,
135
};
136
@@ -296,4 +296,7 @@ class StealthExExchangeProvider extends ExchangeProvider {
296
297
return currency.tag!.toLowerCase();
298
}
299
+
300
+ String _normalizeAddress(String address) =>
301
+ address.startsWith('bitcoincash:') ? address.replaceFirst('bitcoincash:', '') : address;
302
}
lib/exchange/provider/thorchain_exchange.provider.dart
+6
-5
@@ -116,9 +116,7 @@ class ThorChainExchangeProvider extends ExchangeProvider {
116
required bool isFixedRateMode,
117
required bool isSendAll,
118
}) async {
119
- String formattedToAddress = request.toAddress.startsWith('bitcoincash:')
120
- ? request.toAddress.replaceFirst('bitcoincash:', '')
121
- : request.toAddress;
119
+
120
121
final formattedFromAmount = double.parse(request.fromAmount);
122
@@ -126,11 +124,11 @@ class ThorChainExchangeProvider extends ExchangeProvider {
124
'from_asset': _normalizeCurrency(request.fromCurrency),
125
'to_asset': _normalizeCurrency(request.toCurrency),
126
'amount': _doubleToThorChainString(formattedFromAmount),
129
- 'destination': formattedToAddress,
127
+ 'destination': _normalizeAddress(request.toAddress),
128
'affiliate': _affiliateName,
129
'affiliate_bps': _affiliateBps,
130
'refund_address':
133
- isRefundAddressSupported.contains(request.fromCurrency) ? request.refundAddress : '',
131
+ isRefundAddressSupported.contains(request.fromCurrency) ? _normalizeAddress(request.refundAddress) : '',
132
};
133
134
final responseJSON = await _getSwapQuote(params);
@@ -288,4 +286,7 @@ class ThorChainExchangeProvider extends ExchangeProvider {
286
287
return currentState;
288
}
289
+
290
+ String _normalizeAddress(String address) =>
291
+ address.startsWith('bitcoincash:') ? address.replaceFirst('bitcoincash:', '') : address;
292
}
lib/view_model/contact_list/contact_list_view_model.dart
+10
-5
@@ -99,18 +99,23 @@ abstract class ContactListViewModelBase with Store {
99
100
Future<void> delete(ContactRecord contact) async => contact.original.delete();
101
102
- @computed
103
- List<ContactRecord> get contactsToShow =>
104
- contacts.where((element) => _isValidForCurrency(element)).toList();
102
+ ObservableList<ContactRecord> get contactsToShow =>
103
+ ObservableList.of(contacts.where((element) => _isValidForCurrency(element)));
104
105
@computed
106
List<WalletContact> get walletContactsToShow =>
107
walletContacts.where((element) => _isValidForCurrency(element)).toList();
108
109
bool _isValidForCurrency(ContactBase element) {
110
+ if (element.name.contains('Silent Payments')) return false;
111
+ if (element.name.contains('MWEB')) return false;
112
+
113
return _currency == null ||
114
element.type == _currency ||
113
- element.type.title == _currency!.tag ||
114
- element.type.tag == _currency!.tag;
115
+ (element.type.tag != null &&
116
+ _currency?.tag != null &&
117
+ element.type.tag == _currency?.tag) ||
118
+ _currency?.toString() == element.type.tag ||
119
+ _currency?.tag == element.type.toString();
120
}
121
}