cake_wallet/lib/utils/payment_request.dart

33 lines
920 B
Dart
Raw Normal View History

2023-08-01 19:56:34 +00:00
import 'package:cw_nano/nano_util.dart';
class PaymentRequest {
PaymentRequest(this.address, this.amount, this.note, this.scheme);
factory PaymentRequest.fromUri(Uri? uri) {
var address = "";
var amount = "";
var note = "";
var scheme = "";
if (uri != null) {
address = uri.path;
amount = uri.queryParameters['tx_amount'] ?? uri.queryParameters['amount'] ?? "";
2023-08-01 19:56:34 +00:00
note = uri.queryParameters['tx_description'] ?? uri.queryParameters['message'] ?? "";
scheme = uri.scheme;
}
2023-08-01 19:56:34 +00:00
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);
}
final String address;
final String amount;
final String note;
final String scheme;
2023-08-01 19:56:34 +00:00
}