CAKE-278 | added expireAt to Trade() for exchange with fixed rate

OleksandrSobol committed Feb 22, 2021 at 18:04 UTC ae96213aadcc209b851a5f3ab37c42e8ca9762c6
1 file changed +29 -11
lib/exchange/changenow/changenow_exchange_provider.dart
+29 -11
@@ -153,17 +153,35 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
153 final state = TradeState.deserialize(raw: status);
154 final extraId = responseJSON['payinExtraId'] as String;
155 final outputTransaction = responseJSON['payoutHash'] as String;
156 -
157 - return Trade(
158 - id: id,
159 - from: from,
160 - to: to,
161 - provider: description,
162 - inputAddress: inputAddress,
163 - amount: expectedSendAmount,
164 - state: state,
165 - extraId: extraId,
166 - outputTransaction: outputTransaction);
156 + final expiredAtRaw = responseJSON['validUntil'] as String;
157 + final expiredAt = expiredAtRaw != null
158 + ? DateTime.parse(expiredAtRaw).toLocal()
159 + : null;
160 +
161 + if (expiredAt != null) {
162 + return Trade(
163 + id: id,
164 + from: from,
165 + to: to,
166 + provider: description,
167 + inputAddress: inputAddress,
168 + amount: expectedSendAmount,
169 + state: state,
170 + extraId: extraId,
171 + expiredAt: expiredAt,
172 + outputTransaction: outputTransaction);
173 + } else {
174 + return Trade(
175 + id: id,
176 + from: from,
177 + to: to,
178 + provider: description,
179 + inputAddress: inputAddress,
180 + amount: expectedSendAmount,
181 + state: state,
182 + extraId: extraId,
183 + outputTransaction: outputTransaction);
184 + }
185 }
186
187 @override