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,5 +1,9 @@
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import 'package:pshared/provider/organizations.dart';
|
||||
|
||||
import 'package:pweb/app/router/pages.dart';
|
||||
import 'package:pweb/app/router/page_params.dart';
|
||||
import 'package:pweb/pages/2fa/page.dart';
|
||||
@@ -32,7 +36,11 @@ GoRouter createRouter() => GoRouter(
|
||||
name: Pages.sfactor.name,
|
||||
path: routerPage(Pages.sfactor),
|
||||
builder: (context, _) => TwoFactorCodePage(
|
||||
onVerificationSuccess: () => context.goNamed(Pages.dashboard.name),
|
||||
onVerificationSuccess: () {
|
||||
// trigger organization load
|
||||
context.read<OrganizationsProvider>().load();
|
||||
context.goNamed(Pages.dashboard.name);
|
||||
},
|
||||
),
|
||||
),
|
||||
GoRoute(
|
||||
|
||||
26
frontend/pweb/lib/data/mappers/wallet_ui.dart
Normal file
26
frontend/pweb/lib/data/mappers/wallet_ui.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
import 'package:pshared/models/wallet/wallet.dart' as domain;
|
||||
|
||||
import 'package:pweb/models/currency.dart';
|
||||
import 'package:pweb/models/wallet.dart';
|
||||
|
||||
|
||||
extension WalletUiMapper on domain.WalletModel {
|
||||
Wallet toUi() {
|
||||
final amountStr = availableMoney?.amount ?? balance?.available?.amount ?? '0';
|
||||
final currencyStr = availableMoney?.currency ?? balance?.available?.currency ?? Currency.usd.toString().toUpperCase();
|
||||
final parsedAmount = double.tryParse(amountStr) ?? 0;
|
||||
final currency = Currency.values.firstWhere(
|
||||
(c) => c.name.toUpperCase() == currencyStr.toUpperCase(),
|
||||
orElse: () => Currency.usd,
|
||||
);
|
||||
return Wallet(
|
||||
id: walletRef,
|
||||
walletUserID: walletRef,
|
||||
name: metadata?['name'] ?? walletRef,
|
||||
balance: parsedAmount,
|
||||
currency: currency,
|
||||
isHidden: true,
|
||||
calculatedAt: balance?.calculatedAt ?? DateTime.now(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -72,8 +72,9 @@ void main() async {
|
||||
ChangeNotifierProvider(
|
||||
create: (_) => PaymentMethodsProvider(service: MockPaymentMethodsService())..loadMethods(),
|
||||
),
|
||||
ChangeNotifierProvider(
|
||||
create: (_) => WalletsProvider(MockWalletsService())..loadData(),
|
||||
ChangeNotifierProxyProvider<OrganizationsProvider, WalletsProvider>(
|
||||
create: (_) => WalletsProvider(ApiWalletsService()),
|
||||
update: (context, organizations, provider) => provider!..update(organizations),
|
||||
),
|
||||
ChangeNotifierProvider(
|
||||
create: (_) => WalletTransactionsProvider(MockWalletTransactionsService())..load(),
|
||||
|
||||
@@ -8,6 +8,7 @@ class Wallet {
|
||||
final double balance;
|
||||
final Currency currency;
|
||||
final bool isHidden;
|
||||
final DateTime calculatedAt;
|
||||
|
||||
Wallet({
|
||||
required this.id,
|
||||
@@ -15,6 +16,7 @@ class Wallet {
|
||||
required this.name,
|
||||
required this.balance,
|
||||
required this.currency,
|
||||
required this.calculatedAt,
|
||||
this.isHidden = true,
|
||||
});
|
||||
|
||||
@@ -25,14 +27,13 @@ class Wallet {
|
||||
Currency? currency,
|
||||
String? walletUserID,
|
||||
bool? isHidden,
|
||||
}) {
|
||||
return Wallet(
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
balance: balance ?? this.balance,
|
||||
currency: currency ?? this.currency,
|
||||
walletUserID: walletUserID ?? this.walletUserID,
|
||||
isHidden: isHidden ?? this.isHidden,
|
||||
);
|
||||
}
|
||||
}) => Wallet(
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
balance: balance ?? this.balance,
|
||||
currency: currency ?? this.currency,
|
||||
walletUserID: walletUserID ?? this.walletUserID,
|
||||
isHidden: isHidden ?? this.isHidden,
|
||||
calculatedAt: calculatedAt,
|
||||
);
|
||||
}
|
||||
@@ -44,6 +44,7 @@ class _LoginFormState extends State<LoginForm> {
|
||||
locale: context.read<LocaleProvider>().locale.languageCode,
|
||||
);
|
||||
if (outcome.isPending) {
|
||||
// TODO: fix context usage
|
||||
navigateAndReplace(context, Pages.sfactor);
|
||||
} else {
|
||||
onLogin();
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pweb/providers/wallets.dart';
|
||||
import 'package:pweb/widgets/error/snackbar.dart';
|
||||
|
||||
|
||||
class WalletEditHeader extends StatefulWidget {
|
||||
@@ -85,10 +86,11 @@ class _WalletEditHeaderState extends State<WalletEditHeader> {
|
||||
icon: const Icon(Icons.check),
|
||||
color: theme.colorScheme.primary,
|
||||
onPressed: () async {
|
||||
provider.updateName(wallet.id, _controller.text);
|
||||
await provider.updateWallet(wallet.copyWith(name: _controller.text));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Wallet name saved')),
|
||||
await executeActionWithNotification(
|
||||
context: context,
|
||||
action: () async => await provider.updateWallet(wallet.copyWith(name: _controller.text)),
|
||||
errorMessage: 'Failed to update wallet name',
|
||||
successMessage: 'Wallet name saved',
|
||||
);
|
||||
setState(() {
|
||||
_isEditing = false;
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pweb/models/wallet.dart';
|
||||
import 'package:pweb/services/wallets.dart';
|
||||
import 'package:pshared/provider/organizations.dart';
|
||||
import 'package:pshared/provider/resource.dart';
|
||||
import 'package:pshared/utils/exception.dart';
|
||||
|
||||
import 'package:pweb/models/wallet.dart';
|
||||
import 'package:pweb/services/wallets.dart';
|
||||
|
||||
|
||||
class WalletsProvider with ChangeNotifier {
|
||||
final WalletsService _service;
|
||||
late OrganizationsProvider _organizations;
|
||||
|
||||
WalletsProvider(this._service);
|
||||
|
||||
@@ -25,6 +29,15 @@ class WalletsProvider with ChangeNotifier {
|
||||
bool _isRefreshingBalances = false;
|
||||
bool get isRefreshingBalances => _isRefreshingBalances;
|
||||
|
||||
void update(OrganizationsProvider organizations) {
|
||||
_organizations = organizations;
|
||||
if (_organizations.isOrganizationSet) loadWalletsWithBalances();
|
||||
}
|
||||
|
||||
Future<Wallet> updateWallet(Wallet newWallet) {
|
||||
throw Exception('update wallet is not implemented');
|
||||
}
|
||||
|
||||
void selectWallet(Wallet wallet) {
|
||||
_selectedWallet = wallet;
|
||||
notifyListeners();
|
||||
@@ -33,11 +46,11 @@ class WalletsProvider with ChangeNotifier {
|
||||
Future<void> loadWalletsWithBalances() async {
|
||||
_setResource(_resource.copyWith(isLoading: true, error: null));
|
||||
try {
|
||||
final base = await _service.getWallets();
|
||||
final base = await _service.getWallets(_organizations.current.id);
|
||||
final withBalances = <Wallet>[];
|
||||
for (final wallet in base) {
|
||||
try {
|
||||
final balance = await _service.getBalance(wallet.id);
|
||||
final balance = await _service.getBalance(_organizations.current.id, wallet.id);
|
||||
withBalances.add(wallet.copyWith(balance: balance));
|
||||
} catch (e) {
|
||||
_setResource(_resource.copyWith(error: toException(e)));
|
||||
@@ -58,7 +71,7 @@ class WalletsProvider with ChangeNotifier {
|
||||
try {
|
||||
final updated = <Wallet>[];
|
||||
for (final wallet in wallets) {
|
||||
final balance = await _service.getBalance(wallet.id);
|
||||
final balance = await _service.getBalance(_organizations.current.id, wallet.id);
|
||||
updated.add(wallet.copyWith(balance: balance));
|
||||
}
|
||||
_setResource(_resource.copyWith(data: updated));
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pweb/utils/error_handler.dart';
|
||||
import 'package:pweb/utils/snackbar.dart';
|
||||
import 'package:pweb/widgets/error/content.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
@@ -52,13 +53,18 @@ Future<T?> executeActionWithNotification<T>({
|
||||
required BuildContext context,
|
||||
required Future<T> Function() action,
|
||||
required String errorMessage,
|
||||
String? successMessage,
|
||||
int delaySeconds = 3,
|
||||
}) async {
|
||||
final scaffoldMessenger = ScaffoldMessenger.of(context);
|
||||
final localizations = AppLocalizations.of(context)!;
|
||||
|
||||
try {
|
||||
return await action();
|
||||
final res = await action();
|
||||
if (successMessage != null) {
|
||||
notifyUserX(scaffoldMessenger, successMessage, delaySeconds: delaySeconds);
|
||||
}
|
||||
return res;
|
||||
} catch (e) {
|
||||
// Report the error using your existing notifier.
|
||||
notifyUserOfErrorX(
|
||||
|
||||
Reference in New Issue
Block a user