mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-12-02 12:14:09 +01:00
CW-1208: Pay Anything EVM enahancements (#2600)
* feat: Pay Anything EVM enahancements * ifx: Add baseEth to address validator switch case * fix: Error detecting other wallet types * feat: Preserve QR amount and other data through evm chain selection flow * Update container color to surfaceContainer * feat: Add support for Bitcoin Lightning Network detection - Identify Base QR codes when scanned - Display all available currencies for network - Enhance detector to recognize lightning addresses * fix: Update token selection for currently selected wallet * fix: Improve token matching logic for EVM networks * feat: Update selected currency when wallet is switched * ui: Add chain badge to the swap confirmation bottomsheet * fix: Asks to switch wallets even if the current wallet type is the same as the QR. Fix merge conflicts too * fix: Handle matching logic internally and general cleanups * fix: Terminate flow if address is not a valid parsed address --------- Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com> Co-authored-by: tuxsudo <tuxsudo@tux.pizza>
This commit is contained in:
co-authored by
Omar Hatem
tuxsudo
parent
c74f0e5f82
commit
238022c466
@@ -38,3 +38,24 @@ String getQrImage(WalletType type) {
|
||||
return 'assets/images/qr-cake.png';
|
||||
}
|
||||
}
|
||||
|
||||
String getChainMonoImage(WalletType type) {
|
||||
switch (type) {
|
||||
case WalletType.ethereum:
|
||||
return 'assets/images/eth_chain_mono.svg';
|
||||
case WalletType.solana:
|
||||
return 'assets/images/sol_chain_mono.svg';
|
||||
case WalletType.polygon:
|
||||
return 'assets/images/pol_chain_mono.svg';
|
||||
case WalletType.tron:
|
||||
return 'assets/images/trx_chain_mono.svg';
|
||||
case WalletType.zano:
|
||||
return 'assets/images/zano_chain_mono.svg';
|
||||
case WalletType.base:
|
||||
return 'assets/images/base_chain_mono.svg';
|
||||
case WalletType.arbitrum:
|
||||
return 'assets/images/arbitrum_chain_mono.svg';
|
||||
default:
|
||||
return 'assets/images/eth_chain_mono.svg';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:cake_wallet/reactions/wallet_connect.dart';
|
||||
import 'package:cw_core/cake_hive.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
import 'package:cw_core/currency_for_wallet_type.dart';
|
||||
import 'package:cw_core/erc20_token.dart';
|
||||
import 'package:cw_core/spl_token.dart';
|
||||
import 'package:cw_core/tron_token.dart';
|
||||
@@ -149,7 +150,7 @@ class TokenUtilities {
|
||||
|
||||
// More of a fallback for us
|
||||
for (final balanceCurrency in wallet.balance.keys) {
|
||||
if (balanceCurrency is Erc20Token && _matchesToken(balanceCurrency, currency)) {
|
||||
if (balanceCurrency is Erc20Token && _matchesCurrency(balanceCurrency, currency)) {
|
||||
return balanceCurrency;
|
||||
}
|
||||
}
|
||||
@@ -217,10 +218,73 @@ class TokenUtilities {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/// Checks if two currencies match (by title and tag)
|
||||
static bool _matchesToken(Erc20Token token, CryptoCurrency currency) {
|
||||
return token.title.toLowerCase() == currency.title.toLowerCase() &&
|
||||
(token.tag?.toLowerCase() == currency.tag?.toLowerCase() ||
|
||||
(token.tag == null && currency.tag == null));
|
||||
static Future<List<CryptoCurrency>> getAvailableTokensForNetwork(
|
||||
WalletType network,
|
||||
) async {
|
||||
final baseCurrency = walletTypeToCryptoCurrency(network);
|
||||
final allTokens = <CryptoCurrency>[];
|
||||
final addedAddresses = <String>{};
|
||||
|
||||
allTokens.add(baseCurrency);
|
||||
|
||||
for (final currency in CryptoCurrency.all) {
|
||||
// For EVM networks: ETH has no tag, POL/BASE have tags
|
||||
// Match by tag for POL/BASE, match by title==tag for ETH
|
||||
final matches = (baseCurrency.tag == null && baseCurrency.title == currency.tag) ||
|
||||
(baseCurrency.tag != null &&
|
||||
currency.tag?.toLowerCase() == baseCurrency.tag?.toLowerCase());
|
||||
|
||||
if (matches && _shouldAddToken(allTokens, currency, addedAddresses)) {
|
||||
allTokens.add(currency);
|
||||
}
|
||||
}
|
||||
|
||||
// Add user tokens that don't already exist
|
||||
final userTokens = await _getUserTokensForNetwork(baseCurrency);
|
||||
for (final token in userTokens) {
|
||||
if (_shouldAddToken(allTokens, token, addedAddresses)) {
|
||||
allTokens.add(token);
|
||||
if (token is Erc20Token) {
|
||||
addedAddresses.add(token.contractAddress.toLowerCase());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return allTokens;
|
||||
}
|
||||
|
||||
static bool _shouldAddToken(
|
||||
List<CryptoCurrency> existingTokens,
|
||||
CryptoCurrency token,
|
||||
Set<String> addedAddresses,
|
||||
) {
|
||||
if (token is Erc20Token) {
|
||||
final address = token.contractAddress.toLowerCase();
|
||||
if (addedAddresses.contains(address)) {
|
||||
return false;
|
||||
}
|
||||
if (existingTokens.any((existing) => _matchesCurrency(existing, token))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return !existingTokens.any((existing) => _matchesCurrency(existing, token));
|
||||
}
|
||||
|
||||
static bool _matchesCurrency(CryptoCurrency a, CryptoCurrency b) {
|
||||
return a.title.toUpperCase() == b.title.toUpperCase() &&
|
||||
(a.tag?.toUpperCase() == b.tag?.toUpperCase());
|
||||
}
|
||||
|
||||
static Future<List<CryptoCurrency>> _getUserTokensForNetwork(CryptoCurrency baseCurrency) async {
|
||||
final tokens = await TokenUtilities.loadAllUniqueEvmTokens();
|
||||
|
||||
return tokens.where((token) {
|
||||
// Match by tag, except for ETH which has no tag - match by title instead
|
||||
if (baseCurrency.tag == null) return token.tag == baseCurrency.title;
|
||||
|
||||
return token.tag?.toLowerCase() == baseCurrency.tag?.toLowerCase();
|
||||
}).toList();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user