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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user