mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-27 06:18:50 +01:00
* feat: Add network selector and compatible networks screen to send page for EVMs * feat: add redesigned payanything flow and handle cases for evms, solana and tron * feat: adding the swap part to the entire flow * refactor: update navigation and error handling in send and swap flows * adjust structuring and use the chain badge icons, also fix crypto and currency values not consistent on single network picker * fix: modify guard for non-evm chains and minor cleanup * use multipicker layout for receive section, streamline send to available balances and adjust colors as needed * handle btc case for picker, update style and images across * fix all pending issues with scanning qr and network handling for both evm and non evm, plus token and amount resolving * fix all pending issues with scanning qr and network handling for both evm and non evm, plus token and amount resolving * fix: expand fetch for tokens across networks and fix other issues regarding scanning from homepage * auto-reformat * fix conflict * handle evm qr scan from homepage and add guards for swap and switch flows * chore: Cleanup * chore: set estimated fee to 0 when switching wallet * fix merge conflicts * fix to review comments and reformatting for lints * fix: root cause for token bug reported * chore: cleanup * feat: add improved anypay swap screen which focuses on the receive amount fix: fiat input toggle erro (also present on prod) reformat: anypay related widgets * feat: add alert for unsupported networks in payment requests * fix: prevent rate and provider from showing until amount is calculated and loaded fix: remove send icon in rate widget and align to center fix: adjust network badge in swap confirm widget * feat: embed tokens for solana and tron in QR generated for swap from external * test: add unit tests for Tron, Solana, and ERC681 URI handling and detection * fix: review comments * fix: handle more edgecases * feat: enhance ERC681URI to support raw token amounts and decimals * refactor: streamline EVM chain ID retrieval in send page and recipient network row * fix: minor review comments --------- Co-authored-by: Robert Malikowski <malikowskirobert@gmail.com>
141 lines
3.8 KiB
Dart
141 lines
3.8 KiB
Dart
import 'package:cake_wallet/src/screens/wallet_connect/services/chain_service/eth/evm_chain_id.dart';
|
|
import 'package:cake_wallet/src/screens/wallet_connect/services/chain_service/eth/evm_supported_methods.dart';
|
|
import 'package:cake_wallet/src/screens/wallet_connect/services/chain_service/solana/solana_chain_id.dart';
|
|
import 'package:cake_wallet/src/screens/wallet_connect/services/chain_service/solana/solana_supported_methods.dart';
|
|
import 'package:cw_core/wallet_type.dart';
|
|
import 'package:cake_wallet/evm/evm.dart';
|
|
|
|
const List<WalletType> walletConnectCompatibleChains = [
|
|
WalletType.ethereum,
|
|
WalletType.polygon,
|
|
WalletType.base,
|
|
WalletType.arbitrum,
|
|
WalletType.bsc,
|
|
WalletType.solana,
|
|
];
|
|
|
|
String walletConnectCompatibleChainsLabel() {
|
|
final names = walletConnectCompatibleChains.map(walletTypeToDisplayName).toList();
|
|
if (names.length <= 1) return names.join();
|
|
final head = names.sublist(0, names.length - 1).join(', ');
|
|
return '$head, and ${names.last}';
|
|
}
|
|
|
|
String networkDisplayName(WalletType type, int? chainId) {
|
|
if (evm != null && isEVMCompatibleChain(type)) {
|
|
final id = chainId ?? evm!.getChainIdByWalletType(type);
|
|
final info = evm!.getChainInfoByChainId(id);
|
|
if (info != null) {
|
|
return info.name;
|
|
}
|
|
}
|
|
return walletTypeToString(type);
|
|
}
|
|
|
|
bool isEVMCompatibleChain(WalletType walletType) {
|
|
switch (walletType) {
|
|
case WalletType.polygon:
|
|
case WalletType.ethereum:
|
|
case WalletType.base:
|
|
case WalletType.arbitrum:
|
|
case WalletType.bsc:
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Blink Protection is supported on Ethereum and Base chains
|
|
bool canSupportBlinkProtection(int? chainId) {
|
|
if (chainId == null) return false;
|
|
|
|
return chainId == 1 || chainId == 8453;
|
|
}
|
|
|
|
bool isNFTACtivatedChain(WalletType walletType, {int? chainId}) {
|
|
if (chainId != null) {
|
|
switch (chainId) {
|
|
case 1:
|
|
case 8453:
|
|
case 137:
|
|
case 42161:
|
|
case 56:
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
switch (walletType) {
|
|
case WalletType.solana:
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
bool isWalletConnectCompatibleChain(WalletType walletType) =>
|
|
walletConnectCompatibleChains.contains(walletType);
|
|
|
|
String getChainNameSpaceAndIdBasedOnWalletType(WalletType walletType, {int? chainId}) {
|
|
if (chainId != null) {
|
|
return evm!.getCaip2ByChainId(chainId);
|
|
}
|
|
|
|
switch (walletType) {
|
|
case WalletType.ethereum:
|
|
return EVMChainId.ethereum.chain();
|
|
case WalletType.polygon:
|
|
return EVMChainId.polygon.chain();
|
|
case WalletType.base:
|
|
return EVMChainId.base.chain();
|
|
case WalletType.arbitrum:
|
|
return EVMChainId.arbitrum.chain();
|
|
case WalletType.bsc:
|
|
return EVMChainId.bsc.chain();
|
|
case WalletType.solana:
|
|
return SolanaChainId.mainnet.chain();
|
|
default:
|
|
return '';
|
|
}
|
|
}
|
|
|
|
List<String> getChainSupportedMethodsOnWalletType(WalletType walletType) {
|
|
switch (walletType) {
|
|
case WalletType.ethereum:
|
|
case WalletType.polygon:
|
|
case WalletType.base:
|
|
case WalletType.arbitrum:
|
|
case WalletType.bsc:
|
|
return EVMSupportedMethods.values.map((e) => e.name).toList();
|
|
case WalletType.solana:
|
|
return SolanaSupportedMethods.values.map((e) => e.name).toList();
|
|
default:
|
|
return [];
|
|
}
|
|
}
|
|
|
|
String getChainNameBasedOnWalletType(WalletType walletType, {int? chainId}) {
|
|
if (walletType == WalletType.solana) {
|
|
return 'mainnet';
|
|
}
|
|
|
|
if (chainId != null) {
|
|
return evm!.getChainNameByChainId(chainId);
|
|
}
|
|
|
|
return evm!.getChainNameByWalletType(walletType);
|
|
}
|
|
|
|
String getTokenNameBasedOnWalletType(WalletType walletType, {int? chainId}) {
|
|
if (walletType == WalletType.solana) {
|
|
return 'SOL';
|
|
}
|
|
|
|
if (chainId != null) {
|
|
return evm!.getTokenNameByChainId(chainId);
|
|
}
|
|
|
|
return evm!.getTokenNameByWalletType(walletType);
|
|
}
|