179 lines
5.5 KiB
Dart
179 lines
5.5 KiB
Dart
class ShareCardConfig {
|
|
const ShareCardConfig({
|
|
required this.enabled,
|
|
required this.allowMainWallet,
|
|
required this.allowBonusWallet,
|
|
required this.allowTestWallet,
|
|
required this.allowWon,
|
|
required this.allowLost,
|
|
required this.allowRefunded,
|
|
required this.walletOpsEnabled,
|
|
required this.allowDeposit,
|
|
required this.allowWithdrawal,
|
|
required this.allowTransfer,
|
|
});
|
|
|
|
final bool enabled;
|
|
final bool allowMainWallet;
|
|
final bool allowBonusWallet;
|
|
final bool allowTestWallet;
|
|
final bool allowWon;
|
|
final bool allowLost;
|
|
final bool allowRefunded;
|
|
final bool walletOpsEnabled;
|
|
final bool allowDeposit;
|
|
final bool allowWithdrawal;
|
|
final bool allowTransfer;
|
|
|
|
factory ShareCardConfig.fromJson(Map<String, dynamic> json) {
|
|
return ShareCardConfig(
|
|
enabled: json['enabled'] == true,
|
|
allowMainWallet: json['allowMainWallet'] != false,
|
|
allowBonusWallet: json['allowBonusWallet'] != false,
|
|
allowTestWallet: json['allowTestWallet'] == true,
|
|
allowWon: json['allowWon'] != false,
|
|
allowLost: json['allowLost'] != false,
|
|
allowRefunded: json['allowRefunded'] != false,
|
|
walletOpsEnabled: json['walletOpsEnabled'] != false,
|
|
allowDeposit: json['allowDeposit'] != false,
|
|
allowWithdrawal: json['allowWithdrawal'] != false,
|
|
allowTransfer: json['allowTransfer'] != false,
|
|
);
|
|
}
|
|
|
|
bool isPredictionEligible({
|
|
required String? status,
|
|
required String? stakeAccountKind,
|
|
bool requireStatus = true,
|
|
}) {
|
|
if (!enabled) return false;
|
|
final kind = stakeAccountKind ?? 'main';
|
|
if (kind == 'main' && !allowMainWallet) return false;
|
|
if (kind == 'bonus' && !allowBonusWallet) return false;
|
|
if (kind == 'test' && !allowTestWallet) return false;
|
|
if (status == null || status.isEmpty) return !requireStatus;
|
|
if (status != 'won' && status != 'lost' && status != 'refunded') return false;
|
|
if (status == 'won' && !allowWon) return false;
|
|
if (status == 'lost' && !allowLost) return false;
|
|
if (status == 'refunded' && !allowRefunded) return false;
|
|
return true;
|
|
}
|
|
|
|
bool isWalletOpEligible(String operationType) {
|
|
if (!enabled || !walletOpsEnabled) return false;
|
|
switch (operationType) {
|
|
case 'deposit':
|
|
case 'bonus':
|
|
case 'admin_adjustment':
|
|
return allowDeposit;
|
|
case 'withdrawal':
|
|
return allowWithdrawal;
|
|
case 'transfer':
|
|
return allowTransfer;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// Backward-compatible alias.
|
|
bool isEligible({
|
|
required String? status,
|
|
required String? stakeAccountKind,
|
|
bool requireStatus = true,
|
|
}) =>
|
|
isPredictionEligible(
|
|
status: status,
|
|
stakeAccountKind: stakeAccountKind,
|
|
requireStatus: requireStatus,
|
|
);
|
|
}
|
|
|
|
class ShareCardPayload {
|
|
const ShareCardPayload({
|
|
required this.kind,
|
|
required this.verifyUrl,
|
|
this.betId,
|
|
this.gameName,
|
|
this.direction,
|
|
this.status,
|
|
this.resultSignedDisplay,
|
|
this.stakeDisplay,
|
|
this.intervalMinutes,
|
|
this.settledAt,
|
|
this.predictionMode,
|
|
this.isAuto = false,
|
|
this.sequence = const [],
|
|
this.transactionId,
|
|
this.operationType,
|
|
this.amountSignedDisplay,
|
|
this.amountDisplay,
|
|
this.assetSymbol,
|
|
this.assetName,
|
|
this.network,
|
|
this.createdAt,
|
|
this.txStatus,
|
|
});
|
|
|
|
final String kind; // prediction | wallet
|
|
final String verifyUrl;
|
|
|
|
// Prediction
|
|
final String? betId;
|
|
final String? gameName;
|
|
final String? direction;
|
|
final String? status;
|
|
final String? resultSignedDisplay;
|
|
final num? stakeDisplay;
|
|
final int? intervalMinutes;
|
|
final String? settledAt;
|
|
final String? predictionMode;
|
|
final bool isAuto;
|
|
final List<String> sequence;
|
|
|
|
// Wallet
|
|
final String? transactionId;
|
|
final String? operationType;
|
|
final String? amountSignedDisplay;
|
|
final String? amountDisplay;
|
|
final String? assetSymbol;
|
|
final String? assetName;
|
|
final String? network;
|
|
final String? createdAt;
|
|
final String? txStatus;
|
|
|
|
bool get isWallet => kind == 'wallet';
|
|
|
|
factory ShareCardPayload.fromJson(Map<String, dynamic> json) {
|
|
final kind = (json['kind'] ?? 'prediction').toString();
|
|
final seq = json['sequence'];
|
|
return ShareCardPayload(
|
|
kind: kind,
|
|
verifyUrl: (json['verifyUrl'] ?? '').toString(),
|
|
betId: json['betId']?.toString(),
|
|
gameName: (json['gameName'] ?? 'Candle Predict').toString(),
|
|
direction: (json['direction'] ?? 'long').toString(),
|
|
status: json['status']?.toString(),
|
|
resultSignedDisplay: json['resultSignedDisplay']?.toString(),
|
|
stakeDisplay: json['stakeDisplay'] is num
|
|
? json['stakeDisplay'] as num
|
|
: num.tryParse('${json['stakeDisplay']}'),
|
|
intervalMinutes: json['intervalMinutes'] is int
|
|
? json['intervalMinutes'] as int
|
|
: int.tryParse('${json['intervalMinutes']}'),
|
|
settledAt: json['settledAt']?.toString(),
|
|
predictionMode: (json['predictionMode'] ?? 'single').toString(),
|
|
isAuto: json['isAuto'] == true,
|
|
sequence: seq is List ? seq.map((e) => e.toString()).toList() : const <String>[],
|
|
transactionId: json['transactionId']?.toString(),
|
|
operationType: json['operationType']?.toString(),
|
|
amountSignedDisplay: json['amountSignedDisplay']?.toString(),
|
|
amountDisplay: json['amountDisplay']?.toString(),
|
|
assetSymbol: json['assetSymbol']?.toString(),
|
|
assetName: json['assetName']?.toString(),
|
|
network: json['network']?.toString(),
|
|
createdAt: json['createdAt']?.toString(),
|
|
txStatus: json['status']?.toString(),
|
|
);
|
|
}
|
|
}
|