Reformat the whole codebase with 100 line width (#3403)

This commit is contained in:
Omar Hatem
2026-07-15 01:20:33 +03:00
committed by GitHub
parent 1241b28bec
commit 16ddc0837a
801 changed files with 17517 additions and 17091 deletions
+4 -4
View File
@@ -1,5 +1,5 @@
class AnyPayChain {
static const xmr = 'XMR';
static const btc = 'BTC';
static const ltc = 'LTC';
}
static const xmr = 'XMR';
static const btc = 'BTC';
static const ltc = 'LTC';
}
+55 -53
View File
@@ -4,60 +4,62 @@ import 'package:cake_wallet/bitcoin/bitcoin.dart';
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});
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});
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);
}
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;
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:
return monero!.formatterMoneroAmountToString(amount: total);
case AnyPayChain.btc:
return bitcoin!.formatterBitcoinAmountToString(amount: total);
case AnyPayChain.ltc:
return bitcoin!.formatterBitcoinAmountToString(amount: total);
default:
return '';
}
}
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:
return monero!.formatterMoneroAmountToString(amount: total);
case AnyPayChain.btc:
return bitcoin!.formatterBitcoinAmountToString(amount: total);
case AnyPayChain.ltc:
return bitcoin!.formatterBitcoinAmountToString(amount: total);
default:
return '';
}
}
List<String> get outAddresses {
return instructions
.map((instruction) => instruction.outputs.map((out) => out.address))
.expand((e) => e)
.toList();
}
}
List<String> get outAddresses {
return instructions
.map((instruction) => instruction.outputs.map((out) => out.address))
.expand((e) => e)
.toList();
}
}
+12 -12
View File
@@ -1,16 +1,16 @@
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});
const AnyPayPaymentCommittedInfo(
{required this.uri,
required this.currency,
required this.chain,
required this.transactions,
required this.memo});
final String uri;
final String currency;
final String chain;
final List<AnyPayTransaction> transactions;
final String memo;
}
final String uri;
final String currency;
final String chain;
final List<AnyPayTransaction> transactions;
final String memo;
}
+24 -25
View File
@@ -1,31 +1,30 @@
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});
AnyPayPaymentInstruction(
{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>)
.map((dynamic out) =>
AnyPayPaymentInstructionOutput.fromMap(out as Map<String, dynamic>))
.toList();
return AnyPayPaymentInstruction(
type: obj['type'] as String,
requiredFeeRate: obj['requiredFeeRate'] as int,
txKey: obj['tx_key'] as bool? ?? false,
txHash: obj['tx_hash'] as bool? ?? false,
outputs: outputs);
}
factory AnyPayPaymentInstruction.fromMap(Map<String, dynamic> obj) {
final outputs = (obj['outputs'] as List<dynamic>)
.map((dynamic out) => AnyPayPaymentInstructionOutput.fromMap(out as Map<String, dynamic>))
.toList();
return AnyPayPaymentInstruction(
type: obj['type'] as String,
requiredFeeRate: obj['requiredFeeRate'] as int,
txKey: obj['tx_key'] as bool? ?? false,
txHash: obj['tx_hash'] as bool? ?? false,
outputs: outputs);
}
static const transactionType = 'transaction';
static const transactionType = 'transaction';
final String type;
final int requiredFeeRate;
final bool txKey;
final bool txHash;
final List<AnyPayPaymentInstructionOutput> outputs;
}
final String type;
final int requiredFeeRate;
final bool txKey;
final bool txHash;
final List<AnyPayPaymentInstructionOutput> outputs;
}
@@ -1,10 +1,10 @@
class AnyPayPaymentInstructionOutput {
const AnyPayPaymentInstructionOutput(this.address, this.amount);
const AnyPayPaymentInstructionOutput(this.address, this.amount);
factory AnyPayPaymentInstructionOutput.fromMap(Map<String, dynamic> obj) {
return AnyPayPaymentInstructionOutput(obj['address'] as String, obj['amount'] as int);
}
factory AnyPayPaymentInstructionOutput.fromMap(Map<String, dynamic> obj) {
return AnyPayPaymentInstructionOutput(obj['address'] as String, obj['amount'] as int);
}
final String address;
final int amount;
}
final String address;
final int amount;
}
+5 -5
View File
@@ -1,7 +1,7 @@
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 tx;
final String id;
final String? key;
}
+83 -79
View File
@@ -9,101 +9,105 @@ import 'package:cake_wallet/anypay/any_pay_trasnaction.dart';
import 'package:cake_wallet/.secrets.g.dart' as secrets;
class AnyPayApi {
static const contentTypePaymentRequest = 'application/payment-request';
static const contentTypePayment = 'application/payment';
static const xPayproVersion = '2';
static const anypayToken = secrets.anypayToken;
static const contentTypePaymentRequest = 'application/payment-request';
static const contentTypePayment = 'application/payment';
static const xPayproVersion = '2';
static const anypayToken = secrets.anypayToken;
static String chainByScheme(String scheme) {
switch (scheme.toLowerCase()) {
case 'monero':
return CryptoCurrency.xmr.title;
case 'bitcoin':
return CryptoCurrency.btc.title;
case 'litecoin':
return CryptoCurrency.ltc.title;
default:
return '';
}
}
static String chainByScheme(String scheme) {
switch (scheme.toLowerCase()) {
case 'monero':
return CryptoCurrency.xmr.title;
case 'bitcoin':
return CryptoCurrency.btc.title;
case 'litecoin':
return CryptoCurrency.ltc.title;
default:
return '';
}
}
static CryptoCurrency currencyByScheme(String scheme) {
switch (scheme.toLowerCase()) {
case 'monero':
return CryptoCurrency.xmr;
case 'bitcoin':
return CryptoCurrency.btc;
case 'litecoin':
return CryptoCurrency.ltc;
default:
throw Exception('Unexpected scheme: ${scheme}');
}
}
static CryptoCurrency currencyByScheme(String scheme) {
switch (scheme.toLowerCase()) {
case 'monero':
return CryptoCurrency.xmr;
case 'bitcoin':
return CryptoCurrency.btc;
case 'litecoin':
return CryptoCurrency.ltc;
default:
throw Exception('Unexpected scheme: ${scheme}');
}
}
Future<AnyPayPayment> paymentRequest(String uri) async {
final fragments = uri.split(':?r=');
final scheme = fragments.first;
final url = Uri.parse(fragments[1]);
final headers = <String, String>{
'Content-Type': contentTypePaymentRequest,
'X-Paypro-Version': xPayproVersion,
'Accept': '*/*',
'x-wallet': 'cake',
'x-wallet-token': anypayToken,};
final body = <String, dynamic>{
'chain': chainByScheme(scheme),
'currency': currencyByScheme(scheme).title};
final response = await ProxyWrapper().post(
Future<AnyPayPayment> paymentRequest(String uri) async {
final fragments = uri.split(':?r=');
final scheme = fragments.first;
final url = Uri.parse(fragments[1]);
final headers = <String, String>{
'Content-Type': contentTypePaymentRequest,
'X-Paypro-Version': xPayproVersion,
'Accept': '*/*',
'x-wallet': 'cake',
'x-wallet-token': anypayToken,
};
final body = <String, dynamic>{
'chain': chainByScheme(scheme),
'currency': currencyByScheme(scheme).title
};
final response = await ProxyWrapper().post(
clearnetUri: url,
headers: headers,
body: json.encode(body),
);
if (response.statusCode != 200) {
await ExceptionHandler.onError(FlutterErrorDetails(exception: response));
await ExceptionHandler.onError(FlutterErrorDetails(exception: response));
throw Exception('Unexpected response http code: ${response.statusCode}');
}
}
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>{
'Content-Type': contentTypePayment,
'X-Paypro-Version': xPayproVersion,
'Accept': '*/*',
'x-wallet': 'cake',
'x-wallet-token': anypayToken,};
final body = <String, dynamic>{
'chain': chain,
'currency': currency,
'transactions': transactions.map((tx) => {'tx': tx.tx, 'tx_hash': tx.id, 'tx_key': tx.key}).toList()};
final response = await ProxyWrapper().post(
Future<AnyPayPaymentCommittedInfo> payment(String uri,
{required String chain,
required String currency,
required List<AnyPayTransaction> transactions}) async {
final headers = <String, String>{
'Content-Type': contentTypePayment,
'X-Paypro-Version': xPayproVersion,
'Accept': '*/*',
'x-wallet': 'cake',
'x-wallet-token': anypayToken,
};
final body = <String, dynamic>{
'chain': chain,
'currency': currency,
'transactions':
transactions.map((tx) => {'tx': tx.tx, 'tx_hash': tx.id, 'tx_key': tx.key}).toList()
};
final response = await ProxyWrapper().post(
clearnetUri: Uri.parse(uri),
headers: headers,
body: json.encode(body),
);
if (response.statusCode == 400) {
final decodedBody = json.decode(response.body) as Map<String, dynamic>;
throw Exception(decodedBody['message'] as String? ?? 'Unexpected response\nError code: 400');
}
if (response.statusCode != 200) {
throw Exception('Unexpected response');
}
if (response.statusCode == 400) {
final decodedBody = json.decode(response.body) as Map<String, dynamic>;
throw Exception(decodedBody['message'] as String? ?? 'Unexpected response\nError code: 400');
}
final decodedBody = json.decode(response.body) as Map<String, dynamic>;
return AnyPayPaymentCommittedInfo(
uri: uri,
currency: currency,
chain: chain,
transactions: transactions,
memo: decodedBody['memo'] as String);
}
}
if (response.statusCode != 200) {
throw Exception('Unexpected response');
}
final decodedBody = json.decode(response.body) as Map<String, dynamic>;
return AnyPayPaymentCommittedInfo(
uri: uri,
currency: currency,
chain: chain,
transactions: transactions,
memo: decodedBody['memo'] as String);
}
}