Merge pull request #665 from cypherstack/ui-fixes

epic clean up
This commit is contained in:
Diego Salazar 2023-09-11 14:21:18 -06:00 committed by GitHub
commit 8bee18ab0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 219 additions and 270 deletions

View file

@ -340,6 +340,11 @@ class _WalletNetworkSettingsViewState
style: STextStyles.navBarTitle(context), style: STextStyles.navBarTitle(context),
), ),
actions: [ actions: [
if (ref
.read(walletsChangeNotifierProvider)
.getManager(widget.walletId)
.coin !=
Coin.epicCash)
Padding( Padding(
padding: const EdgeInsets.only( padding: const EdgeInsets.only(
top: 10, top: 10,
@ -381,7 +386,8 @@ class _WalletNetworkSettingsViewState
.extension<StackColors>()! .extension<StackColors>()!
.popupBG, .popupBG,
borderRadius: BorderRadius.circular( borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius), Constants
.size.circularBorderRadius),
// boxShadow: [CFColors.standardBoxShadow], // boxShadow: [CFColors.standardBoxShadow],
boxShadow: const [], boxShadow: const [],
), ),
@ -408,8 +414,8 @@ class _WalletNetworkSettingsViewState
color: Colors.transparent, color: Colors.transparent,
child: Text( child: Text(
"Rescan blockchain", "Rescan blockchain",
style: style: STextStyles.baseXS(
STextStyles.baseXS(context), context),
), ),
), ),
), ),
@ -786,11 +792,21 @@ class _WalletNetworkSettingsViewState
.select((value) => value.getManager(widget.walletId).coin)), .select((value) => value.getManager(widget.walletId).coin)),
popBackToRoute: WalletNetworkSettingsView.routeName, popBackToRoute: WalletNetworkSettingsView.routeName,
), ),
if (isDesktop) if (isDesktop &&
ref
.read(walletsChangeNotifierProvider)
.getManager(widget.walletId)
.coin !=
Coin.epicCash)
const SizedBox( const SizedBox(
height: 32, height: 32,
), ),
if (isDesktop) if (isDesktop &&
ref
.read(walletsChangeNotifierProvider)
.getManager(widget.walletId)
.coin !=
Coin.epicCash)
Padding( Padding(
padding: const EdgeInsets.only( padding: const EdgeInsets.only(
bottom: 12, bottom: 12,
@ -806,7 +822,12 @@ class _WalletNetworkSettingsViewState
], ],
), ),
), ),
if (isDesktop) if (isDesktop &&
ref
.read(walletsChangeNotifierProvider)
.getManager(widget.walletId)
.coin !=
Coin.epicCash)
RoundedWhiteContainer( RoundedWhiteContainer(
borderColor: isDesktop borderColor: isDesktop
? Theme.of(context).extension<StackColors>()!.background ? Theme.of(context).extension<StackColors>()!.background

View file

@ -1577,11 +1577,7 @@ class _TransactionDetailsViewState
), ),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat, floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
floatingActionButton: (coin == Coin.epicCash && floatingActionButton: (coin == Coin.epicCash &&
_transaction.isConfirmed( _transaction.getConfirmations(currentHeight) < 1 &&
currentHeight,
coin.requiredConfirmations,
) ==
false &&
_transaction.isCancelled == false) _transaction.isCancelled == false)
? ConditionalParent( ? ConditionalParent(
condition: isDesktop, condition: isDesktop,

View file

@ -421,26 +421,15 @@ class EpicCashWallet extends CoinServiceAPI
late SecureStorageInterface _secureStore; late SecureStorageInterface _secureStore;
Future<String> cancelPendingTransactionAndPost(String txSlateId) async {
String? result;
try {
result = await cancelPendingTransaction(txSlateId);
Logging.instance.log("result?: $result", level: LogLevel.Info);
} catch (e, s) {
Logging.instance.log("$e, $s", level: LogLevel.Error);
}
return result!;
}
//
/// returns an empty String on success, error message on failure /// returns an empty String on success, error message on failure
Future<String> cancelPendingTransaction(String txSlateId) async { Future<String> cancelPendingTransactionAndPost(String txSlateId) async {
final String wallet = try {
(await _secureStore.read(key: '${_walletId}_wallet'))!; final String wallet = (await _secureStore.read(
key: '${_walletId}_wallet',
))!;
String? result; final result = await m.protect(() async {
await m.protect(() async { return await compute(
result = await compute(
_cancelTransactionWrapper, _cancelTransactionWrapper,
Tuple2( Tuple2(
wallet, wallet,
@ -448,7 +437,15 @@ class EpicCashWallet extends CoinServiceAPI
), ),
); );
}); });
return result!; Logging.instance.log(
"cancel $txSlateId result: $result",
level: LogLevel.Info,
);
return result;
} catch (e, s) {
Logging.instance.log("$e, $s", level: LogLevel.Error);
return e.toString();
}
} }
@override @override
@ -667,25 +664,8 @@ class EpicCashWallet extends CoinServiceAPI
await epicUpdateLastScannedBlock(await getRestoreHeight()); await epicUpdateLastScannedBlock(await getRestoreHeight());
if (!await startScans()) { await _startScans();
refreshMutex = false;
GlobalEventBus.instance.fire(
NodeConnectionStatusChangedEvent(
NodeConnectionStatus.disconnected,
walletId,
coin,
),
);
GlobalEventBus.instance.fire(
WalletSyncStatusChangedEvent(
WalletSyncStatus.unableToSync,
walletId,
coin,
),
);
return;
}
await refresh();
GlobalEventBus.instance.fire( GlobalEventBus.instance.fire(
WalletSyncStatusChangedEvent( WalletSyncStatusChangedEvent(
WalletSyncStatus.synced, WalletSyncStatus.synced,
@ -694,12 +674,23 @@ class EpicCashWallet extends CoinServiceAPI
), ),
); );
} catch (e, s) { } catch (e, s) {
GlobalEventBus.instance.fire(
WalletSyncStatusChangedEvent(
WalletSyncStatus.unableToSync,
walletId,
coin,
),
);
Logging.instance.log(
"Exception rethrown from fullRescan(): $e\n$s",
level: LogLevel.Error,
printFullLength: true,
);
rethrow;
} finally {
refreshMutex = false; refreshMutex = false;
Logging.instance
.log("$e, $s", level: LogLevel.Error, printFullLength: true);
} }
refreshMutex = false;
return;
} }
@override @override
@ -1165,58 +1156,97 @@ class EpicCashWallet extends CoinServiceAPI
// TODO: refresh anything that needs to be refreshed/updated due to epicbox info changed // TODO: refresh anything that needs to be refreshed/updated due to epicbox info changed
} }
Future<bool> startScans() async { Future<void> _startScans() async {
try { try {
//First stop the current listener
if (ListenerManager.pointer != null) { if (ListenerManager.pointer != null) {
Logging.instance
.log("LISTENER HANDLER IS NOT NULL ....", level: LogLevel.Info);
Logging.instance
.log("STOPPING ANY WALLET LISTENER ....", level: LogLevel.Info);
epicboxListenerStop(ListenerManager.pointer!); epicboxListenerStop(ListenerManager.pointer!);
} }
final wallet = await _secureStore.read(key: '${_walletId}_wallet'); final wallet = await _secureStore.read(key: '${_walletId}_wallet');
var restoreHeight = epicGetRestoreHeight(); // max number of blocks to scan per loop iteration
var chainHeight = await this.chainHeight; const scanChunkSize = 10000;
if (epicGetLastScannedBlock() == null) {
await epicUpdateLastScannedBlock(await getRestoreHeight()); // force firing of scan progress event
}
int lastScannedBlock = epicGetLastScannedBlock()!;
const MAX_PER_LOOP = 10000;
await getSyncPercent; await getSyncPercent;
for (; lastScannedBlock < chainHeight;) {
chainHeight = await this.chainHeight; // fetch current chain height and last scanned block (should be the
lastScannedBlock = epicGetLastScannedBlock()!; // restore height if full rescan or a wallet restore)
int chainHeight = await this.chainHeight;
int lastScannedBlock =
epicGetLastScannedBlock() ?? await getRestoreHeight();
// loop while scanning in chain in chunks (of blocks?)
while (lastScannedBlock < chainHeight) {
Logging.instance.log( Logging.instance.log(
"chainHeight: $chainHeight, restoreHeight: $restoreHeight, lastScannedBlock: $lastScannedBlock", "chainHeight: $chainHeight, lastScannedBlock: $lastScannedBlock",
level: LogLevel.Info); level: LogLevel.Info,
int? nextScannedBlock; );
await m.protect(() async {
ReceivePort receivePort = await getIsolate({ final int nextScannedBlock = await m.protect(() async {
ReceivePort? receivePort;
try {
receivePort = await getIsolate({
"function": "scanOutPuts", "function": "scanOutPuts",
"wallet": wallet!, "wallet": wallet!,
"startHeight": lastScannedBlock, "startHeight": lastScannedBlock,
"numberOfBlocks": MAX_PER_LOOP, "numberOfBlocks": scanChunkSize,
}, name: walletName); }, name: walletName);
var message = await receivePort.first; // get response
final message = await receivePort.first;
// check for error message
if (message is String) { if (message is String) {
Logging.instance throw Exception("scanOutPuts isolate failed: $message");
.log("this is a string $message", level: LogLevel.Error);
stop(receivePort);
throw Exception("scanOutPuts isolate failed");
} }
nextScannedBlock = int.parse(message['outputs'] as String);
// attempt to grab next scanned block number
final nextScanned = int.tryParse(message['outputs'] as String);
if (nextScanned == null) {
throw Exception(
"scanOutPuts failed to parse next scanned block number from: $message",
);
}
return nextScanned;
} catch (_) {
rethrow;
} finally {
if (receivePort != null) {
// kill isolate
stop(receivePort); stop(receivePort);
Logging.instance }
.log('Closing scanOutPuts!\n $message', level: LogLevel.Info); }
}); });
await epicUpdateLastScannedBlock(nextScannedBlock!);
// update local cache
await epicUpdateLastScannedBlock(nextScannedBlock);
// force firing of scan progress event
await getSyncPercent; await getSyncPercent;
// update while loop condition variables
chainHeight = await this.chainHeight;
lastScannedBlock = nextScannedBlock;
} }
Logging.instance.log("successfully at the tip", level: LogLevel.Info);
Logging.instance.log(
"_startScans successfully at the tip",
level: LogLevel.Info,
);
//Once scanner completes restart listener
await listenToEpicbox(); await listenToEpicbox();
return true;
} catch (e, s) { } catch (e, s) {
Logging.instance.log("$e, $s", level: LogLevel.Warning); Logging.instance.log(
return false; "_startScans failed: $e\n$s",
level: LogLevel.Error,
);
rethrow;
} }
} }
@ -1496,24 +1526,7 @@ class EpicCashWallet extends CoinServiceAPI
final int curAdd = await setCurrentIndex(); final int curAdd = await setCurrentIndex();
await _getReceivingAddressForIndex(curAdd); await _getReceivingAddressForIndex(curAdd);
if (!await startScans()) { await _startScans();
refreshMutex = false;
GlobalEventBus.instance.fire(
NodeConnectionStatusChangedEvent(
NodeConnectionStatus.disconnected,
walletId,
coin,
),
);
GlobalEventBus.instance.fire(
WalletSyncStatusChangedEvent(
WalletSyncStatus.unableToSync,
walletId,
coin,
),
);
return;
}
unawaited(startSync()); unawaited(startSync());
@ -1687,26 +1700,13 @@ class EpicCashWallet extends CoinServiceAPI
final List<Tuple2<isar_models.Transaction, isar_models.Address?>> txnsData = final List<Tuple2<isar_models.Transaction, isar_models.Address?>> txnsData =
[]; [];
// int latestTxnBlockHeight =
// DB.instance.get<dynamic>(boxName: walletId, key: "storedTxnDataHeight")
// as int? ??
// 0;
final slatesToCommits = await getSlatesToCommits(); final slatesToCommits = await getSlatesToCommits();
for (var tx in jsonTransactions) { for (var tx in jsonTransactions) {
Logging.instance.log("tx: $tx", level: LogLevel.Info); Logging.instance.log("tx: $tx", level: LogLevel.Info);
// // TODO: does "confirmed" mean finalized? If so please remove this todo // // TODO: does "confirmed" mean finalized? If so please remove this todo
final isConfirmed = tx["confirmed"] as bool; final isConfirmed = tx["confirmed"] as bool;
// // TODO: since we are now caching tx history in hive are we losing anything by skipping here?
// // TODO: we can skip this filtering if it causes issues as the cache is later merged with updated data anyways
// // this would just make processing and updating cache more efficient
// if (txHeight > 0 &&
// txHeight < latestTxnBlockHeight - MINIMUM_CONFIRMATIONS &&
// isConfirmed) {
// continue;
// }
// Logging.instance.log("Transactions listed below");
// Logging.instance.log(jsonTransactions);
int amt = 0; int amt = 0;
if (tx["tx_type"] == "TxReceived" || if (tx["tx_type"] == "TxReceived" ||
tx["tx_type"] == "TxReceivedCancelled") { tx["tx_type"] == "TxReceivedCancelled") {
@ -1807,24 +1807,7 @@ class EpicCashWallet extends CoinServiceAPI
} }
} }
//
// midSortedTx["inputSize"] = tx["num_inputs"];
// midSortedTx["outputSize"] = tx["num_outputs"];
// midSortedTx["aliens"] = <dynamic>[];
// midSortedTx["inputs"] = <dynamic>[];
// midSortedTx["outputs"] = <dynamic>[];
// key id not used afaik?
// midSortedTx["key_id"] = tx["parent_key_id"];
// if (txHeight >= latestTxnBlockHeight) {
// latestTxnBlockHeight = txHeight;
// }
txnsData.add(Tuple2(txn, transactionAddress)); txnsData.add(Tuple2(txn, transactionAddress));
// cachedMap?.remove(tx["id"].toString());
// cachedMap?.remove(commitId);
// Logging.instance.log("cmap: $cachedMap", level: LogLevel.Info);
} }
await db.addNewTransactionData(txnsData, walletId); await db.addNewTransactionData(txnsData, walletId);
@ -1839,57 +1822,6 @@ class EpicCashWallet extends CoinServiceAPI
), ),
); );
} }
// midSortedArray
// .sort((a, b) => (b["timestamp"] as int) - (a["timestamp"] as int));
//
// final Map<String, dynamic> result = {"dateTimeChunks": <dynamic>[]};
// final dateArray = <dynamic>[];
//
// for (int i = 0; i < midSortedArray.length; i++) {
// final txObject = midSortedArray[i];
// final date = extractDateFromTimestamp(txObject["timestamp"] as int);
//
// final txTimeArray = [txObject["timestamp"], date];
//
// if (dateArray.contains(txTimeArray[1])) {
// result["dateTimeChunks"].forEach((dynamic chunk) {
// if (extractDateFromTimestamp(chunk["timestamp"] as int) ==
// txTimeArray[1]) {
// if (chunk["transactions"] == null) {
// chunk["transactions"] = <Map<String, dynamic>>[];
// }
// chunk["transactions"].add(txObject);
// }
// });
// } else {
// dateArray.add(txTimeArray[1]);
//
// final chunk = {
// "timestamp": txTimeArray[0],
// "transactions": [txObject],
// };sendAll
//
// // result["dateTimeChunks"].
// result["dateTimeChunks"].add(chunk);
// }
// }
// final transactionsMap =
// TransactionData.fromJson(result).getAllTransactions();
// if (cachedMap != null) {
// transactionsMap.addAll(cachedMap);
// }
//
// final txModel = TransactionData.fromMap(transactionsMap);
//
// await DB.instance.put<dynamic>(
// boxName: walletId,
// key: 'storedTxnDataHeight',
// value: latestTxnBlockHeight);
// await DB.instance.put<dynamic>(
// boxName: walletId, key: 'latest_tx_model', value: txModel);
//
// return txModel;
} }
@override @override