Skip to content

Commit

Permalink
add feature of 'import eth wallet'.
Browse files Browse the repository at this point in the history
  • Loading branch information
chenakam committed Aug 14, 2020
1 parent 51edcd2 commit 0901cd7
Show file tree
Hide file tree
Showing 22 changed files with 230 additions and 125 deletions.
52 changes: 32 additions & 20 deletions l10n-arb/intl_messages.arb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"@@last_modified": "2020-08-13T19:21:54.922077",
"@@last_modified": "2020-08-14T15:31:39.836984",
"nkn": "NKN",
"@nkn": {
"description": "",
Expand Down Expand Up @@ -522,12 +522,6 @@
"type": "text",
"placeholders": {}
},
"import_wallet": "Import Wallet",
"@import_wallet": {
"description": "",
"type": "text",
"placeholders": {}
},
"export_wallet": "Export Wallet",
"@export_wallet": {
"description": "",
Expand Down Expand Up @@ -684,7 +678,7 @@
"type": "text",
"placeholders": {}
},
"select_wallet_type_desc": "Select whether to create a NKN Mainnet wallet or an Ethereum based wallet to hold ERC-20 tokens. The two are not compatible.",
"select_wallet_type_desc": "Select whether to create/import a NKN Mainnet wallet or an Ethereum based wallet to hold ERC-20 tokens. The two are not compatible.",
"@select_wallet_type_desc": {
"description": "",
"type": "text",
Expand Down Expand Up @@ -1146,44 +1140,62 @@
"type": "text",
"placeholders": {}
},
"no_wallet_import": "Import Exisiting Wallet",
"no_wallet_import": "Import Existing Wallet",
"@no_wallet_import": {
"description": "",
"type": "text",
"placeholders": {}
},
"create_nkn_wallet_title": "CREATE MAINNET WALLET",
"@create_nkn_wallet_title": {
"import_wallet": "Import Wallet",
"@import_wallet": {
"description": "",
"type": "text",
"placeholders": {}
},
"create_nkn_wallet": "Create Mainnet Wallet",
"@create_nkn_wallet": {
"description": "",
"type": "text",
"placeholders": {}
},
"create_ethereum_wallet": "CREATE ETHEREUM WALLET",
"create_ethereum_wallet": "Create Ethereum Wallet",
"@create_ethereum_wallet": {
"description": "",
"type": "text",
"placeholders": {}
},
"import_keystore_nkn_wallet_title": "Import with Keystore",
"@import_keystore_nkn_wallet_title": {
"import_nkn_wallet": "Import Mainnet Wallet",
"@import_nkn_wallet": {
"description": "",
"type": "text",
"placeholders": {}
},
"import_ethereum_wallet": "Import Ethereum Wallet",
"@import_ethereum_wallet": {
"description": "",
"type": "text",
"placeholders": {}
},
"import_with_keystore_title": "Import with Keystore",
"@import_with_keystore_title": {
"description": "",
"type": "text",
"placeholders": {}
},
"import_keystore_nkn_wallet_desc": "From your existing wallet, find out how to export keystore as well as associated password, make a backup of both, and then use both to import your existing wallet into nMobile.",
"@import_keystore_nkn_wallet_desc": {
"import_with_keystore_desc": "From your existing wallet, find out how to export keystore as well as associated password, make a backup of both, and then use both to import your existing wallet into nMobile.",
"@import_with_keystore_desc": {
"description": "",
"type": "text",
"placeholders": {}
},
"import_seed_nkn_wallet_title": "Import with Seed",
"@import_seed_nkn_wallet_title": {
"import_with_seed_title": "Import with Seed",
"@import_with_seed_title": {
"description": "",
"type": "text",
"placeholders": {}
},
"import_seed_nkn_wallet_desc": "From your existing wallet, find out how to export Seed (also called \"Secret Seed\"), make a backup copy, and then use it to import your existing wallet into nMobile.",
"@import_seed_nkn_wallet_desc": {
"import_with_seed_desc": "From your existing wallet, find out how to export Seed (also called \"Secret Seed\"), make a backup copy, and then use it to import your existing wallet into nMobile.",
"@import_with_seed_desc": {
"description": "",
"type": "text",
"placeholders": {}
Expand Down
46 changes: 29 additions & 17 deletions l10n-arb/intl_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -498,12 +498,6 @@
"type": "text",
"placeholders": {}
},
"import_wallet": "导入钱包",
"@import_wallet": {
"description": "",
"type": "text",
"placeholders": {}
},
"export_wallet": "导出钱包",
"@export_wallet": {
"description": "",
Expand Down Expand Up @@ -660,7 +654,7 @@
"type": "text",
"placeholders": {}
},
"select_wallet_type_desc": "选择创建 NKN 主网钱包还是用来保存 NKN ERC-20 通证的以太坊钱包。两者是不兼容的。",
"select_wallet_type_desc": "选择创建或导入 NKN 主网钱包还是用来保存 NKN ERC-20 通证的以太坊钱包。两者是不兼容的。",
"@select_wallet_type_desc": {
"description": "",
"type": "text",
Expand Down Expand Up @@ -1128,8 +1122,14 @@
"type": "text",
"placeholders": {}
},
"create_nkn_wallet_title": "创建主网钱包",
"@create_nkn_wallet_title": {
"import_wallet": "导入钱包",
"@import_wallet": {
"description": "",
"type": "text",
"placeholders": {}
},
"create_nkn_wallet": "创建主网钱包",
"@create_nkn_wallet": {
"description": "",
"type": "text",
"placeholders": {}
Expand All @@ -1140,26 +1140,38 @@
"type": "text",
"placeholders": {}
},
"import_keystore_nkn_wallet_title": "使用Keystore导入",
"@import_keystore_nkn_wallet_title": {
"import_nkn_wallet": "导入主网钱包",
"@import_nkn_wallet": {
"description": "",
"type": "text",
"placeholders": {}
},
"import_ethereum_wallet": "导入以太坊钱包",
"@import_ethereum_wallet": {
"description": "",
"type": "text",
"placeholders": {}
},
"import_with_keystore_title": "使用Keystore导入",
"@import_with_keystore_title": {
"description": "",
"type": "text",
"placeholders": {}
},
"import_keystore_nkn_wallet_desc": "从已有的钱包中,找出如何导出keystore以及关联的密码,对二者进行备份,然后用其导入nMobile。",
"@import_keystore_nkn_wallet_desc": {
"import_with_keystore_desc": "从已有的钱包中,找出如何导出keystore以及关联的密码,对二者进行备份,然后用其导入nMobile。",
"@import_with_keystore_desc": {
"description": "",
"type": "text",
"placeholders": {}
},
"import_seed_nkn_wallet_title": "使用Seed导入",
"@import_seed_nkn_wallet_title": {
"import_with_seed_title": "使用Seed导入",
"@import_with_seed_title": {
"description": "",
"type": "text",
"placeholders": {}
},
"import_seed_nkn_wallet_desc": "从已有的钱包中,找出如何导出Seed(也称为“秘密种子”),对其进行备份,然后使用它导入nMobile。",
"@import_seed_nkn_wallet_desc": {
"import_with_seed_desc": "从已有的钱包中,找出如何导出Seed(也称为“秘密种子”),对其进行备份,然后使用它导入nMobile。",
"@import_with_seed_desc": {
"description": "",
"type": "text",
"placeholders": {}
Expand Down
2 changes: 1 addition & 1 deletion lib/components/dialog/select_wallet_type.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:nmobile/components/wallet/item.dart';
import 'package:nmobile/consts/colors.dart';
import 'package:nmobile/consts/theme.dart';
import 'package:nmobile/l10n/localization_intl.dart';
import 'package:nmobile/schemas/wallet.dart';
import 'package:nmobile/utils/extensions.dart';

class SelectWalletTypeDialog extends StatefulWidget {
Expand Down
2 changes: 1 addition & 1 deletion lib/components/header/header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Header extends StatelessWidget implements PreferredSizeWidget {
flex: 1,
child: (titleChild ??
Text(
title ?? '',
title?.toUpperCase() ?? '',
textAlign: TextAlign.start,
style: TextStyle(fontSize: DefaultTheme.labelFontSize),
overflow: TextOverflow.fade,
Expand Down
5 changes: 1 addition & 4 deletions lib/components/wallet/item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import 'package:nmobile/schemas/wallet.dart';
import 'package:nmobile/screens/wallet/nkn_wallet_detail.dart';
import 'package:nmobile/utils/extensions.dart';

enum WalletType { nkn, eth }

class WalletItem extends StatefulWidget {
final WalletSchema schema;
final int index;
Expand Down Expand Up @@ -101,8 +99,7 @@ class _WalletItemState extends State<WalletItem> {
alignment: Alignment.center,
padding: const EdgeInsets.only(left: 8, right: 8),
decoration: BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(8)), color: Color(0x1500CC96)),
child: Text(NL10ns.of(context).mainnet,
style: TextStyle(color: Color(0xFF00CC96), fontSize: 10, fontWeight: FontWeight.bold)),
child: Text(NL10ns.of(context).mainnet, style: TextStyle(color: Color(0xFF00CC96), fontSize: 10, fontWeight: FontWeight.bold)),
),
],
),
Expand Down
15 changes: 11 additions & 4 deletions lib/helpers/local_notification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Future _onDidReceiveLocalNotification(int id, String title, String body, String
class LocalNotification {
static FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
static int _notificationId = 0;
static int _notificationIdDebug = 1000;
static final _log = LOG('LocalNotification'.tag());

static init() async {
Expand All @@ -64,7 +65,7 @@ class LocalNotification {

var platformChannelSpecifics = NotificationDetails(null, iOSPlatformChannelSpecifics);
try {
await _flutterLocalNotificationsPlugin.show(_notificationId++, title, content, platformChannelSpecifics);
await _flutterLocalNotificationsPlugin.show(_notificationIdDebug++, title, content, platformChannelSpecifics);
} catch (e) {
debugPrint(e);
debugPrintStack();
Expand All @@ -91,14 +92,14 @@ class LocalNotification {
final nl10ns = Global.appContext != null ? NL10ns.of(Global.appContext) : null;
switch (Settings.localNotificationType) {
case LocalNotificationType.only_name:
await _flutterLocalNotificationsPlugin.show(_notificationId++, title, nl10ns?.you_have_new_message ?? ' ', platformChannelSpecifics);
await _flutterLocalNotificationsPlugin.show(_genNotificationId, title, nl10ns?.you_have_new_message ?? ' ', platformChannelSpecifics);
break;
case LocalNotificationType.name_and_message:
await _flutterLocalNotificationsPlugin.show(_notificationId++, title, content, platformChannelSpecifics);
await _flutterLocalNotificationsPlugin.show(_genNotificationId, title, content, platformChannelSpecifics);
break;
case LocalNotificationType.none:
await _flutterLocalNotificationsPlugin.show(
_notificationId++, nl10ns?.new_message ?? ' ', nl10ns?.you_have_new_message ?? ' ', platformChannelSpecifics);
_genNotificationId, nl10ns?.new_message ?? ' ', nl10ns?.you_have_new_message ?? ' ', platformChannelSpecifics);
break;
}
} catch (e) {
Expand All @@ -109,4 +110,10 @@ class LocalNotification {
static Future cancelAllNotifications() async {
await _flutterLocalNotificationsPlugin.cancelAll();
}

static get _genNotificationId {
_notificationId++;
if (_notificationId > 9) _notificationId = 1;
return _notificationId;
}
}
11 changes: 11 additions & 0 deletions lib/helpers/validation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:nmobile/helpers/utils.dart';
import 'package:nmobile/l10n/localization_intl.dart';
import 'package:nmobile/model/eth_erc20_token.dart';
import 'package:web3dart/credentials.dart';

class Validator {
Expand All @@ -29,6 +30,16 @@ class Validator {
};
}

keystoreEth() {
return (value) {
bool isValid = false;
try {
isValid = Ethereum.isKeystoreValid(value.trim());
} catch (e) {
}
return value.trim().length == 0 ? _localizations.error_required : !isValid ? _localizations.error_keystore_format : null;
};
}
seed() {
return (value) {
return value.trim().length == 0 ? _localizations.error_required : value.trim().length != 64 || !RegExp(r'^[0-9a-f]{64}$').hasMatch(value) ? _localizations.error_seed_format : null;
Expand Down
42 changes: 25 additions & 17 deletions lib/l10n/localization_intl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,6 @@ class NL10ns {
return Intl.message('Click to settings', name: 'click_to_settings', desc: '');
}

String get import_wallet {
return Intl.message('Import Wallet', name: 'import_wallet', desc: '');
}

String get export_wallet {
return Intl.message('Export Wallet', name: 'export_wallet', desc: '');
}
Expand Down Expand Up @@ -474,7 +470,7 @@ class NL10ns {
}

String get select_wallet_type_desc {
return Intl.message('Select whether to create a NKN Mainnet wallet or an Ethereum based wallet to hold ERC-20 tokens. The two are not compatible.',
return Intl.message('Select whether to create/import a NKN Mainnet wallet or an Ethereum based wallet to hold ERC-20 tokens. The two are not compatible.',
name: 'select_wallet_type_desc', desc: '',);
}

Expand Down Expand Up @@ -783,31 +779,43 @@ class NL10ns {
}

String get no_wallet_import {
return Intl.message('Import Exisiting Wallet', name: 'no_wallet_import', desc: '');
return Intl.message('Import Existing Wallet', name: 'no_wallet_import', desc: '');
}

String get import_wallet {
return Intl.message('Import Wallet', name: 'import_wallet', desc: '');
}

String get create_nkn_wallet_title {
return Intl.message('CREATE MAINNET WALLET', name: 'create_nkn_wallet_title', desc: '');
String get create_nkn_wallet {
return Intl.message('Create Mainnet Wallet', name: 'create_nkn_wallet', desc: '');
}

String get create_ethereum_wallet {
return Intl.message('CREATE ETHEREUM WALLET', name: 'create_ethereum_wallet', desc: '');
return Intl.message('Create Ethereum Wallet', name: 'create_ethereum_wallet', desc: '');
}

String get import_nkn_wallet {
return Intl.message('Import Mainnet Wallet', name: 'import_nkn_wallet', desc: '');
}

String get import_ethereum_wallet {
return Intl.message('Import Ethereum Wallet', name: 'import_ethereum_wallet', desc: '');
}

String get import_keystore_nkn_wallet_title {
return Intl.message('Import with Keystore', name: 'import_keystore_nkn_wallet_title', desc: '');
String get import_with_keystore_title {
return Intl.message('Import with Keystore', name: 'import_with_keystore_title', desc: '');
}

String get import_keystore_nkn_wallet_desc {
return Intl.message('From your existing wallet, find out how to export keystore as well as associated password, make a backup of both, and then use both to import your existing wallet into nMobile.', name: 'import_keystore_nkn_wallet_desc', desc: '');
String get import_with_keystore_desc {
return Intl.message('From your existing wallet, find out how to export keystore as well as associated password, make a backup of both, and then use both to import your existing wallet into nMobile.', name: 'import_with_keystore_desc', desc: '');
}

String get import_seed_nkn_wallet_title {
return Intl.message('Import with Seed', name: 'import_seed_nkn_wallet_title', desc: '');
String get import_with_seed_title {
return Intl.message('Import with Seed', name: 'import_with_seed_title', desc: '');
}

String get import_seed_nkn_wallet_desc {
return Intl.message('From your existing wallet, find out how to export Seed (also called "Secret Seed"), make a backup copy, and then use it to import your existing wallet into nMobile.', name: 'import_seed_nkn_wallet_desc', desc: '');
String get import_with_seed_desc {
return Intl.message('From your existing wallet, find out how to export Seed (also called "Secret Seed"), make a backup copy, and then use it to import your existing wallet into nMobile.', name: 'import_with_seed_desc', desc: '');
}

String get error_required {
Expand Down
Loading

0 comments on commit 0901cd7

Please sign in to comment.