Compare commits
6 Commits
SEND005
...
bfe4695b2d
| Author | SHA1 | Date | |
|---|---|---|---|
| bfe4695b2d | |||
|
|
99161c8e7d | ||
| 6901791dd2 | |||
|
|
acb3d14b47 | ||
| aa5f7e271e | |||
|
|
0a01995f53 |
@@ -91,7 +91,7 @@ api:
|
|||||||
insecure: true
|
insecure: true
|
||||||
payment_orchestrator:
|
payment_orchestrator:
|
||||||
address: sendico_payment_orchestrator:50062
|
address: sendico_payment_orchestrator:50062
|
||||||
address_env: PAYMENT_ORCHESTRATOR_ADDRESS
|
address_env: PAYMENTS_ADDRESS
|
||||||
dial_timeout_seconds: 5
|
dial_timeout_seconds: 5
|
||||||
call_timeout_seconds: 5
|
call_timeout_seconds: 5
|
||||||
insecure: true
|
insecure: true
|
||||||
|
|||||||
@@ -15,6 +15,12 @@ type PaymentIntent struct {
|
|||||||
Attributes map[string]string `json:"attributes,omitempty"`
|
Attributes map[string]string `json:"attributes,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AssetResolverStub struct{}
|
||||||
|
|
||||||
|
func (a *AssetResolverStub) IsSupported(_ string) bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func (p *PaymentIntent) Validate() error {
|
func (p *PaymentIntent) Validate() error {
|
||||||
// Kind must be set (non-zero)
|
// Kind must be set (non-zero)
|
||||||
var zeroKind PaymentKind
|
var zeroKind PaymentKind
|
||||||
@@ -33,7 +39,8 @@ func (p *PaymentIntent) Validate() error {
|
|||||||
if p.Amount == nil {
|
if p.Amount == nil {
|
||||||
return merrors.InvalidArgument("amount is required", "intent.amount")
|
return merrors.InvalidArgument("amount is required", "intent.amount")
|
||||||
}
|
}
|
||||||
if err := ValidateMoney(p.Amount); err != nil {
|
//TODO: collect supported currencies and validate against them
|
||||||
|
if err := ValidateMoney(p.Amount, &AssetResolverStub{}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,30 +1,76 @@
|
|||||||
package srequest
|
package srequest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/shopspring/decimal"
|
"github.com/shopspring/decimal"
|
||||||
"github.com/tech/sendico/pkg/merrors"
|
"github.com/tech/sendico/pkg/merrors"
|
||||||
"github.com/tech/sendico/pkg/model"
|
"github.com/tech/sendico/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ValidateMoney(m *model.Money) error {
|
// AssetResolver defines environment-specific supported assets.
|
||||||
if m.Amount == "" {
|
// Implementations should check:
|
||||||
|
// - fiat assets (ISO-4217)
|
||||||
|
// - crypto assets supported by gateways / FX providers
|
||||||
|
type AssetResolver interface {
|
||||||
|
IsSupported(ticker string) bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// Precompile regex for efficiency.
|
||||||
|
var currencySyntax = regexp.MustCompile(`^[A-Z0-9]{2,10}$`)
|
||||||
|
|
||||||
|
func ValidateMoney(m *model.Money, assetResolver AssetResolver) error {
|
||||||
|
if m == nil {
|
||||||
|
return merrors.InvalidArgument("money is required", "intent.amount")
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// 1) Basic presence
|
||||||
|
//
|
||||||
|
if strings.TrimSpace(m.Amount) == "" {
|
||||||
return merrors.InvalidArgument("amount is required", "intent.amount")
|
return merrors.InvalidArgument("amount is required", "intent.amount")
|
||||||
}
|
}
|
||||||
if m.Currency == "" {
|
if strings.TrimSpace(m.Currency) == "" {
|
||||||
return merrors.InvalidArgument("currency is required", "intent.currency")
|
return merrors.InvalidArgument("currency is required", "intent.currency")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := decimal.NewFromString(m.Amount); err != nil {
|
//
|
||||||
return merrors.InvalidArgument("invalid amount decimal", "intent.amount")
|
// 2) Validate decimal amount
|
||||||
|
//
|
||||||
|
amount, err := decimal.NewFromString(m.Amount)
|
||||||
|
if err != nil {
|
||||||
|
return merrors.InvalidArgument("invalid decimal amount", "intent.amount")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(m.Currency) != 3 {
|
if amount.IsNegative() {
|
||||||
return merrors.InvalidArgument("currency must be 3 letters", "intent.currency")
|
return merrors.InvalidArgument("amount must be >= 0", "intent.amount")
|
||||||
}
|
}
|
||||||
for _, c := range m.Currency {
|
|
||||||
if c < 'A' || c > 'Z' {
|
//
|
||||||
return merrors.InvalidArgument("currency must be uppercase A-Z", "intent.currency")
|
// 3) Normalize currency
|
||||||
}
|
//
|
||||||
|
cur := strings.ToUpper(strings.TrimSpace(m.Currency))
|
||||||
|
|
||||||
|
//
|
||||||
|
// 4) Syntax validation first — reject malformed tickers early
|
||||||
|
//
|
||||||
|
if !currencySyntax.MatchString(cur) {
|
||||||
|
return merrors.InvalidArgument(
|
||||||
|
"invalid currency format (must be A–Z0–9, length 2–10)",
|
||||||
|
"intent.currency",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// 5) Dictionary / environment validation
|
||||||
|
//
|
||||||
|
if assetResolver == nil {
|
||||||
|
return merrors.InvalidArgument("asset resolver is not configured", "intent.currency")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !assetResolver.IsSupported(cur) {
|
||||||
|
return merrors.InvalidArgument("unsupported currency/asset", "intent.currency")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ services:
|
|||||||
NATS_PASSWORD: ${NATS_PASSWORD}
|
NATS_PASSWORD: ${NATS_PASSWORD}
|
||||||
CHAIN_GATEWAY_ADDRESS: ${CHAIN_GATEWAY_SERVICE_NAME}:${CHAIN_GATEWAY_GRPC_PORT}
|
CHAIN_GATEWAY_ADDRESS: ${CHAIN_GATEWAY_SERVICE_NAME}:${CHAIN_GATEWAY_GRPC_PORT}
|
||||||
LEDGER_ADDRESS: ${LEDGER_SERVICE_NAME}:${LEDGER_GRPC_PORT}
|
LEDGER_ADDRESS: ${LEDGER_SERVICE_NAME}:${LEDGER_GRPC_PORT}
|
||||||
|
PAYMENTS_ADDRESS: ${PAYMENTS_SERVICE_NAME}:${PAYMENTS_GRPC_PORT}
|
||||||
MONGO_HOST: ${MONGO_HOST}
|
MONGO_HOST: ${MONGO_HOST}
|
||||||
MONGO_PORT: ${MONGO_PORT}
|
MONGO_PORT: ${MONGO_PORT}
|
||||||
MONGO_DATABASE: ${MONGO_DATABASE}
|
MONGO_DATABASE: ${MONGO_DATABASE}
|
||||||
|
|||||||
@@ -11,8 +11,6 @@ class CommonConstants {
|
|||||||
static String apiEndpoint = '/api/v1';
|
static String apiEndpoint = '/api/v1';
|
||||||
static String amplitudeSecret = 'c3d75b3e2520d708440acbb16b923e79';
|
static String amplitudeSecret = 'c3d75b3e2520d708440acbb16b923e79';
|
||||||
static String amplitudeServerZone = 'EU';
|
static String amplitudeServerZone = 'EU';
|
||||||
static String posthogApiKey = '';
|
|
||||||
static String posthogHost = 'https://eu.i.posthog.com';
|
|
||||||
static Locale defaultLocale = const Locale('en');
|
static Locale defaultLocale = const Locale('en');
|
||||||
static String defaultCurrency = 'EUR';
|
static String defaultCurrency = 'EUR';
|
||||||
static int defaultDimensionLength = 500;
|
static int defaultDimensionLength = 500;
|
||||||
@@ -38,8 +36,6 @@ class CommonConstants {
|
|||||||
apiEndpoint = configJson['apiEndpoint'] ?? apiEndpoint;
|
apiEndpoint = configJson['apiEndpoint'] ?? apiEndpoint;
|
||||||
amplitudeSecret = configJson['amplitudeSecret'] ?? amplitudeSecret;
|
amplitudeSecret = configJson['amplitudeSecret'] ?? amplitudeSecret;
|
||||||
amplitudeServerZone = configJson['amplitudeServerZone'] ?? amplitudeServerZone;
|
amplitudeServerZone = configJson['amplitudeServerZone'] ?? amplitudeServerZone;
|
||||||
posthogApiKey = configJson['posthogApiKey'] ?? posthogApiKey;
|
|
||||||
posthogHost = configJson['posthogHost'] ?? posthogHost;
|
|
||||||
defaultLocale = Locale(configJson['defaultLocale'] ?? defaultLocale.languageCode);
|
defaultLocale = Locale(configJson['defaultLocale'] ?? defaultLocale.languageCode);
|
||||||
defaultCurrency = configJson['defaultCurrency'] ?? defaultCurrency;
|
defaultCurrency = configJson['defaultCurrency'] ?? defaultCurrency;
|
||||||
wsProto = configJson['wsProto'] ?? wsProto;
|
wsProto = configJson['wsProto'] ?? wsProto;
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ class Constants extends CommonConstants {
|
|||||||
static String get currentOrgKey => CommonConstants.currentOrgKey;
|
static String get currentOrgKey => CommonConstants.currentOrgKey;
|
||||||
static String get apiUrl => CommonConstants.apiUrl;
|
static String get apiUrl => CommonConstants.apiUrl;
|
||||||
static String get serviceUrl => CommonConstants.serviceUrl;
|
static String get serviceUrl => CommonConstants.serviceUrl;
|
||||||
static String get posthogApiKey => CommonConstants.posthogApiKey;
|
|
||||||
static String get posthogHost => CommonConstants.posthogHost;
|
|
||||||
static int get defaultDimensionLength => CommonConstants.defaultDimensionLength;
|
static int get defaultDimensionLength => CommonConstants.defaultDimensionLength;
|
||||||
static String get deviceIdStorageKey => CommonConstants.deviceIdStorageKey;
|
static String get deviceIdStorageKey => CommonConstants.deviceIdStorageKey;
|
||||||
static String get nilObjectRef => CommonConstants.nilObjectRef;
|
static String get nilObjectRef => CommonConstants.nilObjectRef;
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ extension AppConfigExtension on AppConfig {
|
|||||||
external String? get apiEndpoint;
|
external String? get apiEndpoint;
|
||||||
external String? get amplitudeSecret;
|
external String? get amplitudeSecret;
|
||||||
external String? get amplitudeServerZone;
|
external String? get amplitudeServerZone;
|
||||||
external String? get posthogApiKey;
|
|
||||||
external String? get posthogHost;
|
|
||||||
external String? get defaultLocale;
|
external String? get defaultLocale;
|
||||||
external String? get wsProto;
|
external String? get wsProto;
|
||||||
external String? get wsEndpoint;
|
external String? get wsEndpoint;
|
||||||
@@ -42,8 +40,6 @@ class Constants extends CommonConstants {
|
|||||||
static String get currentOrgKey => CommonConstants.currentOrgKey;
|
static String get currentOrgKey => CommonConstants.currentOrgKey;
|
||||||
static String get apiUrl => CommonConstants.apiUrl;
|
static String get apiUrl => CommonConstants.apiUrl;
|
||||||
static String get serviceUrl => CommonConstants.serviceUrl;
|
static String get serviceUrl => CommonConstants.serviceUrl;
|
||||||
static String get posthogApiKey => CommonConstants.posthogApiKey;
|
|
||||||
static String get posthogHost => CommonConstants.posthogHost;
|
|
||||||
static int get defaultDimensionLength => CommonConstants.defaultDimensionLength;
|
static int get defaultDimensionLength => CommonConstants.defaultDimensionLength;
|
||||||
static String get deviceIdStorageKey => CommonConstants.deviceIdStorageKey;
|
static String get deviceIdStorageKey => CommonConstants.deviceIdStorageKey;
|
||||||
static String get nilObjectRef => CommonConstants.nilObjectRef;
|
static String get nilObjectRef => CommonConstants.nilObjectRef;
|
||||||
@@ -61,8 +57,6 @@ class Constants extends CommonConstants {
|
|||||||
'apiEndpoint': config.apiEndpoint,
|
'apiEndpoint': config.apiEndpoint,
|
||||||
'amplitudeSecret': config.amplitudeSecret,
|
'amplitudeSecret': config.amplitudeSecret,
|
||||||
'amplitudeServerZone': config.amplitudeServerZone,
|
'amplitudeServerZone': config.amplitudeServerZone,
|
||||||
'posthogApiKey': config.posthogApiKey,
|
|
||||||
'posthogHost': config.posthogHost,
|
|
||||||
'defaultLocale': config.defaultLocale,
|
'defaultLocale': config.defaultLocale,
|
||||||
'wsProto': config.wsProto,
|
'wsProto': config.wsProto,
|
||||||
'wsEndpoint': config.wsEndpoint,
|
'wsEndpoint': config.wsEndpoint,
|
||||||
|
|||||||
@@ -79,13 +79,12 @@ enum ResourceType {
|
|||||||
@JsonValue('payments')
|
@JsonValue('payments')
|
||||||
payments,
|
payments,
|
||||||
|
|
||||||
/// Represents payment orchestration service
|
|
||||||
@JsonValue('payment_orchestrator')
|
|
||||||
paymentOrchestrator,
|
|
||||||
|
|
||||||
@JsonValue('payment_methods')
|
@JsonValue('payment_methods')
|
||||||
paymentMethods,
|
paymentMethods,
|
||||||
|
|
||||||
|
@JsonValue('payment_orchestrator')
|
||||||
|
paymentOrchestrator,
|
||||||
|
|
||||||
/// Represents permissions service
|
/// Represents permissions service
|
||||||
@JsonValue('permissions')
|
@JsonValue('permissions')
|
||||||
permissions,
|
permissions,
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import 'dart:async';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:share_plus/share_plus.dart';
|
import 'package:share_plus/share_plus.dart';
|
||||||
@@ -22,9 +20,6 @@ import 'package:pshared/utils/exception.dart';
|
|||||||
|
|
||||||
|
|
||||||
class AccountProvider extends ChangeNotifier {
|
class AccountProvider extends ChangeNotifier {
|
||||||
AccountProvider({Future<void> Function(Account?)? onAccountChanged})
|
|
||||||
: _onAccountChanged = onAccountChanged;
|
|
||||||
|
|
||||||
static String get currentUserRef => Constants.nilObjectRef;
|
static String get currentUserRef => Constants.nilObjectRef;
|
||||||
|
|
||||||
// The resource now wraps our Account? state along with its loading/error state.
|
// The resource now wraps our Account? state along with its loading/error state.
|
||||||
@@ -32,8 +27,6 @@ class AccountProvider extends ChangeNotifier {
|
|||||||
Resource<Account?> get resource => _resource;
|
Resource<Account?> get resource => _resource;
|
||||||
late LocaleProvider _localeProvider;
|
late LocaleProvider _localeProvider;
|
||||||
PendingLogin? _pendingLogin;
|
PendingLogin? _pendingLogin;
|
||||||
Future<void>? _restoreFuture;
|
|
||||||
Future<void> Function(Account?)? _onAccountChanged;
|
|
||||||
|
|
||||||
Account? get account => _resource.data;
|
Account? get account => _resource.data;
|
||||||
PendingLogin? get pendingLogin => _pendingLogin;
|
PendingLogin? get pendingLogin => _pendingLogin;
|
||||||
@@ -60,21 +53,11 @@ class AccountProvider extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Private helper to update the resource and notify listeners.
|
// Private helper to update the resource and notify listeners.
|
||||||
void setAccountChangedListener(Future<void> Function(Account?)? listener) => _onAccountChanged = listener;
|
|
||||||
|
|
||||||
void _setResource(Resource<Account?> newResource) {
|
void _setResource(Resource<Account?> newResource) {
|
||||||
final previousAccount = _resource.data;
|
|
||||||
_resource = newResource;
|
_resource = newResource;
|
||||||
_notifyAccountChanged(previousAccount, newResource.data);
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _notifyAccountChanged(Account? previous, Account? current) {
|
|
||||||
if (previous == current) return;
|
|
||||||
final handler = _onAccountChanged;
|
|
||||||
if (handler != null) unawaited(handler(current));
|
|
||||||
}
|
|
||||||
|
|
||||||
void updateProvider(LocaleProvider localeProvider) => _localeProvider = localeProvider;
|
void updateProvider(LocaleProvider localeProvider) => _localeProvider = localeProvider;
|
||||||
|
|
||||||
void _pickupLocale(String locale) => _localeProvider.setLocale(Locale(locale));
|
void _pickupLocale(String locale) => _localeProvider.setLocale(Locale(locale));
|
||||||
@@ -237,11 +220,4 @@ class AccountProvider extends ChangeNotifier {
|
|||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> restoreIfPossible() {
|
|
||||||
return _restoreFuture ??= AuthorizationService.isAuthorizationStored().then<void>((hasAuth) async {
|
|
||||||
if (!hasAuth) return;
|
|
||||||
await restore();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ class PermissionsProvider extends ChangeNotifier {
|
|||||||
Resource<UserAccess> _userAccess = Resource(data: null, isLoading: false, error: null);
|
Resource<UserAccess> _userAccess = Resource(data: null, isLoading: false, error: null);
|
||||||
late OrganizationsProvider _organizations;
|
late OrganizationsProvider _organizations;
|
||||||
bool _isLoaded = false;
|
bool _isLoaded = false;
|
||||||
bool _errorHandled = false;
|
|
||||||
|
|
||||||
void update(OrganizationsProvider venue) {
|
void update(OrganizationsProvider venue) {
|
||||||
_organizations = venue;
|
_organizations = venue;
|
||||||
@@ -45,7 +44,6 @@ class PermissionsProvider extends ChangeNotifier {
|
|||||||
/// Load the [UserAccess] for the current venue.
|
/// Load the [UserAccess] for the current venue.
|
||||||
Future<UserAccess?> load() async {
|
Future<UserAccess?> load() async {
|
||||||
_userAccess = _userAccess.copyWith(isLoading: true, error: null);
|
_userAccess = _userAccess.copyWith(isLoading: true, error: null);
|
||||||
_errorHandled = false;
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -69,12 +67,6 @@ class PermissionsProvider extends ChangeNotifier {
|
|||||||
return _userAccess.data;
|
return _userAccess.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get hasUnhandledError => error != null && !_errorHandled;
|
|
||||||
|
|
||||||
void markErrorHandled() {
|
|
||||||
_errorHandled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<UserAccess?> changeRole(String accountRef, String newRoleDescRef) async {
|
Future<UserAccess?> changeRole(String accountRef, String newRoleDescRef) async {
|
||||||
final currentRole = roles.firstWhereOrNull((r) => r.accountRef == accountRef);
|
final currentRole = roles.firstWhereOrNull((r) => r.accountRef == accountRef);
|
||||||
final currentDesc = currentRole != null
|
final currentDesc = currentRole != null
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import 'package:pweb/providers/wallets.dart';
|
|||||||
import 'package:pweb/providers/wallet_transactions.dart';
|
import 'package:pweb/providers/wallet_transactions.dart';
|
||||||
import 'package:pweb/services/operations.dart';
|
import 'package:pweb/services/operations.dart';
|
||||||
import 'package:pweb/services/payments/history.dart';
|
import 'package:pweb/services/payments/history.dart';
|
||||||
import 'package:pweb/services/posthog.dart';
|
|
||||||
import 'package:pweb/services/wallet_transactions.dart';
|
import 'package:pweb/services/wallet_transactions.dart';
|
||||||
import 'package:pweb/services/wallets.dart';
|
import 'package:pweb/services/wallets.dart';
|
||||||
|
|
||||||
@@ -41,9 +40,11 @@ void _setupLogging() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
await Constants.initialize();
|
await Constants.initialize();
|
||||||
await PosthogService.initialize();
|
|
||||||
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
|
// await AmplitudeService.initialize();
|
||||||
|
|
||||||
|
|
||||||
_setupLogging();
|
_setupLogging();
|
||||||
@@ -56,12 +57,7 @@ void main() async {
|
|||||||
providers: [
|
providers: [
|
||||||
ChangeNotifierProvider(create: (_) => LocaleProvider(null)),
|
ChangeNotifierProvider(create: (_) => LocaleProvider(null)),
|
||||||
ChangeNotifierProxyProvider<LocaleProvider, AccountProvider>(
|
ChangeNotifierProxyProvider<LocaleProvider, AccountProvider>(
|
||||||
create: (_) => AccountProvider(
|
create: (_) => AccountProvider(),
|
||||||
onAccountChanged: (account) {
|
|
||||||
if (account == null) return Future<void>.value();
|
|
||||||
return PosthogService.identify(account);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
update: (context, localeProvider, provider) => provider!..updateProvider(localeProvider),
|
update: (context, localeProvider, provider) => provider!..updateProvider(localeProvider),
|
||||||
),
|
),
|
||||||
ChangeNotifierProxyProvider<AccountProvider, TwoFactorProvider>(
|
ChangeNotifierProxyProvider<AccountProvider, TwoFactorProvider>(
|
||||||
@@ -74,7 +70,6 @@ void main() async {
|
|||||||
update: (context, orgnization, provider) => provider!..update(orgnization),
|
update: (context, orgnization, provider) => provider!..update(orgnization),
|
||||||
),
|
),
|
||||||
ChangeNotifierProvider(create: (_) => CarouselIndexProvider()),
|
ChangeNotifierProvider(create: (_) => CarouselIndexProvider()),
|
||||||
|
|
||||||
ChangeNotifierProvider(
|
ChangeNotifierProvider(
|
||||||
create: (_) => UploadHistoryProvider(service: MockUploadHistoryService())..load(),
|
create: (_) => UploadHistoryProvider(service: MockUploadHistoryService())..load(),
|
||||||
),
|
),
|
||||||
@@ -96,7 +91,6 @@ void main() async {
|
|||||||
ChangeNotifierProvider(
|
ChangeNotifierProvider(
|
||||||
create: (_) => MockPaymentProvider(),
|
create: (_) => MockPaymentProvider(),
|
||||||
),
|
),
|
||||||
|
|
||||||
ChangeNotifierProvider(
|
ChangeNotifierProvider(
|
||||||
create: (_) => OperationProvider(OperationService())..loadOperations(),
|
create: (_) => OperationProvider(OperationService())..loadOperations(),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import 'dart:async';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
@@ -16,7 +14,6 @@ import 'package:pshared/provider/recipient/pmethods.dart';
|
|||||||
import 'package:pshared/provider/recipient/provider.dart';
|
import 'package:pshared/provider/recipient/provider.dart';
|
||||||
|
|
||||||
import 'package:pweb/pages/address_book/form/view.dart';
|
import 'package:pweb/pages/address_book/form/view.dart';
|
||||||
import 'package:pweb/services/posthog.dart';
|
|
||||||
import 'package:pweb/utils/error/snackbar.dart';
|
import 'package:pweb/utils/error/snackbar.dart';
|
||||||
import 'package:pweb/utils/payment/label.dart';
|
import 'package:pweb/utils/payment/label.dart';
|
||||||
import 'package:pweb/utils/snackbar.dart';
|
import 'package:pweb/utils/snackbar.dart';
|
||||||
@@ -109,11 +106,11 @@ class _AdressBookRecipientFormState extends State<AdressBookRecipientForm> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
unawaited(PosthogService.recipientAddCompleted(
|
// AmplitudeService.recipientAddCompleted(
|
||||||
_type,
|
// _type,
|
||||||
_status,
|
// _status,
|
||||||
_methods.keys.toSet(),
|
// _methods.keys.toSet(),
|
||||||
));
|
// );
|
||||||
final recipient = await executeActionWithNotification(
|
final recipient = await executeActionWithNotification(
|
||||||
context: context,
|
context: context,
|
||||||
action: _doSave,
|
action: _doSave,
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:logging/logging.dart';
|
|
||||||
|
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
@@ -11,50 +10,26 @@ import 'package:pweb/widgets/error/snackbar.dart';
|
|||||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||||
|
|
||||||
|
|
||||||
class AccountLoader extends StatefulWidget {
|
class AccountLoader extends StatelessWidget {
|
||||||
final Widget child;
|
final Widget child;
|
||||||
|
|
||||||
const AccountLoader({super.key, required this.child});
|
const AccountLoader({super.key, required this.child});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<AccountLoader> createState() => _AccountLoaderState();
|
Widget build(BuildContext context) => Consumer<AccountProvider>(builder: (context, provider, _) {
|
||||||
}
|
if (provider.isLoading) return const Center(child: CircularProgressIndicator());
|
||||||
|
if (provider.error != null) {
|
||||||
class _AccountLoaderState extends State<AccountLoader> {
|
postNotifyUserOfErrorX(
|
||||||
@override
|
context: context,
|
||||||
void initState() {
|
errorSituation: AppLocalizations.of(context)!.errorLogin,
|
||||||
super.initState();
|
exception: provider.error!,
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
);
|
||||||
final provider = Provider.of<AccountProvider>(context, listen: false);
|
navigateAndReplace(context, Pages.login);
|
||||||
if (provider.account == null) {
|
}
|
||||||
provider.restoreIfPossible().catchError((error, stack) {
|
if (provider.account == null) {
|
||||||
Logger('Account restore failed: $error');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Consumer<AccountProvider>(builder: (context, provider, _) {
|
|
||||||
if (provider.account != null) {
|
|
||||||
return widget.child;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (provider.error != null) {
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
||||||
postNotifyUserOfErrorX(
|
|
||||||
context: context,
|
|
||||||
errorSituation: AppLocalizations.of(context)!.errorLogin,
|
|
||||||
exception: provider.error!,
|
|
||||||
);
|
|
||||||
navigateAndReplace(context, Pages.login);
|
|
||||||
});
|
|
||||||
return const Center(child: CircularProgressIndicator());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (provider.isLoading) return const Center(child: CircularProgressIndicator());
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) => navigateAndReplace(context, Pages.login));
|
WidgetsBinding.instance.addPostFrameCallback((_) => navigateAndReplace(context, Pages.login));
|
||||||
return const Center(child: CircularProgressIndicator());
|
return const Center(child: CircularProgressIndicator());
|
||||||
});
|
}
|
||||||
}
|
return child;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,29 +21,20 @@ class PermissionsLoader extends StatelessWidget {
|
|||||||
if (provider.isLoading) {
|
if (provider.isLoading) {
|
||||||
return const Center(child: CircularProgressIndicator());
|
return const Center(child: CircularProgressIndicator());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (provider.error != null) {
|
if (provider.error != null) {
|
||||||
if (provider.hasUnhandledError) {
|
postNotifyUserOfErrorX(
|
||||||
provider.markErrorHandled();
|
context: context,
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
errorSituation: AppLocalizations.of(context)!.errorLogin,
|
||||||
postNotifyUserOfErrorX(
|
exception: provider.error!,
|
||||||
context: context,
|
);
|
||||||
errorSituation: AppLocalizations.of(context)!.errorLogin,
|
navigateAndReplace(context, Pages.login);
|
||||||
exception: provider.error!,
|
|
||||||
);
|
|
||||||
navigateAndReplace(context, Pages.login);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return const Center(child: CircularProgressIndicator());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (provider.error == null && !provider.isReady && accountProvider.account != null) {
|
if (provider.error == null && !provider.isReady && accountProvider.account != null) {
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
provider.load();
|
provider.load();
|
||||||
});
|
});
|
||||||
return const Center(child: CircularProgressIndicator());
|
return const Center(child: CircularProgressIndicator());
|
||||||
}
|
}
|
||||||
|
|
||||||
return child;
|
return child;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import 'dart:async';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
@@ -16,7 +14,6 @@ import 'package:pweb/widgets/password/password.dart';
|
|||||||
import 'package:pweb/widgets/username.dart';
|
import 'package:pweb/widgets/username.dart';
|
||||||
import 'package:pweb/widgets/vspacer.dart';
|
import 'package:pweb/widgets/vspacer.dart';
|
||||||
import 'package:pweb/widgets/error/snackbar.dart';
|
import 'package:pweb/widgets/error/snackbar.dart';
|
||||||
import 'package:pweb/services/posthog.dart';
|
|
||||||
|
|
||||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||||
|
|
||||||
@@ -46,7 +43,6 @@ class _LoginFormState extends State<LoginForm> {
|
|||||||
password: _passwordController.text,
|
password: _passwordController.text,
|
||||||
locale: context.read<LocaleProvider>().locale.languageCode,
|
locale: context.read<LocaleProvider>().locale.languageCode,
|
||||||
);
|
);
|
||||||
unawaited(PosthogService.login(pending: outcome.isPending));
|
|
||||||
if (outcome.isPending) {
|
if (outcome.isPending) {
|
||||||
// TODO: fix context usage
|
// TODO: fix context usage
|
||||||
navigateAndReplace(context, Pages.sfactor);
|
navigateAndReplace(context, Pages.sfactor);
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import 'package:pweb/providers/payment_flow.dart';
|
|||||||
import 'package:pweb/pages/payment_methods/payment_page/body.dart';
|
import 'package:pweb/pages/payment_methods/payment_page/body.dart';
|
||||||
import 'package:pweb/providers/wallets.dart';
|
import 'package:pweb/providers/wallets.dart';
|
||||||
import 'package:pweb/widgets/sidebar/destinations.dart';
|
import 'package:pweb/widgets/sidebar/destinations.dart';
|
||||||
import 'package:pweb/services/posthog.dart';
|
|
||||||
|
|
||||||
|
|
||||||
class PaymentPage extends StatefulWidget {
|
class PaymentPage extends StatefulWidget {
|
||||||
@@ -110,7 +109,7 @@ class _PaymentPageState extends State<PaymentPage> {
|
|||||||
|
|
||||||
void _handleSendPayment() {
|
void _handleSendPayment() {
|
||||||
// TODO: Handle Payment logic
|
// TODO: Handle Payment logic
|
||||||
PosthogService.paymentInitiated(method: _flowProvider.selectedType);
|
// AmplitudeService.paymentInitiated();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -196,4 +195,4 @@ class _PaymentPageState extends State<PaymentPage> {
|
|||||||
(method.description?.contains(wallet.walletUserID) ?? false),
|
(method.description?.contains(wallet.walletUserID) ?? false),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@ import 'package:provider/provider.dart';
|
|||||||
|
|
||||||
import 'package:pshared/provider/locale.dart';
|
import 'package:pshared/provider/locale.dart';
|
||||||
|
|
||||||
import 'package:pweb/services/posthog.dart';
|
// import 'package:pweb/services/amplitude.dart';
|
||||||
|
|
||||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ class LocalePicker extends StatelessWidget {
|
|||||||
onChanged: (locale) {
|
onChanged: (locale) {
|
||||||
if (locale != null) {
|
if (locale != null) {
|
||||||
localeProvider.setLocale(locale);
|
localeProvider.setLocale(locale);
|
||||||
PosthogService.localeChanged(locale);
|
// AmplitudeService.localeChanged(locale);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
|
|||||||
@@ -1,136 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'package:logging/logging.dart';
|
|
||||||
|
|
||||||
import 'package:posthog_flutter/posthog_flutter.dart';
|
|
||||||
|
|
||||||
import 'package:pshared/config/constants.dart';
|
|
||||||
import 'package:pshared/models/account/account.dart';
|
|
||||||
import 'package:pshared/models/payment/type.dart';
|
|
||||||
import 'package:pshared/models/recipient/status.dart';
|
|
||||||
import 'package:pshared/models/recipient/type.dart';
|
|
||||||
|
|
||||||
import 'package:pweb/widgets/sidebar/destinations.dart';
|
|
||||||
|
|
||||||
|
|
||||||
class PosthogService {
|
|
||||||
static final _logger = Logger('service.posthog');
|
|
||||||
static String? _identifiedUserId;
|
|
||||||
static bool _initialized = false;
|
|
||||||
|
|
||||||
static bool get isEnabled => _initialized;
|
|
||||||
|
|
||||||
static Future<void> initialize() async {
|
|
||||||
final apiKey = Constants.posthogApiKey;
|
|
||||||
if (apiKey.isEmpty) {
|
|
||||||
_logger.warning('PostHog API key is not configured, analytics disabled.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
final config = PostHogConfig(apiKey)
|
|
||||||
..host = Constants.posthogHost
|
|
||||||
..captureApplicationLifecycleEvents = true;
|
|
||||||
await Posthog().setup(config);
|
|
||||||
await Posthog().register('client_id', Constants.clientId);
|
|
||||||
_initialized = true;
|
|
||||||
_logger.info('PostHog initialized with host ${Constants.posthogHost}');
|
|
||||||
} catch (e, st) {
|
|
||||||
_initialized = false;
|
|
||||||
_logger.warning('Failed to initialize PostHog: $e', e, st);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static Future<void> identify(Account account) async {
|
|
||||||
if (!_initialized) return;
|
|
||||||
if (_identifiedUserId == account.id) return;
|
|
||||||
|
|
||||||
await Posthog().identify(
|
|
||||||
userId: account.id,
|
|
||||||
userProperties: {
|
|
||||||
'email': account.login,
|
|
||||||
'name': account.name,
|
|
||||||
'locale': account.locale,
|
|
||||||
'created_at': account.createdAt.toIso8601String(),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
_identifiedUserId = account.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Future<void> reset() async {
|
|
||||||
if (!_initialized) return;
|
|
||||||
_identifiedUserId = null;
|
|
||||||
await Posthog().reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
static Future<void> login({required bool pending}) async {
|
|
||||||
if (!_initialized) return;
|
|
||||||
await _capture(
|
|
||||||
'login',
|
|
||||||
properties: {
|
|
||||||
'result': pending ? 'pending' : 'success',
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Future<void> pageOpened(PayoutDestination page, {String? path, String? uiSource}) async {
|
|
||||||
if (!_initialized) return;
|
|
||||||
return _capture(
|
|
||||||
'pageOpened',
|
|
||||||
properties: {
|
|
||||||
'page': page.name,
|
|
||||||
if (path != null) 'path': path,
|
|
||||||
if (uiSource != null) 'uiSource': uiSource,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Future<void> localeChanged(Locale locale) async {
|
|
||||||
if (!_initialized) return;
|
|
||||||
return _capture(
|
|
||||||
'localeChanged',
|
|
||||||
properties: {'locale': locale.toLanguageTag()},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Future<void> recipientAddCompleted(
|
|
||||||
RecipientType type,
|
|
||||||
RecipientStatus status,
|
|
||||||
Set<PaymentType> methods,
|
|
||||||
) async {
|
|
||||||
if (!_initialized) return;
|
|
||||||
return _capture(
|
|
||||||
'recipientAddCompleted',
|
|
||||||
properties: {
|
|
||||||
'methods': methods.map((m) => m.name).toList(),
|
|
||||||
'type': type.name,
|
|
||||||
'status': status.name,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Future<void> paymentInitiated({PaymentType? method}) async {
|
|
||||||
if (!_initialized) return;
|
|
||||||
return _capture(
|
|
||||||
'paymentInitiated',
|
|
||||||
properties: {
|
|
||||||
if (method != null) 'method': method.name,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Future<void> _capture(
|
|
||||||
String eventName, {
|
|
||||||
Map<String, Object?>? properties,
|
|
||||||
}) async {
|
|
||||||
if (!_initialized) return;
|
|
||||||
final filtered = <String, Object>{};
|
|
||||||
if (properties != null) {
|
|
||||||
for (final entry in properties.entries) {
|
|
||||||
final value = entry.value;
|
|
||||||
if (value != null) filtered[entry.key] = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await Posthog().capture(eventName: eventName, properties: filtered.isEmpty ? null : filtered);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,12 +6,10 @@ import 'package:pshared/provider/account.dart';
|
|||||||
import 'package:pshared/provider/permissions.dart';
|
import 'package:pshared/provider/permissions.dart';
|
||||||
|
|
||||||
import 'package:pweb/app/router/pages.dart';
|
import 'package:pweb/app/router/pages.dart';
|
||||||
import 'package:pweb/services/posthog.dart';
|
|
||||||
|
|
||||||
|
|
||||||
void logoutUtil(BuildContext context) {
|
void logoutUtil(BuildContext context) {
|
||||||
context.read<AccountProvider>().logout();
|
context.read<AccountProvider>().logout();
|
||||||
context.read<PermissionsProvider>().reset();
|
context.read<PermissionsProvider>().reset();
|
||||||
PosthogService.reset();
|
|
||||||
navigateAndReplace(context, Pages.login);
|
navigateAndReplace(context, Pages.login);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:pweb/services/posthog.dart';
|
// import 'package:pweb/services/amplitude.dart';
|
||||||
import 'package:pweb/widgets/sidebar/destinations.dart';
|
import 'package:pweb/widgets/sidebar/destinations.dart';
|
||||||
|
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ class SideMenuColumn extends StatelessWidget {
|
|||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
onSelected(item);
|
onSelected(item);
|
||||||
PosthogService.pageOpened(item, uiSource: 'sidebar');
|
// AmplitudeService.pageOpened(item, uiSource: 'sidebar');
|
||||||
},
|
},
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
hoverColor: theme.colorScheme.primaryContainer,
|
hoverColor: theme.colorScheme.primaryContainer,
|
||||||
@@ -76,4 +76,4 @@ class SideMenuColumn extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,6 @@ import amplitude_flutter
|
|||||||
import file_selector_macos
|
import file_selector_macos
|
||||||
import flutter_timezone
|
import flutter_timezone
|
||||||
import path_provider_foundation
|
import path_provider_foundation
|
||||||
import posthog_flutter
|
|
||||||
import share_plus
|
import share_plus
|
||||||
import shared_preferences_foundation
|
import shared_preferences_foundation
|
||||||
import sqflite_darwin
|
import sqflite_darwin
|
||||||
@@ -20,7 +19,6 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
|||||||
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
|
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
|
||||||
FlutterTimezonePlugin.register(with: registry.registrar(forPlugin: "FlutterTimezonePlugin"))
|
FlutterTimezonePlugin.register(with: registry.registrar(forPlugin: "FlutterTimezonePlugin"))
|
||||||
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
|
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
|
||||||
PosthogFlutterPlugin.register(with: registry.registrar(forPlugin: "PosthogFlutterPlugin"))
|
|
||||||
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
|
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
|
||||||
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
|
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
|
||||||
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
|
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ dependencies:
|
|||||||
sdk: flutter
|
sdk: flutter
|
||||||
pshared:
|
pshared:
|
||||||
path: ../pshared
|
path: ../pshared
|
||||||
posthog_flutter: ^5.9.0
|
|
||||||
|
|
||||||
# The following adds the Cupertino Icons font to your application.
|
# The following adds the Cupertino Icons font to your application.
|
||||||
# Use with the CupertinoIcons class for iOS style icons.
|
# Use with the CupertinoIcons class for iOS style icons.
|
||||||
|
|||||||
Reference in New Issue
Block a user