mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-11-16 17:27:37 +00:00
CAKE-279 | applied order details to the app
This commit is contained in:
parent
313f829689
commit
60333e235d
16 changed files with 498 additions and 7 deletions
|
@ -27,6 +27,8 @@
|
|||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
<data android:scheme="cakewallet"/>
|
||||
<data android:host="wyre-trade-success"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
|
|
|
@ -1,15 +1,46 @@
|
|||
package com.cakewallet.cake_wallet;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import io.flutter.embedding.android.FlutterFragmentActivity;
|
||||
import io.flutter.embedding.engine.FlutterEngine;
|
||||
import io.flutter.plugin.common.BasicMessageChannel;
|
||||
import io.flutter.plugin.common.BinaryCodec;
|
||||
import io.flutter.plugins.GeneratedPluginRegistrant;
|
||||
|
||||
|
||||
public class MainActivity extends FlutterFragmentActivity {
|
||||
public static final int DATA_EXISTS = 1;
|
||||
public static final int DATA_NOT_EXISTS = 0;
|
||||
BasicMessageChannel<ByteBuffer> dataChannel;
|
||||
Handler handler = new Handler(Looper.getMainLooper());
|
||||
|
||||
@Override
|
||||
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
|
||||
GeneratedPluginRegistrant.registerWith(flutterEngine);
|
||||
|
||||
dataChannel = new BasicMessageChannel<ByteBuffer>(
|
||||
flutterEngine.getDartExecutor().getBinaryMessenger(),
|
||||
"data_change", BinaryCodec.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
ByteBuffer buffer = ByteBuffer.allocateDirect(4);
|
||||
if (data != null) {
|
||||
buffer.putInt(DATA_EXISTS);
|
||||
} else {
|
||||
buffer.putInt(DATA_NOT_EXISTS);
|
||||
}
|
||||
handler.post(() -> dataChannel.send(buffer));
|
||||
}
|
||||
}
|
BIN
assets/images/wyre-icon.png
Normal file
BIN
assets/images/wyre-icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
21
lib/di.dart
21
lib/di.dart
|
@ -4,6 +4,7 @@ import 'package:cake_wallet/core/wallet_service.dart';
|
|||
import 'package:cake_wallet/entities/biometric_auth.dart';
|
||||
import 'package:cake_wallet/entities/contact_record.dart';
|
||||
import 'package:cake_wallet/entities/load_current_wallet.dart';
|
||||
import 'package:cake_wallet/entities/order.dart';
|
||||
import 'package:cake_wallet/entities/transaction_description.dart';
|
||||
import 'package:cake_wallet/entities/transaction_info.dart';
|
||||
import 'package:cake_wallet/monero/monero_wallet_service.dart';
|
||||
|
@ -22,6 +23,7 @@ import 'package:cake_wallet/src/screens/faq/faq_page.dart';
|
|||
import 'package:cake_wallet/src/screens/new_wallet/new_wallet_type_page.dart';
|
||||
import 'package:cake_wallet/src/screens/nodes/node_create_or_edit_page.dart';
|
||||
import 'package:cake_wallet/src/screens/nodes/nodes_list_page.dart';
|
||||
import 'package:cake_wallet/src/screens/order_details/order_details_page.dart';
|
||||
import 'package:cake_wallet/src/screens/pin_code/pin_code_widget.dart';
|
||||
import 'package:cake_wallet/src/screens/rescan/rescan_page.dart';
|
||||
import 'package:cake_wallet/src/screens/restore/restore_from_backup_page.dart';
|
||||
|
@ -39,6 +41,7 @@ import 'package:cake_wallet/src/screens/transaction_details/transaction_details_
|
|||
import 'package:cake_wallet/src/screens/wallet_keys/wallet_keys_page.dart';
|
||||
import 'package:cake_wallet/src/screens/exchange/exchange_page.dart';
|
||||
import 'package:cake_wallet/src/screens/exchange/exchange_template_page.dart';
|
||||
import 'package:cake_wallet/store/dashboard/orders_store.dart';
|
||||
import 'package:cake_wallet/store/node_list_store.dart';
|
||||
import 'package:cake_wallet/store/secret_store.dart';
|
||||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
|
@ -63,6 +66,7 @@ import 'package:cake_wallet/view_model/exchange/exchange_trade_view_model.dart';
|
|||
import 'package:cake_wallet/view_model/monero_account_list/account_list_item.dart';
|
||||
import 'package:cake_wallet/view_model/node_list/node_list_view_model.dart';
|
||||
import 'package:cake_wallet/view_model/node_list/node_create_or_edit_view_model.dart';
|
||||
import 'package:cake_wallet/view_model/order_details_view_model.dart';
|
||||
import 'package:cake_wallet/view_model/rescan_view_model.dart';
|
||||
import 'package:cake_wallet/view_model/restore_from_backup_view_model.dart';
|
||||
import 'package:cake_wallet/view_model/setup_pin_code_view_model.dart';
|
||||
|
@ -115,6 +119,7 @@ Box<Trade> _tradesSource;
|
|||
Box<Template> _templates;
|
||||
Box<ExchangeTemplate> _exchangeTemplates;
|
||||
Box<TransactionDescription> _transactionDescriptionBox;
|
||||
Box<Order> _ordersSource;
|
||||
|
||||
Future setup(
|
||||
{Box<WalletInfo> walletInfoSource,
|
||||
|
@ -123,7 +128,8 @@ Future setup(
|
|||
Box<Trade> tradesSource,
|
||||
Box<Template> templates,
|
||||
Box<ExchangeTemplate> exchangeTemplates,
|
||||
Box<TransactionDescription> transactionDescriptionBox}) async {
|
||||
Box<TransactionDescription> transactionDescriptionBox,
|
||||
Box<Order> ordersSource}) async {
|
||||
_walletInfoSource = walletInfoSource;
|
||||
_nodeSource = nodeSource;
|
||||
_contactSource = contactSource;
|
||||
|
@ -131,6 +137,7 @@ Future setup(
|
|||
_templates = templates;
|
||||
_exchangeTemplates = exchangeTemplates;
|
||||
_transactionDescriptionBox = transactionDescriptionBox;
|
||||
_ordersSource = ordersSource;
|
||||
|
||||
if (!_isSetupFinished) {
|
||||
getIt.registerSingletonAsync<SharedPreferences>(
|
||||
|
@ -157,6 +164,8 @@ Future setup(
|
|||
nodeListStore: getIt.get<NodeListStore>()));
|
||||
getIt.registerSingleton<TradesStore>(TradesStore(
|
||||
tradesSource: _tradesSource, settingsStore: getIt.get<SettingsStore>()));
|
||||
getIt.registerSingleton<OrdersStore>(OrdersStore(
|
||||
ordersSource: _ordersSource, settingsStore: getIt.get<SettingsStore>()));
|
||||
getIt.registerSingleton<TradeFilterStore>(TradeFilterStore());
|
||||
getIt.registerSingleton<TransactionFilterStore>(TransactionFilterStore());
|
||||
getIt.registerSingleton<FiatConversionStore>(FiatConversionStore());
|
||||
|
@ -219,7 +228,9 @@ Future setup(
|
|||
appStore: getIt.get<AppStore>(),
|
||||
tradesStore: getIt.get<TradesStore>(),
|
||||
tradeFilterStore: getIt.get<TradeFilterStore>(),
|
||||
transactionFilterStore: getIt.get<TransactionFilterStore>()));
|
||||
transactionFilterStore: getIt.get<TransactionFilterStore>(),
|
||||
ordersSource: _ordersSource,
|
||||
ordersStore: getIt.get<OrdersStore>()));
|
||||
|
||||
getIt.registerFactory<AuthService>(() => AuthService(
|
||||
secureStorage: getIt.get<FlutterSecureStorage>(),
|
||||
|
@ -482,6 +493,9 @@ Future setup(
|
|||
getIt.registerFactoryParam<TradeDetailsViewModel, Trade, void>((trade, _) =>
|
||||
TradeDetailsViewModel(tradeForDetails: trade, trades: _tradesSource));
|
||||
|
||||
getIt.registerFactoryParam<OrderDetailsViewModel, Order, void>((order, _) =>
|
||||
OrderDetailsViewModel(orderForDetails: order));
|
||||
|
||||
getIt.registerFactory(() => BackupService(
|
||||
getIt.get<FlutterSecureStorage>(),
|
||||
_walletInfoSource,
|
||||
|
@ -511,6 +525,9 @@ Future setup(
|
|||
getIt.registerFactoryParam<TradeDetailsPage, Trade, void>((Trade trade, _) =>
|
||||
TradeDetailsPage(getIt.get<TradeDetailsViewModel>(param1: trade)));
|
||||
|
||||
getIt.registerFactoryParam<OrderDetailsPage, Order, void>((Order order, _) =>
|
||||
OrderDetailsPage(getIt.get<OrderDetailsViewModel>(param1: order)));
|
||||
|
||||
getIt.registerFactory(() => SupportViewModel());
|
||||
|
||||
getIt.registerFactory(() => SupportPage(getIt.get<SupportViewModel>()));
|
||||
|
|
40
lib/entities/find_order_by_id.dart
Normal file
40
lib/entities/find_order_by_id.dart
Normal file
|
@ -0,0 +1,40 @@
|
|||
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()
|
||||
);
|
||||
}
|
55
lib/entities/order.dart
Normal file
55
lib/entities/order.dart
Normal file
|
@ -0,0 +1,55 @@
|
|||
import 'package:hive/hive.dart';
|
||||
import 'package:cake_wallet/exchange/trade_state.dart';
|
||||
import 'package:cake_wallet/entities/format_amount.dart';
|
||||
|
||||
part 'order.g.dart';
|
||||
|
||||
@HiveType(typeId: Order.typeId)
|
||||
class Order extends HiveObject {
|
||||
Order(
|
||||
{this.id,
|
||||
this.transferId,
|
||||
this.from,
|
||||
this.to,
|
||||
TradeState state,
|
||||
this.createdAt,
|
||||
this.amount,
|
||||
this.receiveAddress,
|
||||
this.walletId})
|
||||
: stateRaw = state?.raw;
|
||||
|
||||
static const typeId = 8;
|
||||
static const boxName = 'Orders';
|
||||
static const boxKey = 'ordersBoxKey';
|
||||
|
||||
@HiveField(0)
|
||||
String id;
|
||||
|
||||
@HiveField(1)
|
||||
String transferId;
|
||||
|
||||
@HiveField(2)
|
||||
String from;
|
||||
|
||||
@HiveField(3)
|
||||
String to;
|
||||
|
||||
@HiveField(4)
|
||||
String stateRaw;
|
||||
|
||||
TradeState get state => TradeState.deserialize(raw: stateRaw);
|
||||
|
||||
@HiveField(5)
|
||||
DateTime createdAt;
|
||||
|
||||
@HiveField(6)
|
||||
String amount;
|
||||
|
||||
@HiveField(7)
|
||||
String receiveAddress;
|
||||
|
||||
@HiveField(8)
|
||||
String walletId;
|
||||
|
||||
String amountFormatted() => formatAmount(amount);
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
import 'package:cake_wallet/entities/order.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
|
@ -69,11 +70,17 @@ Future<void> main() async {
|
|||
Hive.registerAdapter(ExchangeTemplateAdapter());
|
||||
}
|
||||
|
||||
if (!Hive.isAdapterRegistered(Order.typeId)) {
|
||||
Hive.registerAdapter(OrderAdapter());
|
||||
}
|
||||
|
||||
final secureStorage = FlutterSecureStorage();
|
||||
final transactionDescriptionsBoxKey = await getEncryptionKey(
|
||||
secureStorage: secureStorage, forKey: TransactionDescription.boxKey);
|
||||
final tradesBoxKey = await getEncryptionKey(
|
||||
secureStorage: secureStorage, forKey: Trade.boxKey);
|
||||
final ordersBoxKey = await getEncryptionKey(
|
||||
secureStorage: secureStorage, forKey: Order.boxKey);
|
||||
final contacts = await Hive.openBox<Contact>(Contact.boxName);
|
||||
final nodes = await Hive.openBox<Node>(Node.boxName);
|
||||
final transactionDescriptions = await Hive.openBox<TransactionDescription>(
|
||||
|
@ -81,6 +88,8 @@ Future<void> main() async {
|
|||
encryptionKey: transactionDescriptionsBoxKey);
|
||||
final trades =
|
||||
await Hive.openBox<Trade>(Trade.boxName, encryptionKey: tradesBoxKey);
|
||||
final orders =
|
||||
await Hive.openBox<Order>(Order.boxName, encryptionKey: ordersBoxKey);
|
||||
final walletInfoSource = await Hive.openBox<WalletInfo>(WalletInfo.boxName);
|
||||
final templates = await Hive.openBox<Template>(Template.boxName);
|
||||
final exchangeTemplates =
|
||||
|
@ -91,6 +100,7 @@ Future<void> main() async {
|
|||
walletInfoSource: walletInfoSource,
|
||||
contactSource: contacts,
|
||||
tradesSource: trades,
|
||||
ordersSource: orders,
|
||||
// fiatConvertationService: fiatConvertationService,
|
||||
templates: templates,
|
||||
exchangeTemplates: exchangeTemplates,
|
||||
|
@ -118,6 +128,7 @@ Future<void> initialSetup(
|
|||
@required Box<WalletInfo> walletInfoSource,
|
||||
@required Box<Contact> contactSource,
|
||||
@required Box<Trade> tradesSource,
|
||||
@required Box<Order> ordersSource,
|
||||
// @required FiatConvertationService fiatConvertationService,
|
||||
@required Box<Template> templates,
|
||||
@required Box<ExchangeTemplate> exchangeTemplates,
|
||||
|
@ -139,7 +150,8 @@ Future<void> initialSetup(
|
|||
tradesSource: tradesSource,
|
||||
templates: templates,
|
||||
exchangeTemplates: exchangeTemplates,
|
||||
transactionDescriptionBox: transactionDescriptions);
|
||||
transactionDescriptionBox: transactionDescriptions,
|
||||
ordersSource: ordersSource);
|
||||
await bootstrap(navigatorKey);
|
||||
monero_wallet.onStartup();
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import 'package:cake_wallet/entities/contact_record.dart';
|
||||
import 'package:cake_wallet/entities/order.dart';
|
||||
import 'package:cake_wallet/entities/transaction_description.dart';
|
||||
import 'package:cake_wallet/src/screens/backup/backup_page.dart';
|
||||
import 'package:cake_wallet/src/screens/backup/edit_backup_password_page.dart';
|
||||
import 'package:cake_wallet/src/screens/order_details/order_details_page.dart';
|
||||
import 'package:cake_wallet/src/screens/pin_code/pin_code_widget.dart';
|
||||
import 'package:cake_wallet/src/screens/restore/restore_from_backup_page.dart';
|
||||
import 'package:cake_wallet/src/screens/restore/wallet_restore_page.dart';
|
||||
|
@ -285,6 +287,11 @@ Route<dynamic> createRoute(RouteSettings settings) {
|
|||
builder: (_) =>
|
||||
getIt.get<TradeDetailsPage>(param1: settings.arguments as Trade));
|
||||
|
||||
case Routes.orderDetails:
|
||||
return MaterialPageRoute<void>(
|
||||
builder: (_) =>
|
||||
getIt.get<OrderDetailsPage>(param1: settings.arguments as Order));
|
||||
|
||||
case Routes.restoreWalletFromSeedDetails:
|
||||
final args = settings.arguments as List;
|
||||
final walletRestorationFromSeedVM =
|
||||
|
|
|
@ -52,4 +52,5 @@ class Routes {
|
|||
static const editBackupPassword = '/edit_backup_passowrd';
|
||||
static const restoreFromBackup = '/restore_from_backup';
|
||||
static const support = '/support';
|
||||
static const orderDetails = '/order_details';
|
||||
}
|
72
lib/src/screens/dashboard/widgets/order_row.dart
Normal file
72
lib/src/screens/dashboard/widgets/order_row.dart
Normal file
|
@ -0,0 +1,72 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class OrderRow extends StatelessWidget {
|
||||
OrderRow({
|
||||
@required this.onTap,
|
||||
this.from,
|
||||
this.to,
|
||||
this.createdAtFormattedDate,
|
||||
this.formattedAmount});
|
||||
final VoidCallback onTap;
|
||||
final String from;
|
||||
final String to;
|
||||
final String createdAtFormattedDate;
|
||||
final String formattedAmount;
|
||||
final wyreImage =
|
||||
Image.asset('assets/images/wyre-icon.png', width: 36, height: 36);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
padding: EdgeInsets.fromLTRB(24, 8, 24, 8),
|
||||
color: Colors.transparent,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
wyreImage,
|
||||
SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: <Widget>[
|
||||
Text('$from → $to',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).accentTextTheme.
|
||||
display3.backgroundColor
|
||||
)),
|
||||
formattedAmount != null
|
||||
? Text(formattedAmount + ' ' + to,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).accentTextTheme.
|
||||
display3.backgroundColor
|
||||
))
|
||||
: Container()
|
||||
]),
|
||||
SizedBox(height: 5),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: <Widget>[
|
||||
Text(createdAtFormattedDate,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Theme.of(context).textTheme
|
||||
.overline.backgroundColor))
|
||||
])
|
||||
],
|
||||
)
|
||||
)
|
||||
],
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
|
@ -1,3 +1,5 @@
|
|||
import 'package:cake_wallet/src/screens/dashboard/widgets/order_row.dart';
|
||||
import 'package:cake_wallet/view_model/dashboard/order_list_item.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart';
|
||||
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||
|
@ -75,6 +77,21 @@ class TransactionsPage extends StatelessWidget {
|
|||
);
|
||||
}
|
||||
|
||||
if (item is OrderListItem) {
|
||||
final order = item.order;
|
||||
|
||||
return OrderRow(
|
||||
onTap: () => Navigator.of(context).pushNamed(
|
||||
Routes.orderDetails,
|
||||
arguments: order),
|
||||
from: order.from,
|
||||
to: order.to,
|
||||
createdAtFormattedDate:
|
||||
DateFormat('HH:mm').format(order.createdAt),
|
||||
formattedAmount: item.orderFormattedAmount,
|
||||
);
|
||||
}
|
||||
|
||||
return Container(
|
||||
color: Colors.transparent,
|
||||
height: 1);
|
||||
|
|
47
lib/src/screens/order_details/order_details_page.dart
Normal file
47
lib/src/screens/order_details/order_details_page.dart
Normal file
|
@ -0,0 +1,47 @@
|
|||
import 'package:cake_wallet/src/widgets/standard_list.dart';
|
||||
import 'package:cake_wallet/utils/show_bar.dart';
|
||||
import 'package:cake_wallet/view_model/order_details_view_model.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/src/screens/base_page.dart';
|
||||
import 'package:cake_wallet/src/widgets/standart_list_row.dart';
|
||||
import 'package:cake_wallet/src/screens/trade_details/track_trade_list_item.dart';
|
||||
|
||||
class OrderDetailsPage extends BasePage {
|
||||
OrderDetailsPage(this.orderDetailsViewModel);
|
||||
|
||||
@override
|
||||
String get title => 'Order Details';
|
||||
|
||||
final OrderDetailsViewModel orderDetailsViewModel;
|
||||
|
||||
@override
|
||||
Widget body(BuildContext context) {
|
||||
return Observer(builder: (_) {
|
||||
return SectionStandardList(
|
||||
sectionCount: 1,
|
||||
itemCounter: (int _) => orderDetailsViewModel.items.length,
|
||||
itemBuilder: (_, __, index) {
|
||||
final item = orderDetailsViewModel.items[index];
|
||||
|
||||
if (item is TrackTradeListItem) {
|
||||
return GestureDetector(
|
||||
onTap: item.onTap,
|
||||
child: StandartListRow(
|
||||
title: '${item.title}', value: '${item.value}'));
|
||||
} else {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
Clipboard.setData(ClipboardData(text: '${item.value}'));
|
||||
showBar<void>(context, S.of(context).copied_to_clipboard);
|
||||
},
|
||||
child: StandartListRow(
|
||||
title: '${item.title}', value: '${item.value}'));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
40
lib/store/dashboard/orders_store.dart
Normal file
40
lib/store/dashboard/orders_store.dart
Normal file
|
@ -0,0 +1,40 @@
|
|||
import 'dart:async';
|
||||
import 'package:cake_wallet/entities/order.dart';
|
||||
import 'package:cake_wallet/view_model/dashboard/order_list_item.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
|
||||
part 'orders_store.g.dart';
|
||||
|
||||
class OrdersStore = OrdersStoreBase with _$OrdersStore;
|
||||
|
||||
abstract class OrdersStoreBase with Store {
|
||||
OrdersStoreBase({this.ordersSource, this.settingsStore}) {
|
||||
orders = <OrderListItem>[];
|
||||
|
||||
_onOrdersChanged =
|
||||
ordersSource.watch().listen((_) async => await updateOrderList());
|
||||
|
||||
updateOrderList();
|
||||
}
|
||||
|
||||
Box<Order> ordersSource;
|
||||
StreamSubscription<BoxEvent> _onOrdersChanged;
|
||||
SettingsStore settingsStore;
|
||||
|
||||
@observable
|
||||
List<OrderListItem> orders;
|
||||
|
||||
@observable
|
||||
Order order;
|
||||
|
||||
@action
|
||||
void setOrder(Order order) => this.order = order;
|
||||
|
||||
@action
|
||||
Future updateOrderList() async => orders =
|
||||
ordersSource.values.map((order) => OrderListItem(
|
||||
order: order,
|
||||
displayMode: settingsStore.balanceDisplayMode)).toList();
|
||||
}
|
|
@ -4,7 +4,10 @@ import 'dart:io';
|
|||
import 'package:cake_wallet/bitcoin/bitcoin_transaction_info.dart';
|
||||
import 'package:cake_wallet/bitcoin/bitcoin_wallet.dart';
|
||||
import 'package:cake_wallet/entities/balance.dart';
|
||||
import 'package:cake_wallet/entities/find_order_by_id.dart';
|
||||
import 'package:cake_wallet/entities/order.dart';
|
||||
import 'package:cake_wallet/entities/transaction_history.dart';
|
||||
import 'package:cake_wallet/exchange/trade_state.dart';
|
||||
import 'package:cake_wallet/monero/account.dart';
|
||||
import 'package:cake_wallet/monero/monero_balance.dart';
|
||||
import 'package:cake_wallet/monero/monero_transaction_history.dart';
|
||||
|
@ -16,14 +19,18 @@ import 'package:cake_wallet/entities/transaction_direction.dart';
|
|||
import 'package:cake_wallet/entities/transaction_info.dart';
|
||||
import 'package:cake_wallet/exchange/exchange_provider_description.dart';
|
||||
import 'package:cake_wallet/exchange/trade.dart';
|
||||
import 'package:cake_wallet/store/dashboard/orders_store.dart';
|
||||
import 'package:cake_wallet/utils/mobx.dart';
|
||||
import 'package:cake_wallet/view_model/dashboard/balance_view_model.dart';
|
||||
import 'package:cake_wallet/view_model/dashboard/filter_item.dart';
|
||||
import 'package:cake_wallet/view_model/dashboard/order_list_item.dart';
|
||||
import 'package:cake_wallet/view_model/dashboard/trade_list_item.dart';
|
||||
import 'package:cake_wallet/view_model/dashboard/transaction_list_item.dart';
|
||||
import 'package:cake_wallet/view_model/dashboard/action_list_item.dart';
|
||||
import 'package:cake_wallet/view_model/dashboard/action_list_display_mode.dart';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/core/wallet_base.dart';
|
||||
|
@ -49,7 +56,9 @@ abstract class DashboardViewModelBase with Store {
|
|||
this.appStore,
|
||||
this.tradesStore,
|
||||
this.tradeFilterStore,
|
||||
this.transactionFilterStore}) {
|
||||
this.transactionFilterStore,
|
||||
this.ordersSource,
|
||||
this.ordersStore}) {
|
||||
filterItems = {
|
||||
S.current.transactions: [
|
||||
FilterItem(
|
||||
|
@ -135,8 +144,27 @@ abstract class DashboardViewModelBase with Store {
|
|||
|
||||
return true;
|
||||
});
|
||||
|
||||
dataChannel.setMessageHandler((ByteData message) async {
|
||||
final type = ByteData.view(message.buffer, 0, 4).getInt32(0);
|
||||
|
||||
switch (type) {
|
||||
case _dataExists:
|
||||
print('Wyre: Data exists');
|
||||
break;
|
||||
case _dataNotExists:
|
||||
print('Wyre: Data not exists');
|
||||
break;
|
||||
}
|
||||
|
||||
return ByteData(0);
|
||||
});
|
||||
}
|
||||
|
||||
static const dataChannel = BasicMessageChannel('data_change', BinaryCodec());
|
||||
static const _dataExists = 1;
|
||||
static const _dataNotExists = 0;
|
||||
|
||||
@observable
|
||||
WalletType type;
|
||||
|
||||
|
@ -179,6 +207,11 @@ abstract class DashboardViewModelBase with Store {
|
|||
.where((trade) => trade.trade.walletId == wallet.id)
|
||||
.toList();
|
||||
|
||||
@computed
|
||||
List<OrderListItem> get orders => ordersStore.orders
|
||||
.where((item) => item.order.walletId == wallet.id)
|
||||
.toList();
|
||||
|
||||
@computed
|
||||
double get price => balanceViewModel.price;
|
||||
|
||||
|
@ -188,6 +221,7 @@ abstract class DashboardViewModelBase with Store {
|
|||
|
||||
_items.addAll(transactionFilterStore.filtered(transactions: transactions));
|
||||
_items.addAll(tradeFilterStore.filtered(trades: trades, wallet: wallet));
|
||||
_items.addAll(orders);
|
||||
|
||||
return formattedItemsList(_items);
|
||||
}
|
||||
|
@ -197,12 +231,16 @@ abstract class DashboardViewModelBase with Store {
|
|||
|
||||
bool get hasRescan => wallet.type == WalletType.monero;
|
||||
|
||||
Box<Order> ordersSource;
|
||||
|
||||
BalanceViewModel balanceViewModel;
|
||||
|
||||
AppStore appStore;
|
||||
|
||||
TradesStore tradesStore;
|
||||
|
||||
OrdersStore ordersStore;
|
||||
|
||||
TradeFilterStore tradeFilterStore;
|
||||
|
||||
TransactionFilterStore transactionFilterStore;
|
||||
|
@ -296,10 +334,12 @@ abstract class DashboardViewModelBase with Store {
|
|||
final secretKey = secrets.wyre_secret_key;
|
||||
final accountId = secrets.wyre_account_id;
|
||||
final body = {
|
||||
'destCurrency' : walletTypeToCryptoCurrency(type).title,
|
||||
'dest' : walletTypeToString(type).toLowerCase() + ':' + address,
|
||||
//'destCurrency' : walletTypeToCryptoCurrency(type).title,
|
||||
//'dest' : walletTypeToString(type).toLowerCase() + ':' + address,
|
||||
'referrerAccountId' : accountId,
|
||||
'lockFields' : ['destCurrency', 'dest']
|
||||
'redirectUrl' : 'http://google.com'
|
||||
//'redirectUrl' : 'cakewallet://wyre-trade-success'
|
||||
//'lockFields' : ['destCurrency', 'dest']
|
||||
};
|
||||
|
||||
final response = await post(url,
|
||||
|
@ -315,6 +355,13 @@ abstract class DashboardViewModelBase with Store {
|
|||
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
||||
final urlFromResponse = responseJSON['url'] as String;
|
||||
if (await canLaunch(urlFromResponse)) await launch(urlFromResponse);
|
||||
|
||||
/*final orderId = '';
|
||||
final order = await findOrderById(orderId);
|
||||
order.receiveAddress = address;
|
||||
order.walletId = wallet.id;
|
||||
await ordersSource.add(order);
|
||||
ordersStore.setOrder(order);*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
21
lib/view_model/dashboard/order_list_item.dart
Normal file
21
lib/view_model/dashboard/order_list_item.dart
Normal file
|
@ -0,0 +1,21 @@
|
|||
import 'package:cake_wallet/entities/order.dart';
|
||||
import 'package:cake_wallet/view_model/dashboard/action_list_item.dart';
|
||||
import 'package:cake_wallet/entities/balance_display_mode.dart';
|
||||
|
||||
class OrderListItem extends ActionListItem {
|
||||
OrderListItem({this.order, this.displayMode});
|
||||
|
||||
final Order order;
|
||||
final BalanceDisplayMode displayMode;
|
||||
|
||||
String get orderFormattedAmount {
|
||||
return order.amount != null
|
||||
? displayMode == BalanceDisplayMode.hiddenBalance
|
||||
? '---'
|
||||
: order.amountFormatted()
|
||||
: order.amount;
|
||||
}
|
||||
|
||||
@override
|
||||
DateTime get date => order.createdAt;
|
||||
}
|
82
lib/view_model/order_details_view_model.dart
Normal file
82
lib/view_model/order_details_view_model.dart
Normal file
|
@ -0,0 +1,82 @@
|
|||
import 'dart:async';
|
||||
import 'package:cake_wallet/entities/find_order_by_id.dart';
|
||||
import 'package:cake_wallet/entities/order.dart';
|
||||
import 'package:cake_wallet/utils/date_formatter.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/src/screens/transaction_details/standart_list_item.dart';
|
||||
import 'package:cake_wallet/src/screens/trade_details/track_trade_list_item.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
part 'order_details_view_model.g.dart';
|
||||
|
||||
class OrderDetailsViewModel = OrderDetailsViewModelBase
|
||||
with _$OrderDetailsViewModel;
|
||||
|
||||
abstract class OrderDetailsViewModelBase with Store {
|
||||
OrderDetailsViewModelBase({Order orderForDetails}) {
|
||||
order = orderForDetails;
|
||||
|
||||
items = ObservableList<StandartListItem>();
|
||||
|
||||
_updateItems();
|
||||
|
||||
_updateOrder();
|
||||
|
||||
_timer = Timer.periodic(Duration(seconds: 20), (_) async => _updateOrder());
|
||||
}
|
||||
|
||||
@observable
|
||||
Order order;
|
||||
|
||||
@observable
|
||||
ObservableList<StandartListItem> items;
|
||||
|
||||
Timer _timer;
|
||||
|
||||
@action
|
||||
Future<void> _updateOrder() async {
|
||||
try {
|
||||
final updatedOrder = await findOrderById(order.id);
|
||||
|
||||
updatedOrder.receiveAddress = order.receiveAddress;
|
||||
updatedOrder.walletId = order.walletId;
|
||||
order = updatedOrder;
|
||||
|
||||
_updateItems();
|
||||
} catch (e) {
|
||||
print(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
void _updateItems() {
|
||||
final dateFormat = DateFormatter.withCurrentLocal();
|
||||
final buildURL =
|
||||
'https://dashboard-test.testwyre.com/track/${order.transferId}';
|
||||
|
||||
items?.clear();
|
||||
|
||||
items.addAll([
|
||||
StandartListItem(
|
||||
title: 'Transfer ID',
|
||||
value: order.transferId),
|
||||
StandartListItem(
|
||||
title: S.current.trade_details_state,
|
||||
value: order.state != null
|
||||
? order.state.toString()
|
||||
: S.current.trade_details_fetching),
|
||||
TrackTradeListItem(
|
||||
title: 'Track',
|
||||
value: buildURL,
|
||||
onTap: () {
|
||||
launch(buildURL);
|
||||
}),
|
||||
StandartListItem(
|
||||
title: S.current.trade_details_created_at,
|
||||
value: dateFormat.format(order.createdAt).toString()),
|
||||
StandartListItem(
|
||||
title: S.current.trade_details_pair,
|
||||
value: '${order.from} → ${order.to}')
|
||||
]);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue