recharge_order.dart 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /// 链上充值父币种 — GET uc/coin-network/recharge-parents
  2. class RechargeParentCoin {
  3. final String name;
  4. final String nameCn;
  5. final String unit;
  6. final int status;
  7. final int canRecharge;
  8. final int sort;
  9. const RechargeParentCoin({
  10. required this.name,
  11. required this.nameCn,
  12. required this.unit,
  13. this.status = 0,
  14. this.canRecharge = 0,
  15. this.sort = 0,
  16. });
  17. factory RechargeParentCoin.fromJson(Map<String, dynamic> json) {
  18. return RechargeParentCoin(
  19. name: json['name']?.toString() ?? '',
  20. nameCn: json['nameCn']?.toString() ?? '',
  21. unit: json['unit']?.toString() ?? '',
  22. status: int.tryParse(json['status']?.toString() ?? '') ?? 0,
  23. canRecharge: int.tryParse(json['canRecharge']?.toString() ?? '') ?? 0,
  24. sort: int.tryParse(json['sort']?.toString() ?? '') ?? 0,
  25. );
  26. }
  27. }
  28. /// 充值主网 — GET uc/coin-network/recharge-networks
  29. class RechargeNetworkItem {
  30. final int id;
  31. final String name;
  32. final String protocol;
  33. final int? status;
  34. final int sort;
  35. const RechargeNetworkItem({
  36. required this.id,
  37. required this.name,
  38. required this.protocol,
  39. this.status,
  40. this.sort = 0,
  41. });
  42. factory RechargeNetworkItem.fromJson(Map<String, dynamic> json) {
  43. return RechargeNetworkItem(
  44. id: int.tryParse(json['id']?.toString() ?? '') ?? 0,
  45. name: json['name']?.toString() ?? '',
  46. protocol: json['protocol']?.toString() ?? '',
  47. status: json['status'] != null
  48. ? int.tryParse(json['status']?.toString() ?? '')
  49. : null,
  50. sort: int.tryParse(json['sort']?.toString() ?? '') ?? 0,
  51. );
  52. }
  53. }
  54. /// 某主网下 coin_network_config 一行 — GET uc/coin-network/recharge-configs
  55. class RechargeConfigOption {
  56. final int networkConfigId;
  57. final String coinName;
  58. final String coinNameCn;
  59. final int networkId;
  60. final String networkName;
  61. final String protocol;
  62. final String contractAddress;
  63. final String rechargeAddress;
  64. final int sort;
  65. const RechargeConfigOption({
  66. required this.networkConfigId,
  67. required this.coinName,
  68. required this.coinNameCn,
  69. required this.networkId,
  70. required this.networkName,
  71. required this.protocol,
  72. required this.contractAddress,
  73. required this.rechargeAddress,
  74. this.sort = 0,
  75. });
  76. factory RechargeConfigOption.fromJson(Map<String, dynamic> json) {
  77. final network = json['network'];
  78. return RechargeConfigOption(
  79. networkConfigId:
  80. int.tryParse(json['networkConfigId']?.toString() ?? json['id']?.toString() ?? '') ??
  81. 0,
  82. coinName: json['coinName']?.toString() ?? '',
  83. coinNameCn: json['coinNameCn']?.toString() ?? '',
  84. networkId: int.tryParse(json['networkId']?.toString() ??
  85. (network is Map ? network['id']?.toString() : null) ??
  86. '') ??
  87. 0,
  88. networkName: json['networkName']?.toString() ??
  89. (network is Map ? network['name']?.toString() : null) ??
  90. '',
  91. protocol: json['protocol']?.toString() ??
  92. (network is Map ? network['protocol']?.toString() : null) ??
  93. '',
  94. contractAddress: json['contractAddress']?.toString() ?? '',
  95. rechargeAddress: json['rechargeAddress']?.toString() ?? '',
  96. sort: int.tryParse(json['sort']?.toString() ?? '') ?? 0,
  97. );
  98. }
  99. bool get hasTokenContract => contractAddress.trim().isNotEmpty;
  100. }
  101. /// 扁平化后的充值网络选项(供钱包/EVM 工具使用,与 Web `RechargeFlatNetworkOption` 一致)
  102. class RechargeFlatNetworkOption {
  103. final String coinName;
  104. final String coinNameCn;
  105. final int networkConfigId;
  106. final int networkId;
  107. final String networkName;
  108. final String protocol;
  109. final String contractAddress;
  110. final String rechargeAddress;
  111. final int sort;
  112. const RechargeFlatNetworkOption({
  113. required this.coinName,
  114. required this.coinNameCn,
  115. required this.networkConfigId,
  116. required this.networkId,
  117. required this.networkName,
  118. required this.protocol,
  119. required this.contractAddress,
  120. required this.rechargeAddress,
  121. this.sort = 0,
  122. });
  123. factory RechargeFlatNetworkOption.fromConfig(RechargeConfigOption cfg) {
  124. return RechargeFlatNetworkOption(
  125. coinName: cfg.coinName,
  126. coinNameCn: cfg.coinNameCn,
  127. networkConfigId: cfg.networkConfigId,
  128. networkId: cfg.networkId,
  129. networkName: cfg.networkName,
  130. protocol: cfg.protocol,
  131. contractAddress: cfg.contractAddress,
  132. rechargeAddress: cfg.rechargeAddress,
  133. sort: cfg.sort,
  134. );
  135. }
  136. bool get hasTokenContract => contractAddress.trim().isNotEmpty;
  137. }
  138. /// 充值订单详情
  139. class RechargeOrderDetail {
  140. final int id;
  141. final String orderNo;
  142. final String coinName;
  143. final String networkName;
  144. final String rechargeAddress;
  145. final String amount;
  146. final String? txHash;
  147. final int status;
  148. final String createTime;
  149. const RechargeOrderDetail({
  150. this.id = 0,
  151. this.orderNo = '',
  152. this.coinName = '',
  153. this.networkName = '',
  154. this.rechargeAddress = '',
  155. this.amount = '0',
  156. this.txHash,
  157. this.status = 0,
  158. this.createTime = '',
  159. });
  160. factory RechargeOrderDetail.fromJson(Map<String, dynamic> json) {
  161. final th = json['txHash'];
  162. return RechargeOrderDetail(
  163. id: int.tryParse(json['id']?.toString() ?? '') ?? 0,
  164. orderNo: json['orderNo']?.toString() ?? '',
  165. coinName: json['coinName']?.toString() ?? '',
  166. networkName: json['networkName']?.toString() ?? '',
  167. rechargeAddress: json['rechargeAddress']?.toString() ?? '',
  168. amount: json['amount']?.toString() ?? '0',
  169. txHash: th != null && th.toString().isNotEmpty ? th.toString() : null,
  170. status: int.tryParse(json['status']?.toString() ?? '') ?? 0,
  171. createTime: json['createTime']?.toString() ?? '',
  172. );
  173. }
  174. bool get isPendingPayment => status == 0;
  175. }