front dev update

This commit is contained in:
Stephan D
2026-01-30 16:54:56 +01:00
parent 51f5b0804a
commit 102c5d3668
31 changed files with 755 additions and 74 deletions

View File

@@ -1,6 +1,7 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:pshared/data/dto/describable.dart';
import 'package:pshared/data/dto/ledger/role.dart';
import 'package:pshared/data/dto/ledger/type.dart';
part 'create.g.dart';
@@ -11,7 +12,7 @@ class CreateLedgerAccountRequest {
final Map<String, String>? metadata;
final String currency;
final bool allowNegative;
final bool isSettlement;
final LedgerAccountRoleDTO role;
final DescribableDTO describable;
final String? ownerRef;
final LedgerAccountTypeDTO accountType;
@@ -20,7 +21,7 @@ class CreateLedgerAccountRequest {
this.metadata,
required this.currency,
required this.allowNegative,
required this.isSettlement,
required this.role,
required this.describable,
required this.accountType,
this.ownerRef,

View File

@@ -0,0 +1,19 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:pshared/api/responses/base.dart';
import 'package:pshared/api/responses/token.dart';
part 'cursor_page.g.dart';
@JsonSerializable(explicitToJson: true)
class CursorPageResponse extends BaseAuthorizedResponse {
@JsonKey(name: 'next_cursor')
final String? nextCursor;
const CursorPageResponse({required super.accessToken, required this.nextCursor});
factory CursorPageResponse.fromJson(Map<String, dynamic> json) => _$CursorPageResponseFromJson(json);
@override
Map<String, dynamic> toJson() => _$CursorPageResponseToJson(this);
}

View File

@@ -1,6 +1,6 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:pshared/api/responses/base.dart';
import 'package:pshared/api/responses/cursor_page.dart';
import 'package:pshared/api/responses/token.dart';
import 'package:pshared/data/dto/payment/payment.dart';
@@ -8,11 +8,14 @@ part 'payments.g.dart';
@JsonSerializable(explicitToJson: true)
class PaymentsResponse extends BaseAuthorizedResponse {
class PaymentsResponse extends CursorPageResponse {
final List<PaymentDTO> payments;
const PaymentsResponse({required super.accessToken, required this.payments});
const PaymentsResponse({
required super.accessToken,
required super.nextCursor,
required this.payments,
});
factory PaymentsResponse.fromJson(Map<String, dynamic> json) => _$PaymentsResponseFromJson(json);
@override

View File

@@ -4,10 +4,6 @@ import 'package:flutter/material.dart';
class CommonConstants {
static String apiProto = 'https';
static String apiHost = 'app.sendico.io';
// static String apiProto = const String.fromEnvironment('API_PROTO', defaultValue: 'http');
// static String apiHost = const String.fromEnvironment('API_HOST', defaultValue: 'localhost');
// static String apiHost = 'localhost';
// static String apiHost = '10.0.2.2';
static String apiEndpoint = '/api/v1';
static String amplitudeSecret = 'c3d75b3e2520d708440acbb16b923e79';
static String amplitudeServerZone = 'EU';

View File

@@ -0,0 +1,49 @@
import 'package:flutter/material.dart';
class CommonConstants {
static String apiProto = 'http';
static String apiHost = 'localhost:8080';
static String apiEndpoint = '/api/v1';
static String amplitudeSecret = 'c3d75b3e2520d708440acbb16b923e79';
static String amplitudeServerZone = 'EU';
static String posthogApiKey = 'phc_lVhbruaZpxiQxppHBJpL36ARnPlkqbCewv6cauoceTN';
static String posthogHost = 'https://eu.i.posthog.com';
static Locale defaultLocale = const Locale('en');
static String defaultCurrency = 'EUR';
static int defaultDimensionLength = 500;
static String clientId = '';
static String wsProto = 'ws';
static String wsEndpoint = '/ws';
static Color themeColor = Color.fromARGB(255, 80, 63, 224);
static String nilObjectRef = '000000000000000000000000';
// Public getters for shared properties
static String get serviceUrl => '$apiProto://$apiHost';
static String get apiUrl => '$serviceUrl$apiEndpoint';
static String get wsUrl => '$wsProto://$apiHost$apiEndpoint$wsEndpoint';
static const String accessTokenStorageKey = 'access_token';
static const String refreshTokenStorageKey = 'refresh_token';
static const String currentOrgKey = 'current_org';
static const String deviceIdStorageKey = 'device_id';
// Method to apply the configuration, called by platform-specific implementations
static void applyConfiguration(Map<String, dynamic> configJson) {
apiProto = configJson['apiProto'] ?? apiProto;
apiHost = configJson['apiHost'] ?? apiHost;
apiEndpoint = configJson['apiEndpoint'] ?? apiEndpoint;
amplitudeSecret = configJson['amplitudeSecret'] ?? amplitudeSecret;
amplitudeServerZone = configJson['amplitudeServerZone'] ?? amplitudeServerZone;
posthogApiKey = configJson['posthogApiKey'] ?? posthogApiKey;
posthogHost = configJson['posthogHost'] ?? posthogHost;
defaultLocale = Locale(configJson['defaultLocale'] ?? defaultLocale.languageCode);
defaultCurrency = configJson['defaultCurrency'] ?? defaultCurrency;
wsProto = configJson['wsProto'] ?? wsProto;
wsEndpoint = configJson['wsEndpoint'] ?? wsEndpoint;
defaultDimensionLength = configJson['defaultDimensionLength'] ?? defaultDimensionLength;
clientId = configJson['clientId'] ?? clientId;
if (configJson.containsKey('themeColor')) {
themeColor = Color(int.parse(configJson['themeColor']));
}
}
}

View File

@@ -2,6 +2,7 @@ import 'package:json_annotation/json_annotation.dart';
import 'package:pshared/data/dto/describable.dart';
import 'package:pshared/data/dto/ledger/balance.dart';
import 'package:pshared/data/dto/ledger/role.dart';
import 'package:pshared/data/dto/ledger/status.dart';
import 'package:pshared/data/dto/ledger/type.dart';
@@ -20,7 +21,8 @@ class LedgerAccountDTO {
@JsonKey(fromJson: ledgerAccountStatusFromJson, toJson: ledgerAccountStatusToJson)
final LedgerAccountStatusDTO status;
final bool allowNegative;
final bool isSettlement;
@JsonKey(fromJson: ledgerAccountRoleFromJson, toJson: ledgerAccountRoleToJson)
final LedgerAccountRoleDTO role;
final Map<String, String>? metadata;
final DateTime? createdAt;
final DateTime? updatedAt;
@@ -38,7 +40,7 @@ class LedgerAccountDTO {
required this.currency,
required this.status,
required this.allowNegative,
required this.isSettlement,
required this.role,
this.metadata,
this.createdAt,
this.updatedAt,

View File

@@ -0,0 +1,107 @@
import 'package:json_annotation/json_annotation.dart';
enum LedgerAccountRoleDTO {
@JsonValue('unspecified')
unspecified,
@JsonValue('operating')
operating,
@JsonValue('hold')
hold,
@JsonValue('transit')
transit,
@JsonValue('settlement')
settlement,
@JsonValue('clearing')
clearing,
@JsonValue('pending')
pending,
@JsonValue('reserve')
reserve,
@JsonValue('liquidity')
liquidity,
@JsonValue('fee')
fee,
@JsonValue('chargeback')
chargeback,
@JsonValue('adjustment')
adjustment,
}
LedgerAccountRoleDTO ledgerAccountRoleFromJson(Object? value) {
final raw = value?.toString() ?? '';
var normalized = raw.trim().toLowerCase();
const prefix = 'account_role_';
if (normalized.startsWith(prefix)) {
normalized = normalized.substring(prefix.length);
}
switch (normalized) {
case 'operating':
return LedgerAccountRoleDTO.operating;
case 'hold':
return LedgerAccountRoleDTO.hold;
case 'transit':
return LedgerAccountRoleDTO.transit;
case 'settlement':
return LedgerAccountRoleDTO.settlement;
case 'clearing':
return LedgerAccountRoleDTO.clearing;
case 'pending':
return LedgerAccountRoleDTO.pending;
case 'reserve':
return LedgerAccountRoleDTO.reserve;
case 'liquidity':
return LedgerAccountRoleDTO.liquidity;
case 'fee':
return LedgerAccountRoleDTO.fee;
case 'chargeback':
return LedgerAccountRoleDTO.chargeback;
case 'adjustment':
return LedgerAccountRoleDTO.adjustment;
case 'unspecified':
case '':
return LedgerAccountRoleDTO.unspecified;
default:
return LedgerAccountRoleDTO.unspecified;
}
}
String ledgerAccountRoleToJson(LedgerAccountRoleDTO value) {
switch (value) {
case LedgerAccountRoleDTO.operating:
return 'operating';
case LedgerAccountRoleDTO.hold:
return 'hold';
case LedgerAccountRoleDTO.transit:
return 'transit';
case LedgerAccountRoleDTO.settlement:
return 'settlement';
case LedgerAccountRoleDTO.clearing:
return 'clearing';
case LedgerAccountRoleDTO.pending:
return 'pending';
case LedgerAccountRoleDTO.reserve:
return 'reserve';
case LedgerAccountRoleDTO.liquidity:
return 'liquidity';
case LedgerAccountRoleDTO.fee:
return 'fee';
case LedgerAccountRoleDTO.chargeback:
return 'chargeback';
case LedgerAccountRoleDTO.adjustment:
return 'adjustment';
case LedgerAccountRoleDTO.unspecified:
return 'unspecified';
}
}

View File

@@ -1,6 +1,7 @@
import 'package:pshared/data/dto/ledger/account.dart';
import 'package:pshared/data/mapper/describable.dart';
import 'package:pshared/data/mapper/ledger/balance.dart';
import 'package:pshared/data/mapper/ledger/role.dart';
import 'package:pshared/data/mapper/ledger/status.dart';
import 'package:pshared/data/mapper/ledger/type.dart';
import 'package:pshared/models/describable.dart';
@@ -17,7 +18,7 @@ extension LedgerAccountDTOMapper on LedgerAccountDTO {
currency: currency,
status: status.toDomain(),
allowNegative: allowNegative,
isSettlement: isSettlement,
role: role.toDomain(),
metadata: metadata,
createdAt: createdAt,
updatedAt: updatedAt,
@@ -36,7 +37,7 @@ extension LedgerAccountModelMapper on LedgerAccount {
currency: currency,
status: status.toDTO(),
allowNegative: allowNegative,
isSettlement: isSettlement,
role: role.toDTO(),
metadata: metadata,
createdAt: createdAt,
updatedAt: updatedAt,

View File

@@ -0,0 +1,65 @@
import 'package:pshared/data/dto/ledger/role.dart';
import 'package:pshared/models/ledger/role.dart';
extension LedgerAccountRoleDTOMapper on LedgerAccountRoleDTO {
LedgerAccountRole toDomain() {
switch (this) {
case LedgerAccountRoleDTO.unspecified:
return LedgerAccountRole.unspecified;
case LedgerAccountRoleDTO.operating:
return LedgerAccountRole.operating;
case LedgerAccountRoleDTO.hold:
return LedgerAccountRole.hold;
case LedgerAccountRoleDTO.transit:
return LedgerAccountRole.transit;
case LedgerAccountRoleDTO.settlement:
return LedgerAccountRole.settlement;
case LedgerAccountRoleDTO.clearing:
return LedgerAccountRole.clearing;
case LedgerAccountRoleDTO.pending:
return LedgerAccountRole.pending;
case LedgerAccountRoleDTO.reserve:
return LedgerAccountRole.reserve;
case LedgerAccountRoleDTO.liquidity:
return LedgerAccountRole.liquidity;
case LedgerAccountRoleDTO.fee:
return LedgerAccountRole.fee;
case LedgerAccountRoleDTO.chargeback:
return LedgerAccountRole.chargeback;
case LedgerAccountRoleDTO.adjustment:
return LedgerAccountRole.adjustment;
}
}
}
extension LedgerAccountRoleModelMapper on LedgerAccountRole {
LedgerAccountRoleDTO toDTO() {
switch (this) {
case LedgerAccountRole.unspecified:
return LedgerAccountRoleDTO.unspecified;
case LedgerAccountRole.operating:
return LedgerAccountRoleDTO.operating;
case LedgerAccountRole.hold:
return LedgerAccountRoleDTO.hold;
case LedgerAccountRole.transit:
return LedgerAccountRoleDTO.transit;
case LedgerAccountRole.settlement:
return LedgerAccountRoleDTO.settlement;
case LedgerAccountRole.clearing:
return LedgerAccountRoleDTO.clearing;
case LedgerAccountRole.pending:
return LedgerAccountRoleDTO.pending;
case LedgerAccountRole.reserve:
return LedgerAccountRoleDTO.reserve;
case LedgerAccountRole.liquidity:
return LedgerAccountRoleDTO.liquidity;
case LedgerAccountRole.fee:
return LedgerAccountRoleDTO.fee;
case LedgerAccountRole.chargeback:
return LedgerAccountRoleDTO.chargeback;
case LedgerAccountRole.adjustment:
return LedgerAccountRoleDTO.adjustment;
}
}
}

View File

@@ -90,6 +90,8 @@ ChainNetwork chainNetworkFromValue(String? value) {
return ChainNetwork.ethereumMainnet;
case 'arbitrum_one':
return ChainNetwork.arbitrumOne;
case 'arbitrum_sepolia':
return ChainNetwork.arbitrumSepolia;
case 'tron_mainnet':
return ChainNetwork.tronMainnet;
case 'tron_nile':
@@ -111,6 +113,8 @@ String chainNetworkToValue(ChainNetwork chain) {
return 'tron_mainnet';
case ChainNetwork.tronNile:
return 'tron_nile';
case ChainNetwork.arbitrumSepolia:
return 'arbitrum_sepolia';
case ChainNetwork.unspecified:
return 'unspecified';
}

View File

@@ -46,6 +46,11 @@
"description": "Label for the Arbitrum One network"
},
"chainNetworkArbitrumSepolia": "Arbitrum Sepolia",
"@chainNetworkArbitrumSepolia": {
"description": "Label for the Arbitrum Sepolia network"
},
"chainNetworkTronMainnet": "Tron Mainnet",
"@chainNetworkTronMainnet": {
"description": "Label for the Tron mainnet network"

View File

@@ -46,6 +46,11 @@
"description": "Label for the Arbitrum One network"
},
"chainNetworkArbitrumSepolia": "Arbitrum Sepolia",
"@chainNetworkArbitrumSepolia": {
"description": "Label for the Arbitrum Sepolia network"
},
"chainNetworkTronMainnet": "Tron Mainnet",
"@chainNetworkTronMainnet": {
"description": "Label for the Tron mainnet network"

View File

@@ -1,5 +1,6 @@
import 'package:pshared/models/describable.dart';
import 'package:pshared/models/ledger/balance.dart';
import 'package:pshared/models/ledger/role.dart';
import 'package:pshared/models/ledger/status.dart';
import 'package:pshared/models/ledger/type.dart';
@@ -13,7 +14,7 @@ class LedgerAccount implements Describable {
final String currency;
final LedgerAccountStatus status;
final bool allowNegative;
final bool isSettlement;
final LedgerAccountRole role;
final Map<String, String>? metadata;
final DateTime? createdAt;
final DateTime? updatedAt;
@@ -35,7 +36,7 @@ class LedgerAccount implements Describable {
required this.currency,
required this.status,
required this.allowNegative,
required this.isSettlement,
required this.role,
this.metadata,
this.createdAt,
this.updatedAt,
@@ -55,7 +56,7 @@ class LedgerAccount implements Describable {
currency: currency,
status: status,
allowNegative: allowNegative,
isSettlement: isSettlement,
role: role,
metadata: metadata,
createdAt: createdAt,
updatedAt: updatedAt,

View File

@@ -0,0 +1,14 @@
enum LedgerAccountRole {
unspecified,
operating,
hold,
transit,
settlement,
clearing,
pending,
reserve,
liquidity,
fee,
chargeback,
adjustment,
}

View File

@@ -0,0 +1,6 @@
class CursorPage<T> {
final List<T> items;
final String? nextCursor;
const CursorPage({required this.items, required this.nextCursor});
}

View File

@@ -2,6 +2,7 @@ enum ChainNetwork {
unspecified,
ethereumMainnet,
arbitrumOne,
arbitrumSepolia,
tronMainnet,
tronNile
tronNile,
}

View File

@@ -0,0 +1,5 @@
import 'package:pshared/models/pagination/cursor_page.dart';
import 'package:pshared/models/payment/payment.dart';
typedef PaymentPage =CursorPage<Payment>;

View File

@@ -8,6 +8,7 @@ import 'package:collection/collection.dart';
import 'package:pshared/models/currency.dart';
import 'package:pshared/models/describable.dart';
import 'package:pshared/models/ledger/account.dart';
import 'package:pshared/models/ledger/role.dart';
import 'package:pshared/models/payment/wallet.dart';
import 'package:pshared/provider/organizations.dart';
import 'package:pshared/provider/resource.dart';
@@ -24,7 +25,7 @@ class LedgerAccountsProvider with ChangeNotifier {
Resource<List<LedgerAccount>> _resource = Resource(data: []);
Resource<List<LedgerAccount>> get resource => _resource;
List<LedgerAccount> get accounts => (_resource.data ?? []).whereNot((la)=> la.isSettlement).toList();
List<LedgerAccount> get accounts => (_resource.data ?? []).where((la) => la.role == LedgerAccountRole.operating).toList();
bool get isLoading => _resource.isLoading;
Exception? get error => _resource.error;

View File

@@ -0,0 +1,181 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:pshared/models/payment/payment.dart';
import 'package:pshared/provider/organizations.dart';
import 'package:pshared/provider/resource.dart';
import 'package:pshared/service/payment/service.dart';
import 'package:pshared/utils/exception.dart';
class PaymentsProvider with ChangeNotifier {
OrganizationsProvider? _organizations;
String? _loadedOrganizationRef;
Resource<List<Payment>> _resource = Resource(data: []);
bool _isLoaded = false;
bool _isLoadingMore = false;
String? _nextCursor;
int? _limit;
String? _sourceRef;
String? _destinationRef;
List<String>? _states;
int _opSeq = 0;
Resource<List<Payment>> get resource => _resource;
List<Payment> get payments => _resource.data ?? [];
bool get isLoading => _resource.isLoading;
Exception? get error => _resource.error;
bool get isReady => _isLoaded && !_resource.isLoading && _resource.error == null;
bool get isLoadingMore => _isLoadingMore;
String? get nextCursor => _nextCursor;
bool get canLoadMore => _nextCursor != null && _nextCursor!.isNotEmpty;
void update(OrganizationsProvider organizations) {
_organizations = organizations;
if (!organizations.isOrganizationSet) {
reset();
return;
}
final orgRef = organizations.current.id;
if (_loadedOrganizationRef != orgRef) {
_loadedOrganizationRef = orgRef;
unawaited(refresh());
}
}
Future<void> refresh({
int? limit,
String? sourceRef,
String? destinationRef,
List<String>? states,
}) async {
final org = _organizations;
if (org == null || !org.isOrganizationSet) return;
_limit = limit;
_sourceRef = _normalize(sourceRef);
_destinationRef = _normalize(destinationRef);
_states = _normalizeStates(states);
_nextCursor = null;
_isLoadingMore = false;
final seq = ++_opSeq;
_applyResource(_resource.copyWith(isLoading: true, error: null), notify: true);
try {
final page = await PaymentService.listPage(
org.current.id,
limit: _limit,
cursor: null,
sourceRef: _sourceRef,
destinationRef: _destinationRef,
states: _states,
);
if (seq != _opSeq) return;
_isLoaded = true;
_nextCursor = _normalize(page.nextCursor);
_applyResource(
Resource(data: page.items, isLoading: false, error: null),
notify: true,
);
} catch (e) {
if (seq != _opSeq) return;
_applyResource(
_resource.copyWith(isLoading: false, error: toException(e)),
notify: true,
);
}
}
Future<void> loadMore() async {
final org = _organizations;
if (org == null || !org.isOrganizationSet) return;
if (_isLoadingMore || _resource.isLoading) return;
final cursor = _normalize(_nextCursor);
if (cursor == null) return;
final seq = _opSeq;
_isLoadingMore = true;
_applyResource(_resource.copyWith(error: null), notify: false);
notifyListeners();
try {
final page = await PaymentService.listPage(
org.current.id,
limit: _limit,
cursor: cursor,
sourceRef: _sourceRef,
destinationRef: _destinationRef,
states: _states,
);
if (seq != _opSeq) return;
final combined = List<Payment>.from(payments)..addAll(page.items);
_nextCursor = _normalize(page.nextCursor);
_applyResource(
_resource.copyWith(data: combined, error: null),
notify: false,
);
} catch (e) {
if (seq != _opSeq) return;
_applyResource(
_resource.copyWith(error: toException(e)),
notify: false,
);
} finally {
if (seq == _opSeq) {
_isLoadingMore = false;
notifyListeners();
}
}
}
void reset() {
_opSeq++;
_isLoaded = false;
_isLoadingMore = false;
_nextCursor = null;
_limit = null;
_sourceRef = null;
_destinationRef = null;
_states = null;
_resource = Resource(data: []);
notifyListeners();
}
void _applyResource(Resource<List<Payment>> newResource, {required bool notify}) {
_resource = newResource;
if (notify) notifyListeners();
}
String? _normalize(String? value) {
final trimmed = value?.trim();
if (trimmed == null || trimmed.isEmpty) return null;
return trimmed;
}
List<String>? _normalizeStates(List<String>? states) {
if (states == null || states.isEmpty) return null;
final normalized = states
.map((state) => state.trim())
.where((state) => state.isNotEmpty)
.toList();
if (normalized.isEmpty) return null;
return normalized;
}
}

View File

@@ -5,6 +5,7 @@ import 'package:pshared/provider/organizations.dart';
import 'package:pshared/provider/payment/quotation/quotation.dart';
import 'package:pshared/provider/resource.dart';
import 'package:pshared/service/payment/service.dart';
import 'package:pshared/utils/exception.dart';
class PaymentProvider extends ChangeNotifier {
@@ -53,11 +54,7 @@ class PaymentProvider extends ChangeNotifier {
_isLoaded = true;
_setResource(_payment.copyWith(data: response, isLoading: false, error: null));
} catch (e) {
_setResource(_payment.copyWith(
data: null,
error: e is Exception ? e : Exception(e.toString()),
isLoading: false,
));
_setResource(_payment.copyWith(data: null, error: toException(e), isLoading: false));
}
return _payment.data;
}

View File

@@ -1,4 +1,6 @@
import 'package:pshared/controllers/balance_mask/wallets.dart';
import 'package:pshared/models/payment/asset.dart';
import 'package:pshared/models/payment/chain_network.dart';
import 'package:pshared/models/payment/currency_pair.dart';
import 'package:pshared/models/payment/customer.dart';
import 'package:pshared/models/payment/fx/intent.dart';
@@ -55,6 +57,10 @@ class QuotationIntentBuilder {
destination: paymentData,
source: ManagedWalletPaymentMethod(
managedWalletRef: selectedWallet.id,
asset: PaymentAsset(
tokenSymbol: selectedWallet.tokenSymbol ?? '',
chain: selectedWallet.network ?? ChainNetwork.unspecified,
)
),
fx: fxIntent,
settlementMode: payment.payerCoversFee ? SettlementMode.fixReceived : SettlementMode.fixSource,

View File

@@ -18,6 +18,7 @@ import 'package:pshared/models/resources.dart';
import 'package:pshared/provider/organizations.dart';
import 'package:pshared/provider/resource.dart';
import 'package:pshared/service/permissions.dart';
import 'package:pshared/utils/exception.dart';
class PermissionsProvider extends ChangeNotifier {
@@ -43,10 +44,7 @@ class PermissionsProvider extends ChangeNotifier {
await operation();
return await load();
} catch (e) {
_userAccess = _userAccess.copyWith(
error: e is Exception ? e : Exception(e.toString()),
isLoading: false,
);
_userAccess = _userAccess.copyWith(error: toException(e), isLoading: false);
notifyListeners();
return _userAccess.data;
}

View File

@@ -4,11 +4,13 @@ import 'package:pshared/api/responses/ledger/balance.dart';
import 'package:pshared/data/mapper/describable.dart';
import 'package:pshared/data/mapper/ledger/account.dart';
import 'package:pshared/data/mapper/ledger/balance.dart';
import 'package:pshared/data/mapper/ledger/role.dart';
import 'package:pshared/data/mapper/ledger/type.dart';
import 'package:pshared/models/currency.dart';
import 'package:pshared/models/describable.dart';
import 'package:pshared/models/ledger/account.dart';
import 'package:pshared/models/ledger/balance.dart';
import 'package:pshared/models/ledger/role.dart';
import 'package:pshared/models/ledger/type.dart';
import 'package:pshared/service/authorization/service.dart';
import 'package:pshared/service/services.dart';
@@ -49,7 +51,7 @@ class LedgerService {
describable: describable.toDTO(),
ownerRef: ownerRef,
allowNegative: false,
isSettlement: false,
role: LedgerAccountRole.operating.toDTO(),
accountType: LedgerAccountType.asset.toDTO(),
currency: currencyCodeToString(currency),
).toJson(),

View File

@@ -6,16 +6,18 @@ import 'package:pshared/api/requests/payment/initiate.dart';
import 'package:pshared/api/responses/payment/payment.dart';
import 'package:pshared/api/responses/payment/payments.dart';
import 'package:pshared/data/mapper/payment/payment_response.dart';
import 'package:pshared/models/payment/page.dart';
import 'package:pshared/models/payment/payment.dart';
import 'package:pshared/service/authorization/service.dart';
import 'package:pshared/service/services.dart';
import 'package:pshared/utils/http/params.dart';
class PaymentService {
static final _logger = Logger('service.payment');
static const String _objectType = Services.payments;
static Future<List<Payment>> list(
static Future<PaymentPage> listPage(
String organizationRef, {
int? limit,
String? cursor,
@@ -25,12 +27,6 @@ class PaymentService {
}) async {
_logger.fine('Listing payments for organization $organizationRef');
final queryParams = <String, String>{};
if (limit != null) {
queryParams['limit'] = limit.toString();
}
if (cursor != null && cursor.isNotEmpty) {
queryParams['cursor'] = cursor;
}
if (sourceRef != null && sourceRef.isNotEmpty) {
queryParams['source_ref'] = sourceRef;
}
@@ -41,12 +37,35 @@ class PaymentService {
queryParams['state'] = states.join(',');
}
final path = '/$organizationRef';
final url = queryParams.isEmpty
? path
: Uri(path: path, queryParameters: queryParams).toString();
final url = cursorParamsToUriString(
path: '/$organizationRef',
limit: limit,
cursor: cursor,
queryParams: queryParams,
);
final response = await AuthorizationService.getGETResponse(_objectType, url);
return PaymentsResponse.fromJson(response).payments.map((payment) => payment.toDomain()).toList();
final parsed = PaymentsResponse.fromJson(response);
final payments = parsed.payments.map((payment) => payment.toDomain()).toList();
return PaymentPage(items: payments, nextCursor: parsed.nextCursor);
}
static Future<List<Payment>> list(
String organizationRef, {
int? limit,
String? cursor,
String? sourceRef,
String? destinationRef,
List<String>? states,
}) async {
final page = await listPage(
organizationRef,
limit: limit,
cursor: cursor,
sourceRef: sourceRef,
destinationRef: destinationRef,
states: states,
);
return page.items;
}
static Future<Payment> pay(
@@ -68,4 +87,5 @@ class PaymentService {
);
return PaymentResponse.fromJson(response).payment.toDomain();
}
}

View File

@@ -2,6 +2,7 @@
const String _limitParam = 'limit';
const String _offsetParam = 'offset';
const String _archivedParam = 'archived';
const String _cursorParam = 'cursor';
void _addIfNotNull(Map<String, String> params, String key, dynamic value) {
if (value != null) {
@@ -9,6 +10,13 @@ void _addIfNotNull(Map<String, String> params, String key, dynamic value) {
}
}
void _addIfNotBlank(Map<String, String> params, String key, String? value) {
final trimmed = value?.trim();
if (trimmed != null && trimmed.isNotEmpty) {
params[key] = trimmed;
}
}
Uri paramsToUri({
required String path,
int? limit,
@@ -36,3 +44,32 @@ String paramsToUriString({
int? offset,
bool? fetchArchived,
}) => paramsToUri(path: path, limit: limit, offset: offset, fetchArchived: fetchArchived).toString();
Uri cursorParamsToUri({
required String path,
int? limit,
String? cursor,
Map<String, String> queryParams = const {},
}) {
final params = Map<String, String>.from(queryParams);
_addIfNotNull(params, _limitParam, limit);
_addIfNotBlank(params, _cursorParam, cursor);
params.removeWhere((_, value) => value.trim().isEmpty);
return Uri(
path: path,
queryParameters: params.isEmpty ? null : params,
);
}
String cursorParamsToUriString({
required String path,
int? limit,
String? cursor,
Map<String, String> queryParams = const {},
}) => cursorParamsToUri(
path: path,
limit: limit,
cursor: cursor,
queryParams: queryParams,
).toString();

View File

@@ -15,6 +15,8 @@ extension ChainNetworkL10n on ChainNetwork {
return l10n.chainNetworkEthereumMainnet;
case ChainNetwork.arbitrumOne:
return l10n.chainNetworkArbitrumOne;
case ChainNetwork.arbitrumSepolia:
return l10n.chainNetworkArbitrumSepolia;
case ChainNetwork.tronMainnet:
return l10n.chainNetworkTronMainnet;
case ChainNetwork.tronNile: