mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-17 05:41:29 +02:00
* fix: update Bitcoin and Litecoin Bech32 address patterns for improved detection for pay anything flow * feat: add Litecoin MWEB address detection patterns for pay anything flow * feat: Add support for ERC-681 payment scheme to QR and link to exchange send from external QR * feat: Introduce TokenUtilities to centralize token management across viewmodels - Added TokenUtilities class to centralize token-related operations for EVM, Solana, and Tron tokens. - Refactored existing methods in ExchangeTradeViewModel and SendViewModel to utilize TokenUtilities. - Updated PaymentRequest to include contractAddress. - Enhanced payment QR scanning to fetch token details for QRs with contract addresses - ERC-681 QR scheme * fix: Prefill amount with other data when app is brought up via payment deeplink on QR scan * fix: Reduce trade not created errors WIP * feat: Add exchange provider logging functionality * feat: Enhance ERC681URI with amount normalization, prevents parsing issues with various input formats for amounts * - Use regex from address validator for btc/ltc manual checks - Add check for solana addresses - Handle failures in normalizeToInteger method - fix issue with address only being added when there's an amount * feat: Trigger pay anything flow when address is pasted via ctrl v or paste input * fix: remove duplicate registration * fix: disable text selection in SendCard address field * feat: Prevent swap option from showing for Mweb and Silent Payment addresses in Pay Anything flow * refactor: remove notes widget and controllers from swap confirmation bottomsheet * fix: Issue with tap send all button not responsive, and updateing fiat amount, after wallet syncing is complete if it was previously tapped while wallet was syncing * fix: Resolve excessive decimal places error with input sanitization and formatting for amount entry * fix: Add check for already usable amount format to prevent errors with Nano QR scanning * fix: Improve fiat input handling by preventing unnecessary updates during user input * fix: Handle potential null case for setReceiveAmountFromFiat * Update lib/src/widgets/bottom_sheet/payment_confirmation_bottom_sheet.dart --------- Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
99 lines
3.2 KiB
Dart
99 lines
3.2 KiB
Dart
import 'package:cake_wallet/core/payment_uris.dart';
|
|
import 'package:cake_wallet/nano/nano.dart';
|
|
|
|
class PaymentRequest {
|
|
PaymentRequest(this.address, this.amount, this.note, this.scheme, this.pjUri,
|
|
{this.callbackUrl, this.callbackMessage, this.contractAddress});
|
|
|
|
factory PaymentRequest.fromUri(Uri? uri) {
|
|
var address = "";
|
|
var amount = "";
|
|
var note = "";
|
|
var scheme = "";
|
|
String? walletType;
|
|
String? callbackUrl;
|
|
String? callbackMessage;
|
|
String? pjUri;
|
|
String? contractAddress;
|
|
|
|
if (uri != null) {
|
|
if (uri.queryParameters['pj'] != null) {
|
|
pjUri = uri.toString();
|
|
}
|
|
|
|
address = uri.queryParameters['address'] ?? uri.path;
|
|
amount = uri.queryParameters['tx_amount'] ?? uri.queryParameters['amount'] ?? "";
|
|
note = uri.queryParameters['tx_description'] ?? uri.queryParameters['message'] ?? "";
|
|
scheme = uri.scheme;
|
|
callbackUrl = uri.queryParameters['callback'];
|
|
callbackMessage = uri.queryParameters['callbackMessage'];
|
|
walletType = uri.queryParameters['type'];
|
|
|
|
if (scheme == "ethereum") {
|
|
final paymentUri = ERC681URI.fromUri(uri);
|
|
|
|
address = paymentUri.address;
|
|
amount = paymentUri.amount;
|
|
contractAddress = paymentUri.contractAddress;
|
|
}
|
|
}
|
|
|
|
if (scheme == "nano-gpt") {
|
|
scheme = walletType ?? "nano";
|
|
}
|
|
|
|
if (nano != null) {
|
|
if (amount.isNotEmpty) {
|
|
if (!_isAlreadyUsableAmount(amount)) {
|
|
if (address.contains("nano")) {
|
|
amount = nanoUtil!.getRawAsUsableString(amount, nanoUtil!.rawPerNano);
|
|
} else if (address.contains("ban")) {
|
|
amount = nanoUtil!.getRawAsUsableString(amount, nanoUtil!.rawPerBanano);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return PaymentRequest(
|
|
address,
|
|
amount,
|
|
note,
|
|
scheme,
|
|
pjUri,
|
|
callbackUrl: callbackUrl,
|
|
callbackMessage: callbackMessage,
|
|
contractAddress: contractAddress,
|
|
);
|
|
}
|
|
|
|
final String address;
|
|
final String amount;
|
|
final String note;
|
|
final String scheme;
|
|
final String? pjUri;
|
|
final String? callbackUrl;
|
|
final String? callbackMessage;
|
|
final String? contractAddress;
|
|
|
|
/// Checks if the amount string is already in a usable format (e.g., "123.45") and doesn't need to be converted from raw format.
|
|
///
|
|
/// This was causing an error for us when we scan Nano QRs with amounts in them, the amounts are already in usable format so when the parsing was done, it returns 0 wrongly.
|
|
static bool _isAlreadyUsableAmount(String amount) {
|
|
if (amount.isEmpty) return false;
|
|
|
|
// Try to parse as double - if successful, it's already in usable format
|
|
final parsed = double.tryParse(amount.replaceAll(',', '.'));
|
|
if (parsed == null) return false;
|
|
|
|
// Check if the amount contains a decimal point and is a reasonable number,
|
|
// it's likely already in usable format rather than raw format
|
|
// Raw amounts are typically very large integers without decimal points
|
|
if (amount.contains('.') && parsed > 0 && parsed < 1000000000) return true;
|
|
|
|
// If it's a small integer (less than 1 billion), it's likely already usable
|
|
if (parsed == parsed.toInt() && parsed < 1000000000) return true;
|
|
|
|
return false;
|
|
}
|
|
}
|