mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-20 06:08:34 +02:00
* feat: initialize cw_arbitrum package with essential files - Implement ArbitrumClient for transaction handling - Add ArbitrumWallet and related classes for wallet management - Establish transaction history and info classes for Arbitrum transactions - Add ArbitrumWalletService for wallet operations and management * feat: Add arbitrum related secrets to workflow * feat: Add nodes for arbitrum * feat: Add Arbitrum support to cryptocurrency handling * refactor: Update Arbitrum currency references from 'ARB' to 'ETH' * feat: Add Arbitrum support to wallet type and transaction handling * feat: Add Arbitrum URL schemes to Android and iOS configurations * feat: Add Arbitrum SVG icons and a WebP image * feat: Setup Arbitrum proxy * fix: Add localization * feat: Integrate Arbitrum support across various configurations and files - Updated cakewallet.bat to include Arbitrum in app configuration. - Added Arbitrum node list to pubspec_base.yaml. - Modified Android, iOS, Linux, and macOS app configuration scripts to support Arbitrum. - Introduced Arbitrum output path and generation logic in configure.dart. - Enhanced wallet type and pubspec generation to include Arbitrum. - Added Arbitrum-related secrets in secret_key.dart. * feat: Enhance Arbitrum integration with new URI class and updates across various components - Introduced ArbitrumURI class for handling Arbitrum payment URIs. - Updated seed validator, wallet creation service, and other components to support Arbitrum. - Added Arbitrum node handling in default settings migration and node list management. - Enhanced preferences and settings store to include Arbitrum-specific configurations. - Updated QR utility and token utilities to accommodate Arbitrum functionalities. * feat: Add Arbitrum support to various buy providers - Updated DFXBuyProvider, KryptonimBuyProvider, OnRamperBuyProvider, and RobinhoodBuyProvider to include Arbitrum wallet type and blockchain references. - Enhanced integration for Arbitrum across multiple components to ensure consistent support. * feat: Implement Arbitrum support in wallet selection and settings - Added Arbitrum wallet type handling in common test flows and wallet services. - Integrated Arbitrum icons in desktop wallet selection and menu widgets. - Updated privacy settings to include ArbiScan options. - Enhanced key service to support Arbitrum private and public key retrieval. * feat: Expand Arbitrum support across various view models and components - Integrated Arbitrum wallet type handling in advanced privacy settings, transaction details, and wallet management. - Added Arbitrum-specific methods for transaction and wallet creation, restoration, and fee management. - Updated dashboard and home settings to accommodate Arbitrum functionalities, including token management and transaction display. - Enhanced exchange and send view models to support Arbitrum transactions and currency handling. - Included Arbitrum in wallet address list and privacy settings for improved user experience. * refactor: Simplify token initialization in Arbitrum wallet service - Removed the migration flag from the addInitialTokens method in ArbitrumWalletService. - Updated addInitialTokens method in ArbitrumWallet to handle existing tokens more efficiently. - Enhanced initial token retrieval logic in DefaultArbitrumErc20Tokens to prioritize iconPath assignment. - Improved token update logic in BaseWallet for consistency across wallet services. * chore: Update Dart SDK constraints in pubspec.yaml * fix: Update file paths for arbitrum assets * fix: Correct box name formatting in Arbitrum wallet initialization * Update .github/workflows/pr_test_build_android.yml [skip ci * Update .github/workflows/pr_test_build_android.yml * fix: Add missing evm params * fix: Remove duplicate method declaration * refactor: simplify isSwapsXyzSendingEVMTokenSwap check * fix: Update arbitrum configs with sql storage update * feat: Add estimated fee retrieval for Arbitrum and revamp priority fee handling for EVMChainWallet * refactor: Update transaction priority handling and estimated fee calculations across EVMChain chains, also remove priority fee levels for Arbitrum --------- Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
244 lines
7.4 KiB
Dart
244 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',
|
|
'ARB' => 'Arbitrum',
|
|
'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.arbEth => 'Arbitrum',
|
|
CryptoCurrency.maticpoly => 'Matic',
|
|
_ => null,
|
|
};
|
|
}
|
|
|
|
return blockchain ?? cur.fullName ?? '';
|
|
}
|
|
}
|