Cw 805 fix bch refund address (#1782)
Some checks failed
Cache Dependencies / test (push) Has been cancelled

* fix bch address format for exolix, stealth, thorchain, simpleswap

* exclude SP and MWEB from the exchange address book

* address pr review comments
This commit is contained in:
Serhii 2024-11-05 11:33:24 +02:00 committed by GitHub
parent b8ffd47f06
commit 459f0d352d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 32 additions and 18 deletions

View file

@ -106,8 +106,7 @@ class AddressValidator extends TextValidator {
case CryptoCurrency.wow:
pattern = '[0-9a-zA-Z]+';
case CryptoCurrency.bch:
pattern =
'(?!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}';
pattern = '^(bitcoincash:)?(q|p)[0-9a-zA-Z]{41,42}';
case CryptoCurrency.bnb:
pattern = '[0-9a-zA-Z]+';
case CryptoCurrency.hbar:

View file

@ -141,8 +141,8 @@ class ExolixExchangeProvider extends ExchangeProvider {
'coinTo': _normalizeCurrency(request.toCurrency),
'networkFrom': _networkFor(request.fromCurrency),
'networkTo': _networkFor(request.toCurrency),
'withdrawalAddress': request.toAddress,
'refundAddress': request.refundAddress,
'withdrawalAddress': _normalizeAddress(request.toAddress),
'refundAddress': _normalizeAddress(request.refundAddress),
'rateType': _getRateType(isFixedRateMode),
'apiToken': apiKey,
};
@ -275,4 +275,7 @@ class ExolixExchangeProvider extends ExchangeProvider {
return tag;
}
}
String _normalizeAddress(String address) =>
address.startsWith('bitcoincash:') ? address.replaceFirst('bitcoincash:', '') : address;
}

View file

@ -129,8 +129,8 @@ class SimpleSwapExchangeProvider extends ExchangeProvider {
"currency_to": _normalizeCurrency(request.toCurrency),
"amount": request.fromAmount,
"fixed": isFixedRateMode,
"user_refund_address": request.refundAddress,
"address_to": request.toAddress
"user_refund_address": _normalizeAddress(request.refundAddress),
"address_to": _normalizeAddress(request.toAddress)
};
final uri = Uri.https(apiAuthority, createExchangePath, params);
@ -243,4 +243,7 @@ class SimpleSwapExchangeProvider extends ExchangeProvider {
return currency.title.toLowerCase();
}
}
String _normalizeAddress(String address) =>
address.startsWith('bitcoincash:') ? address.replaceFirst('bitcoincash:', '') : address;
}

View file

@ -129,8 +129,8 @@ class StealthExExchangeProvider extends ExchangeProvider {
if (isFixedRateMode) 'rate_id': rateId,
'amount':
isFixedRateMode ? double.parse(request.toAmount) : double.parse(request.fromAmount),
'address': request.toAddress,
'refund_address': request.refundAddress,
'address': _normalizeAddress(request.toAddress),
'refund_address': _normalizeAddress(request.refundAddress),
'additional_fee_percent': _additionalFeePercent,
};
@ -296,4 +296,7 @@ class StealthExExchangeProvider extends ExchangeProvider {
return currency.tag!.toLowerCase();
}
String _normalizeAddress(String address) =>
address.startsWith('bitcoincash:') ? address.replaceFirst('bitcoincash:', '') : address;
}

View file

@ -116,9 +116,7 @@ class ThorChainExchangeProvider extends ExchangeProvider {
required bool isFixedRateMode,
required bool isSendAll,
}) async {
String formattedToAddress = request.toAddress.startsWith('bitcoincash:')
? request.toAddress.replaceFirst('bitcoincash:', '')
: request.toAddress;
final formattedFromAmount = double.parse(request.fromAmount);
@ -126,11 +124,11 @@ class ThorChainExchangeProvider extends ExchangeProvider {
'from_asset': _normalizeCurrency(request.fromCurrency),
'to_asset': _normalizeCurrency(request.toCurrency),
'amount': _doubleToThorChainString(formattedFromAmount),
'destination': formattedToAddress,
'destination': _normalizeAddress(request.toAddress),
'affiliate': _affiliateName,
'affiliate_bps': _affiliateBps,
'refund_address':
isRefundAddressSupported.contains(request.fromCurrency) ? request.refundAddress : '',
isRefundAddressSupported.contains(request.fromCurrency) ? _normalizeAddress(request.refundAddress) : '',
};
final responseJSON = await _getSwapQuote(params);
@ -288,4 +286,7 @@ class ThorChainExchangeProvider extends ExchangeProvider {
return currentState;
}
String _normalizeAddress(String address) =>
address.startsWith('bitcoincash:') ? address.replaceFirst('bitcoincash:', '') : address;
}

View file

@ -99,18 +99,23 @@ abstract class ContactListViewModelBase with Store {
Future<void> delete(ContactRecord contact) async => contact.original.delete();
@computed
List<ContactRecord> get contactsToShow =>
contacts.where((element) => _isValidForCurrency(element)).toList();
ObservableList<ContactRecord> get contactsToShow =>
ObservableList.of(contacts.where((element) => _isValidForCurrency(element)));
@computed
List<WalletContact> get walletContactsToShow =>
walletContacts.where((element) => _isValidForCurrency(element)).toList();
bool _isValidForCurrency(ContactBase element) {
if (element.name.contains('Silent Payments')) return false;
if (element.name.contains('MWEB')) return false;
return _currency == null ||
element.type == _currency ||
element.type.title == _currency!.tag ||
element.type.tag == _currency!.tag;
(element.type.tag != null &&
_currency?.tag != null &&
element.type.tag == _currency?.tag) ||
_currency?.toString() == element.type.tag ||
_currency?.tag == element.type.toString();
}
}