implemented backend wallet service connection
Some checks failed
ci/woodpecker/push/chain_gateway Pipeline was successful
ci/woodpecker/push/billing_fees Pipeline was successful
ci/woodpecker/push/bff Pipeline was successful
ci/woodpecker/push/frontend Pipeline was successful
ci/woodpecker/push/db Pipeline was successful
ci/woodpecker/push/fx_ingestor Pipeline was successful
ci/woodpecker/push/fx_oracle Pipeline was successful
ci/woodpecker/push/nats Pipeline was successful
ci/woodpecker/push/ledger Pipeline was successful
ci/woodpecker/push/notification Pipeline was successful
ci/woodpecker/push/payments_orchestrator Pipeline was successful
ci/woodpecker/push/bump_version Pipeline failed
Some checks failed
ci/woodpecker/push/chain_gateway Pipeline was successful
ci/woodpecker/push/billing_fees Pipeline was successful
ci/woodpecker/push/bff Pipeline was successful
ci/woodpecker/push/frontend Pipeline was successful
ci/woodpecker/push/db Pipeline was successful
ci/woodpecker/push/fx_ingestor Pipeline was successful
ci/woodpecker/push/fx_oracle Pipeline was successful
ci/woodpecker/push/nats Pipeline was successful
ci/woodpecker/push/ledger Pipeline was successful
ci/woodpecker/push/notification Pipeline was successful
ci/woodpecker/push/payments_orchestrator Pipeline was successful
ci/woodpecker/push/bump_version Pipeline failed
This commit is contained in:
@@ -1,33 +1,28 @@
|
||||
import 'package:pshared/service/wallet.dart' as shared_wallet_service;
|
||||
|
||||
import 'package:pweb/models/currency.dart';
|
||||
import 'package:pweb/models/wallet.dart';
|
||||
import 'package:pweb/data/mappers/wallet_ui.dart';
|
||||
|
||||
|
||||
abstract class WalletsService {
|
||||
Future<List<Wallet>> getWallets();
|
||||
Future<double> getBalance(String walletRef);
|
||||
Future<List<Wallet>> getWallets(String organizationRef);
|
||||
Future<double> getBalance(String organizationRef, String walletRef);
|
||||
}
|
||||
|
||||
class MockWalletsService implements WalletsService {
|
||||
final List<Wallet> _wallets = [
|
||||
Wallet(id: '1124', walletUserID: 'WA-12345667', name: 'Main Wallet', balance: 10000000.0, currency: Currency.rub),
|
||||
Wallet(id: '2124', walletUserID: 'WA-76654321', name: 'Savings', balance: 2500.5, currency: Currency.usd),
|
||||
Wallet(id: '1124', walletUserID: 'WA-12345667', name: 'Main Wallet', balance: 10000000.0, currency: Currency.rub, calculatedAt: DateTime.now()),
|
||||
Wallet(id: '2124', walletUserID: 'WA-76654321', name: 'Savings', balance: 2500.5, currency: Currency.usd, calculatedAt: DateTime.now()),
|
||||
];
|
||||
|
||||
@override
|
||||
Future<List<Wallet>> getWallets() async {
|
||||
Future<List<Wallet>> getWallets(String _) async {
|
||||
return _wallets;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Wallet> getWallet(String walletId) async {
|
||||
return _wallets.firstWhere(
|
||||
(wallet) => wallet.id == walletId,
|
||||
orElse: () => throw Exception('Wallet not found'),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<double> getBalance(String walletRef) async {
|
||||
Future<double> getBalance(String _, String walletRef) async {
|
||||
final wallet = _wallets.firstWhere(
|
||||
(w) => w.id == walletRef,
|
||||
orElse: () => throw Exception('Wallet not found'),
|
||||
@@ -35,3 +30,21 @@ class MockWalletsService implements WalletsService {
|
||||
return wallet.balance;
|
||||
}
|
||||
}
|
||||
|
||||
class ApiWalletsService implements WalletsService {
|
||||
@override
|
||||
Future<List<Wallet>> getWallets(String organizationRef) async {
|
||||
final models = await shared_wallet_service.WalletService.list(organizationRef);
|
||||
return models.map((m) => m.toUi()).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<double> getBalance(String organizationRef, String walletRef) async {
|
||||
final balance = await shared_wallet_service.WalletService.getBalance(
|
||||
organizationRef: organizationRef,
|
||||
walletRef: walletRef,
|
||||
);
|
||||
final amount = balance.available?.amount;
|
||||
return amount == null ? 0 : double.tryParse(amount) ?? 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user