CAKE-279 | canceled changes in AndroidManifest.xml and MainActivity.java; added static constants to wyre_service.dart; moved WyreException class into own file; imported WyreService by di.dart

OleksandrSobol committed Mar 23, 2021 at 20:57 UTC 1cbbc71201ec147e738f87d0508f50fe60c1982b
6 files changed +29 -53
android/app/src/main/AndroidManifest.xml
-2
@@ -27,8 +27,6 @@
27 <intent-filter>
28 <action android:name="android.intent.action.MAIN"/>
29 <category android:name="android.intent.category.LAUNCHER"/>
30 - <data android:scheme="cakewallet"/>
31 - <data android:host="wyre-trade-success"/>
30 </intent-filter>
31 </activity>
32
android/app/src/main/java/com/cakewallet/cake_wallet/MainActivity.java
-31
@@ -1,46 +1,15 @@
1 package com.cakewallet.cake_wallet;
2
3 -import android.content.Intent;
4 -import android.os.Bundle;
5 -import android.os.Handler;
6 -import android.os.Looper;
7 -
3 import androidx.annotation.NonNull;
9 -import androidx.annotation.Nullable;
10 -
11 -import java.nio.ByteBuffer;
4
5 import io.flutter.embedding.android.FlutterFragmentActivity;
6 import io.flutter.embedding.engine.FlutterEngine;
15 -import io.flutter.plugin.common.BasicMessageChannel;
16 -import io.flutter.plugin.common.BinaryCodec;
7 import io.flutter.plugins.GeneratedPluginRegistrant;
8
9
10 public class MainActivity extends FlutterFragmentActivity {
21 - public static final int DATA_EXISTS = 1;
22 - public static final int DATA_NOT_EXISTS = 0;
23 - BasicMessageChannel<ByteBuffer> dataChannel;
24 - Handler handler = new Handler(Looper.getMainLooper());
25 -
11 @Override
12 public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
13 GeneratedPluginRegistrant.registerWith(flutterEngine);
29 -
30 - dataChannel = new BasicMessageChannel<ByteBuffer>(
31 - flutterEngine.getDartExecutor().getBinaryMessenger(),
32 - "data_change", BinaryCodec.INSTANCE);
33 - }
34 -
35 - @Override
36 - protected void onActivityResult(int requestCode, int resultCode, Intent data) {
37 - super.onActivityResult(requestCode, resultCode, data);
38 - ByteBuffer buffer = ByteBuffer.allocateDirect(4);
39 - if (data != null) {
40 - buffer.putInt(DATA_EXISTS);
41 - } else {
42 - buffer.putInt(DATA_NOT_EXISTS);
43 - }
44 - handler.post(() -> dataChannel.send(buffer));
14 }
15 }
\ No newline at end of file
lib/di.dart
+8 -1
@@ -7,6 +7,7 @@ import 'package:cake_wallet/entities/load_current_wallet.dart';
7 import 'package:cake_wallet/entities/order.dart';
8 import 'package:cake_wallet/entities/transaction_description.dart';
9 import 'package:cake_wallet/entities/transaction_info.dart';
10 +import 'package:cake_wallet/entities/wyre_service.dart';
11 import 'package:cake_wallet/monero/monero_wallet_service.dart';
12 import 'package:cake_wallet/entities/contact.dart';
13 import 'package:cake_wallet/entities/node.dart';
@@ -525,10 +526,16 @@ Future setup(
526 getIt.registerFactoryParam<TradeDetailsPage, Trade, void>((Trade trade, _) =>
527 TradeDetailsPage(getIt.get<TradeDetailsViewModel>(param1: trade)));
528
529 + getIt.registerFactory(() {
530 + final wallet = getIt.get<AppStore>().wallet;
531 + return WyreService(walletType: wallet.type, walletAddress: wallet.address);
532 + });
533 +
534 getIt.registerFactory(() {
535 final wallet = getIt.get<AppStore>().wallet;
536 return WyreViewModel(ordersSource, getIt.get<OrdersStore>(),
531 - walletId: wallet.id, address: wallet.address, type: wallet.type);
537 + walletId: wallet.id, address: wallet.address, type: wallet.type,
538 + wyreService: getIt.get<WyreService>());
539 });
540
541 getIt.registerFactoryParam<WyrePage, String, void>((String url, _) =>
lib/entities/wyre_exception.dart new
+8
@@ -0,0 +1,8 @@
1 +class WyreException implements Exception {
2 + WyreException(this.description);
3 +
4 + String description;
5 +
6 + @override
7 + String toString() => description;
8 +}
\ No newline at end of file
lib/entities/wyre_service.dart
+9 -13
@@ -1,4 +1,5 @@
1 import 'dart:convert';
2 +import 'package:cake_wallet/entities/wyre_exception.dart';
3 import 'package:cake_wallet/exchange/trade_state.dart';
4 import 'package:flutter/foundation.dart';
5 import 'package:http/http.dart';
@@ -12,13 +13,17 @@ class WyreService {
13 @required this.walletAddress,
14 this.isTestEnvironment = false}) {
15 baseApiUrl = isTestEnvironment
15 - ? 'https://api.testwyre.com'
16 - : 'https://api.sendwyre.com';
16 + ? _baseTestApiUrl
17 + : _baseProductApiUrl;
18 trackUrl = isTestEnvironment
18 - ? 'https://dash.testwyre.com/track/'
19 - : 'https://dash.sendwyre.com/track/';
19 + ? _trackTestUrl
20 + : _trackProductUrl;
21 }
22
23 + static const _baseTestApiUrl = 'https://api.testwyre.com';
24 + static const _baseProductApiUrl = 'https://api.sendwyre.com';
25 + static const _trackTestUrl = 'https://dash.testwyre.com/track/';
26 + static const _trackProductUrl = 'https://dash.sendwyre.com/track/';
27 static const _ordersSuffix = '/v3/orders';
28 static const _reserveSuffix = '/reserve';
29 static const _timeStampSuffix = '?timestamp=';
@@ -103,13 +108,4 @@ class WyreService {
108 amount: amount.toString()
109 );
110 }
106 -}
107 -
108 -class WyreException implements Exception {
109 - WyreException(this.description);
110 -
111 - String description;
112 -
113 - @override
114 - String toString() => description;
111 }
\ No newline at end of file
lib/view_model/wyre_view_model.dart
+4 -6
@@ -12,8 +12,8 @@ class WyreViewModel = WyreViewModelBase with _$WyreViewModel;
12
13 abstract class WyreViewModelBase with Store {
14 WyreViewModelBase(this.ordersSource, this.ordersStore,
15 - {@required this.walletId, @required this.address, @required this.type})
16 - : wyreService = WyreService(walletType: type, walletAddress: address);
15 + {@required this.walletId, @required this.address, @required this.type,
16 + @required this.wyreService});
17
18 Future<String> get wyreUrl => wyreService.getWyreUrl();
19
@@ -26,7 +26,7 @@ abstract class WyreViewModelBase with Store {
26 final WalletType type;
27 final String address;
28
29 - WyreService wyreService;
29 + final WyreService wyreService;
30
31 Future<void> saveOrder(String orderId) async {
32 try {
@@ -39,6 +39,4 @@ abstract class WyreViewModelBase with Store {
39 print(e.toString());
40 }
41 }
42 -
43 -
44 -}
42 +}
\ No newline at end of file