2022-07-28 17:03:16 +00:00
|
|
|
import 'package:cake_wallet/anypay/any_pay_chain.dart';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:cake_wallet/anypay/any_pay_payment_instruction.dart';
|
2022-08-04 13:27:28 +00:00
|
|
|
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
|
|
|
import 'package:cake_wallet/monero/monero.dart';
|
2022-07-28 17:03:16 +00:00
|
|
|
|
|
|
|
class AnyPayPayment {
|
|
|
|
AnyPayPayment({
|
2022-10-12 17:09:57 +00:00
|
|
|
required this.time,
|
|
|
|
required this.expires,
|
|
|
|
required this.memo,
|
|
|
|
required this.paymentUrl,
|
|
|
|
required this.paymentId,
|
|
|
|
required this.chain,
|
|
|
|
required this.network,
|
|
|
|
required this.instructions});
|
2022-07-28 17:03:16 +00:00
|
|
|
|
|
|
|
factory AnyPayPayment.fromMap(Map<String, dynamic> obj) {
|
|
|
|
final instructions = (obj['instructions'] as List<dynamic>)
|
|
|
|
.map((dynamic instruction) => AnyPayPaymentInstruction.fromMap(instruction as Map<String, dynamic>))
|
|
|
|
.toList();
|
|
|
|
return AnyPayPayment(
|
|
|
|
time: DateTime.parse(obj['time'] as String),
|
|
|
|
expires: DateTime.parse(obj['expires'] as String),
|
|
|
|
memo: obj['memo'] as String,
|
|
|
|
paymentUrl: obj['paymentUrl'] as String,
|
|
|
|
paymentId: obj['paymentId'] as String,
|
|
|
|
chain: obj['chain'] as String,
|
|
|
|
network: obj['network'] as String,
|
|
|
|
instructions: instructions);
|
|
|
|
}
|
|
|
|
|
|
|
|
final DateTime time;
|
|
|
|
final DateTime expires;
|
|
|
|
final String memo;
|
|
|
|
final String paymentUrl;
|
|
|
|
final String paymentId;
|
|
|
|
final String chain;
|
|
|
|
final String network;
|
|
|
|
final List<AnyPayPaymentInstruction> instructions;
|
|
|
|
|
|
|
|
String get totalAmount {
|
|
|
|
final total = instructions
|
|
|
|
.fold<int>(0, (int acc, instruction) => acc + instruction.outputs
|
|
|
|
.fold<int>(0, (int outAcc, out) => outAcc + out.amount));
|
|
|
|
switch (chain) {
|
|
|
|
case AnyPayChain.xmr:
|
2022-10-12 17:09:57 +00:00
|
|
|
return monero!.formatterMoneroAmountToString(amount: total);
|
2022-07-28 17:03:16 +00:00
|
|
|
case AnyPayChain.btc:
|
2022-10-12 17:09:57 +00:00
|
|
|
return bitcoin!.formatterBitcoinAmountToString(amount: total);
|
2022-07-28 17:03:16 +00:00
|
|
|
case AnyPayChain.ltc:
|
2022-10-12 17:09:57 +00:00
|
|
|
return bitcoin!.formatterBitcoinAmountToString(amount: total);
|
2022-07-28 17:03:16 +00:00
|
|
|
default:
|
2022-10-12 17:09:57 +00:00
|
|
|
return '';
|
2022-07-28 17:03:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
List<String> get outAddresses {
|
|
|
|
return instructions
|
2023-02-04 22:59:57 +00:00
|
|
|
.map((instruction) => instruction.outputs.map((out) => out.address))
|
2022-07-28 17:03:16 +00:00
|
|
|
.expand((e) => e)
|
|
|
|
.toList();
|
|
|
|
}
|
|
|
|
}
|