151 lines
3.5 KiB
Dart
151 lines
3.5 KiB
Dart
import '../destinations/transport.dart';
|
|
import '../models/wallet.dart';
|
|
|
|
class AccountDTO {
|
|
AccountDTO(
|
|
this.id,
|
|
this.currency,
|
|
this.precision,
|
|
this.available, {
|
|
this.payoutMethod = '',
|
|
this.payoutLabel = '',
|
|
this.canFund = true,
|
|
});
|
|
final String payoutMethod, payoutLabel;
|
|
final bool canFund;
|
|
final String id, currency;
|
|
final int precision;
|
|
int available;
|
|
}
|
|
|
|
class RequestDTO {
|
|
const RequestDTO(
|
|
this.kind,
|
|
this.source,
|
|
this.destination,
|
|
this.amount,
|
|
this.recipient, {
|
|
this.payoutInput,
|
|
});
|
|
final String kind, source, recipient;
|
|
final String? destination;
|
|
final int amount;
|
|
final DestinationInputDTO? payoutInput;
|
|
}
|
|
|
|
class QuoteDTO {
|
|
const QuoteDTO(
|
|
this.id,
|
|
this.request,
|
|
this.fee,
|
|
this.debit,
|
|
this.credit,
|
|
this.expires,
|
|
this.numerator,
|
|
this.denominator, {
|
|
this.payoutSnapshot,
|
|
this.payoutTerms,
|
|
});
|
|
final String id;
|
|
final RequestDTO request;
|
|
final int fee, debit, credit, numerator, denominator;
|
|
final DateTime expires;
|
|
final DestinationDTO? payoutSnapshot;
|
|
final PayoutTermsDTO? payoutTerms;
|
|
}
|
|
|
|
class OperationDTO {
|
|
OperationDTO(
|
|
this.id,
|
|
this.quote,
|
|
this.created,
|
|
this.ready, {
|
|
this.status = 'pending',
|
|
this.fail = false,
|
|
});
|
|
final String id;
|
|
final QuoteDTO quote;
|
|
final DateTime created, ready;
|
|
String status;
|
|
final bool fail;
|
|
}
|
|
|
|
class ProfileDTO {
|
|
const ProfileDTO(this.locale);
|
|
final String locale;
|
|
}
|
|
|
|
abstract final class WalletMapper {
|
|
static CurrencyAccount account(AccountDTO d) => CurrencyAccount(
|
|
id: d.id,
|
|
currency: d.currency,
|
|
precision: d.precision,
|
|
available: d.available,
|
|
payoutMethod: d.payoutMethod,
|
|
payoutLabel: d.payoutLabel,
|
|
canFund: d.canFund,
|
|
);
|
|
static RequestDTO request(
|
|
TransferRequest r, {
|
|
bool includePayoutInput = true,
|
|
}) => RequestDTO(
|
|
r.kind.name,
|
|
r.source,
|
|
r.destination,
|
|
r.amount,
|
|
r.recipient,
|
|
payoutInput: !includePayoutInput || r.payoutDestination == null
|
|
? null
|
|
: DestinationInputMapper.toDTO(r.payoutDestination!),
|
|
);
|
|
static TransferRequest fromRequest(RequestDTO d) => TransferRequest(
|
|
kind: TransferKind.values.byName(d.kind),
|
|
source: d.source,
|
|
destination: d.destination,
|
|
amount: d.amount,
|
|
recipient: d.recipient,
|
|
payoutDestination: d.payoutInput == null
|
|
? null
|
|
: DestinationInputMapper.fromDTO(d.payoutInput!),
|
|
);
|
|
static Quote quote(QuoteDTO d) => Quote(
|
|
id: d.id,
|
|
request: fromRequest(d.request),
|
|
fee: d.fee,
|
|
debit: d.debit,
|
|
credit: d.credit,
|
|
expiresAt: d.expires,
|
|
rateNumerator: d.numerator,
|
|
rateDenominator: d.denominator,
|
|
payoutTerms: d.payoutTerms == null
|
|
? null
|
|
: PayoutTerms(
|
|
d.payoutTerms!.amount,
|
|
d.payoutTerms!.precision,
|
|
d.payoutTerms!.assetLabel,
|
|
d.payoutTerms!.expectedSeconds,
|
|
),
|
|
payoutSnapshot: d.payoutSnapshot == null
|
|
? null
|
|
: DestinationMapper.fromDTO(d.payoutSnapshot!),
|
|
);
|
|
static WalletOperation operation(OperationDTO d) => WalletOperation(
|
|
id: d.id,
|
|
quote: quote(d.quote),
|
|
status: OperationStatus.values.byName(d.status),
|
|
createdAt: d.created,
|
|
);
|
|
static AccountProfile profile(ProfileDTO dto) => AccountProfile(dto.locale);
|
|
}
|
|
|
|
class PayoutTermsDTO {
|
|
const PayoutTermsDTO(
|
|
this.amount,
|
|
this.precision,
|
|
this.assetLabel,
|
|
this.expectedSeconds,
|
|
);
|
|
final int amount, precision, expectedSeconds;
|
|
final String assetLabel;
|
|
}
|