mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-22 06:28:39 +02:00
Fixes.
This commit is contained in:
@@ -67,8 +67,22 @@ final dates = {
|
||||
"2019-5": 1824671,
|
||||
"2019-6": 1847005,
|
||||
"2019-7": 1868590,
|
||||
"2019-8": 1888590,
|
||||
"2019-9": 1898590,
|
||||
"2019-8": 1890552,
|
||||
"2019-9": 1912212,
|
||||
"2019-10": 1932200,
|
||||
"2019-11": 1957040,
|
||||
"2019-12": 1978090,
|
||||
"2020-1": 2001290,
|
||||
"2020-2": 2022688,
|
||||
"2020-3": 2043987,
|
||||
"2020-4": 2066536,
|
||||
"2020-5": 2090797,
|
||||
"2020-6": 2111633,
|
||||
"2020-7": 2131433,
|
||||
"2020-8": 2153983,
|
||||
"2020-9": 2176466,
|
||||
"2020-10": 2198453,
|
||||
"2020-11": 2221803
|
||||
};
|
||||
|
||||
int getHeigthByDate({DateTime date}) {
|
||||
|
||||
@@ -19,7 +19,6 @@ import 'package:cake_wallet/entities/wallet_info.dart';
|
||||
import 'package:cake_wallet/entities/node.dart';
|
||||
import 'package:cake_wallet/entities/transaction_priority.dart';
|
||||
|
||||
|
||||
part 'monero_wallet.g.dart';
|
||||
|
||||
const moneroBlockSize = 1000;
|
||||
@@ -80,7 +79,7 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
|
||||
final MoneroAccountList accountList;
|
||||
|
||||
String _filename;
|
||||
SyncListner _listener;
|
||||
SyncListener _listener;
|
||||
ReactionDisposer _onAccountChangeReaction;
|
||||
int _cachedRefreshHeight;
|
||||
|
||||
@@ -96,6 +95,15 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
|
||||
address = subaddress.address;
|
||||
_setListeners();
|
||||
await transactionHistory.update();
|
||||
|
||||
if (walletInfo.isRecovery) {
|
||||
monero_wallet.setRecoveringFromSeed(isRecovery: walletInfo.isRecovery);
|
||||
|
||||
if (monero_wallet.getCurrentHeight() <= 1) {
|
||||
monero_wallet.setRefreshFromBlockHeight(
|
||||
height: walletInfo.restoreHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void close() {
|
||||
@@ -103,6 +111,24 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
|
||||
_onAccountChangeReaction?.reaction?.dispose();
|
||||
}
|
||||
|
||||
Future<bool> validate() async {
|
||||
await accountList.update();
|
||||
final accountListLength = accountList.accounts?.length ?? 0;
|
||||
|
||||
if (accountListLength <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
subaddressList.update(accountIndex: accountList.accounts.first.id);
|
||||
final subaddressListLength = subaddressList.subaddresses?.length ?? 0;
|
||||
|
||||
if (subaddressListLength <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> connectToNode({@required Node node}) async {
|
||||
try {
|
||||
@@ -275,8 +301,6 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
|
||||
return;
|
||||
}
|
||||
|
||||
syncStatus = SyncedSyncStatus();
|
||||
|
||||
if (walletInfo.isRecovery) {
|
||||
_askForUpdateTransactionHistory();
|
||||
_askForUpdateBalance();
|
||||
@@ -285,11 +309,19 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
|
||||
final currentHeight = getCurrentHeight();
|
||||
final nodeHeight = monero_wallet.getNodeHeightSync();
|
||||
|
||||
if (walletInfo.isRecovery &&
|
||||
(nodeHeight - currentHeight < moneroBlockSize)) {
|
||||
await setAsRecovered();
|
||||
if (nodeHeight - currentHeight < moneroBlockSize) {
|
||||
syncStatus = SyncedSyncStatus();
|
||||
|
||||
if (walletInfo.isRecovery) {
|
||||
await setAsRecovered();
|
||||
}
|
||||
}
|
||||
|
||||
// if (walletInfo.isRecovery &&
|
||||
// (nodeHeight - currentHeight < moneroBlockSize)) {
|
||||
// await setAsRecovered();
|
||||
// }
|
||||
|
||||
if (currentHeight - _cachedRefreshHeight > moneroBlockSize) {
|
||||
_cachedRefreshHeight = currentHeight;
|
||||
await save();
|
||||
|
||||
@@ -25,6 +25,11 @@ class MoneroRestoreWalletFromSeedCredentials extends WalletCredentials {
|
||||
final String mnemonic;
|
||||
}
|
||||
|
||||
class MoneroWalletLoadingException implements Exception {
|
||||
@override
|
||||
String toString() => 'The wallet is damaged.';
|
||||
}
|
||||
|
||||
class MoneroRestoreWalletFromKeysCredentials extends WalletCredentials {
|
||||
MoneroRestoreWalletFromKeysCredentials(
|
||||
{String name,
|
||||
@@ -88,11 +93,29 @@ class MoneroWalletService extends WalletService<
|
||||
Future<MoneroWallet> openWallet(String name, String password) async {
|
||||
try {
|
||||
final path = await pathForWallet(name: name, type: WalletType.monero);
|
||||
await monero_wallet_manager.openWalletAsync({'path': path, 'password': password});
|
||||
await monero_wallet_manager
|
||||
.openWalletAsync({'path': path, 'password': password});
|
||||
final walletInfo = walletInfoSource.values.firstWhere(
|
||||
(info) => info.id == WalletBase.idFor(name, WalletType.monero), orElse: () => null);
|
||||
(info) => info.id == WalletBase.idFor(name, WalletType.monero),
|
||||
orElse: () => null);
|
||||
final wallet = MoneroWallet(
|
||||
filename: monero_wallet.getFilename(), walletInfo: walletInfo);
|
||||
final isValid = await wallet.validate();
|
||||
|
||||
if (!isValid) {
|
||||
if (wallet.seed?.isNotEmpty ?? false) {
|
||||
// let restore from seed in this case;
|
||||
final seed = wallet.seed;
|
||||
final credentials = MoneroRestoreWalletFromSeedCredentials(
|
||||
name: name, password: password, mnemonic: seed, height: 2000000)
|
||||
..walletInfo = walletInfo;
|
||||
await remove(name);
|
||||
return restoreFromSeed(credentials);
|
||||
}
|
||||
|
||||
throw MoneroWalletLoadingException();
|
||||
}
|
||||
|
||||
await wallet.init();
|
||||
|
||||
return wallet;
|
||||
@@ -104,9 +127,15 @@ class MoneroWalletService extends WalletService<
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> remove(String wallet) async =>
|
||||
File(await pathForWalletDir(name: wallet, type: WalletType.bitcoin))
|
||||
.delete(recursive: true);
|
||||
Future<void> remove(String wallet) async {
|
||||
final path = await pathForWalletDir(name: wallet, type: WalletType.monero);
|
||||
final file = Directory(path);
|
||||
final isExist = file.existsSync();
|
||||
|
||||
if (isExist) {
|
||||
await file.delete(recursive: true);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<MoneroWallet> restoreFromKeys(
|
||||
|
||||
@@ -32,42 +32,41 @@ class AnnotatedEditableText extends EditableText {
|
||||
Color selectionColor,
|
||||
Color backgroundCursorColor,
|
||||
TextSelectionControls selectionControls,
|
||||
TextStyle textStyle = const TextStyle(
|
||||
color: Colors.black,
|
||||
backgroundColor: Colors.transparent,
|
||||
fontWeight: FontWeight.normal,
|
||||
fontSize: 16),
|
||||
@required this.words,
|
||||
}) : textAnnotations = words
|
||||
.map((word) => TextAnnotation(
|
||||
text: word,
|
||||
style: TextStyle(
|
||||
color: Colors.black,
|
||||
backgroundColor: Colors.transparent,
|
||||
fontWeight: FontWeight.normal,
|
||||
fontSize: 16)))
|
||||
.toList(),
|
||||
.map((word) => TextAnnotation(text: word, style: textStyle))
|
||||
.toList(),
|
||||
super(
|
||||
maxLines: null,
|
||||
key: key,
|
||||
focusNode: focusNode,
|
||||
controller: controller,
|
||||
cursorColor: cursorColor,
|
||||
style: style,
|
||||
keyboardType: TextInputType.text,
|
||||
autocorrect: false,
|
||||
autofocus: false,
|
||||
selectionColor: selectionColor,
|
||||
selectionControls: selectionControls,
|
||||
backgroundCursorColor: backgroundCursorColor,
|
||||
onChanged: onChanged,
|
||||
onSubmitted: onSubmitted,
|
||||
toolbarOptions: const ToolbarOptions(
|
||||
copy: true,
|
||||
cut: true,
|
||||
paste: true,
|
||||
selectAll: true,
|
||||
),
|
||||
enableSuggestions: false,
|
||||
enableInteractiveSelection: true,
|
||||
showSelectionHandles: true,
|
||||
showCursor: true,
|
||||
) {
|
||||
maxLines: null,
|
||||
key: key,
|
||||
focusNode: focusNode,
|
||||
controller: controller,
|
||||
cursorColor: cursorColor,
|
||||
style: style,
|
||||
keyboardType: TextInputType.text,
|
||||
autocorrect: false,
|
||||
autofocus: false,
|
||||
selectionColor: selectionColor,
|
||||
selectionControls: selectionControls,
|
||||
backgroundCursorColor: backgroundCursorColor,
|
||||
onChanged: onChanged,
|
||||
onSubmitted: onSubmitted,
|
||||
toolbarOptions: const ToolbarOptions(
|
||||
copy: true,
|
||||
cut: true,
|
||||
paste: true,
|
||||
selectAll: true,
|
||||
),
|
||||
enableSuggestions: false,
|
||||
enableInteractiveSelection: true,
|
||||
showSelectionHandles: true,
|
||||
showCursor: true,
|
||||
) {
|
||||
textAnnotations.add(TextAnnotation(
|
||||
text: ' ', style: TextStyle(backgroundColor: Colors.transparent)));
|
||||
}
|
||||
@@ -86,7 +85,7 @@ class AnnotatedEditableTextState extends EditableTextState {
|
||||
List<Annotation> getRanges() {
|
||||
final source = widget.textAnnotations
|
||||
.map((item) => range(item.text, textEditingValue.text)
|
||||
.map((range) => Annotation(style: item.style, range: range)))
|
||||
.map((range) => Annotation(style: item.style, range: range)))
|
||||
.expand((e) => e)
|
||||
.toList();
|
||||
final result = List<Annotation>();
|
||||
@@ -123,7 +122,7 @@ class AnnotatedEditableTextState extends EditableTextState {
|
||||
if (result.length > 0 && result.last.range.end < text.length) {
|
||||
result.add(Annotation(
|
||||
range: TextRange(start: result.last.range.end, end: text.length),
|
||||
style: TextStyle( backgroundColor: Colors.transparent)));
|
||||
style: TextStyle(backgroundColor: Colors.transparent)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -132,8 +131,8 @@ class AnnotatedEditableTextState extends EditableTextState {
|
||||
final result = List<TextRange>();
|
||||
|
||||
for (int index = source.indexOf(pattern);
|
||||
index >= 0;
|
||||
index = source.indexOf(pattern, index + 1)) {
|
||||
index >= 0;
|
||||
index = source.indexOf(pattern, index + 1)) {
|
||||
final start = index;
|
||||
final end = start + pattern.length;
|
||||
result.add(TextRange(start: start, end: end));
|
||||
@@ -152,10 +151,10 @@ class AnnotatedEditableTextState extends EditableTextState {
|
||||
style: widget.style,
|
||||
children: ranges
|
||||
.map((item) => TextSpan(
|
||||
style: item.style, text: item.range.textInside(text)))
|
||||
style: item.style, text: item.range.textInside(text)))
|
||||
.toList());
|
||||
}
|
||||
|
||||
return TextSpan(style: widget.style, text: text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,16 +78,22 @@ class SeedWidgetState extends State<SeedWidget> {
|
||||
Padding(
|
||||
padding: EdgeInsets.only(right: 40, top: 10),
|
||||
child: AnnotatedEditableText(
|
||||
cursorColor: Colors.green,
|
||||
backgroundCursorColor: Colors.blue,
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
color: Colors.red,
|
||||
fontWeight: FontWeight.normal,
|
||||
backgroundColor: Colors.transparent),
|
||||
focusNode: focusNode,
|
||||
controller: controller,
|
||||
words: words)),
|
||||
cursorColor: Colors.blue,
|
||||
backgroundCursorColor: Colors.blue,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: Colors.red,
|
||||
fontWeight: FontWeight.normal,
|
||||
backgroundColor: Colors.transparent),
|
||||
focusNode: focusNode,
|
||||
controller: controller,
|
||||
words: words,
|
||||
textStyle: TextStyle(
|
||||
color: Theme.of(context).primaryTextTheme.title.color,
|
||||
backgroundColor: Colors.transparent,
|
||||
fontWeight: FontWeight.normal,
|
||||
fontSize: 16),
|
||||
)),
|
||||
Positioned(
|
||||
top: 0,
|
||||
right: 0,
|
||||
|
||||
@@ -34,8 +34,8 @@ abstract class WalletCreationVMBase with Store {
|
||||
|
||||
Future<void> create({dynamic options}) async {
|
||||
try {
|
||||
name = await generateName();
|
||||
state = IsExecutingState();
|
||||
name = await generateName();
|
||||
final dirPath = await pathForWalletDir(name: name, type: type);
|
||||
final path = await pathForWallet(name: name, type: type);
|
||||
final credentials = getCredentials(options);
|
||||
|
||||
@@ -55,7 +55,8 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
|
||||
spendKey: spendKey,
|
||||
viewKey: viewKey,
|
||||
address: address,
|
||||
password: password);
|
||||
password: password,
|
||||
language: 'English');
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user