mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-11-18 09:54:01 +01:00
* chore: Create Base package template * chore: Update configuration scripts and dependencies to include 'base' coin support * chore: Update pubspec.yaml, adjust SDK constraints, and add new dependencies * feat: Add support for base wallet type and cryptocurrency in related configurations * feat: Implement BaseWallet and DefaultBaseTokens classes for managing base cryptocurrency transactions * feat: Add BaseTransactionHistory and BaseTransactionInfo classes for handling base cryptocurrency transaction data * feat: Implement BaseClient, BaseWalletService, and BaseMnemonicIsIncorrectException * feat: Setup base proxy for main package and adjust token class name * feat: Setup initial base node configuration * feat: Integrate support for base wallet type across various functions and services * feat: Add base support to exchange and outputs * feat: Add base wallet type integration to wallet creation and node management * feat: Add base support to transaction details and transaction list item * feat: Implement BaseURI class and add base support across wallet creation and keys view models * feat: Add support for BaseScan preference in settings store * feat: Integrate Base support into various workflows and documentation * feat: Addingbase config to windows and secret key support * feat: Add base support to settings and address handling * chore: Move walletTypeToCurrency to another file and adjust across codebase * feat: Add 'basescan_history' string localization * feat: Remove Cryptocurrency.base, it doesn't have a base currency * feat: Set eth as native currency * feat: Enhance Base support across various sending, exchange, transaction details, fees, dashboard and balance * feat: Integrate Base wallet support in advanced privacy settings and home settings view models * feat: Add Base wallet support with icon and integration across providers, default settings migration, preferences, wallet connect, settings and token utilities * feat: Update currency handling to use baseEth for Base wallet integration across various components * fix: Update default token symbol to ETH in Base wallet transaction model * refactor: Change default currency references from BASE to ETH across client, transaction info, and wallet components * feat: Introduce normalizedIconPath for CryptoCurrency to standardize icon retrieval across wallet components * fix: Include baseEth as a native token in EVMChainClient for currency handling * chore: Update base_icon.png * feat: Add more nodes to base_node_list.yml * refactor: Update wallet icon retrieval to use normalizedIconPath * chore: Remove unused cases and cleanup impl. * feat: Add base proxy generation to configure * refactor: Update base proxy and generation code in configure.dart * feat: Add missing wallet and mono images * fix: Wrong image path for pr and add missing base qr image * feat: Enhance EVMTransactionErrorFeesHandler to parse new insufficient funds error format and calculate transaction fees in ETH and USD * feat: Add gas price safety buffer for Base chain transactions to improve fee estimation accuracy, also fixes send all not calculating correctly * Update model_generator.sh [skip ci] * Update assets/base_node_list.yml [skip ci] * Update cw_base/lib/default_base_erc20_tokens.dart [skip ci] * Review fixes * fixes --------- Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
242 lines
7.4 KiB
Dart
242 lines
7.4 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:cake_wallet/.secrets.g.dart' as secrets;
|
|
import 'package:cake_wallet/buy/buy_provider.dart';
|
|
import 'package:cake_wallet/buy/buy_quote.dart';
|
|
import 'package:cake_wallet/buy/pairs_utils.dart';
|
|
import 'package:cake_wallet/buy/payment_method.dart';
|
|
import 'package:cake_wallet/entities/fiat_currency.dart';
|
|
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
|
|
import 'package:cake_wallet/utils/show_pop_up.dart';
|
|
import 'package:cw_core/crypto_currency.dart';
|
|
import 'package:cw_core/utils/proxy_wrapper.dart';
|
|
import 'package:cw_core/wallet_base.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'dart:developer';
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
class KryptonimBuyProvider extends BuyProvider {
|
|
KryptonimBuyProvider({required WalletBase wallet, bool isTestEnvironment = false})
|
|
: super(
|
|
wallet: wallet,
|
|
isTestEnvironment: isTestEnvironment,
|
|
hardwareWalletVM: null,
|
|
supportedCryptoList: supportedCryptoToFiatPairs(
|
|
notSupportedCrypto: _notSupportedCrypto, notSupportedFiat: _notSupportedFiat),
|
|
supportedFiatList: supportedFiatToCryptoPairs(
|
|
notSupportedFiat: _notSupportedFiat, notSupportedCrypto: _notSupportedCrypto));
|
|
|
|
static const _isProduction = true;
|
|
|
|
static const _baseUrl = _isProduction ? 'app.kryptonim.com' : 'intg-api.kryptonim.com';
|
|
static const _baseWidgetUrl = _isProduction ? 'buy.kryptonim.com' : 'intg.kryptonim.com';
|
|
static const _quotePath = '/v2/ramp/buy/quotes';
|
|
static const _merchantId = 'a70fe053';
|
|
|
|
static String get _kryptonimApiKey => secrets.kryptonimApiKey;
|
|
|
|
static const List<CryptoCurrency> _notSupportedCrypto = [];
|
|
static const List<FiatCurrency> _notSupportedFiat = [];
|
|
|
|
@override
|
|
String get title => 'Kryptonim';
|
|
|
|
@override
|
|
String get providerDescription => 'Kryptonim Buy Provider';
|
|
|
|
@override
|
|
String get lightIcon => 'assets/images/kryptonim_light.png';
|
|
|
|
@override
|
|
String get darkIcon => 'assets/images/kryptonim_dark.png';
|
|
|
|
@override
|
|
bool get isAggregator => false;
|
|
|
|
Future<Map<String, dynamic>> getExchangeRates(
|
|
{required CryptoCurrency cryptoCurrency,
|
|
required String fiatCurrency,
|
|
required double amount}) async {
|
|
final url = Uri.https(_baseUrl, _quotePath, {'m': _merchantId});
|
|
|
|
final headers = {
|
|
'accept': 'application/json',
|
|
'Content-Type': 'application/json',
|
|
'Authorization': _kryptonimApiKey,
|
|
};
|
|
|
|
final body = jsonEncode({
|
|
'amount': amount,
|
|
'currency': fiatCurrency,
|
|
'converted_currency': cryptoCurrency.title,
|
|
'blockchain': _normalizeBlockChain(cryptoCurrency),
|
|
'quote_currency': fiatCurrency,
|
|
});
|
|
|
|
try {
|
|
final response = await ProxyWrapper().post(
|
|
clearnetUri: url,
|
|
headers: headers,
|
|
body: body,
|
|
);
|
|
|
|
if (response.statusCode == 200 || response.statusCode == 201 || response.statusCode == 401) {
|
|
|
|
return jsonDecode(response.body) as Map<String, dynamic>;
|
|
} else {
|
|
return {};
|
|
}
|
|
} catch (e) {
|
|
return {};
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<List<PaymentMethod>> getAvailablePaymentTypes(
|
|
String fiatCurrency, CryptoCurrency cryptoCurrency, bool isBuyAction) async {
|
|
|
|
final data = await getExchangeRates(
|
|
cryptoCurrency: cryptoCurrency,
|
|
fiatCurrency: fiatCurrency,
|
|
amount: 100.0,
|
|
);
|
|
|
|
if (data.isEmpty || !data.containsKey('data')) return [];
|
|
|
|
final paymentMethods = (data['data'] as List<dynamic>)
|
|
.map((e) => PaymentMethod.fromKryptonimJson(e as Map<String, dynamic>))
|
|
.toList();
|
|
|
|
return paymentMethods;
|
|
}
|
|
|
|
@override
|
|
Future<List<Quote>?> fetchQuote({
|
|
required CryptoCurrency cryptoCurrency,
|
|
required FiatCurrency fiatCurrency,
|
|
required double amount,
|
|
required bool isBuyAction,
|
|
required String walletAddress,
|
|
PaymentType? paymentType,
|
|
String? customPaymentMethodType,
|
|
String? countryCode,
|
|
}) async {
|
|
log('Kryptonim: Fetching quote: ${isBuyAction ? cryptoCurrency : fiatCurrency} -> ${isBuyAction ? fiatCurrency : cryptoCurrency}, amount: $amount');
|
|
|
|
final data = await getExchangeRates(
|
|
cryptoCurrency: cryptoCurrency,
|
|
fiatCurrency: fiatCurrency.toString(),
|
|
amount: amount,
|
|
);
|
|
|
|
if (!data.containsKey('data') || (data['data'] as List).isEmpty) {
|
|
return null;
|
|
}
|
|
|
|
final quotesList = data['data'] as List<dynamic>;
|
|
|
|
Map<String, dynamic>? selectedPaymentMethod;
|
|
|
|
if (paymentType == PaymentType.all || paymentType == null) {
|
|
selectedPaymentMethod = quotesList.first as Map<String, dynamic>;
|
|
} else {
|
|
for (var quote in quotesList) {
|
|
final quotePaymentType = PaymentMethod.getPaymentTypeId(quote['payment_method'] as String?);
|
|
if (quotePaymentType == paymentType) {
|
|
selectedPaymentMethod = quote as Map<String, dynamic>;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (selectedPaymentMethod == null) {
|
|
return null;
|
|
}
|
|
|
|
final selectedPaymentType =
|
|
PaymentMethod.getPaymentTypeId(selectedPaymentMethod['payment_method'] as String?);
|
|
final quote = Quote.fromKryptonimJson(selectedPaymentMethod, isBuyAction, selectedPaymentType ?? PaymentType.unknown);
|
|
|
|
quote.setFiatCurrency = fiatCurrency;
|
|
quote.setCryptoCurrency = cryptoCurrency;
|
|
|
|
return [quote];
|
|
}
|
|
|
|
@override
|
|
Future<void>? launchProvider(
|
|
{required BuildContext context,
|
|
required Quote quote,
|
|
required double amount,
|
|
required bool isBuyAction,
|
|
required String cryptoCurrencyAddress,
|
|
String? countryCode}) async {
|
|
final params = {
|
|
'amount': amount.toInt().toString(),
|
|
'currency': quote.fiatCurrency.name,
|
|
'convertedCurrency': quote.cryptoCurrency.title,
|
|
'blockchain': _normalizeBlockChain(quote.cryptoCurrency),
|
|
'address': cryptoCurrencyAddress,
|
|
'paymentMethod': normalizePaymentMethod(quote.paymentType),
|
|
};
|
|
|
|
final uri = Uri.https(_baseWidgetUrl, '/redirect-form', params);
|
|
|
|
try {
|
|
if (await canLaunchUrl(uri)) {
|
|
await launchUrl(uri, mode: LaunchMode.externalApplication);
|
|
} else {
|
|
throw Exception('Could not launch URL');
|
|
}
|
|
} catch (e) {
|
|
await showPopUp<void>(
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
return AlertWithOneAction(
|
|
alertTitle: "Kryptonim",
|
|
alertContent: "Payment provider is unavailable: $e",
|
|
buttonText: "OK",
|
|
buttonAction: () => Navigator.of(context).pop(),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
String normalizePaymentMethod(PaymentType paymentType) {
|
|
switch (paymentType) {
|
|
case PaymentType.bankTransfer:
|
|
return 'bank';
|
|
case PaymentType.creditCard:
|
|
case PaymentType.debitCard:
|
|
return 'card';
|
|
default:
|
|
return paymentType.name.toLowerCase();
|
|
}
|
|
}
|
|
|
|
String _normalizeBlockChain(CryptoCurrency cur) {
|
|
String? blockchain = switch (cur.tag) {
|
|
'ETH' => 'Ethereum',
|
|
'BASE' => 'Base',
|
|
'POL' => 'Polygon',
|
|
'AVAXC' => 'Avalanche',
|
|
'SOL' => 'Solana',
|
|
_ => null,
|
|
};
|
|
|
|
if (blockchain == null) {
|
|
blockchain = switch (cur) {
|
|
CryptoCurrency.btc => 'Bitcoin',
|
|
CryptoCurrency.ltc => 'Litecoin',
|
|
CryptoCurrency.eth => 'Ethereum',
|
|
CryptoCurrency.baseEth => 'Base',
|
|
CryptoCurrency.maticpoly => 'Matic',
|
|
_ => null,
|
|
};
|
|
}
|
|
|
|
return blockchain ?? cur.fullName ?? '';
|
|
}
|
|
}
|