multiple payout page and small fixes
This commit is contained in:
47
frontend/pshared/lib/utils/payment/fx_helpers.dart
Normal file
47
frontend/pshared/lib/utils/payment/fx_helpers.dart
Normal file
@@ -0,0 +1,47 @@
|
||||
import 'package:pshared/models/payment/currency_pair.dart';
|
||||
import 'package:pshared/models/payment/fx/intent.dart';
|
||||
import 'package:pshared/models/payment/fx/side.dart';
|
||||
import 'package:pshared/models/money.dart';
|
||||
|
||||
|
||||
class FxIntentHelper {
|
||||
static FxIntent? buildSellBaseBuyQuote({
|
||||
required String baseCurrency,
|
||||
required String quoteCurrency,
|
||||
bool enabled = true,
|
||||
}) {
|
||||
if (!enabled) return null;
|
||||
final base = baseCurrency.trim();
|
||||
final quote = quoteCurrency.trim();
|
||||
if (base.isEmpty || quote.isEmpty) return null;
|
||||
if (base.toUpperCase() == quote.toUpperCase()) return null;
|
||||
return FxIntent(
|
||||
pair: CurrencyPair(base: base, quote: quote),
|
||||
side: FxSide.sellBaseBuyQuote,
|
||||
);
|
||||
}
|
||||
|
||||
static String resolveSettlementCurrency({
|
||||
required Money amount,
|
||||
FxIntent? fx,
|
||||
}) {
|
||||
final pair = fx?.pair;
|
||||
if (pair != null) {
|
||||
switch (fx?.side ?? FxSide.unspecified) {
|
||||
case FxSide.buyBaseSellQuote:
|
||||
if (pair.base.isNotEmpty) return pair.base;
|
||||
break;
|
||||
case FxSide.sellBaseBuyQuote:
|
||||
if (pair.quote.isNotEmpty) return pair.quote;
|
||||
break;
|
||||
case FxSide.unspecified:
|
||||
break;
|
||||
}
|
||||
if (amount.currency == pair.base && pair.quote.isNotEmpty) return pair.quote;
|
||||
if (amount.currency == pair.quote && pair.base.isNotEmpty) return pair.base;
|
||||
if (pair.quote.isNotEmpty) return pair.quote;
|
||||
if (pair.base.isNotEmpty) return pair.base;
|
||||
}
|
||||
return amount.currency;
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,17 @@ import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
|
||||
ScaffoldFeatureController<SnackBar, SnackBarClosedReason> notifyUserX(ScaffoldMessengerState sm, String message, { int delaySeconds = 3 })
|
||||
{
|
||||
ScaffoldFeatureController<SnackBar, SnackBarClosedReason> notifyUserX(
|
||||
ScaffoldMessengerState sm,
|
||||
String message, {
|
||||
int delaySeconds = 3,
|
||||
}) {
|
||||
final durationSeconds = _normalizeDelaySeconds(delaySeconds);
|
||||
sm.clearSnackBars();
|
||||
return sm.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(message),
|
||||
duration: Duration(seconds: delaySeconds),
|
||||
duration: Duration(seconds: durationSeconds),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -18,8 +23,10 @@ ScaffoldFeatureController<SnackBar, SnackBarClosedReason> notifyUser(BuildContex
|
||||
}
|
||||
|
||||
Future<ScaffoldFeatureController<SnackBar, SnackBarClosedReason>> postNotifyUser(
|
||||
BuildContext context, String message, {int delaySeconds = 3}) {
|
||||
|
||||
BuildContext context,
|
||||
String message, {
|
||||
int delaySeconds = 3,
|
||||
}) {
|
||||
final completer = Completer<ScaffoldFeatureController<SnackBar, SnackBarClosedReason>>();
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
@@ -29,3 +36,6 @@ Future<ScaffoldFeatureController<SnackBar, SnackBarClosedReason>> postNotifyUser
|
||||
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
int _normalizeDelaySeconds(int delaySeconds) =>
|
||||
delaySeconds <= 0 ? 3 : delaySeconds;
|
||||
|
||||
Reference in New Issue
Block a user