diff --git a/lib/mm2/mm2_api/mm2_api.dart b/lib/mm2/mm2_api/mm2_api.dart index 52c770b860..b2f6560f4b 100644 --- a/lib/mm2/mm2_api/mm2_api.dart +++ b/lib/mm2/mm2_api/mm2_api.dart @@ -789,7 +789,7 @@ class Mm2Api { return OrderbookResponse( request: request, - result: Orderbook.fromJson(json), + result: Orderbook.fromJson(json['result'] as Map), ); } catch (e, s) { log( diff --git a/lib/mm2/mm2_api/rpc/best_orders/best_orders.dart b/lib/mm2/mm2_api/rpc/best_orders/best_orders.dart index cade27c162..4e96bcb2bd 100644 --- a/lib/mm2/mm2_api/rpc/best_orders/best_orders.dart +++ b/lib/mm2/mm2_api/rpc/best_orders/best_orders.dart @@ -38,7 +38,7 @@ class BestOrder { maxVolume: order.maxVolume, minVolume: order.minVolume ?? Rational.zero, coin: coin ?? order.base, - address: order.address ?? '', + address: order.address?.addressData ?? '', uuid: order.uuid ?? '', ); } diff --git a/lib/mm2/mm2_api/rpc/orderbook/orderbook_request.dart b/lib/mm2/mm2_api/rpc/orderbook/orderbook_request.dart index d742cb063e..678a5dec17 100644 --- a/lib/mm2/mm2_api/rpc/orderbook/orderbook_request.dart +++ b/lib/mm2/mm2_api/rpc/orderbook/orderbook_request.dart @@ -15,9 +15,12 @@ class OrderbookRequest implements BaseRequest { @override Map toJson() => { + 'mmrpc': '2.0', 'userpass': userpass, 'method': method, - 'base': base, - 'rel': rel, + 'params': { + 'base': base, + 'rel': rel, + } }; } diff --git a/lib/model/orderbook/order.dart b/lib/model/orderbook/order.dart index f80b63c0dc..cf07107aa3 100644 --- a/lib/model/orderbook/order.dart +++ b/lib/model/orderbook/order.dart @@ -25,16 +25,18 @@ class Order { base: json['coin'], rel: otherCoin, direction: direction, - address: json['address'], + address: + json['address'] != null ? Address.fromJson(json['address']) : null, uuid: json['uuid'], pubkey: json['pubkey'], - price: fract2rat(json['price_fraction']) ?? Rational.parse(json['price']), - maxVolume: fract2rat(json['base_max_volume_fraction']) ?? - Rational.parse(json['base_max_volume']), - minVolume: fract2rat(json['base_min_volume_fraction']) ?? - Rational.parse(json['base_min_volume']), - minVolumeRel: fract2rat(json['rel_min_volume_fraction']) ?? - Rational.parse(json['rel_min_volume']), + price: fract2rat(json['price']['fraction']) ?? + Rational.parse(json['price']['rational']), + maxVolume: fract2rat(json['base_max_volume']['fraction']) ?? + Rational.parse(json['base_max_volume']['rational']), + minVolume: fract2rat(json['base_min_volume']['fraction']) ?? + Rational.parse(json['base_min_volume']['rational']), + minVolumeRel: fract2rat(json['rel_min_volume']['fraction']) ?? + Rational.parse(json['rel_min_volume']['rational']), ); } @@ -43,7 +45,7 @@ class Order { final OrderDirection direction; final Rational maxVolume; final Rational price; - final String? address; + final Address? address; final String? uuid; final String? pubkey; final Rational? minVolume; @@ -58,3 +60,17 @@ enum OrderDirection { bid, ask } // This const is used to identify and highlight newly created // order preview in maker form orderbook (instead of isTarget flag) final String orderPreviewUuid = const Uuid().v1(); + +class Address { + Address({required this.addressType, required this.addressData}); + + final String addressType; + final String addressData; + + factory Address.fromJson(Map json) { + return Address( + addressData: json['address_data'], + addressType: json['address_type'], + ); + } +} diff --git a/lib/model/orderbook/orderbook.dart b/lib/model/orderbook/orderbook.dart index 386ba0dcfb..3503e26add 100644 --- a/lib/model/orderbook/orderbook.dart +++ b/lib/model/orderbook/orderbook.dart @@ -33,14 +33,14 @@ class Orderbook { otherCoin: json['base'], )) .toList(), - bidsBaseVolTotal: fract2rat(json['total_bids_base_vol_fraction']) ?? - Rational.parse(json['total_bids_base_vol']), - bidsRelVolTotal: fract2rat(json['total_bids_rel_vol_fraction']) ?? - Rational.parse(json['total_bids_rel_vol']), - asksBaseVolTotal: fract2rat(json['total_asks_base_vol_fraction']) ?? - Rational.parse(json['total_asks_base_vol']), - asksRelVolTotal: fract2rat(json['total_asks_rel_vol_fraction']) ?? - Rational.parse(json['total_asks_rel_vol']), + bidsBaseVolTotal: fract2rat(json['total_bids_base_vol']['fraction']) ?? + Rational.parse(json['total_bids_base_vol']['rational']), + bidsRelVolTotal: fract2rat(json['total_bids_rel_vol']['fraction']) ?? + Rational.parse(json['total_bids_rel_vol']['rational']), + asksBaseVolTotal: fract2rat(json['total_asks_base_vol']['fraction']) ?? + Rational.parse(json['total_asks_base_vol']['rational']), + asksRelVolTotal: fract2rat(json['total_asks_rel_vol']['fraction']) ?? + Rational.parse(json['total_asks_rel_vol']['rational']), timestamp: json['timestamp'], ); } diff --git a/lib/views/dex/orderbook/orderbook_table_item.dart b/lib/views/dex/orderbook/orderbook_table_item.dart index af743b8d5e..a3ef1d1660 100644 --- a/lib/views/dex/orderbook/orderbook_table_item.dart +++ b/lib/views/dex/orderbook/orderbook_table_item.dart @@ -33,8 +33,8 @@ class _OrderbookTableItemState extends State { @override void initState() { _isPreview = widget.order.uuid == orderPreviewUuid; - _isTradeWithSelf = - widget.order.address == coinsBloc.getCoin(widget.order.rel)?.address; + _isTradeWithSelf = widget.order.address?.addressData == + coinsBloc.getCoin(widget.order.rel)?.address; _style = const TextStyle(fontSize: 11, fontWeight: FontWeight.w500); _color = _isPreview ? theme.custom.targetColor