| 1 | import "package:cake_wallet/core/universal_address_detector.dart"; |
| 2 | import "package:cake_wallet/utils/payment_request.dart"; |
| 3 | import "package:cw_core/amount/money.dart"; |
| 4 | import "package:cw_core/crypto_currency.dart"; |
| 5 | import "package:cw_core/wallet_info.dart"; |
| 6 | import "package:cw_core/wallet_type.dart"; |
| 7 | |
| 8 | sealed class ChainBinding { |
| 9 | const ChainBinding(); |
| 10 | } |
| 11 | |
| 12 | class ExplicitEvmChain extends ChainBinding { |
| 13 | const ExplicitEvmChain(this.chainId); |
| 14 | |
| 15 | final int chainId; |
| 16 | } |
| 17 | |
| 18 | class ChainlessEvm extends ChainBinding { |
| 19 | const ChainlessEvm(); |
| 20 | } |
| 21 | |
| 22 | class NoEvmBinding extends ChainBinding { |
| 23 | const NoEvmBinding(); |
| 24 | } |
| 25 | |
| 26 | class AnyPayRequest { |
| 27 | AnyPayRequest({ |
| 28 | required this.rawInput, |
| 29 | required this.paymentRequest, |
| 30 | required this.detection, |
| 31 | required this.chainBinding, |
| 32 | }); |
| 33 | |
| 34 | final String rawInput; |
| 35 | final PaymentRequest paymentRequest; |
| 36 | final AddressDetectionResult detection; |
| 37 | final ChainBinding chainBinding; |
| 38 | |
| 39 | String get address => paymentRequest.address; |
| 40 | |
| 41 | String get amount => paymentRequest.amount; |
| 42 | |
| 43 | String? get contractAddress => paymentRequest.contractAddress; |
| 44 | |
| 45 | bool get hasContract => contractAddress != null && contractAddress!.isNotEmpty; |
| 46 | |
| 47 | bool get isLightning => detection.detectedCurrency == CryptoCurrency.btcln; |
| 48 | } |
| 49 | |
| 50 | class WalletSnapshot { |
| 51 | WalletSnapshot({ |
| 52 | required this.type, |
| 53 | required this.currentWalletIsEvm, |
| 54 | required this.currentChainId, |
| 55 | required this.wallets, |
| 56 | required this.supportedEvmChains, |
| 57 | required this.hasEvmProxy, |
| 58 | required this.hasSolanaProxy, |
| 59 | required this.hasTronProxy, |
| 60 | }); |
| 61 | |
| 62 | final WalletType type; |
| 63 | final bool currentWalletIsEvm; |
| 64 | final int? currentChainId; |
| 65 | final List<WalletInfo> wallets; |
| 66 | final Map<int, WalletType> supportedEvmChains; |
| 67 | final bool hasEvmProxy; |
| 68 | final bool hasSolanaProxy; |
| 69 | final bool hasTronProxy; |
| 70 | |
| 71 | List<WalletInfo> walletsOfType(WalletType walletType) => |
| 72 | wallets.where((wallet) => wallet.type == walletType).toList(); |
| 73 | } |
| 74 | |
| 75 | sealed class AnyPayResolution { |
| 76 | const AnyPayResolution(); |
| 77 | } |
| 78 | |
| 79 | class NoTokenRequested extends AnyPayResolution { |
| 80 | const NoTokenRequested(); |
| 81 | } |
| 82 | |
| 83 | class TokenResolved extends AnyPayResolution { |
| 84 | const TokenResolved({required this.token, this.chainId, this.amountOverride}); |
| 85 | |
| 86 | final CryptoCurrency token; |
| 87 | final int? chainId; |
| 88 | final String? amountOverride; |
| 89 | } |
| 90 | |
| 91 | class TokenUnknown extends AnyPayResolution { |
| 92 | const TokenUnknown(this.contract); |
| 93 | |
| 94 | final String contract; |
| 95 | } |
| 96 | |
| 97 | sealed class AnyPayDecision { |
| 98 | const AnyPayDecision(); |
| 99 | } |
| 100 | |
| 101 | class AnyPayApplyToCurrentWallet extends AnyPayDecision { |
| 102 | const AnyPayApplyToCurrentWallet({ |
| 103 | this.token, |
| 104 | this.amountOverride, |
| 105 | this.fallbackCurrency, |
| 106 | }); |
| 107 | |
| 108 | final CryptoCurrency? token; |
| 109 | final String? amountOverride; |
| 110 | final CryptoCurrency? fallbackCurrency; |
| 111 | } |
| 112 | |
| 113 | class AnyPayEvmNetworkChoice extends AnyPayDecision { |
| 114 | const AnyPayEvmNetworkChoice(); |
| 115 | } |
| 116 | |
| 117 | class AnyPayCrossChainPayment extends AnyPayDecision { |
| 118 | const AnyPayCrossChainPayment({ |
| 119 | required this.targetWalletType, |
| 120 | required this.wallets, |
| 121 | this.targetChainId, |
| 122 | this.token, |
| 123 | this.amountOverride, |
| 124 | this.canSwap = true, |
| 125 | }); |
| 126 | |
| 127 | final WalletType targetWalletType; |
| 128 | final int? targetChainId; |
| 129 | final List<WalletInfo> wallets; |
| 130 | final CryptoCurrency? token; |
| 131 | final String? amountOverride; |
| 132 | final bool canSwap; |
| 133 | |
| 134 | bool get hasCompatibleWallet => wallets.isNotEmpty; |
| 135 | } |
| 136 | |
| 137 | class AnyPayUnsupportedNetwork extends AnyPayDecision { |
| 138 | const AnyPayUnsupportedNetwork(this.chainId); |
| 139 | |
| 140 | final int chainId; |
| 141 | } |
| 142 | |
| 143 | class AnyPayUnsupportedToken extends AnyPayDecision { |
| 144 | const AnyPayUnsupportedToken(this.contract); |
| 145 | |
| 146 | final String contract; |
| 147 | } |
| 148 | |
| 149 | class AnyPayEmptyInput extends AnyPayDecision { |
| 150 | const AnyPayEmptyInput(); |
| 151 | } |
| 152 | |
| 153 | class AnyPayEvaluation { |
| 154 | AnyPayEvaluation({required this.request, required this.decision}); |
| 155 | |
| 156 | final AnyPayRequest request; |
| 157 | final AnyPayDecision decision; |
| 158 | } |
| 159 | |
| 160 | class AnyPaySwapIntent { |
| 161 | AnyPaySwapIntent({ |
| 162 | required this.request, |
| 163 | required this.receiveCurrency, |
| 164 | required this.targetWalletType, |
| 165 | this.receiveAmount, |
| 166 | }); |
| 167 | |
| 168 | final AnyPayRequest request; |
| 169 | final CryptoCurrency receiveCurrency; |
| 170 | final WalletType targetWalletType; |
| 171 | final Money? receiveAmount; |
| 172 | |
| 173 | String get recipientAddress => request.address; |
| 174 | } |