Compare commits
2 Commits
SEND010
...
41abf723e6
| Author | SHA1 | Date | |
|---|---|---|---|
| 41abf723e6 | |||
|
|
2d6586430f |
@@ -5,9 +5,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tech/sendico/payments/orchestrator/storage/model"
|
"github.com/tech/sendico/payments/orchestrator/storage/model"
|
||||||
"github.com/tech/sendico/pkg/merrors"
|
|
||||||
fxv1 "github.com/tech/sendico/pkg/proto/common/fx/v1"
|
fxv1 "github.com/tech/sendico/pkg/proto/common/fx/v1"
|
||||||
paginationv1 "github.com/tech/sendico/pkg/proto/common/pagination/v1"
|
|
||||||
chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"
|
chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"
|
||||||
oraclev1 "github.com/tech/sendico/pkg/proto/oracle/v1"
|
oraclev1 "github.com/tech/sendico/pkg/proto/oracle/v1"
|
||||||
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
|
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
|
||||||
@@ -413,74 +411,3 @@ func cloneNetworkEstimate(resp *chainv1.EstimateTransferFeeResponse) *chainv1.Es
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func protoFailureToModel(code orchestratorv1.PaymentFailureCode) model.PaymentFailureCode {
|
|
||||||
switch code {
|
|
||||||
case orchestratorv1.PaymentFailureCode_PAYMENT_FAILURE_CODE_BALANCE:
|
|
||||||
return model.PaymentFailureCodeBalance
|
|
||||||
case orchestratorv1.PaymentFailureCode_PAYMENT_FAILURE_CODE_LEDGER:
|
|
||||||
return model.PaymentFailureCodeLedger
|
|
||||||
case orchestratorv1.PaymentFailureCode_PAYMENT_FAILURE_CODE_FX:
|
|
||||||
return model.PaymentFailureCodeFX
|
|
||||||
case orchestratorv1.PaymentFailureCode_PAYMENT_FAILURE_CODE_CHAIN:
|
|
||||||
return model.PaymentFailureCodeChain
|
|
||||||
case orchestratorv1.PaymentFailureCode_PAYMENT_FAILURE_CODE_FEES:
|
|
||||||
return model.PaymentFailureCodeFees
|
|
||||||
case orchestratorv1.PaymentFailureCode_PAYMENT_FAILURE_CODE_POLICY:
|
|
||||||
return model.PaymentFailureCodePolicy
|
|
||||||
default:
|
|
||||||
return model.PaymentFailureCodeUnspecified
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func applyProtoPaymentToModel(src *orchestratorv1.Payment, dst *model.Payment) error {
|
|
||||||
if src == nil || dst == nil {
|
|
||||||
return merrors.InvalidArgument("payment payload is required")
|
|
||||||
}
|
|
||||||
dst.PaymentRef = strings.TrimSpace(src.GetPaymentRef())
|
|
||||||
dst.IdempotencyKey = strings.TrimSpace(src.GetIdempotencyKey())
|
|
||||||
dst.Intent = intentFromProto(src.GetIntent())
|
|
||||||
dst.State = modelStateFromProto(src.GetState())
|
|
||||||
dst.FailureCode = protoFailureToModel(src.GetFailureCode())
|
|
||||||
dst.FailureReason = strings.TrimSpace(src.GetFailureReason())
|
|
||||||
dst.Metadata = cloneMetadata(src.GetMetadata())
|
|
||||||
dst.LastQuote = quoteSnapshotToModel(src.GetLastQuote())
|
|
||||||
dst.Execution = executionFromProto(src.GetExecution())
|
|
||||||
if src.GetCardPayout() != nil {
|
|
||||||
dst.CardPayout = &model.CardPayout{
|
|
||||||
PayoutRef: strings.TrimSpace(src.GetCardPayout().GetPayoutRef()),
|
|
||||||
ProviderPaymentID: strings.TrimSpace(src.GetCardPayout().GetProviderPaymentId()),
|
|
||||||
Status: strings.TrimSpace(src.GetCardPayout().GetStatus()),
|
|
||||||
FailureReason: strings.TrimSpace(src.GetCardPayout().GetFailureReason()),
|
|
||||||
CardCountry: strings.TrimSpace(src.GetCardPayout().GetCardCountry()),
|
|
||||||
MaskedPan: strings.TrimSpace(src.GetCardPayout().GetMaskedPan()),
|
|
||||||
ProviderCode: strings.TrimSpace(src.GetCardPayout().GetProviderCode()),
|
|
||||||
GatewayReference: strings.TrimSpace(src.GetCardPayout().GetGatewayReference()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func executionFromProto(src *orchestratorv1.ExecutionRefs) *model.ExecutionRefs {
|
|
||||||
if src == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return &model.ExecutionRefs{
|
|
||||||
DebitEntryRef: strings.TrimSpace(src.GetDebitEntryRef()),
|
|
||||||
CreditEntryRef: strings.TrimSpace(src.GetCreditEntryRef()),
|
|
||||||
FXEntryRef: strings.TrimSpace(src.GetFxEntryRef()),
|
|
||||||
ChainTransferRef: strings.TrimSpace(src.GetChainTransferRef()),
|
|
||||||
CardPayoutRef: strings.TrimSpace(src.GetCardPayoutRef()),
|
|
||||||
FeeTransferRef: strings.TrimSpace(src.GetFeeTransferRef()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func ensurePageRequest(req *orchestratorv1.ListPaymentsRequest) *paginationv1.CursorPageRequest {
|
|
||||||
if req == nil {
|
|
||||||
return &paginationv1.CursorPageRequest{}
|
|
||||||
}
|
|
||||||
if req.GetPage() == nil {
|
|
||||||
return &paginationv1.CursorPageRequest{}
|
|
||||||
}
|
|
||||||
return req.GetPage()
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -214,20 +214,6 @@ func decimalFromMoney(m *moneyv1.Money) (decimal.Decimal, error) {
|
|||||||
return decimal.NewFromString(m.GetAmount())
|
return decimal.NewFromString(m.GetAmount())
|
||||||
}
|
}
|
||||||
|
|
||||||
func decimalFromMoneyMatching(reference, candidate *moneyv1.Money) (*decimal.Decimal, error) {
|
|
||||||
if reference == nil || candidate == nil {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
if !strings.EqualFold(reference.GetCurrency(), candidate.GetCurrency()) {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
value, err := decimal.NewFromString(candidate.GetAmount())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &value, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func makeMoney(currency string, value decimal.Decimal) *moneyv1.Money {
|
func makeMoney(currency string, value decimal.Decimal) *moneyv1.Money {
|
||||||
return &moneyv1.Money{
|
return &moneyv1.Money{
|
||||||
Currency: currency,
|
Currency: currency,
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ func TestMinQuoteExpiry(t *testing.T) {
|
|||||||
later := now.Add(10 * time.Minute)
|
later := now.Add(10 * time.Minute)
|
||||||
earliest := now.Add(5 * time.Minute)
|
earliest := now.Add(5 * time.Minute)
|
||||||
|
|
||||||
min, ok := minQuoteExpiry([]time.Time{later, time.Time{}, earliest})
|
min, ok := minQuoteExpiry([]time.Time{later, {}, earliest})
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("expected min expiry to be set")
|
t.Fatal("expected min expiry to be set")
|
||||||
}
|
}
|
||||||
@@ -65,7 +65,7 @@ func TestMinQuoteExpiry(t *testing.T) {
|
|||||||
t.Fatalf("expected min expiry %v, got %v", earliest, min)
|
t.Fatalf("expected min expiry %v, got %v", earliest, min)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := minQuoteExpiry([]time.Time{time.Time{}}); ok {
|
if _, ok := minQuoteExpiry([]time.Time{{}}); ok {
|
||||||
t.Fatal("expected min expiry to be unset")
|
t.Fatal("expected min expiry to be unset")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
25
frontend/pshared/lib/api/requests/payment/quotes.dart
Normal file
25
frontend/pshared/lib/api/requests/payment/quotes.dart
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import 'package:json_annotation/json_annotation.dart';
|
||||||
|
import 'package:pshared/api/requests/payment/base.dart';
|
||||||
|
import 'package:pshared/data/dto/payment/intent/payment.dart';
|
||||||
|
|
||||||
|
part 'quotes.g.dart';
|
||||||
|
|
||||||
|
|
||||||
|
@JsonSerializable()
|
||||||
|
class QuotePaymentsRequest extends PaymentBaseRequest {
|
||||||
|
final List<PaymentIntentDTO> intents;
|
||||||
|
|
||||||
|
@JsonKey(defaultValue: false)
|
||||||
|
final bool previewOnly;
|
||||||
|
|
||||||
|
const QuotePaymentsRequest({
|
||||||
|
required super.idempotencyKey,
|
||||||
|
super.metadata,
|
||||||
|
required this.intents,
|
||||||
|
this.previewOnly = false,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory QuotePaymentsRequest.fromJson(Map<String, dynamic> json) => _$QuotePaymentsRequestFromJson(json);
|
||||||
|
@override
|
||||||
|
Map<String, dynamic> toJson() => _$QuotePaymentsRequestToJson(this);
|
||||||
|
}
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
import 'package:json_annotation/json_annotation.dart';
|
|
||||||
|
|
||||||
part 'username.g.dart';
|
|
||||||
|
|
||||||
|
|
||||||
@JsonSerializable()
|
|
||||||
class ResetUserNameRequest {
|
|
||||||
final String userName;
|
|
||||||
|
|
||||||
const ResetUserNameRequest({
|
|
||||||
required this.userName,
|
|
||||||
});
|
|
||||||
|
|
||||||
factory ResetUserNameRequest.fromJson(Map<String, dynamic> json) => _$ResetUserNameRequestFromJson(json);
|
|
||||||
Map<String, dynamic> toJson() => _$ResetUserNameRequestToJson(this);
|
|
||||||
|
|
||||||
static ResetUserNameRequest build({
|
|
||||||
required String userName,
|
|
||||||
}) => ResetUserNameRequest(userName: userName);
|
|
||||||
}
|
|
||||||
20
frontend/pshared/lib/api/responses/payment/quotes.dart
Normal file
20
frontend/pshared/lib/api/responses/payment/quotes.dart
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import 'package:json_annotation/json_annotation.dart';
|
||||||
|
|
||||||
|
import 'package:pshared/api/responses/base.dart';
|
||||||
|
import 'package:pshared/api/responses/token.dart';
|
||||||
|
import 'package:pshared/data/dto/payment/quotes.dart';
|
||||||
|
|
||||||
|
part 'quotes.g.dart';
|
||||||
|
|
||||||
|
|
||||||
|
@JsonSerializable(explicitToJson: true)
|
||||||
|
class PaymentQuotesResponse extends BaseAuthorizedResponse {
|
||||||
|
|
||||||
|
final PaymentQuotesDTO quote;
|
||||||
|
|
||||||
|
const PaymentQuotesResponse({required super.accessToken, required this.quote});
|
||||||
|
|
||||||
|
factory PaymentQuotesResponse.fromJson(Map<String, dynamic> json) => _$PaymentQuotesResponseFromJson(json);
|
||||||
|
@override
|
||||||
|
Map<String, dynamic> toJson() => _$PaymentQuotesResponseToJson(this);
|
||||||
|
}
|
||||||
24
frontend/pshared/lib/data/dto/payment/quote_aggregate.dart
Normal file
24
frontend/pshared/lib/data/dto/payment/quote_aggregate.dart
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import 'package:json_annotation/json_annotation.dart';
|
||||||
|
|
||||||
|
import 'package:pshared/data/dto/payment/money.dart';
|
||||||
|
|
||||||
|
part 'quote_aggregate.g.dart';
|
||||||
|
|
||||||
|
|
||||||
|
@JsonSerializable()
|
||||||
|
class PaymentQuoteAggregateDTO {
|
||||||
|
final List<MoneyDTO>? debitAmounts;
|
||||||
|
final List<MoneyDTO>? expectedSettlementAmounts;
|
||||||
|
final List<MoneyDTO>? expectedFeeTotals;
|
||||||
|
final List<MoneyDTO>? networkFeeTotals;
|
||||||
|
|
||||||
|
const PaymentQuoteAggregateDTO({
|
||||||
|
this.debitAmounts,
|
||||||
|
this.expectedSettlementAmounts,
|
||||||
|
this.expectedFeeTotals,
|
||||||
|
this.networkFeeTotals,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory PaymentQuoteAggregateDTO.fromJson(Map<String, dynamic> json) => _$PaymentQuoteAggregateDTOFromJson(json);
|
||||||
|
Map<String, dynamic> toJson() => _$PaymentQuoteAggregateDTOToJson(this);
|
||||||
|
}
|
||||||
23
frontend/pshared/lib/data/dto/payment/quotes.dart
Normal file
23
frontend/pshared/lib/data/dto/payment/quotes.dart
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import 'package:json_annotation/json_annotation.dart';
|
||||||
|
|
||||||
|
import 'package:pshared/data/dto/payment/quote_aggregate.dart';
|
||||||
|
import 'package:pshared/data/dto/payment/payment_quote.dart';
|
||||||
|
|
||||||
|
part 'quotes.g.dart';
|
||||||
|
|
||||||
|
|
||||||
|
@JsonSerializable()
|
||||||
|
class PaymentQuotesDTO {
|
||||||
|
final String quoteRef;
|
||||||
|
final PaymentQuoteAggregateDTO? aggregate;
|
||||||
|
final List<PaymentQuoteDTO>? quotes;
|
||||||
|
|
||||||
|
const PaymentQuotesDTO({
|
||||||
|
required this.quoteRef,
|
||||||
|
this.aggregate,
|
||||||
|
this.quotes,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory PaymentQuotesDTO.fromJson(Map<String, dynamic> json) => _$PaymentQuotesDTOFromJson(json);
|
||||||
|
Map<String, dynamic> toJson() => _$PaymentQuotesDTOToJson(this);
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import 'package:pshared/data/dto/payment/quote_aggregate.dart';
|
||||||
|
import 'package:pshared/data/mapper/payment/money.dart';
|
||||||
|
import 'package:pshared/models/payment/quote_aggregate.dart';
|
||||||
|
|
||||||
|
|
||||||
|
extension PaymentQuoteAggregateDTOMapper on PaymentQuoteAggregateDTO {
|
||||||
|
PaymentQuoteAggregate toDomain() => PaymentQuoteAggregate(
|
||||||
|
debitAmounts: debitAmounts?.map((amount) => amount.toDomain()).toList(),
|
||||||
|
expectedSettlementAmounts: expectedSettlementAmounts?.map((amount) => amount.toDomain()).toList(),
|
||||||
|
expectedFeeTotals: expectedFeeTotals?.map((amount) => amount.toDomain()).toList(),
|
||||||
|
networkFeeTotals: networkFeeTotals?.map((amount) => amount.toDomain()).toList(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
extension PaymentQuoteAggregateMapper on PaymentQuoteAggregate {
|
||||||
|
PaymentQuoteAggregateDTO toDTO() => PaymentQuoteAggregateDTO(
|
||||||
|
debitAmounts: debitAmounts?.map((amount) => amount.toDTO()).toList(),
|
||||||
|
expectedSettlementAmounts: expectedSettlementAmounts?.map((amount) => amount.toDTO()).toList(),
|
||||||
|
expectedFeeTotals: expectedFeeTotals?.map((amount) => amount.toDTO()).toList(),
|
||||||
|
networkFeeTotals: networkFeeTotals?.map((amount) => amount.toDTO()).toList(),
|
||||||
|
);
|
||||||
|
}
|
||||||
21
frontend/pshared/lib/data/mapper/payment/quotes.dart
Normal file
21
frontend/pshared/lib/data/mapper/payment/quotes.dart
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import 'package:pshared/data/dto/payment/quotes.dart';
|
||||||
|
import 'package:pshared/data/mapper/payment/payment_quote.dart';
|
||||||
|
import 'package:pshared/data/mapper/payment/quote_aggregate.dart';
|
||||||
|
import 'package:pshared/models/payment/quotes.dart';
|
||||||
|
|
||||||
|
|
||||||
|
extension PaymentQuotesDTOMapper on PaymentQuotesDTO {
|
||||||
|
PaymentQuotes toDomain() => PaymentQuotes(
|
||||||
|
quoteRef: quoteRef,
|
||||||
|
aggregate: aggregate?.toDomain(),
|
||||||
|
quotes: quotes?.map((quote) => quote.toDomain()).toList(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
extension PaymentQuotesMapper on PaymentQuotes {
|
||||||
|
PaymentQuotesDTO toDTO() => PaymentQuotesDTO(
|
||||||
|
quoteRef: quoteRef,
|
||||||
|
aggregate: aggregate?.toDTO(),
|
||||||
|
quotes: quotes?.map((quote) => quote.toDTO()).toList(),
|
||||||
|
);
|
||||||
|
}
|
||||||
16
frontend/pshared/lib/models/payment/quote_aggregate.dart
Normal file
16
frontend/pshared/lib/models/payment/quote_aggregate.dart
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import 'package:pshared/models/payment/money.dart';
|
||||||
|
|
||||||
|
|
||||||
|
class PaymentQuoteAggregate {
|
||||||
|
final List<Money>? debitAmounts;
|
||||||
|
final List<Money>? expectedSettlementAmounts;
|
||||||
|
final List<Money>? expectedFeeTotals;
|
||||||
|
final List<Money>? networkFeeTotals;
|
||||||
|
|
||||||
|
const PaymentQuoteAggregate({
|
||||||
|
required this.debitAmounts,
|
||||||
|
required this.expectedSettlementAmounts,
|
||||||
|
required this.expectedFeeTotals,
|
||||||
|
required this.networkFeeTotals,
|
||||||
|
});
|
||||||
|
}
|
||||||
15
frontend/pshared/lib/models/payment/quotes.dart
Normal file
15
frontend/pshared/lib/models/payment/quotes.dart
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import 'package:pshared/models/payment/quote.dart';
|
||||||
|
import 'package:pshared/models/payment/quote_aggregate.dart';
|
||||||
|
|
||||||
|
|
||||||
|
class PaymentQuotes {
|
||||||
|
final String quoteRef;
|
||||||
|
final PaymentQuoteAggregate? aggregate;
|
||||||
|
final List<PaymentQuote>? quotes;
|
||||||
|
|
||||||
|
const PaymentQuotes({
|
||||||
|
required this.quoteRef,
|
||||||
|
required this.aggregate,
|
||||||
|
required this.quotes,
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -228,19 +228,6 @@ class AccountProvider extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Account> resetUsername(String userName) async {
|
|
||||||
if (account == null) throw ErrorUnauthorized();
|
|
||||||
_setResource(_resource.copyWith(isLoading: true, error: null));
|
|
||||||
try {
|
|
||||||
final updated = await AccountService.resetUsername(account!, userName);
|
|
||||||
_setResource(Resource(data: updated, isLoading: false));
|
|
||||||
return updated;
|
|
||||||
} catch (e) {
|
|
||||||
_setResource(_resource.copyWith(isLoading: false, error: toException(e)));
|
|
||||||
rethrow;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> forgotPassword(String email) async {
|
Future<void> forgotPassword(String email) async {
|
||||||
_setResource(_resource.copyWith(isLoading: true, error: null));
|
_setResource(_resource.copyWith(isLoading: true, error: null));
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
|
|
||||||
import 'package:share_plus/share_plus.dart';
|
import 'package:share_plus/share_plus.dart';
|
||||||
|
|
||||||
import 'package:pshared/api/requests/signup.dart';
|
import 'package:pshared/api/requests/signup.dart';
|
||||||
@@ -9,7 +10,6 @@ import 'package:pshared/api/requests/password/forgot.dart';
|
|||||||
import 'package:pshared/api/requests/password/reset.dart';
|
import 'package:pshared/api/requests/password/reset.dart';
|
||||||
import 'package:pshared/data/mapper/account/account.dart';
|
import 'package:pshared/data/mapper/account/account.dart';
|
||||||
import 'package:pshared/models/account/account.dart';
|
import 'package:pshared/models/account/account.dart';
|
||||||
import 'package:pshared/models/describable.dart';
|
|
||||||
import 'package:pshared/models/auth/login_outcome.dart';
|
import 'package:pshared/models/auth/login_outcome.dart';
|
||||||
import 'package:pshared/service/authorization/service.dart';
|
import 'package:pshared/service/authorization/service.dart';
|
||||||
import 'package:pshared/service/files.dart';
|
import 'package:pshared/service/files.dart';
|
||||||
@@ -61,14 +61,6 @@ class AccountService {
|
|||||||
await getPOSTResponse(_objectType, 'password/reset/$accountRef/$token', ResetPasswordRequest.build(password: newPassword).toJson());
|
await getPOSTResponse(_objectType, 'password/reset/$accountRef/$token', ResetPasswordRequest.build(password: newPassword).toJson());
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<Account> resetUsername(Account account, String userName) async {
|
|
||||||
_logger.fine('Updating username for account: ${account.id}');
|
|
||||||
final updatedAccount = account.copyWith(
|
|
||||||
describable: account.describable.copyWith(name: userName),
|
|
||||||
);
|
|
||||||
return update(updatedAccount);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Future<Account> changePassword(String oldPassword, String newPassword) async {
|
static Future<Account> changePassword(String oldPassword, String newPassword) async {
|
||||||
_logger.fine('Changing password');
|
_logger.fine('Changing password');
|
||||||
return _getAccount(AuthorizationService.getPATCHResponse(
|
return _getAccount(AuthorizationService.getPATCHResponse(
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
|
|
||||||
import 'package:pshared/api/requests/payment/quote.dart';
|
import 'package:pshared/api/requests/payment/quote.dart';
|
||||||
|
import 'package:pshared/api/requests/payment/quotes.dart';
|
||||||
import 'package:pshared/api/responses/payment/quotation.dart';
|
import 'package:pshared/api/responses/payment/quotation.dart';
|
||||||
|
import 'package:pshared/api/responses/payment/quotes.dart';
|
||||||
import 'package:pshared/data/mapper/payment/payment_quote.dart';
|
import 'package:pshared/data/mapper/payment/payment_quote.dart';
|
||||||
|
import 'package:pshared/data/mapper/payment/quotes.dart';
|
||||||
import 'package:pshared/models/payment/quote.dart';
|
import 'package:pshared/models/payment/quote.dart';
|
||||||
|
import 'package:pshared/models/payment/quotes.dart';
|
||||||
import 'package:pshared/service/authorization/service.dart';
|
import 'package:pshared/service/authorization/service.dart';
|
||||||
import 'package:pshared/service/services.dart';
|
import 'package:pshared/service/services.dart';
|
||||||
|
|
||||||
@@ -21,4 +25,14 @@ class QuotationService {
|
|||||||
);
|
);
|
||||||
return PaymentQuoteResponse.fromJson(response).quote.toDomain();
|
return PaymentQuoteResponse.fromJson(response).quote.toDomain();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<PaymentQuotes> getMultipleQuotation(String organizationRef, QuotePaymentsRequest request) async {
|
||||||
|
_logger.fine('Quoting payments for organization $organizationRef');
|
||||||
|
final response = await AuthorizationService.getPOSTResponse(
|
||||||
|
_objectType,
|
||||||
|
'/quote-multiple/$organizationRef',
|
||||||
|
request.toJson(),
|
||||||
|
);
|
||||||
|
return PaymentQuotesResponse.fromJson(response).quote.toDomain();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,13 +9,7 @@
|
|||||||
"usernameErrorInvalid": "Provide a valid email address",
|
"usernameErrorInvalid": "Provide a valid email address",
|
||||||
"usernameUnknownTLD": "Domain .{domain} is not known, please, check it",
|
"usernameUnknownTLD": "Domain .{domain} is not known, please, check it",
|
||||||
"password": "Password",
|
"password": "Password",
|
||||||
"oldPassword": "Current password",
|
|
||||||
"newPassword": "New password",
|
|
||||||
"confirmPassword": "Confirm password",
|
"confirmPassword": "Confirm password",
|
||||||
"changePassword": "Change password",
|
|
||||||
"savePassword": "Save changed password",
|
|
||||||
"changePasswordSuccess": "Password updated",
|
|
||||||
"changePasswordError": "Could not update password",
|
|
||||||
"passwordValidationRuleDigit": "has digit",
|
"passwordValidationRuleDigit": "has digit",
|
||||||
"passwordValidationRuleUpperCase": "has uppercase letter",
|
"passwordValidationRuleUpperCase": "has uppercase letter",
|
||||||
"passwordValidationRuleLowerCase": "has lowercase letter",
|
"passwordValidationRuleLowerCase": "has lowercase letter",
|
||||||
|
|||||||
@@ -9,13 +9,7 @@
|
|||||||
"usernameErrorInvalid": "Укажите действительный адрес электронной почты",
|
"usernameErrorInvalid": "Укажите действительный адрес электронной почты",
|
||||||
"usernameUnknownTLD": "Домен .{domain} неизвестен, пожалуйста, проверьте его",
|
"usernameUnknownTLD": "Домен .{domain} неизвестен, пожалуйста, проверьте его",
|
||||||
"password": "Пароль",
|
"password": "Пароль",
|
||||||
"oldPassword": "Текущий пароль",
|
|
||||||
"newPassword": "Новый пароль",
|
|
||||||
"confirmPassword": "Подтвердите пароль",
|
"confirmPassword": "Подтвердите пароль",
|
||||||
"changePassword": "Изменить пароль",
|
|
||||||
"savePassword": "Сохранить пароль",
|
|
||||||
"changePasswordSuccess": "Пароль обновлен",
|
|
||||||
"changePasswordError": "Не удалось обновить пароль",
|
|
||||||
"passwordValidationRuleDigit": "содержит цифру",
|
"passwordValidationRuleDigit": "содержит цифру",
|
||||||
"passwordValidationRuleUpperCase": "содержит заглавную букву",
|
"passwordValidationRuleUpperCase": "содержит заглавную букву",
|
||||||
"passwordValidationRuleLowerCase": "содержит строчную букву",
|
"passwordValidationRuleLowerCase": "содержит строчную букву",
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
enum EditState { view, edit, saving }
|
|
||||||
@@ -1,9 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:provider/provider.dart';
|
|
||||||
|
|
||||||
import 'package:pweb/models/edit_state.dart';
|
|
||||||
import 'package:pshared/provider/account.dart';
|
|
||||||
|
|
||||||
class AccountName extends StatefulWidget {
|
class AccountName extends StatefulWidget {
|
||||||
final String name;
|
final String name;
|
||||||
@@ -30,9 +26,8 @@ class _AccountNameState extends State<AccountName> {
|
|||||||
static const double _borderWidth = 2;
|
static const double _borderWidth = 2;
|
||||||
|
|
||||||
late final TextEditingController _controller;
|
late final TextEditingController _controller;
|
||||||
EditState _editState = EditState.view;
|
bool _isEditing = false;
|
||||||
late String _originalName;
|
late String _originalName;
|
||||||
String _errorText = '';
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -47,131 +42,86 @@ class _AccountNameState extends State<AccountName> {
|
|||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _startEditing() => setState(() => _editState = EditState.edit);
|
void _startEditing() => setState(() => _isEditing = true);
|
||||||
|
|
||||||
void _cancelEditing() {
|
void _cancelEditing() {
|
||||||
setState(() {
|
setState(() {
|
||||||
_controller.text = _originalName;
|
_controller.text = _originalName;
|
||||||
_editState = EditState.view;
|
_isEditing = false;
|
||||||
_errorText = '';
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _saveEditing(AccountProvider provider) async {
|
void _saveEditing() {
|
||||||
final newName = _controller.text.trim();
|
|
||||||
if (newName.isEmpty || newName == _originalName) {
|
|
||||||
_cancelEditing();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_editState = EditState.saving;
|
_originalName = _controller.text;
|
||||||
_errorText = '';
|
_isEditing = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
|
||||||
await provider.resetUsername(newName);
|
|
||||||
if (!mounted) return;
|
|
||||||
setState(() {
|
|
||||||
_originalName = newName;
|
|
||||||
_editState = EditState.view;
|
|
||||||
});
|
|
||||||
} catch (_) {
|
|
||||||
if (!mounted) return;
|
|
||||||
setState(() {
|
|
||||||
_errorText = widget.errorText;
|
|
||||||
_editState = EditState.edit;
|
|
||||||
});
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(content: Text(widget.errorText)),
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
} finally {
|
|
||||||
if (!mounted) return;
|
|
||||||
if (_editState == EditState.saving) {
|
|
||||||
setState(() => _editState = EditState.edit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
return Consumer<AccountProvider>(
|
return Column(
|
||||||
builder: (context, provider, _) {
|
mainAxisSize: MainAxisSize.min,
|
||||||
final isEditing = _editState != EditState.view;
|
children: [
|
||||||
final currentName = provider.account?.name ?? _originalName;
|
Row(
|
||||||
final isBusy = provider.isLoading || _editState == EditState.saving;
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
|
||||||
if (!isEditing && currentName != _originalName) {
|
|
||||||
_originalName = currentName;
|
|
||||||
_controller.text = currentName;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
children: [
|
||||||
Row(
|
if (_isEditing)
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
SizedBox(
|
||||||
children: [
|
width: _inputWidth,
|
||||||
if (isEditing)
|
child: TextFormField(
|
||||||
SizedBox(
|
controller: _controller,
|
||||||
width: _inputWidth,
|
style: theme.textTheme.headlineMedium?.copyWith(
|
||||||
child: TextFormField(
|
fontWeight: FontWeight.bold,
|
||||||
controller: _controller,
|
),
|
||||||
style: theme.textTheme.headlineMedium?.copyWith(
|
autofocus: true,
|
||||||
fontWeight: FontWeight.bold,
|
decoration: InputDecoration(
|
||||||
),
|
hintText: widget.hintText,
|
||||||
autofocus: true,
|
isDense: true,
|
||||||
enabled: !isBusy,
|
border: UnderlineInputBorder(
|
||||||
decoration: InputDecoration(
|
borderSide: BorderSide(
|
||||||
hintText: widget.hintText,
|
color: theme.colorScheme.primary,
|
||||||
isDense: true,
|
width: _borderWidth,
|
||||||
border: UnderlineInputBorder(
|
|
||||||
borderSide: BorderSide(
|
|
||||||
color: theme.colorScheme.primary,
|
|
||||||
width: _borderWidth,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
|
||||||
else
|
|
||||||
Text(
|
|
||||||
_originalName,
|
|
||||||
style: theme.textTheme.headlineMedium?.copyWith(
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
const SizedBox(width: _spacing),
|
),
|
||||||
if (isEditing) ...[
|
)
|
||||||
IconButton(
|
else
|
||||||
icon: Icon(Icons.check, color: theme.colorScheme.primary),
|
|
||||||
onPressed: isBusy ? null : () => _saveEditing(provider),
|
|
||||||
),
|
|
||||||
IconButton(
|
|
||||||
icon: Icon(Icons.close, color: theme.colorScheme.error),
|
|
||||||
onPressed: isBusy ? null : _cancelEditing,
|
|
||||||
),
|
|
||||||
] else
|
|
||||||
IconButton(
|
|
||||||
icon: Icon(Icons.edit, color: theme.colorScheme.primary),
|
|
||||||
onPressed: isBusy ? null : _startEditing,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: _errorSpacing),
|
|
||||||
if (_errorText.isNotEmpty)
|
|
||||||
Text(
|
Text(
|
||||||
_errorText,
|
_originalName,
|
||||||
style: theme.textTheme.bodySmall?.copyWith(
|
style: theme.textTheme.headlineMedium?.copyWith(
|
||||||
color: theme.colorScheme.error,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
const SizedBox(width: _spacing),
|
||||||
|
if (_isEditing) ...[
|
||||||
|
IconButton(
|
||||||
|
icon: Icon(Icons.check, color: theme.colorScheme.primary),
|
||||||
|
onPressed: _saveEditing,
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
icon: Icon(Icons.close, color: theme.colorScheme.error),
|
||||||
|
onPressed: _cancelEditing,
|
||||||
|
),
|
||||||
|
] else
|
||||||
|
IconButton(
|
||||||
|
icon: Icon(Icons.edit, color: theme.colorScheme.primary),
|
||||||
|
onPressed: _startEditing,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
);
|
),
|
||||||
},
|
const SizedBox(height: _errorSpacing),
|
||||||
|
if (widget.errorText.isEmpty)
|
||||||
|
Text(
|
||||||
|
widget.errorText,
|
||||||
|
style: theme.textTheme.bodySmall?.copyWith(
|
||||||
|
color: theme.colorScheme.error,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,129 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'package:pshared/provider/account.dart';
|
|
||||||
|
|
||||||
import 'package:pweb/providers/password_form.dart';
|
|
||||||
|
|
||||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
|
||||||
|
|
||||||
|
|
||||||
class PasswordForm extends StatelessWidget {
|
|
||||||
const PasswordForm({
|
|
||||||
super.key,
|
|
||||||
required this.formProvider,
|
|
||||||
required this.accountProvider,
|
|
||||||
required this.isBusy,
|
|
||||||
required this.oldPasswordLabel,
|
|
||||||
required this.newPasswordLabel,
|
|
||||||
required this.confirmPasswordLabel,
|
|
||||||
required this.savePassword,
|
|
||||||
required this.successText,
|
|
||||||
required this.errorText,
|
|
||||||
required this.loc,
|
|
||||||
});
|
|
||||||
|
|
||||||
static const double _fieldWidth = 320;
|
|
||||||
static const double _gapMedium = 12;
|
|
||||||
static const double _gapSmall = 8;
|
|
||||||
|
|
||||||
final PasswordFormProvider formProvider;
|
|
||||||
final AccountProvider accountProvider;
|
|
||||||
final bool isBusy;
|
|
||||||
final String oldPasswordLabel;
|
|
||||||
final String newPasswordLabel;
|
|
||||||
final String confirmPasswordLabel;
|
|
||||||
final String savePassword;
|
|
||||||
final String successText;
|
|
||||||
final String errorText;
|
|
||||||
final AppLocalizations loc;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final theme = Theme.of(context);
|
|
||||||
final isFormBusy = isBusy || formProvider.isSaving;
|
|
||||||
|
|
||||||
return Column(
|
|
||||||
children: [
|
|
||||||
const SizedBox(height: _gapMedium),
|
|
||||||
Form(
|
|
||||||
key: formProvider.formKey,
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
SizedBox(
|
|
||||||
width: _fieldWidth,
|
|
||||||
child: TextFormField(
|
|
||||||
controller: formProvider.oldPasswordController,
|
|
||||||
obscureText: true,
|
|
||||||
enabled: !isFormBusy,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText: oldPasswordLabel,
|
|
||||||
border: const OutlineInputBorder(),
|
|
||||||
),
|
|
||||||
validator: (value) =>
|
|
||||||
(value == null || value.isEmpty) ? loc.errorPasswordMissing : null,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: _gapSmall),
|
|
||||||
SizedBox(
|
|
||||||
width: _fieldWidth,
|
|
||||||
child: TextFormField(
|
|
||||||
controller: formProvider.newPasswordController,
|
|
||||||
obscureText: true,
|
|
||||||
enabled: !isFormBusy,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText: newPasswordLabel,
|
|
||||||
border: const OutlineInputBorder(),
|
|
||||||
),
|
|
||||||
validator: (value) =>
|
|
||||||
(value == null || value.isEmpty) ? loc.errorPasswordMissing : null,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: _gapSmall),
|
|
||||||
SizedBox(
|
|
||||||
width: _fieldWidth,
|
|
||||||
child: TextFormField(
|
|
||||||
controller: formProvider.confirmPasswordController,
|
|
||||||
obscureText: true,
|
|
||||||
enabled: !isFormBusy,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText: confirmPasswordLabel,
|
|
||||||
border: const OutlineInputBorder(),
|
|
||||||
),
|
|
||||||
validator: (value) {
|
|
||||||
if (value == null || value.isEmpty) return loc.errorPasswordMissing;
|
|
||||||
if (value != formProvider.newPasswordController.text) {
|
|
||||||
return loc.passwordsDoNotMatch;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: _gapMedium),
|
|
||||||
ElevatedButton.icon(
|
|
||||||
onPressed: isFormBusy
|
|
||||||
? null
|
|
||||||
: () => formProvider.submit(
|
|
||||||
context: context,
|
|
||||||
accountProvider: accountProvider,
|
|
||||||
successText: successText,
|
|
||||||
errorText: errorText,
|
|
||||||
),
|
|
||||||
icon: const Icon(Icons.save_outlined),
|
|
||||||
label: Text(savePassword),
|
|
||||||
),
|
|
||||||
if (formProvider.errorText.isNotEmpty) ...[
|
|
||||||
const SizedBox(height: _gapSmall),
|
|
||||||
Text(
|
|
||||||
formProvider.errorText,
|
|
||||||
style: theme.textTheme.bodySmall?.copyWith(
|
|
||||||
color: theme.colorScheme.error,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,187 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'package:provider/provider.dart';
|
|
||||||
|
|
||||||
import 'package:pshared/provider/account.dart';
|
|
||||||
import 'package:pshared/utils/snackbar.dart';
|
|
||||||
|
|
||||||
import 'package:pweb/models/edit_state.dart';
|
|
||||||
import 'package:pweb/utils/error/snackbar.dart';
|
|
||||||
|
|
||||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
|
||||||
|
|
||||||
|
|
||||||
class AccountPassword extends StatefulWidget {
|
|
||||||
final String title;
|
|
||||||
final String successText;
|
|
||||||
final String errorText;
|
|
||||||
final String oldPasswordLabel;
|
|
||||||
final String newPasswordLabel;
|
|
||||||
final String confirmPasswordLabel;
|
|
||||||
final String savePassword;
|
|
||||||
|
|
||||||
const AccountPassword({
|
|
||||||
super.key,
|
|
||||||
required this.title,
|
|
||||||
required this.successText,
|
|
||||||
required this.errorText,
|
|
||||||
required this.oldPasswordLabel,
|
|
||||||
required this.newPasswordLabel,
|
|
||||||
required this.confirmPasswordLabel,
|
|
||||||
required this.savePassword,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<AccountPassword> createState() => _AccountPasswordState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _AccountPasswordState extends State<AccountPassword> {
|
|
||||||
static const double _fieldWidth = 320;
|
|
||||||
static const double _gapMedium = 12;
|
|
||||||
static const double _gapSmall = 8;
|
|
||||||
|
|
||||||
final _formKey = GlobalKey<FormState>();
|
|
||||||
final _oldPasswordController = TextEditingController();
|
|
||||||
final _newPasswordController = TextEditingController();
|
|
||||||
final _confirmPasswordController = TextEditingController();
|
|
||||||
|
|
||||||
EditState _state = EditState.view;
|
|
||||||
String _errorText = '';
|
|
||||||
|
|
||||||
bool get _isSaving => _state == EditState.saving;
|
|
||||||
bool get _isExpanded => _state != EditState.view;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
_oldPasswordController.dispose();
|
|
||||||
_newPasswordController.dispose();
|
|
||||||
_confirmPasswordController.dispose();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _changePassword(AccountProvider provider) async {
|
|
||||||
if (!_formKey.currentState!.validate()) return;
|
|
||||||
|
|
||||||
setState(() {
|
|
||||||
_state = EditState.saving;
|
|
||||||
_errorText = '';
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
|
||||||
await provider.changePassword(_oldPasswordController.text, _newPasswordController.text);
|
|
||||||
if (!mounted) return;
|
|
||||||
_oldPasswordController.clear();
|
|
||||||
_newPasswordController.clear();
|
|
||||||
_confirmPasswordController.clear();
|
|
||||||
notifyUser(context, widget.successText);
|
|
||||||
} catch (e) {
|
|
||||||
if (!mounted) return;
|
|
||||||
setState(() => _errorText = widget.errorText);
|
|
||||||
await postNotifyUserOfErrorX(
|
|
||||||
context: context,
|
|
||||||
errorSituation: widget.errorText,
|
|
||||||
exception: e,
|
|
||||||
);
|
|
||||||
} finally {
|
|
||||||
if (mounted) {
|
|
||||||
setState(() => _state = EditState.edit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final theme = Theme.of(context);
|
|
||||||
final loc = AppLocalizations.of(context)!;
|
|
||||||
|
|
||||||
return Consumer<AccountProvider>(
|
|
||||||
builder: (context, provider, _) {
|
|
||||||
final isBusy = provider.isLoading || _isSaving;
|
|
||||||
|
|
||||||
return Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
TextButton.icon(
|
|
||||||
onPressed: isBusy
|
|
||||||
? null
|
|
||||||
: () => setState(() {
|
|
||||||
_state = _isExpanded ? EditState.view : EditState.edit;
|
|
||||||
_errorText = '';
|
|
||||||
}),
|
|
||||||
icon: Icon(Icons.lock_outline, color: theme.colorScheme.primary),
|
|
||||||
label: Text(widget.title, style: theme.textTheme.bodyMedium),
|
|
||||||
),
|
|
||||||
if (_isExpanded) ...[
|
|
||||||
const SizedBox(height: _gapMedium),
|
|
||||||
Form(
|
|
||||||
key: _formKey,
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
SizedBox(
|
|
||||||
width: _fieldWidth,
|
|
||||||
child: TextFormField(
|
|
||||||
controller: _oldPasswordController,
|
|
||||||
obscureText: true,
|
|
||||||
enabled: !isBusy,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText: widget.oldPasswordLabel,
|
|
||||||
border: const OutlineInputBorder(),
|
|
||||||
),
|
|
||||||
validator: (value) => (value == null || value.isEmpty) ? loc.errorPasswordMissing : null,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: _gapSmall),
|
|
||||||
SizedBox(
|
|
||||||
width: _fieldWidth,
|
|
||||||
child: TextFormField(
|
|
||||||
controller: _newPasswordController,
|
|
||||||
obscureText: true,
|
|
||||||
enabled: !isBusy,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText: widget.newPasswordLabel,
|
|
||||||
border: const OutlineInputBorder(),
|
|
||||||
),
|
|
||||||
validator: (value) => (value == null || value.isEmpty) ? loc.errorPasswordMissing : null,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: _gapSmall),
|
|
||||||
SizedBox(
|
|
||||||
width: _fieldWidth,
|
|
||||||
child: TextFormField(
|
|
||||||
controller: _confirmPasswordController,
|
|
||||||
obscureText: true,
|
|
||||||
enabled: !isBusy,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText: widget.confirmPasswordLabel,
|
|
||||||
border: const OutlineInputBorder(),
|
|
||||||
),
|
|
||||||
validator: (value) {
|
|
||||||
if (value == null || value.isEmpty) return loc.errorPasswordMissing;
|
|
||||||
if (value != _newPasswordController.text) return loc.passwordsDoNotMatch;
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: _gapMedium),
|
|
||||||
ElevatedButton.icon(
|
|
||||||
onPressed: isBusy ? null : () => _changePassword(provider),
|
|
||||||
icon: const Icon(Icons.save_outlined),
|
|
||||||
label: Text(widget.savePassword),
|
|
||||||
),
|
|
||||||
if (_errorText.isNotEmpty) ...[
|
|
||||||
const SizedBox(height: _gapSmall),
|
|
||||||
Text(
|
|
||||||
_errorText,
|
|
||||||
style: theme.textTheme.bodySmall?.copyWith(color: theme.colorScheme.error),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
|
|
||||||
class PasswordToggleButton extends StatelessWidget {
|
|
||||||
const PasswordToggleButton({
|
|
||||||
super.key,
|
|
||||||
required this.title,
|
|
||||||
required this.isExpanded,
|
|
||||||
required this.isBusy,
|
|
||||||
required this.onToggle,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String title;
|
|
||||||
final bool isExpanded;
|
|
||||||
final bool isBusy;
|
|
||||||
final VoidCallback onToggle;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final theme = Theme.of(context);
|
|
||||||
final iconColor = theme.colorScheme.primary;
|
|
||||||
|
|
||||||
return TextButton.icon(
|
|
||||||
onPressed: isBusy
|
|
||||||
? null
|
|
||||||
: () {
|
|
||||||
onToggle();
|
|
||||||
},
|
|
||||||
icon: Icon(
|
|
||||||
isExpanded ? Icons.lock_open : Icons.lock_outline,
|
|
||||||
color: iconColor,
|
|
||||||
),
|
|
||||||
label: Text(title, style: theme.textTheme.bodyMedium),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +1,8 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:provider/provider.dart';
|
|
||||||
|
|
||||||
import 'package:pshared/provider/account.dart';
|
|
||||||
|
|
||||||
import 'package:pweb/pages/settings/profile/account/avatar.dart';
|
import 'package:pweb/pages/settings/profile/account/avatar.dart';
|
||||||
import 'package:pweb/pages/settings/profile/account/locale.dart';
|
import 'package:pweb/pages/settings/profile/account/locale.dart';
|
||||||
import 'package:pweb/pages/settings/profile/account/name.dart';
|
import 'package:pweb/pages/settings/profile/account/name.dart';
|
||||||
import 'package:pweb/pages/settings/profile/account/password/password.dart';
|
|
||||||
|
|
||||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||||
|
|
||||||
@@ -23,48 +18,34 @@ class ProfileSettingsPage extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final loc = AppLocalizations.of(context)!;
|
final loc = AppLocalizations.of(context)!;
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
final accountName = context.select<AccountProvider, String?>(
|
|
||||||
(provider) => provider.account?.describable.name,
|
|
||||||
);
|
|
||||||
|
|
||||||
return Align(
|
return Material(
|
||||||
alignment: Alignment.topCenter,
|
elevation: 4,
|
||||||
child: Material(
|
borderRadius: BorderRadius.circular(_cardRadius),
|
||||||
elevation: 4,
|
clipBehavior: Clip.antiAlias,
|
||||||
borderRadius: BorderRadius.circular(_cardRadius),
|
color: theme.colorScheme.onSecondary,
|
||||||
color: theme.colorScheme.onSecondary,
|
child: Padding(
|
||||||
child: Padding(
|
padding: _cardPadding,
|
||||||
padding: _cardPadding,
|
child: Column(
|
||||||
child: Column(
|
mainAxisSize: MainAxisSize.min,
|
||||||
mainAxisSize: MainAxisSize.min,
|
spacing: _itemSpacing,
|
||||||
spacing: _itemSpacing,
|
children: [
|
||||||
children: [
|
AvatarTile(
|
||||||
AvatarTile(
|
avatarUrl: 'https://avatars.githubusercontent.com/u/65651201',
|
||||||
avatarUrl: 'https://avatars.githubusercontent.com/u/65651201',
|
title: loc.avatar,
|
||||||
title: loc.avatar,
|
description: loc.avatarHint,
|
||||||
description: loc.avatarHint,
|
errorText: loc.avatarUpdateError,
|
||||||
errorText: loc.avatarUpdateError,
|
),
|
||||||
),
|
AccountName(
|
||||||
AccountName(
|
name: loc.userNamePlaceholder,
|
||||||
name: accountName ?? loc.userNamePlaceholder,
|
title: loc.accountName,
|
||||||
title: loc.accountName,
|
hintText: loc.accountNameHint,
|
||||||
hintText: loc.accountNameHint,
|
errorText: loc.accountNameUpdateError,
|
||||||
errorText: loc.accountNameUpdateError,
|
),
|
||||||
),
|
LocalePicker(
|
||||||
AccountPassword(
|
title: loc.language,
|
||||||
title: loc.changePassword,
|
),
|
||||||
successText: loc.changePasswordSuccess,
|
],
|
||||||
errorText: loc.changePasswordError,
|
|
||||||
oldPasswordLabel: loc.oldPassword,
|
|
||||||
newPasswordLabel: loc.newPassword,
|
|
||||||
confirmPasswordLabel: loc.confirmPassword,
|
|
||||||
savePassword: loc.savePassword,
|
|
||||||
),
|
|
||||||
LocalePicker(
|
|
||||||
title: loc.language,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:flutter_settings_ui/flutter_settings_ui.dart';
|
import 'package:flutter_settings_ui/flutter_settings_ui.dart';
|
||||||
|
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||||
import 'package:pweb/models/edit_state.dart';
|
|
||||||
import 'package:pweb/utils/error/snackbar.dart';
|
import 'package:pweb/utils/error/snackbar.dart';
|
||||||
|
|
||||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
enum _EditState { view, edit, saving }
|
||||||
|
|
||||||
|
|
||||||
|
/// Базовый класс, управляющий состояниями (view/edit/saving),
|
||||||
|
/// показом snackbar ошибок и успешного сохранения.
|
||||||
abstract class BaseEditTile<T> extends AbstractSettingsTile {
|
abstract class BaseEditTile<T> extends AbstractSettingsTile {
|
||||||
const BaseEditTile({
|
const BaseEditTile({
|
||||||
super.key,
|
super.key,
|
||||||
@@ -24,8 +24,11 @@ abstract class BaseEditTile<T> extends AbstractSettingsTile {
|
|||||||
final Future<void> Function(T) valueSetter;
|
final Future<void> Function(T) valueSetter;
|
||||||
final String errorSituation;
|
final String errorSituation;
|
||||||
|
|
||||||
|
/// Рисует в режиме просмотра (read-only).
|
||||||
Widget buildView(BuildContext context, T? value);
|
Widget buildView(BuildContext context, T? value);
|
||||||
|
|
||||||
|
/// Рисует UI редактора.
|
||||||
|
/// Если [useDialogEditor]==true, его обернут в диалог.
|
||||||
Widget buildEditor(
|
Widget buildEditor(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
T? initial,
|
T? initial,
|
||||||
@@ -34,6 +37,7 @@ abstract class BaseEditTile<T> extends AbstractSettingsTile {
|
|||||||
bool isSaving,
|
bool isSaving,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/// true → показывать редактор в диалоге, false → inline под заголовком.
|
||||||
bool get useDialogEditor => false;
|
bool get useDialogEditor => false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -48,16 +52,16 @@ class _BaseEditTileBody<T> extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _BaseEditTileBodyState<T> extends State<_BaseEditTileBody<T>> {
|
class _BaseEditTileBodyState<T> extends State<_BaseEditTileBody<T>> {
|
||||||
EditState _state = EditState.view;
|
_EditState _state = _EditState.view;
|
||||||
bool get _isSaving => _state == EditState.saving;
|
bool get _isSaving => _state == _EditState.saving;
|
||||||
|
|
||||||
Future<void> _performSave(T newValue) async {
|
Future<void> _performSave(T newValue) async {
|
||||||
final current = widget.delegate.valueGetter();
|
final current = widget.delegate.valueGetter();
|
||||||
if (newValue == current) {
|
if (newValue == current) {
|
||||||
setState(() => _state = EditState.view);
|
setState(() => _state = _EditState.view);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setState(() => _state = EditState.saving);
|
setState(() => _state = _EditState.saving);
|
||||||
final sms = ScaffoldMessenger.of(context);
|
final sms = ScaffoldMessenger.of(context);
|
||||||
final locs = AppLocalizations.of(context)!;
|
final locs = AppLocalizations.of(context)!;
|
||||||
try {
|
try {
|
||||||
@@ -74,7 +78,7 @@ class _BaseEditTileBodyState<T> extends State<_BaseEditTileBody<T>> {
|
|||||||
exception: e,
|
exception: e,
|
||||||
);
|
);
|
||||||
} finally {
|
} finally {
|
||||||
if (mounted) setState(() => _state = EditState.view);
|
if (mounted) setState(() => _state = _EditState.view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,6 +112,7 @@ class _BaseEditTileBodyState<T> extends State<_BaseEditTileBody<T>> {
|
|||||||
final delegate = widget.delegate;
|
final delegate = widget.delegate;
|
||||||
final current = delegate.valueGetter();
|
final current = delegate.valueGetter();
|
||||||
|
|
||||||
|
// Диалоговый режим
|
||||||
if (delegate.useDialogEditor) {
|
if (delegate.useDialogEditor) {
|
||||||
return SettingsTile.navigation(
|
return SettingsTile.navigation(
|
||||||
leading: Icon(delegate.icon),
|
leading: Icon(delegate.icon),
|
||||||
@@ -117,20 +122,21 @@ class _BaseEditTileBodyState<T> extends State<_BaseEditTileBody<T>> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Inline-режим (под заголовком будет редактор прямо в tile)
|
||||||
return SettingsTile.navigation(
|
return SettingsTile.navigation(
|
||||||
leading: Icon(delegate.icon),
|
leading: Icon(delegate.icon),
|
||||||
title: Text(delegate.title),
|
title: Text(delegate.title),
|
||||||
value: _state == EditState.view
|
value: _state == _EditState.view
|
||||||
? delegate.buildView(context, current)
|
? delegate.buildView(context, current)
|
||||||
: delegate.buildEditor(
|
: delegate.buildEditor(
|
||||||
context,
|
context,
|
||||||
current,
|
current,
|
||||||
_performSave,
|
_performSave,
|
||||||
() => setState(() => _state = EditState.view),
|
() => setState(() => _state = _EditState.view),
|
||||||
_isSaving,
|
_isSaving,
|
||||||
),
|
),
|
||||||
onPressed: (_) {
|
onPressed: (_) {
|
||||||
if (_state == EditState.view) setState(() => _state = EditState.edit);
|
if (_state == _EditState.view) setState(() => _state = _EditState.edit);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,87 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'package:pshared/provider/account.dart';
|
|
||||||
import 'package:pshared/utils/snackbar.dart';
|
|
||||||
|
|
||||||
import 'package:pweb/models/edit_state.dart';
|
|
||||||
import 'package:pweb/utils/error/snackbar.dart';
|
|
||||||
|
|
||||||
|
|
||||||
class PasswordFormProvider extends ChangeNotifier {
|
|
||||||
final formKey = GlobalKey<FormState>();
|
|
||||||
final oldPasswordController = TextEditingController();
|
|
||||||
final newPasswordController = TextEditingController();
|
|
||||||
final confirmPasswordController = TextEditingController();
|
|
||||||
|
|
||||||
EditState _state = EditState.view;
|
|
||||||
String _errorText = '';
|
|
||||||
bool _disposed = false;
|
|
||||||
|
|
||||||
bool get isExpanded => _state != EditState.view;
|
|
||||||
bool get isSaving => _state == EditState.saving;
|
|
||||||
String get errorText => _errorText;
|
|
||||||
EditState get state => _state;
|
|
||||||
|
|
||||||
void toggleExpanded() {
|
|
||||||
if (_state == EditState.saving) return;
|
|
||||||
_setState(_state == EditState.view ? EditState.edit : EditState.view);
|
|
||||||
_setError('');
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> submit({
|
|
||||||
required BuildContext context,
|
|
||||||
required AccountProvider accountProvider,
|
|
||||||
required String successText,
|
|
||||||
required String errorText,
|
|
||||||
}) async {
|
|
||||||
final currentForm = formKey.currentState;
|
|
||||||
if (currentForm == null || !currentForm.validate()) return;
|
|
||||||
|
|
||||||
_setState(EditState.saving);
|
|
||||||
_setError('');
|
|
||||||
|
|
||||||
try {
|
|
||||||
await accountProvider.changePassword(
|
|
||||||
oldPasswordController.text,
|
|
||||||
newPasswordController.text,
|
|
||||||
);
|
|
||||||
|
|
||||||
oldPasswordController.clear();
|
|
||||||
newPasswordController.clear();
|
|
||||||
confirmPasswordController.clear();
|
|
||||||
if (!context.mounted) return;
|
|
||||||
notifyUser(context, successText);
|
|
||||||
} catch (e) {
|
|
||||||
_setError(errorText);
|
|
||||||
if (!context.mounted) return;
|
|
||||||
await postNotifyUserOfErrorX(
|
|
||||||
context: context,
|
|
||||||
errorSituation: errorText,
|
|
||||||
exception: e,
|
|
||||||
);
|
|
||||||
} finally {
|
|
||||||
_setState(EditState.edit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void _setState(EditState value) {
|
|
||||||
if (_state == value || _disposed) return;
|
|
||||||
_state = value;
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
void _setError(String value) {
|
|
||||||
if (_disposed) return;
|
|
||||||
_errorText = value;
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
_disposed = true;
|
|
||||||
oldPasswordController.dispose();
|
|
||||||
newPasswordController.dispose();
|
|
||||||
confirmPasswordController.dispose();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:provider/provider.dart';
|
|
||||||
|
|
||||||
import 'package:pshared/provider/account.dart';
|
|
||||||
|
|
||||||
import 'package:pweb/widgets/sidebar/destinations.dart';
|
import 'package:pweb/widgets/sidebar/destinations.dart';
|
||||||
import 'package:pweb/widgets/sidebar/side_menu.dart';
|
import 'package:pweb/widgets/sidebar/side_menu.dart';
|
||||||
import 'package:pweb/widgets/sidebar/user.dart';
|
import 'package:pweb/widgets/sidebar/user.dart';
|
||||||
@@ -22,7 +18,7 @@ class PayoutSidebar extends StatelessWidget {
|
|||||||
|
|
||||||
final PayoutDestination selected;
|
final PayoutDestination selected;
|
||||||
final ValueChanged<PayoutDestination> onSelected;
|
final ValueChanged<PayoutDestination> onSelected;
|
||||||
final Future<void> Function()? onLogout;
|
final VoidCallback? onLogout;
|
||||||
|
|
||||||
final String? userName;
|
final String? userName;
|
||||||
final String? avatarUrl;
|
final String? avatarUrl;
|
||||||
@@ -31,15 +27,6 @@ class PayoutSidebar extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final accountName = context.select<AccountProvider, String?>(
|
|
||||||
(provider) => provider.account?.describable.name,
|
|
||||||
);
|
|
||||||
final accountAvatar = context.select<AccountProvider, String?>(
|
|
||||||
(provider) => provider.account?.avatarUrl,
|
|
||||||
);
|
|
||||||
final resolvedUserName = userName ?? accountName;
|
|
||||||
final resolvedAvatarUrl = avatarUrl ?? accountAvatar;
|
|
||||||
|
|
||||||
final menuItems = items ??
|
final menuItems = items ??
|
||||||
<PayoutDestination>[
|
<PayoutDestination>[
|
||||||
PayoutDestination.dashboard,
|
PayoutDestination.dashboard,
|
||||||
@@ -55,16 +42,16 @@ class PayoutSidebar extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
UserProfileCard(
|
UserProfileCard(
|
||||||
theme: theme,
|
theme: theme,
|
||||||
avatarUrl: resolvedAvatarUrl,
|
avatarUrl: avatarUrl,
|
||||||
userName: resolvedUserName,
|
userName: userName,
|
||||||
selected: selected,
|
selected: selected,
|
||||||
onSelected: onSelected
|
onSelected: onSelected
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
SideMenuColumn(
|
SideMenuColumn(
|
||||||
theme: theme,
|
theme: theme,
|
||||||
avatarUrl: resolvedAvatarUrl,
|
avatarUrl: avatarUrl,
|
||||||
userName: resolvedUserName,
|
userName: userName,
|
||||||
items: menuItems,
|
items: menuItems,
|
||||||
selected: selected,
|
selected: selected,
|
||||||
onSelected: onSelected,
|
onSelected: onSelected,
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ dependencies:
|
|||||||
flutter_settings_ui: ^3.0.1
|
flutter_settings_ui: ^3.0.1
|
||||||
pin_code_fields: ^8.0.1
|
pin_code_fields: ^8.0.1
|
||||||
fl_chart: ^1.0.0
|
fl_chart: ^1.0.0
|
||||||
syncfusion_flutter_charts: ^31.2.10
|
syncfusion_flutter_charts: ^32.1.19
|
||||||
flutter_multi_formatter: ^2.13.7
|
flutter_multi_formatter: ^2.13.7
|
||||||
dotted_border: ^3.1.0
|
dotted_border: ^3.1.0
|
||||||
qr_flutter: ^4.1.0
|
qr_flutter: ^4.1.0
|
||||||
|
|||||||
Reference in New Issue
Block a user