Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sia-demo): migrate to orderbook v2 #2495

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/mm2/mm2_api/mm2_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ class Mm2Api {

return OrderbookResponse(
request: request,
result: Orderbook.fromJson(json),
result: Orderbook.fromJson(json['result'] as Map<String, dynamic>),
);
} catch (e, s) {
log(
Expand Down
2 changes: 1 addition & 1 deletion lib/mm2/mm2_api/rpc/best_orders/best_orders.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? '',
);
}
Expand Down
7 changes: 5 additions & 2 deletions lib/mm2/mm2_api/rpc/orderbook/orderbook_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ class OrderbookRequest implements BaseRequest {

@override
Map<String, dynamic> toJson() => <String, dynamic>{
'mmrpc': '2.0',
'userpass': userpass,
'method': method,
'base': base,
'rel': rel,
'params': {
'base': base,
'rel': rel,
}
};
}
34 changes: 25 additions & 9 deletions lib/model/orderbook/order.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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']),
);
}

Expand All @@ -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;
Expand All @@ -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<String, dynamic> json) {
return Address(
addressData: json['address_data'],
addressType: json['address_type'],
);
}
}
16 changes: 8 additions & 8 deletions lib/model/orderbook/orderbook.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/views/dex/orderbook/orderbook_table_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class _OrderbookTableItemState extends State<OrderbookTableItem> {
@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
Expand Down
Loading