139 lines
3.2 KiB
Dart
139 lines
3.2 KiB
Dart
import '../destinations/models.dart';
|
|
|
|
enum TransferKind { topUp, exchange, payout }
|
|
|
|
enum OperationStatus { pending, completed, failed }
|
|
|
|
enum WalletError {
|
|
unavailable,
|
|
invalidAmount,
|
|
insufficientFunds,
|
|
limitExceeded,
|
|
expiredQuote,
|
|
invalidRecipient,
|
|
unsupported,
|
|
notFound,
|
|
uncertain,
|
|
destinationChanged,
|
|
}
|
|
|
|
class WalletException implements Exception {
|
|
const WalletException(this.code);
|
|
final WalletError code;
|
|
}
|
|
|
|
class CurrencyAccount {
|
|
const CurrencyAccount({
|
|
required this.id,
|
|
required this.currency,
|
|
required this.precision,
|
|
required this.available,
|
|
this.payoutMethod = '',
|
|
this.payoutLabel = '',
|
|
this.canFund = true,
|
|
});
|
|
final String id, currency;
|
|
final int precision, available;
|
|
final String payoutMethod, payoutLabel;
|
|
final bool canFund;
|
|
|
|
/// Locale-aware decimal input, integer money. Grouping/exponents are rejected.
|
|
int? parse(String input) {
|
|
final value = input.trim().replaceAll(',', '.');
|
|
if (!RegExp(r'^\d+(\.\d+)?$').hasMatch(value)) return null;
|
|
final parts = value.split('.');
|
|
if (parts.length > 1 && parts[1].length > precision) return null;
|
|
final major = int.tryParse(parts[0]);
|
|
if (major == null || major > 100000000) return null;
|
|
final fraction = parts.length > 1
|
|
? int.parse(parts[1].padRight(precision, '0'))
|
|
: 0;
|
|
return major * scale + fraction;
|
|
}
|
|
|
|
int get scale {
|
|
var v = 1;
|
|
for (var i = 0; i < precision; i++) {
|
|
v *= 10;
|
|
}
|
|
return v;
|
|
}
|
|
}
|
|
|
|
class TransferRequest {
|
|
const TransferRequest({
|
|
required this.kind,
|
|
required this.source,
|
|
required this.amount,
|
|
this.destination,
|
|
this.recipient = '',
|
|
this.payoutDestination,
|
|
});
|
|
final TransferKind kind;
|
|
final String source;
|
|
final int amount;
|
|
final String? destination;
|
|
final String recipient;
|
|
final DestinationInput? payoutDestination;
|
|
}
|
|
|
|
class Quote {
|
|
const Quote({
|
|
required this.id,
|
|
required this.request,
|
|
required this.fee,
|
|
required this.debit,
|
|
required this.credit,
|
|
required this.expiresAt,
|
|
required this.rateNumerator,
|
|
required this.rateDenominator,
|
|
this.payoutSnapshot,
|
|
this.payoutTerms,
|
|
});
|
|
final String id;
|
|
final TransferRequest request;
|
|
final int fee, debit, credit, rateNumerator, rateDenominator;
|
|
final DateTime expiresAt;
|
|
final DestinationDetails? payoutSnapshot;
|
|
final PayoutTerms? payoutTerms;
|
|
}
|
|
|
|
class WalletOperation {
|
|
const WalletOperation({
|
|
required this.id,
|
|
required this.quote,
|
|
required this.status,
|
|
required this.createdAt,
|
|
});
|
|
final String id;
|
|
final Quote quote;
|
|
final OperationStatus status;
|
|
final DateTime createdAt;
|
|
}
|
|
|
|
class WalletSnapshot {
|
|
WalletSnapshot({
|
|
required List<CurrencyAccount> accounts,
|
|
required List<WalletOperation> operations,
|
|
}) : accounts = List.unmodifiable(accounts),
|
|
operations = List.unmodifiable(operations);
|
|
final List<CurrencyAccount> accounts;
|
|
final List<WalletOperation> operations;
|
|
}
|
|
|
|
class AccountProfile {
|
|
const AccountProfile(this.locale);
|
|
final String locale;
|
|
}
|
|
|
|
class PayoutTerms {
|
|
const PayoutTerms(
|
|
this.amount,
|
|
this.precision,
|
|
this.assetLabel,
|
|
this.expectedSeconds,
|
|
);
|
|
final int amount, precision, expectedSeconds;
|
|
final String assetLabel;
|
|
}
|