transfer_pair.dart 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // 与 Web `stores/transfer.ts` 对齐的账户类型与划转组合规则。
  2. const kWalletSpot = 'SPOT';
  3. const kWalletSwap = 'SWAP';
  4. const kWalletFollow = 'FOLLOW';
  5. const kWalletSpotTrading = 'SPOT_TRADING';
  6. const kOtherWalletTypes = <String>[
  7. kWalletSwap,
  8. kWalletFollow,
  9. kWalletSpotTrading,
  10. ];
  11. const kSwapAccountIdx = 0;
  12. const kFollowAccountIdx = 1;
  13. const kSpotAccountIdx = 2;
  14. /// 有效组合:仅「资金↔合约/跟单」或「资金↔现货交易账户」,其余回退 SPOT↔SWAP。
  15. (String, String) normalizeTransferPair(String a, String b) {
  16. if (a == b) {
  17. return (kWalletSpot, kWalletSwap);
  18. }
  19. final isSpotTradingBridge =
  20. (a == kWalletSpot && b == kWalletSpotTrading) ||
  21. (a == kWalletSpotTrading && b == kWalletSpot);
  22. if (isSpotTradingBridge) {
  23. return (a, b);
  24. }
  25. final isFundingBridge = (a == kWalletSpot &&
  26. (b == kWalletSwap || b == kWalletFollow)) ||
  27. (b == kWalletSpot && (a == kWalletSwap || a == kWalletFollow));
  28. if (isFundingBridge) {
  29. return (a, b);
  30. }
  31. return (kWalletSpot, kWalletSwap);
  32. }
  33. bool involvesSpotTradingBridge(String from, String to) {
  34. return (from == kWalletSpot && to == kWalletSpotTrading) ||
  35. (from == kWalletSpotTrading && to == kWalletSpot);
  36. }
  37. int walletTypeToAccountIndex(String walletType) {
  38. switch (walletType) {
  39. case kWalletSwap:
  40. return kSwapAccountIdx;
  41. case kWalletFollow:
  42. return kFollowAccountIdx;
  43. case kWalletSpot:
  44. return kSpotAccountIdx;
  45. default:
  46. return -1;
  47. }
  48. }