mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-27 04:56:02 +00:00
40 lines
1.3 KiB
Dart
40 lines
1.3 KiB
Dart
|
import 'dart:convert';
|
||
|
import 'package:cake_wallet/entities/order.dart';
|
||
|
import 'package:cake_wallet/exchange/trade_state.dart';
|
||
|
import 'package:http/http.dart';
|
||
|
|
||
|
Future<Order> findOrderById(String id) async {
|
||
|
final orderUrl = 'https://api.testwyre.com/v3/orders/' + id;
|
||
|
|
||
|
final orderResponse = await get(orderUrl);
|
||
|
|
||
|
final orderResponseJSON =
|
||
|
json.decode(orderResponse.body) as Map<String, dynamic>;
|
||
|
final transferId = orderResponseJSON['transferId'] as String;
|
||
|
final from = orderResponseJSON['sourceCurrency'] as String;
|
||
|
final to = orderResponseJSON['destCurrency'] as String;
|
||
|
final status = orderResponseJSON['status'] as String;
|
||
|
final state = TradeState.deserialize(raw: status.toLowerCase());
|
||
|
final createdAtRaw = orderResponseJSON['createdAt'] as int;
|
||
|
final createdAt =
|
||
|
DateTime.fromMillisecondsSinceEpoch(createdAtRaw).toLocal();
|
||
|
|
||
|
final transferUrl =
|
||
|
'https://api.testwyre.com/v2/transfer/' + transferId + '/track';
|
||
|
|
||
|
final transferResponse = await get(transferUrl);
|
||
|
|
||
|
final transferResponseJSON =
|
||
|
json.decode(transferResponse.body) as Map<String, dynamic>;
|
||
|
final amount = transferResponseJSON['destAmount'] as double;
|
||
|
|
||
|
return Order(
|
||
|
id: id,
|
||
|
transferId: transferId,
|
||
|
from: from,
|
||
|
to: to,
|
||
|
state: state,
|
||
|
createdAt: createdAt,
|
||
|
amount: amount.toString()
|
||
|
);
|
||
|
}
|