mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-03 09:29:48 +00:00
- Add Linter rules for return types and final fields
- Enhance exception_handler code - Add ShareUtil to unify modification point
This commit is contained in:
parent
318e3b92e5
commit
8a45cb4dc7
7 changed files with 44 additions and 38 deletions
|
@ -18,6 +18,8 @@ analyzer:
|
||||||
linter:
|
linter:
|
||||||
rules:
|
rules:
|
||||||
- cancel_subscriptions
|
- cancel_subscriptions
|
||||||
|
- always_declare_return_types
|
||||||
|
- prefer_final_fields
|
||||||
|
|
||||||
|
|
||||||
# analyzer:
|
# analyzer:
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
import 'package:cake_wallet/src/screens/base_page.dart';
|
import 'package:cake_wallet/src/screens/base_page.dart';
|
||||||
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
|
|
||||||
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
|
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
|
||||||
import 'package:cake_wallet/src/widgets/keyboard_done_button.dart';
|
import 'package:cake_wallet/src/widgets/keyboard_done_button.dart';
|
||||||
import 'package:cake_wallet/src/widgets/primary_button.dart';
|
|
||||||
import 'package:cake_wallet/store/settings_store.dart';
|
|
||||||
import 'package:cake_wallet/themes/theme_base.dart';
|
import 'package:cake_wallet/themes/theme_base.dart';
|
||||||
|
import 'package:cake_wallet/utils/share_util.dart';
|
||||||
import 'package:cake_wallet/utils/show_pop_up.dart';
|
import 'package:cake_wallet/utils/show_pop_up.dart';
|
||||||
import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart';
|
import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
@ -15,7 +13,6 @@ import 'package:cake_wallet/generated/i18n.dart';
|
||||||
import 'package:flutter_mobx/flutter_mobx.dart';
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||||
import 'package:keyboard_actions/keyboard_actions.dart';
|
import 'package:keyboard_actions/keyboard_actions.dart';
|
||||||
import 'package:mobx/mobx.dart';
|
import 'package:mobx/mobx.dart';
|
||||||
import 'package:share_plus/share_plus.dart';
|
|
||||||
|
|
||||||
class AddressPage extends BasePage {
|
class AddressPage extends BasePage {
|
||||||
AddressPage({
|
AddressPage({
|
||||||
|
@ -101,11 +98,9 @@ class AddressPage extends BasePage {
|
||||||
splashColor: Colors.transparent,
|
splashColor: Colors.transparent,
|
||||||
iconSize: 25,
|
iconSize: 25,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
final box = context.findRenderObject() as RenderBox?;
|
ShareUtil.share(
|
||||||
|
text: addressListViewModel.address.address,
|
||||||
Share.share(
|
context: context,
|
||||||
addressListViewModel.address.address,
|
|
||||||
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
icon: shareImage,
|
icon: shareImage,
|
||||||
|
|
|
@ -305,7 +305,7 @@ class ExchangeTradeState extends State<ExchangeTradeForm> {
|
||||||
_effectsInstalled = true;
|
_effectsInstalled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
transactionStatePopup() {
|
void transactionStatePopup() {
|
||||||
showPopUp<void>(
|
showPopUp<void>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext popupContext) {
|
builder: (BuildContext popupContext) {
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
import 'package:cake_wallet/src/widgets/keyboard_done_button.dart';
|
import 'package:cake_wallet/src/widgets/keyboard_done_button.dart';
|
||||||
import 'package:cake_wallet/src/widgets/section_divider.dart';
|
import 'package:cake_wallet/src/widgets/section_divider.dart';
|
||||||
import 'package:cake_wallet/themes/theme_base.dart';
|
import 'package:cake_wallet/themes/theme_base.dart';
|
||||||
|
import 'package:cake_wallet/utils/share_util.dart';
|
||||||
import 'package:cake_wallet/utils/show_pop_up.dart';
|
import 'package:cake_wallet/utils/show_pop_up.dart';
|
||||||
import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart';
|
|
||||||
import 'package:cw_core/wallet_type.dart';
|
import 'package:cw_core/wallet_type.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
|
||||||
import 'package:flutter_mobx/flutter_mobx.dart';
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||||
import 'package:share_plus/share_plus.dart';
|
|
||||||
import 'package:cake_wallet/routes.dart';
|
import 'package:cake_wallet/routes.dart';
|
||||||
import 'package:cake_wallet/generated/i18n.dart';
|
import 'package:cake_wallet/generated/i18n.dart';
|
||||||
import 'package:cake_wallet/di.dart';
|
import 'package:cake_wallet/di.dart';
|
||||||
|
@ -102,11 +100,9 @@ class ReceivePage extends BasePage {
|
||||||
splashColor: Colors.transparent,
|
splashColor: Colors.transparent,
|
||||||
iconSize: 25,
|
iconSize: 25,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
final box = context.findRenderObject() as RenderBox?;
|
ShareUtil.share(
|
||||||
|
text: addressListViewModel.address.address,
|
||||||
Share.share(
|
context: context,
|
||||||
addressListViewModel.address.address,
|
|
||||||
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
icon: shareImage
|
icon: shareImage
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
import 'package:cake_wallet/palette.dart';
|
import 'package:cake_wallet/palette.dart';
|
||||||
import 'package:cake_wallet/themes/theme_base.dart';
|
import 'package:cake_wallet/themes/theme_base.dart';
|
||||||
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
|
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
|
||||||
|
import 'package:cake_wallet/utils/share_util.dart';
|
||||||
import 'package:cake_wallet/utils/show_bar.dart';
|
import 'package:cake_wallet/utils/show_bar.dart';
|
||||||
import 'package:cake_wallet/utils/show_pop_up.dart';
|
import 'package:cake_wallet/utils/show_pop_up.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:share_plus/share_plus.dart';
|
|
||||||
import 'package:flutter_mobx/flutter_mobx.dart';
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||||
import 'package:cake_wallet/generated/i18n.dart';
|
import 'package:cake_wallet/generated/i18n.dart';
|
||||||
import 'package:cake_wallet/src/widgets/primary_button.dart';
|
import 'package:cake_wallet/src/widgets/primary_button.dart';
|
||||||
|
@ -160,11 +159,9 @@ class WalletSeedPage extends BasePage {
|
||||||
padding: EdgeInsets.only(right: 8.0),
|
padding: EdgeInsets.only(right: 8.0),
|
||||||
child: PrimaryButton(
|
child: PrimaryButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
final box = context.findRenderObject() as RenderBox?;
|
ShareUtil.share(
|
||||||
|
text: walletSeedViewModel.seed,
|
||||||
Share.share(
|
context: context,
|
||||||
walletSeedViewModel.seed,
|
|
||||||
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
text: S.of(context).save,
|
text: S.of(context).save,
|
||||||
|
|
|
@ -14,6 +14,7 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
class ExceptionHandler {
|
class ExceptionHandler {
|
||||||
static bool _hasError = false;
|
static bool _hasError = false;
|
||||||
|
static const coolDownDurationInDays = 7;
|
||||||
|
|
||||||
static void _saveException(String? error, StackTrace? stackTrace) async {
|
static void _saveException(String? error, StackTrace? stackTrace) async {
|
||||||
final appDocDir = await getApplicationDocumentsDirectory();
|
final appDocDir = await getApplicationDocumentsDirectory();
|
||||||
|
@ -77,12 +78,11 @@ class ExceptionHandler {
|
||||||
|
|
||||||
final lastPopupDate =
|
final lastPopupDate =
|
||||||
DateTime.tryParse(sharedPrefs.getString(PreferencesKey.lastPopupDate) ?? '') ??
|
DateTime.tryParse(sharedPrefs.getString(PreferencesKey.lastPopupDate) ?? '') ??
|
||||||
DateTime.parse("2001-01-01");
|
DateTime.now().subtract(Duration(days: coolDownDurationInDays + 1));
|
||||||
|
|
||||||
final durationSinceLastReport = DateTime.now().difference(lastPopupDate).inDays;
|
final durationSinceLastReport = DateTime.now().difference(lastPopupDate).inDays;
|
||||||
|
|
||||||
// cool-down duration to be 7 days between reports
|
if (_hasError || durationSinceLastReport < coolDownDurationInDays) {
|
||||||
if (_hasError || durationSinceLastReport < 7) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_hasError = true;
|
_hasError = true;
|
||||||
|
@ -117,14 +117,17 @@ class ExceptionHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ignore User related errors or system errors
|
/// Ignore User related errors or system errors
|
||||||
static bool _ignoreError(String error) {
|
static bool _ignoreError(String error) =>
|
||||||
return error.contains("errno = 103") || // SocketException: Software caused connection abort
|
_ignoredErrors.any((element) => error.contains(element));
|
||||||
error.contains("errno = 9") || // SocketException: Bad file descriptor
|
|
||||||
error.contains("errno = 32") || // SocketException: Write failed (OS Error: Broken pipe)
|
static const List<String> _ignoredErrors = const [
|
||||||
error.contains("errno = 60") || // SocketException: Operation timed out
|
"errno = 103", // SocketException: Software caused connection abort
|
||||||
error.contains("errno = 54") || // SocketException: Connection reset by peer
|
"errno = 9", // SocketException: Bad file descriptor
|
||||||
error.contains("errno = 49") || // SocketException: Can't assign requested address
|
"errno = 32", // SocketException: Write failed (OS Error: Broken pipe)
|
||||||
error.contains("PERMISSION_NOT_GRANTED") ||
|
"errno = 60", // SocketException: Operation timed out
|
||||||
error.contains("errno = 28"); // OS Error: No space left on device
|
"errno = 54", // SocketException: Connection reset by peer
|
||||||
}
|
"errno = 49", // SocketException: Can't assign requested address
|
||||||
|
"errno = 28", // OS Error: No space left on device
|
||||||
|
"PERMISSION_NOT_GRANTED",
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
13
lib/utils/share_util.dart
Normal file
13
lib/utils/share_util.dart
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:share_plus/share_plus.dart';
|
||||||
|
|
||||||
|
class ShareUtil {
|
||||||
|
static void share({required String text, required BuildContext context}) {
|
||||||
|
final box = context.findRenderObject() as RenderBox?;
|
||||||
|
|
||||||
|
Share.share(
|
||||||
|
text,
|
||||||
|
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue