Merge branch 'main' into CW-247-Exchange-confirmation-screen-address-labels

This commit is contained in:
Serhii
2023-01-26 11:54:03 +02:00
35 changed files with 1603 additions and 95 deletions
+6 -2
View File
@@ -20,7 +20,9 @@ class LanguageService {
'hr': 'Hrvatski (Croatian)',
'it': 'Italiano (Italian)',
'th': 'ภาษาไทย (Thai)',
'ar': 'العربية (Arabic)'
'ar': 'العربية (Arabic)',
'tr': 'Türkçe (Turkish)',
'my': 'မြန်မာ (Burmese)',
};
static const Map<String, String> localeCountryCode = {
@@ -40,7 +42,9 @@ class LanguageService {
'hr': 'hrv',
'it': 'ita',
'th': 'tha',
'ar': 'sau'
'ar': 'sau',
'tr': 'tur',
'my': 'mmr',
};
static final list = <String, String> {};
+99 -12
View File
@@ -1,14 +1,22 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:isolate';
import 'package:cake_wallet/bitcoin/bitcoin.dart';
import 'package:cake_wallet/core/auth_service.dart';
import 'package:cake_wallet/entities/language_service.dart';
import 'package:cake_wallet/buy/order.dart';
import 'package:cake_wallet/entities/preferences_key.dart';
import 'package:cake_wallet/ionia/ionia_category.dart';
import 'package:cake_wallet/ionia/ionia_merchant.dart';
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
import 'package:cake_wallet/store/yat/yat_store.dart';
import 'package:cake_wallet/themes/theme_list.dart';
import 'package:cake_wallet/utils/show_pop_up.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_mailer/flutter_mailer.dart';
import 'package:hive/hive.dart';
import 'package:cake_wallet/di.dart';
import 'package:path_provider/path_provider.dart';
@@ -44,9 +52,22 @@ final rootKey = GlobalKey<RootState>();
final RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>();
Future<void> main() async {
try {
await runZonedGuarded(() async {
WidgetsFlutterBinding.ensureInitialized();
FlutterError.onError = (errorDetails) {
_onError(errorDetails);
};
/// A callback that is invoked when an unhandled error occurs in the root
/// isolate.
PlatformDispatcher.instance.onError = (error, stack) {
_onError(FlutterErrorDetails(exception: error, stack: stack));
return true;
};
final appDir = await getApplicationDocumentsDirectory();
await Hive.close();
Hive.init(appDir.path);
@@ -132,20 +153,86 @@ Future<void> main() async {
secureStorage: secureStorage,
initialMigrationVersion: 19);
runApp(App());
} catch (e, stacktrace) {
runApp(MaterialApp(
debugShowCheckedModeBanner: true,
home: Scaffold(
body: Container(
margin:
EdgeInsets.only(top: 50, left: 20, right: 20, bottom: 20),
child: Text(
'Error:\n${e.toString()}\nStacktrace: $stacktrace',
style: TextStyle(fontSize: 22),
)))));
}, (error, stackTrace) async {
_onError(FlutterErrorDetails(exception: error, stack: stackTrace));
});
}
void _saveException(String? error, StackTrace? stackTrace) async {
final appDocDir = await getApplicationDocumentsDirectory();
final file = File('${appDocDir.path}/error.txt');
final exception = {
"${DateTime.now()}": {
"Error": error,
"StackTrace": stackTrace.toString(),
}
};
const String separator =
'''\n\n==========================================================
==========================================================\n\n''';
await file.writeAsString(
jsonEncode(exception) + separator,
mode: FileMode.append,
);
}
void _sendExceptionFile() async {
try {
final appDocDir = await getApplicationDocumentsDirectory();
final file = File('${appDocDir.path}/error.txt');
final MailOptions mailOptions = MailOptions(
subject: 'Mobile App Issue',
recipients: ['support@cakewallet.com'],
attachments: [file.path],
);
final result = await FlutterMailer.send(mailOptions);
// Clear file content if the error was sent or saved.
// On android we can't know if it was sent or saved
if (result.name == MailerResponse.sent.name ||
result.name == MailerResponse.saved.name ||
result.name == MailerResponse.android.name) {
file.writeAsString("", mode: FileMode.write);
}
} catch (e, s) {
_saveException(e.toString(), s);
}
}
void _onError(FlutterErrorDetails errorDetails) {
_saveException(errorDetails.exception.toString(), errorDetails.stack);
WidgetsBinding.instance.addPostFrameCallback(
(timeStamp) {
showPopUp<void>(
context: navigatorKey.currentContext!,
builder: (context) {
return AlertWithTwoActions(
isDividerExist: true,
alertTitle: S.of(context).error,
alertContent: S.of(context).error_dialog_content,
rightButtonText: S.of(context).send,
leftButtonText: S.of(context).do_not_send,
actionRightButton: () {
Navigator.of(context).pop();
_sendExceptionFile();
},
actionLeftButton: () {
Navigator.of(context).pop();
},
);
},
);
},
);
}
Future<void> initialSetup(
{required SharedPreferences sharedPreferences,
required Box<Node> nodes,
+15 -18
View File
@@ -9,11 +9,10 @@ import 'package:cake_wallet/src/screens/base_page.dart';
import 'package:cake_wallet/store/dashboard/orders_store.dart';
import 'package:cake_wallet/view_model/buy/buy_view_model.dart';
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
class BuyWebViewPage extends BasePage {
BuyWebViewPage({required this.buyViewModel,
required this.ordersStore, required this.url});
BuyWebViewPage({required this.buyViewModel, required this.ordersStore, required this.url});
final OrdersStore ordersStore;
final String url;
@@ -46,12 +45,12 @@ class BuyWebViewPageBody extends StatefulWidget {
class BuyWebViewPageBodyState extends State<BuyWebViewPageBody> {
BuyWebViewPageBodyState()
: _webViewkey = GlobalKey(),
_isSaving = false,
orderId = '';
: _webViewkey = GlobalKey(),
_isSaving = false,
orderId = '';
String orderId;
WebViewController? _webViewController;
InAppWebViewController? _webViewController;
GlobalKey _webViewkey;
Timer? _timer;
bool _isSaving;
@@ -63,8 +62,6 @@ class BuyWebViewPageBodyState extends State<BuyWebViewPageBody> {
_isSaving = false;
widget.ordersStore.orderId = '';
if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
if (widget.buyViewModel.selectedProvider is WyreBuyProvider) {
_saveOrder(keyword: 'completed', splitSymbol: '/');
}
@@ -76,31 +73,31 @@ class BuyWebViewPageBodyState extends State<BuyWebViewPageBody> {
@override
Widget build(BuildContext context) {
return WebView(
return InAppWebView(
key: _webViewkey,
initialUrl: widget.url,
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController controller) =>
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(transparentBackground: true),
),
initialUrlRequest: URLRequest(url: Uri.tryParse(widget.url ?? '')),
onWebViewCreated: (InAppWebViewController controller) =>
setState(() => _webViewController = controller));
}
void _saveOrder({required String keyword, required String splitSymbol}) {
_timer?.cancel();
_timer = Timer.periodic(Duration(seconds: 1), (timer) async {
try {
if (_webViewController == null || _isSaving) {
return;
}
final url = await _webViewController!.currentUrl();
final url = (await _webViewController!.getUrl())?.toString();
if (url == null) {
throw Exception('_saveOrder: Url is null');
}
if (url!.contains(keyword)) {
final urlParts = url!.split(splitSymbol);
if (url.contains(keyword)) {
final urlParts = url.split(splitSymbol);
orderId = urlParts.last;
widget.ordersStore.orderId = orderId;
+33 -31
View File
@@ -1,16 +1,14 @@
import 'dart:io';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/screens/base_page.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:cake_wallet/.secrets.g.dart' as secrets;
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:permission_handler/permission_handler.dart';
class OnRamperPage extends BasePage {
OnRamperPage({
required this.settingsStore,
required this.wallet});
OnRamperPage({required this.settingsStore, required this.wallet});
final SettingsStore settingsStore;
final WalletBase wallet;
@@ -25,22 +23,20 @@ class OnRamperPage extends BasePage {
settingsStore: settingsStore,
wallet: wallet,
darkMode: darkMode,
backgroundColor: darkMode
? backgroundDarkColor
: backgroundLightColor,
backgroundColor: darkMode ? backgroundDarkColor : backgroundLightColor,
supportSell: false,
supportSwap: false);
}
}
class OnRamperPageBody extends StatefulWidget {
OnRamperPageBody({
required this.settingsStore,
required this.wallet,
required this.darkMode,
required this.supportSell,
required this.supportSwap,
required this.backgroundColor});
OnRamperPageBody(
{required this.settingsStore,
required this.wallet,
required this.darkMode,
required this.supportSell,
required this.supportSwap,
required this.backgroundColor});
static const baseUrl = 'widget.onramper.com';
final SettingsStore settingsStore;
@@ -50,18 +46,15 @@ class OnRamperPageBody extends StatefulWidget {
final bool supportSell;
final bool supportSwap;
Uri get uri
=> Uri.https(
baseUrl,
'',
<String, dynamic>{
Uri get uri => Uri.https(baseUrl, '', <String, dynamic>{
'apiKey': secrets.onramperApiKey,
'defaultCrypto': wallet.currency.title,
'defaultFiat': settingsStore.fiatCurrency.title,
'wallets': '${wallet.currency.title}:${wallet.walletAddresses.address}',
'darkMode': darkMode.toString(),
'supportSell': supportSell.toString(),
'supportSwap': supportSwap.toString()});
'supportSwap': supportSwap.toString()
});
@override
OnRamperPageBodyState createState() => OnRamperPageBodyState();
@@ -70,17 +63,26 @@ class OnRamperPageBody extends StatefulWidget {
class OnRamperPageBodyState extends State<OnRamperPageBody> {
OnRamperPageBodyState();
@override
void initState() {
super.initState();
if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
}
@override
Widget build(BuildContext context) {
return WebView(
initialUrl: widget.uri.toString(),
backgroundColor: widget.backgroundColor,
javascriptMode: JavascriptMode.unrestricted);
return InAppWebView(
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(transparentBackground: true),
),
initialUrlRequest: URLRequest(url: widget.uri),
androidOnPermissionRequest: (_, __, resources) async {
bool permissionGranted = await Permission.camera.status == PermissionStatus.granted;
if (!permissionGranted) {
permissionGranted = await Permission.camera.request().isGranted;
}
return PermissionRequestResponse(
resources: resources,
action: permissionGranted
? PermissionRequestResponseAction.GRANT
: PermissionRequestResponseAction.DENY,
);
},
);
}
}
@@ -32,8 +32,8 @@ class IoniaCreateAccountPage extends BasePage {
final FocusNode _emailFocus;
final TextEditingController _emailController;
static const privacyPolicyUrl = 'https://ionia.docsend.com/view/jaqsmbq9w7dzvnqf';
static const termsAndConditionsUrl = 'https://ionia.docsend.com/view/hi9awnwxr6mqgiqj';
static const privacyPolicyUrl = 'https://ionia.docsend.com/view/jhjvdn7qq7k3ukwt';
static const termsAndConditionsUrl = 'https://ionia.docsend.com/view/uceirymz2ijacq5g';
@override
Widget middle(BuildContext context) {
@@ -1,9 +1,5 @@
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/palette.dart';
import 'package:cake_wallet/src/screens/nodes/widgets/node_indicator.dart';
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
import 'package:cake_wallet/src/widgets/standard_list.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class NodeListRow extends StandardListRow {
@@ -23,7 +19,7 @@ class NodeListRow extends StandardListRow {
builder: (context, snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.done:
return NodeIndicator(isLive: (snapshot.data as bool)??false);
return NodeIndicator(isLive: (snapshot.data as bool?) ?? false);
default:
return NodeIndicator(isLive: false);
}
@@ -40,7 +36,7 @@ class NodeHeaderListRow extends StandardListRow {
return SizedBox(
width: 20,
child: Icon(Icons.add,
color: Theme.of(context).accentTextTheme!.subtitle1!.color!, size: 24.0),
color: Theme.of(context).accentTextTheme.subtitle1?.color, size: 24.0),
);
}
}
+2 -1
View File
@@ -180,7 +180,8 @@ abstract class SendViewModelBase with Store {
WalletType get walletType => _wallet.type;
String? get walletCurrencyName => _wallet.currency.name?.toLowerCase();
String? get walletCurrencyName =>
_wallet.currency.fullName?.toLowerCase() ?? _wallet.currency.name;
bool get hasCurrecyChanger => walletType == WalletType.haven;