mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-25 05:58:42 +01:00
Flutter upgrade
This commit is contained in:
@@ -6,14 +6,14 @@ import 'package:cake_wallet/monero/monero.dart';
|
||||
|
||||
class AnyPayPayment {
|
||||
AnyPayPayment({
|
||||
@required this.time,
|
||||
@required this.expires,
|
||||
@required this.memo,
|
||||
@required this.paymentUrl,
|
||||
@required this.paymentId,
|
||||
@required this.chain,
|
||||
@required this.network,
|
||||
@required this.instructions});
|
||||
required this.time,
|
||||
required this.expires,
|
||||
required this.memo,
|
||||
required this.paymentUrl,
|
||||
required this.paymentId,
|
||||
required this.chain,
|
||||
required this.network,
|
||||
required this.instructions});
|
||||
|
||||
factory AnyPayPayment.fromMap(Map<String, dynamic> obj) {
|
||||
final instructions = (obj['instructions'] as List<dynamic>)
|
||||
@@ -45,13 +45,13 @@ class AnyPayPayment {
|
||||
.fold<int>(0, (int outAcc, out) => outAcc + out.amount));
|
||||
switch (chain) {
|
||||
case AnyPayChain.xmr:
|
||||
return monero.formatterMoneroAmountToString(amount: total);
|
||||
return monero!.formatterMoneroAmountToString(amount: total);
|
||||
case AnyPayChain.btc:
|
||||
return bitcoin.formatterBitcoinAmountToString(amount: total);
|
||||
return bitcoin!.formatterBitcoinAmountToString(amount: total);
|
||||
case AnyPayChain.ltc:
|
||||
return bitcoin.formatterBitcoinAmountToString(amount: total);
|
||||
return bitcoin!.formatterBitcoinAmountToString(amount: total);
|
||||
default:
|
||||
return null;
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,11 +3,11 @@ import 'package:cake_wallet/anypay/any_pay_trasnaction.dart';
|
||||
|
||||
class AnyPayPaymentCommittedInfo {
|
||||
const AnyPayPaymentCommittedInfo({
|
||||
@required this.uri,
|
||||
@required this.currency,
|
||||
@required this.chain,
|
||||
@required this.transactions,
|
||||
@required this.memo});
|
||||
required this.uri,
|
||||
required this.currency,
|
||||
required this.chain,
|
||||
required this.transactions,
|
||||
required this.memo});
|
||||
|
||||
final String uri;
|
||||
final String currency;
|
||||
|
||||
@@ -3,11 +3,11 @@ import 'package:cake_wallet/anypay/any_pay_payment_instruction_output.dart';
|
||||
|
||||
class AnyPayPaymentInstruction {
|
||||
AnyPayPaymentInstruction({
|
||||
@required this.type,
|
||||
@required this.requiredFeeRate,
|
||||
@required this.txKey,
|
||||
@required this.txHash,
|
||||
@required this.outputs});
|
||||
required this.type,
|
||||
required this.requiredFeeRate,
|
||||
required this.txKey,
|
||||
required this.txHash,
|
||||
required this.outputs});
|
||||
|
||||
factory AnyPayPaymentInstruction.fromMap(Map<String, dynamic> obj) {
|
||||
final outputs = (obj['outputs'] as List<dynamic>)
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
class AnyPayTransaction {
|
||||
const AnyPayTransaction(this.tx, {@required this.id, @required this.key});
|
||||
const AnyPayTransaction(this.tx, {required this.id, required this.key});
|
||||
|
||||
final String tx;
|
||||
final String id;
|
||||
final String key;
|
||||
final String? key;
|
||||
}
|
||||
+12
-12
@@ -33,15 +33,15 @@ class AnyPayApi {
|
||||
case 'litecoin':
|
||||
return CryptoCurrency.ltc;
|
||||
default:
|
||||
return null;
|
||||
throw Exception('Unexpected scheme: ${scheme}');
|
||||
}
|
||||
}
|
||||
|
||||
Future<AnyPayPayment> paymentRequest(String uri) async {
|
||||
final fragments = uri.split(':?r=');
|
||||
final scheme = fragments.first;
|
||||
final url = fragments[1];
|
||||
final headers = <String, String>{
|
||||
final url = Uri.parse(fragments[1]);
|
||||
final headers = <String, String>{
|
||||
'Content-Type': contentTypePaymentRequest,
|
||||
'X-Paypro-Version': xPayproVersion,
|
||||
'Accept': '*/*',};
|
||||
@@ -50,20 +50,20 @@ class AnyPayApi {
|
||||
'currency': currencyByScheme(scheme).title};
|
||||
final response = await post(url, headers: headers, body: utf8.encode(json.encode(body)));
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
return null;
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('Unexpected response http code: ${response.statusCode}');
|
||||
}
|
||||
|
||||
final decodedBody = json.decode(response.body) as Map<String, dynamic>;
|
||||
return AnyPayPayment.fromMap(decodedBody);
|
||||
final decodedBody = json.decode(response.body) as Map<String, dynamic>;
|
||||
return AnyPayPayment.fromMap(decodedBody);
|
||||
}
|
||||
|
||||
Future<AnyPayPaymentCommittedInfo> payment(
|
||||
String uri,
|
||||
{@required String chain,
|
||||
@required String currency,
|
||||
@required List<AnyPayTransaction> transactions}) async {
|
||||
final headers = <String, String>{
|
||||
{required String chain,
|
||||
required String currency,
|
||||
required List<AnyPayTransaction> transactions}) async {
|
||||
final headers = <String, String>{
|
||||
'Content-Type': contentTypePayment,
|
||||
'X-Paypro-Version': xPayproVersion,
|
||||
'Accept': '*/*',};
|
||||
@@ -71,7 +71,7 @@ class AnyPayApi {
|
||||
'chain': chain,
|
||||
'currency': currency,
|
||||
'transactions': transactions.map((tx) => {'tx': tx.tx, 'tx_hash': tx.id, 'tx_key': tx.key}).toList()};
|
||||
final response = await post(uri, headers: headers, body: utf8.encode(json.encode(body)));
|
||||
final response = await post(Uri.parse(uri), headers: headers, body: utf8.encode(json.encode(body)));
|
||||
if (response.statusCode == 400) {
|
||||
final decodedBody = json.decode(response.body) as Map<String, dynamic>;
|
||||
throw Exception(decodedBody['message'] as String);
|
||||
|
||||
Reference in New Issue
Block a user