Build exchange workspace and shared transaction services (#28)
This commit is contained in:
1 parent
52b7135eda
commit
c496da8a55
48 files changed
+4757
-120
No files matched your search
@@ -0,0 +1,89 @@
|
||||
import '../models/wallet.dart';
|
||||
|
||||
class AccountDTO {
|
||||
AccountDTO(this.id, this.currency, this.precision, this.available);
|
||||
final String id, currency;
|
||||
final int precision;
|
||||
int available;
|
||||
}
|
||||
|
||||
class RequestDTO {
|
||||
const RequestDTO(
|
||||
this.kind,
|
||||
this.source,
|
||||
this.destination,
|
||||
this.amount,
|
||||
this.recipient,
|
||||
);
|
||||
final String kind, source, recipient;
|
||||
final String? destination;
|
||||
final int amount;
|
||||
}
|
||||
|
||||
class QuoteDTO {
|
||||
const QuoteDTO(
|
||||
this.id,
|
||||
this.request,
|
||||
this.fee,
|
||||
this.debit,
|
||||
this.credit,
|
||||
this.expires,
|
||||
this.numerator,
|
||||
this.denominator,
|
||||
);
|
||||
final String id;
|
||||
final RequestDTO request;
|
||||
final int fee, debit, credit, numerator, denominator;
|
||||
final DateTime expires;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
abstract final class WalletMapper {
|
||||
static CurrencyAccount account(AccountDTO d) => CurrencyAccount(
|
||||
id: d.id,
|
||||
currency: d.currency,
|
||||
precision: d.precision,
|
||||
available: d.available,
|
||||
);
|
||||
static RequestDTO request(TransferRequest r) =>
|
||||
RequestDTO(r.kind.name, r.source, r.destination, r.amount, r.recipient);
|
||||
static TransferRequest fromRequest(RequestDTO d) => TransferRequest(
|
||||
kind: TransferKind.values.byName(d.kind),
|
||||
source: d.source,
|
||||
destination: d.destination,
|
||||
amount: d.amount,
|
||||
recipient: d.recipient,
|
||||
);
|
||||
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,
|
||||
);
|
||||
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(String locale) => AccountProfile(locale);
|
||||
}
|
||||
Reference in new issue
Block a user