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:
16
frontend/pshared/lib/api/responses/wallet_balance.dart
Normal file
16
frontend/pshared/lib/api/responses/wallet_balance.dart
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import 'package:json_annotation/json_annotation.dart';
|
||||||
|
|
||||||
|
import 'package:pshared/data/dto/wallet/balance.dart';
|
||||||
|
|
||||||
|
part 'wallet_balance.g.dart';
|
||||||
|
|
||||||
|
|
||||||
|
@JsonSerializable(explicitToJson: true)
|
||||||
|
class WalletBalanceResponse {
|
||||||
|
final WalletBalanceDTO balance;
|
||||||
|
|
||||||
|
const WalletBalanceResponse({required this.balance});
|
||||||
|
|
||||||
|
factory WalletBalanceResponse.fromJson(Map<String, dynamic> json) => _$WalletBalanceResponseFromJson(json);
|
||||||
|
Map<String, dynamic> toJson() => _$WalletBalanceResponseToJson(this);
|
||||||
|
}
|
||||||
16
frontend/pshared/lib/api/responses/wallets.dart
Normal file
16
frontend/pshared/lib/api/responses/wallets.dart
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import 'package:json_annotation/json_annotation.dart';
|
||||||
|
|
||||||
|
import 'package:pshared/data/dto/wallet/wallet.dart';
|
||||||
|
|
||||||
|
part 'wallets.g.dart';
|
||||||
|
|
||||||
|
|
||||||
|
@JsonSerializable(explicitToJson: true)
|
||||||
|
class WalletsResponse {
|
||||||
|
final List<WalletDTO> wallets;
|
||||||
|
|
||||||
|
const WalletsResponse({required this.wallets});
|
||||||
|
|
||||||
|
factory WalletsResponse.fromJson(Map<String, dynamic> json) => _$WalletsResponseFromJson(json);
|
||||||
|
Map<String, dynamic> toJson() => _$WalletsResponseToJson(this);
|
||||||
|
}
|
||||||
20
frontend/pshared/lib/data/dto/wallet/asset.dart
Normal file
20
frontend/pshared/lib/data/dto/wallet/asset.dart
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import 'package:json_annotation/json_annotation.dart';
|
||||||
|
|
||||||
|
part 'asset.g.dart';
|
||||||
|
|
||||||
|
|
||||||
|
@JsonSerializable()
|
||||||
|
class WalletAssetDTO {
|
||||||
|
final String chain;
|
||||||
|
final String tokenSymbol;
|
||||||
|
final String contractAddress;
|
||||||
|
|
||||||
|
const WalletAssetDTO({
|
||||||
|
required this.chain,
|
||||||
|
required this.tokenSymbol,
|
||||||
|
required this.contractAddress,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory WalletAssetDTO.fromJson(Map<String, dynamic> json) => _$WalletAssetDTOFromJson(json);
|
||||||
|
Map<String, dynamic> toJson() => _$WalletAssetDTOToJson(this);
|
||||||
|
}
|
||||||
24
frontend/pshared/lib/data/dto/wallet/balance.dart
Normal file
24
frontend/pshared/lib/data/dto/wallet/balance.dart
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import 'package:json_annotation/json_annotation.dart';
|
||||||
|
|
||||||
|
import 'package:pshared/data/dto/wallet/money.dart';
|
||||||
|
|
||||||
|
part 'balance.g.dart';
|
||||||
|
|
||||||
|
|
||||||
|
@JsonSerializable()
|
||||||
|
class WalletBalanceDTO {
|
||||||
|
final MoneyDTO? available;
|
||||||
|
final MoneyDTO? pendingInbound;
|
||||||
|
final MoneyDTO? pendingOutbound;
|
||||||
|
final String? calculatedAt;
|
||||||
|
|
||||||
|
const WalletBalanceDTO({
|
||||||
|
required this.available,
|
||||||
|
required this.pendingInbound,
|
||||||
|
required this.pendingOutbound,
|
||||||
|
required this.calculatedAt,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory WalletBalanceDTO.fromJson(Map<String, dynamic> json) => _$WalletBalanceDTOFromJson(json);
|
||||||
|
Map<String, dynamic> toJson() => _$WalletBalanceDTOToJson(this);
|
||||||
|
}
|
||||||
18
frontend/pshared/lib/data/dto/wallet/money.dart
Normal file
18
frontend/pshared/lib/data/dto/wallet/money.dart
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import 'package:json_annotation/json_annotation.dart';
|
||||||
|
|
||||||
|
part 'money.g.dart';
|
||||||
|
|
||||||
|
|
||||||
|
@JsonSerializable()
|
||||||
|
class MoneyDTO {
|
||||||
|
final String amount;
|
||||||
|
final String currency;
|
||||||
|
|
||||||
|
const MoneyDTO({
|
||||||
|
required this.amount,
|
||||||
|
required this.currency,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory MoneyDTO.fromJson(Map<String, dynamic> json) => _$MoneyDTOFromJson(json);
|
||||||
|
Map<String, dynamic> toJson() => _$MoneyDTOToJson(this);
|
||||||
|
}
|
||||||
34
frontend/pshared/lib/data/dto/wallet/wallet.dart
Normal file
34
frontend/pshared/lib/data/dto/wallet/wallet.dart
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import 'package:json_annotation/json_annotation.dart';
|
||||||
|
|
||||||
|
import 'package:pshared/data/dto/wallet/asset.dart';
|
||||||
|
|
||||||
|
part 'wallet.g.dart';
|
||||||
|
|
||||||
|
|
||||||
|
@JsonSerializable()
|
||||||
|
class WalletDTO {
|
||||||
|
final String walletRef;
|
||||||
|
final String organizationRef;
|
||||||
|
final String ownerRef;
|
||||||
|
final WalletAssetDTO asset;
|
||||||
|
final String depositAddress;
|
||||||
|
final String status;
|
||||||
|
final Map<String, String>? metadata;
|
||||||
|
final String? createdAt;
|
||||||
|
final String? updatedAt;
|
||||||
|
|
||||||
|
const WalletDTO({
|
||||||
|
required this.walletRef,
|
||||||
|
required this.organizationRef,
|
||||||
|
required this.ownerRef,
|
||||||
|
required this.asset,
|
||||||
|
required this.depositAddress,
|
||||||
|
required this.status,
|
||||||
|
this.metadata,
|
||||||
|
this.createdAt,
|
||||||
|
this.updatedAt,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory WalletDTO.fromJson(Map<String, dynamic> json) => _$WalletDTOFromJson(json);
|
||||||
|
Map<String, dynamic> toJson() => _$WalletDTOToJson(this);
|
||||||
|
}
|
||||||
15
frontend/pshared/lib/data/mapper/wallet/balance.dart
Normal file
15
frontend/pshared/lib/data/mapper/wallet/balance.dart
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import 'package:pshared/data/dto/wallet/balance.dart';
|
||||||
|
import 'package:pshared/data/mapper/wallet/money.dart';
|
||||||
|
import 'package:pshared/models/wallet/balance.dart';
|
||||||
|
|
||||||
|
|
||||||
|
extension WalletBalanceDTOMapper on WalletBalanceDTO {
|
||||||
|
WalletBalance toDomain() => WalletBalance(
|
||||||
|
available: available?.toDomain(),
|
||||||
|
pendingInbound: pendingInbound?.toDomain(),
|
||||||
|
pendingOutbound: pendingOutbound?.toDomain(),
|
||||||
|
calculatedAt: (calculatedAt == null || calculatedAt!.isEmpty)
|
||||||
|
? null
|
||||||
|
: DateTime.tryParse(calculatedAt!),
|
||||||
|
);
|
||||||
|
}
|
||||||
10
frontend/pshared/lib/data/mapper/wallet/money.dart
Normal file
10
frontend/pshared/lib/data/mapper/wallet/money.dart
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import 'package:pshared/data/dto/wallet/money.dart';
|
||||||
|
import 'package:pshared/models/wallet/money.dart';
|
||||||
|
|
||||||
|
|
||||||
|
extension MoneyDTOMapper on MoneyDTO {
|
||||||
|
WalletMoney toDomain() => WalletMoney(
|
||||||
|
amount: amount,
|
||||||
|
currency: currency,
|
||||||
|
);
|
||||||
|
}
|
||||||
14
frontend/pshared/lib/data/mapper/wallet/response.dart
Normal file
14
frontend/pshared/lib/data/mapper/wallet/response.dart
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import 'package:pshared/api/responses/wallet_balance.dart';
|
||||||
|
import 'package:pshared/api/responses/wallets.dart';
|
||||||
|
import 'package:pshared/data/mapper/wallet/balance.dart';
|
||||||
|
import 'package:pshared/data/mapper/wallet/wallet.dart';
|
||||||
|
import 'package:pshared/models/wallet/balance.dart';
|
||||||
|
import 'package:pshared/models/wallet/wallet.dart';
|
||||||
|
|
||||||
|
extension WalletsResponseMapper on WalletsResponse {
|
||||||
|
List<WalletModel> toDomain() => wallets.map((w) => w.toDomain()).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
extension WalletBalanceResponseMapper on WalletBalanceResponse {
|
||||||
|
WalletBalance toDomain() => balance.toDomain();
|
||||||
|
}
|
||||||
26
frontend/pshared/lib/data/mapper/wallet/wallet.dart
Normal file
26
frontend/pshared/lib/data/mapper/wallet/wallet.dart
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import 'package:pshared/data/dto/wallet/balance.dart';
|
||||||
|
import 'package:pshared/data/dto/wallet/wallet.dart';
|
||||||
|
import 'package:pshared/data/mapper/wallet/balance.dart';
|
||||||
|
import 'package:pshared/data/mapper/wallet/money.dart';
|
||||||
|
import 'package:pshared/models/wallet/wallet.dart';
|
||||||
|
|
||||||
|
|
||||||
|
extension WalletDTOMapper on WalletDTO {
|
||||||
|
WalletModel toDomain({WalletBalanceDTO? balance}) => WalletModel(
|
||||||
|
walletRef: walletRef,
|
||||||
|
organizationRef: organizationRef,
|
||||||
|
ownerRef: ownerRef,
|
||||||
|
asset: WalletAsset(
|
||||||
|
chain: asset.chain,
|
||||||
|
tokenSymbol: asset.tokenSymbol,
|
||||||
|
contractAddress: asset.contractAddress,
|
||||||
|
),
|
||||||
|
depositAddress: depositAddress,
|
||||||
|
status: status,
|
||||||
|
metadata: metadata,
|
||||||
|
createdAt: (createdAt == null || createdAt!.isEmpty) ? null : DateTime.tryParse(createdAt!),
|
||||||
|
updatedAt: (updatedAt == null || updatedAt!.isEmpty) ? null : DateTime.tryParse(updatedAt!),
|
||||||
|
balance: balance?.toDomain(),
|
||||||
|
availableMoney: balance?.available?.toDomain(),
|
||||||
|
);
|
||||||
|
}
|
||||||
16
frontend/pshared/lib/models/wallet/balance.dart
Normal file
16
frontend/pshared/lib/models/wallet/balance.dart
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import 'package:pshared/models/wallet/money.dart';
|
||||||
|
|
||||||
|
|
||||||
|
class WalletBalance {
|
||||||
|
final WalletMoney? available;
|
||||||
|
final WalletMoney? pendingInbound;
|
||||||
|
final WalletMoney? pendingOutbound;
|
||||||
|
final DateTime? calculatedAt;
|
||||||
|
|
||||||
|
const WalletBalance({
|
||||||
|
required this.available,
|
||||||
|
required this.pendingInbound,
|
||||||
|
required this.pendingOutbound,
|
||||||
|
required this.calculatedAt,
|
||||||
|
});
|
||||||
|
}
|
||||||
9
frontend/pshared/lib/models/wallet/money.dart
Normal file
9
frontend/pshared/lib/models/wallet/money.dart
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
class WalletMoney {
|
||||||
|
final String amount;
|
||||||
|
final String currency;
|
||||||
|
|
||||||
|
const WalletMoney({
|
||||||
|
required this.amount,
|
||||||
|
required this.currency,
|
||||||
|
});
|
||||||
|
}
|
||||||
62
frontend/pshared/lib/models/wallet/wallet.dart
Normal file
62
frontend/pshared/lib/models/wallet/wallet.dart
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
import 'package:pshared/models/wallet/balance.dart';
|
||||||
|
import 'package:pshared/models/wallet/money.dart';
|
||||||
|
|
||||||
|
|
||||||
|
class WalletAsset {
|
||||||
|
final String chain;
|
||||||
|
final String tokenSymbol;
|
||||||
|
final String contractAddress;
|
||||||
|
|
||||||
|
const WalletAsset({
|
||||||
|
required this.chain,
|
||||||
|
required this.tokenSymbol,
|
||||||
|
required this.contractAddress,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
class WalletModel {
|
||||||
|
final String walletRef;
|
||||||
|
final String organizationRef;
|
||||||
|
final String ownerRef;
|
||||||
|
final WalletAsset asset;
|
||||||
|
final String depositAddress;
|
||||||
|
final String status;
|
||||||
|
final Map<String, String>? metadata;
|
||||||
|
final DateTime? createdAt;
|
||||||
|
final DateTime? updatedAt;
|
||||||
|
final WalletBalance? balance;
|
||||||
|
final WalletMoney? availableMoney;
|
||||||
|
|
||||||
|
const WalletModel({
|
||||||
|
required this.walletRef,
|
||||||
|
required this.organizationRef,
|
||||||
|
required this.ownerRef,
|
||||||
|
required this.asset,
|
||||||
|
required this.depositAddress,
|
||||||
|
required this.status,
|
||||||
|
this.metadata,
|
||||||
|
this.createdAt,
|
||||||
|
this.updatedAt,
|
||||||
|
this.balance,
|
||||||
|
this.availableMoney,
|
||||||
|
});
|
||||||
|
|
||||||
|
WalletModel copyWith({
|
||||||
|
WalletBalance? balance,
|
||||||
|
WalletMoney? availableMoney,
|
||||||
|
}) {
|
||||||
|
return WalletModel(
|
||||||
|
walletRef: walletRef,
|
||||||
|
organizationRef: organizationRef,
|
||||||
|
ownerRef: ownerRef,
|
||||||
|
asset: asset,
|
||||||
|
depositAddress: depositAddress,
|
||||||
|
status: status,
|
||||||
|
metadata: metadata,
|
||||||
|
createdAt: createdAt,
|
||||||
|
updatedAt: updatedAt,
|
||||||
|
balance: balance ?? this.balance,
|
||||||
|
availableMoney: availableMoney ?? this.availableMoney,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ class Services {
|
|||||||
static const String organization = 'organizations';
|
static const String organization = 'organizations';
|
||||||
static const String permission = 'permissions';
|
static const String permission = 'permissions';
|
||||||
static const String storage = 'storage';
|
static const String storage = 'storage';
|
||||||
|
static const String chainWallets = 'chain_wallets';
|
||||||
|
|
||||||
static const String amplitude = 'amplitude';
|
static const String amplitude = 'amplitude';
|
||||||
static const String clients = 'clients';
|
static const String clients = 'clients';
|
||||||
|
|||||||
31
frontend/pshared/lib/service/wallet.dart
Normal file
31
frontend/pshared/lib/service/wallet.dart
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import 'package:pshared/api/responses/wallet_balance.dart';
|
||||||
|
import 'package:pshared/api/responses/wallets.dart';
|
||||||
|
import 'package:pshared/data/mapper/wallet/response.dart';
|
||||||
|
import 'package:pshared/models/wallet/balance.dart';
|
||||||
|
import 'package:pshared/models/wallet/wallet.dart';
|
||||||
|
import 'package:pshared/service/authorization/service.dart';
|
||||||
|
import 'package:pshared/service/services.dart';
|
||||||
|
|
||||||
|
|
||||||
|
class WalletService {
|
||||||
|
static const String _objectType = Services.chainWallets;
|
||||||
|
|
||||||
|
static Future<List<WalletModel>> list(String organizationRef) async {
|
||||||
|
final json = await AuthorizationService.getGETResponse(
|
||||||
|
_objectType,
|
||||||
|
'/$organizationRef',
|
||||||
|
);
|
||||||
|
return WalletsResponse.fromJson(json).toDomain();
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<WalletBalance> getBalance({
|
||||||
|
required String organizationRef,
|
||||||
|
required String walletRef,
|
||||||
|
}) async {
|
||||||
|
final json = await AuthorizationService.getGETResponse(
|
||||||
|
_objectType,
|
||||||
|
'/$organizationRef/$walletRef/balance',
|
||||||
|
);
|
||||||
|
return WalletBalanceResponse.fromJson(json).toDomain();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
import 'package:go_router/go_router.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/pages.dart';
|
||||||
import 'package:pweb/app/router/page_params.dart';
|
import 'package:pweb/app/router/page_params.dart';
|
||||||
import 'package:pweb/pages/2fa/page.dart';
|
import 'package:pweb/pages/2fa/page.dart';
|
||||||
@@ -32,7 +36,11 @@ GoRouter createRouter() => GoRouter(
|
|||||||
name: Pages.sfactor.name,
|
name: Pages.sfactor.name,
|
||||||
path: routerPage(Pages.sfactor),
|
path: routerPage(Pages.sfactor),
|
||||||
builder: (context, _) => TwoFactorCodePage(
|
builder: (context, _) => TwoFactorCodePage(
|
||||||
onVerificationSuccess: () => context.goNamed(Pages.dashboard.name),
|
onVerificationSuccess: () {
|
||||||
|
// trigger organization load
|
||||||
|
context.read<OrganizationsProvider>().load();
|
||||||
|
context.goNamed(Pages.dashboard.name);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
GoRoute(
|
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(
|
ChangeNotifierProvider(
|
||||||
create: (_) => PaymentMethodsProvider(service: MockPaymentMethodsService())..loadMethods(),
|
create: (_) => PaymentMethodsProvider(service: MockPaymentMethodsService())..loadMethods(),
|
||||||
),
|
),
|
||||||
ChangeNotifierProvider(
|
ChangeNotifierProxyProvider<OrganizationsProvider, WalletsProvider>(
|
||||||
create: (_) => WalletsProvider(MockWalletsService())..loadData(),
|
create: (_) => WalletsProvider(ApiWalletsService()),
|
||||||
|
update: (context, organizations, provider) => provider!..update(organizations),
|
||||||
),
|
),
|
||||||
ChangeNotifierProvider(
|
ChangeNotifierProvider(
|
||||||
create: (_) => WalletTransactionsProvider(MockWalletTransactionsService())..load(),
|
create: (_) => WalletTransactionsProvider(MockWalletTransactionsService())..load(),
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ class Wallet {
|
|||||||
final double balance;
|
final double balance;
|
||||||
final Currency currency;
|
final Currency currency;
|
||||||
final bool isHidden;
|
final bool isHidden;
|
||||||
|
final DateTime calculatedAt;
|
||||||
|
|
||||||
Wallet({
|
Wallet({
|
||||||
required this.id,
|
required this.id,
|
||||||
@@ -15,6 +16,7 @@ class Wallet {
|
|||||||
required this.name,
|
required this.name,
|
||||||
required this.balance,
|
required this.balance,
|
||||||
required this.currency,
|
required this.currency,
|
||||||
|
required this.calculatedAt,
|
||||||
this.isHidden = true,
|
this.isHidden = true,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -25,14 +27,13 @@ class Wallet {
|
|||||||
Currency? currency,
|
Currency? currency,
|
||||||
String? walletUserID,
|
String? walletUserID,
|
||||||
bool? isHidden,
|
bool? isHidden,
|
||||||
}) {
|
}) => Wallet(
|
||||||
return Wallet(
|
id: id ?? this.id,
|
||||||
id: id ?? this.id,
|
name: name ?? this.name,
|
||||||
name: name ?? this.name,
|
balance: balance ?? this.balance,
|
||||||
balance: balance ?? this.balance,
|
currency: currency ?? this.currency,
|
||||||
currency: currency ?? this.currency,
|
walletUserID: walletUserID ?? this.walletUserID,
|
||||||
walletUserID: walletUserID ?? this.walletUserID,
|
isHidden: isHidden ?? this.isHidden,
|
||||||
isHidden: isHidden ?? this.isHidden,
|
calculatedAt: calculatedAt,
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -44,6 +44,7 @@ class _LoginFormState extends State<LoginForm> {
|
|||||||
locale: context.read<LocaleProvider>().locale.languageCode,
|
locale: context.read<LocaleProvider>().locale.languageCode,
|
||||||
);
|
);
|
||||||
if (outcome.isPending) {
|
if (outcome.isPending) {
|
||||||
|
// TODO: fix context usage
|
||||||
navigateAndReplace(context, Pages.sfactor);
|
navigateAndReplace(context, Pages.sfactor);
|
||||||
} else {
|
} else {
|
||||||
onLogin();
|
onLogin();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
import 'package:pweb/providers/wallets.dart';
|
import 'package:pweb/providers/wallets.dart';
|
||||||
|
import 'package:pweb/widgets/error/snackbar.dart';
|
||||||
|
|
||||||
|
|
||||||
class WalletEditHeader extends StatefulWidget {
|
class WalletEditHeader extends StatefulWidget {
|
||||||
@@ -85,10 +86,11 @@ class _WalletEditHeaderState extends State<WalletEditHeader> {
|
|||||||
icon: const Icon(Icons.check),
|
icon: const Icon(Icons.check),
|
||||||
color: theme.colorScheme.primary,
|
color: theme.colorScheme.primary,
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
provider.updateName(wallet.id, _controller.text);
|
await executeActionWithNotification(
|
||||||
await provider.updateWallet(wallet.copyWith(name: _controller.text));
|
context: context,
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
action: () async => await provider.updateWallet(wallet.copyWith(name: _controller.text)),
|
||||||
const SnackBar(content: Text('Wallet name saved')),
|
errorMessage: 'Failed to update wallet name',
|
||||||
|
successMessage: 'Wallet name saved',
|
||||||
);
|
);
|
||||||
setState(() {
|
setState(() {
|
||||||
_isEditing = false;
|
_isEditing = false;
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:pweb/models/wallet.dart';
|
import 'package:pshared/provider/organizations.dart';
|
||||||
import 'package:pweb/services/wallets.dart';
|
|
||||||
import 'package:pshared/provider/resource.dart';
|
import 'package:pshared/provider/resource.dart';
|
||||||
import 'package:pshared/utils/exception.dart';
|
import 'package:pshared/utils/exception.dart';
|
||||||
|
|
||||||
|
import 'package:pweb/models/wallet.dart';
|
||||||
|
import 'package:pweb/services/wallets.dart';
|
||||||
|
|
||||||
|
|
||||||
class WalletsProvider with ChangeNotifier {
|
class WalletsProvider with ChangeNotifier {
|
||||||
final WalletsService _service;
|
final WalletsService _service;
|
||||||
|
late OrganizationsProvider _organizations;
|
||||||
|
|
||||||
WalletsProvider(this._service);
|
WalletsProvider(this._service);
|
||||||
|
|
||||||
@@ -25,6 +29,15 @@ class WalletsProvider with ChangeNotifier {
|
|||||||
bool _isRefreshingBalances = false;
|
bool _isRefreshingBalances = false;
|
||||||
bool get isRefreshingBalances => _isRefreshingBalances;
|
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) {
|
void selectWallet(Wallet wallet) {
|
||||||
_selectedWallet = wallet;
|
_selectedWallet = wallet;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
@@ -33,11 +46,11 @@ class WalletsProvider with ChangeNotifier {
|
|||||||
Future<void> loadWalletsWithBalances() async {
|
Future<void> loadWalletsWithBalances() async {
|
||||||
_setResource(_resource.copyWith(isLoading: true, error: null));
|
_setResource(_resource.copyWith(isLoading: true, error: null));
|
||||||
try {
|
try {
|
||||||
final base = await _service.getWallets();
|
final base = await _service.getWallets(_organizations.current.id);
|
||||||
final withBalances = <Wallet>[];
|
final withBalances = <Wallet>[];
|
||||||
for (final wallet in base) {
|
for (final wallet in base) {
|
||||||
try {
|
try {
|
||||||
final balance = await _service.getBalance(wallet.id);
|
final balance = await _service.getBalance(_organizations.current.id, wallet.id);
|
||||||
withBalances.add(wallet.copyWith(balance: balance));
|
withBalances.add(wallet.copyWith(balance: balance));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_setResource(_resource.copyWith(error: toException(e)));
|
_setResource(_resource.copyWith(error: toException(e)));
|
||||||
@@ -58,7 +71,7 @@ class WalletsProvider with ChangeNotifier {
|
|||||||
try {
|
try {
|
||||||
final updated = <Wallet>[];
|
final updated = <Wallet>[];
|
||||||
for (final wallet in wallets) {
|
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));
|
updated.add(wallet.copyWith(balance: balance));
|
||||||
}
|
}
|
||||||
_setResource(_resource.copyWith(data: updated));
|
_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/currency.dart';
|
||||||
import 'package:pweb/models/wallet.dart';
|
import 'package:pweb/models/wallet.dart';
|
||||||
|
import 'package:pweb/data/mappers/wallet_ui.dart';
|
||||||
|
|
||||||
|
|
||||||
abstract class WalletsService {
|
abstract class WalletsService {
|
||||||
Future<List<Wallet>> getWallets();
|
Future<List<Wallet>> getWallets(String organizationRef);
|
||||||
Future<double> getBalance(String walletRef);
|
Future<double> getBalance(String organizationRef, String walletRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
class MockWalletsService implements WalletsService {
|
class MockWalletsService implements WalletsService {
|
||||||
final List<Wallet> _wallets = [
|
final List<Wallet> _wallets = [
|
||||||
Wallet(id: '1124', walletUserID: 'WA-12345667', name: 'Main Wallet', balance: 10000000.0, currency: Currency.rub),
|
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),
|
Wallet(id: '2124', walletUserID: 'WA-76654321', name: 'Savings', balance: 2500.5, currency: Currency.usd, calculatedAt: DateTime.now()),
|
||||||
];
|
];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<Wallet>> getWallets() async {
|
Future<List<Wallet>> getWallets(String _) async {
|
||||||
return _wallets;
|
return _wallets;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Wallet> getWallet(String walletId) async {
|
Future<double> getBalance(String _, String walletRef) async {
|
||||||
return _wallets.firstWhere(
|
|
||||||
(wallet) => wallet.id == walletId,
|
|
||||||
orElse: () => throw Exception('Wallet not found'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<double> getBalance(String walletRef) async {
|
|
||||||
final wallet = _wallets.firstWhere(
|
final wallet = _wallets.firstWhere(
|
||||||
(w) => w.id == walletRef,
|
(w) => w.id == walletRef,
|
||||||
orElse: () => throw Exception('Wallet not found'),
|
orElse: () => throw Exception('Wallet not found'),
|
||||||
@@ -35,3 +30,21 @@ class MockWalletsService implements WalletsService {
|
|||||||
return wallet.balance;
|
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:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:pweb/utils/error_handler.dart';
|
import 'package:pweb/utils/error_handler.dart';
|
||||||
|
import 'package:pweb/utils/snackbar.dart';
|
||||||
import 'package:pweb/widgets/error/content.dart';
|
import 'package:pweb/widgets/error/content.dart';
|
||||||
|
|
||||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||||
@@ -52,13 +53,18 @@ Future<T?> executeActionWithNotification<T>({
|
|||||||
required BuildContext context,
|
required BuildContext context,
|
||||||
required Future<T> Function() action,
|
required Future<T> Function() action,
|
||||||
required String errorMessage,
|
required String errorMessage,
|
||||||
|
String? successMessage,
|
||||||
int delaySeconds = 3,
|
int delaySeconds = 3,
|
||||||
}) async {
|
}) async {
|
||||||
final scaffoldMessenger = ScaffoldMessenger.of(context);
|
final scaffoldMessenger = ScaffoldMessenger.of(context);
|
||||||
final localizations = AppLocalizations.of(context)!;
|
final localizations = AppLocalizations.of(context)!;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await action();
|
final res = await action();
|
||||||
|
if (successMessage != null) {
|
||||||
|
notifyUserX(scaffoldMessenger, successMessage, delaySeconds: delaySeconds);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Report the error using your existing notifier.
|
// Report the error using your existing notifier.
|
||||||
notifyUserOfErrorX(
|
notifyUserOfErrorX(
|
||||||
|
|||||||
Reference in New Issue
Block a user