Skip to content

Commit

Permalink
fix: avoid showing log when SocketException
Browse files Browse the repository at this point in the history
  • Loading branch information
gabaldon committed Nov 19, 2024
1 parent 9189326 commit 007cbfb
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 33 deletions.
54 changes: 31 additions & 23 deletions lib/auto_updater_overlay.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,38 @@ class AutoUpdateState extends State<AutoUpdate> {

@override
Widget build(BuildContext context) {
return UpdatWindowManager(
getLatestVersion: () async {
final data = await http.get(Uri.parse(
LATEST_RELEASE_URL,
));

// Return the tag name, which is always a semantically versioned string.
return jsonDecode(data.body)["tag_name"];
},
getBinaryUrl: (version) async {
return "$DOWNLOAD_BASE_URL/$version/$fileName";
},
appName: "myWitWallet", // This is used to name the downloaded files.
getChangelog: (_, __) async {
final data = await http.get(Uri.parse(
LATEST_RELEASE_URL,
));
return jsonDecode(data.body)["body"];
return FutureBuilder(
future: http.get(Uri.parse(
LATEST_RELEASE_URL,
)),
builder: (context, snapshot) {
if (snapshot.toString().contains(SOCKET_EXCEPTION)) {
return widget.child;
}
return UpdatWindowManager(
getLatestVersion: () async {
if (snapshot.hasData) {
return jsonDecode(snapshot.data!.body)["tag_name"];
}
return VERSION_NUMBER;
},
getBinaryUrl: (version) async {
return "$DOWNLOAD_BASE_URL/$version/$fileName";
},
appName: "myWitWallet", // This is used to name the downloaded files.
getChangelog: (_, __) async {
if (snapshot.hasData) {
return jsonDecode(snapshot.data!.body)["body"];
}
return '';
},
updateDialogBuilder: customDialog,
updateChipBuilder: customChip,
currentVersion: VERSION_NUMBER,
callback: (status) {},
child: widget.child,
);
},
updateDialogBuilder: customDialog,
updateChipBuilder: customChip,
currentVersion: VERSION_NUMBER,
callback: (status) {},
child: widget.child,
);
}
}
Expand Down
17 changes: 11 additions & 6 deletions lib/bloc/explorer/explorer_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ class ExplorerBloc extends Bloc<ExplorerEvent, ExplorerState> {
.setStats(walletId, savedStatsByAddress ?? statsByAddressToSave);
} catch (err) {
print('Error updating stats $err');
rethrow;
}
}

Expand Down Expand Up @@ -565,12 +566,16 @@ class ExplorerBloc extends Bloc<ExplorerEvent, ExplorerState> {
} else if (wallet.walletType == WalletType.single) {
List<Utxo> utxoList = await Locator.instance<ApiExplorer>()
.utxos(address: wallet.masterAccount!.address);

await _updateDBStatsFromExplorer(
currentWallet: wallet, database: database);
await syncWalletStorage(
utxos: {wallet.masterAccount!.address: utxoList}, wallet: wallet);
_updateWalletList(storage: storage, wallet: wallet);
try {
await _updateDBStatsFromExplorer(
currentWallet: wallet, database: database);
await syncWalletStorage(
utxos: {wallet.masterAccount!.address: utxoList}, wallet: wallet);
_updateWalletList(storage: storage, wallet: wallet);
} catch (err) {
print('Error syncing node wallet $err');
rethrow;
}
}

for (int i = 0; i < unconfirmedVtts.length; i++) {
Expand Down
1 change: 1 addition & 0 deletions lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ const int ENCRYPTED_XPRV_LENGTH = 293;
const int XPRV_LENGTH = 117;
const int MAX_VT_WEIGHT = 20000;
const double MAX_LAYOUT_WIDTH = 600;
const String SOCKET_EXCEPTION = 'SocketException';

List<LocalizationsDelegate<dynamic>> localizationDelegates = [
AppLocalizations.delegate,
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/dashboard/view/stats.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class BlockStatsState extends State<Stats> with TickerProviderStateMixin {
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox(height: 8),
SizedBox(height: 16),
Text(localization.networkContribution,
style: theme.textTheme.titleMedium),
SizedBox(height: 8),
Expand Down
1 change: 0 additions & 1 deletion lib/util/clear_and_redirect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:my_wit_wallet/widgets/layouts/dashboard_layout.dart';

void clearAndRedirectToDashboard(BuildContext context) {
BlocProvider.of<TransactionBloc>(context).add(ResetTransactionEvent());
ScaffoldMessenger.of(context).clearSnackBars();
Navigator.push(
context,
CustomPageRoute(
Expand Down
18 changes: 16 additions & 2 deletions lib/widgets/layouts/layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ class LayoutState extends State<Layout> with TickerProviderStateMixin {
panel.setCloseState();
}

String? getLogMessage(String? message) {
return (message != null && message.contains(SOCKET_EXCEPTION))
? null
: message;
}

BlocListener<TransactionBloc, TransactionState> _vttListener(Widget child) {
final theme = Theme.of(context);
final extendedTheme = theme.extension<ExtendedTheme>()!;
Expand Down Expand Up @@ -101,7 +107,7 @@ class LayoutState extends State<Layout> with TickerProviderStateMixin {
ScaffoldMessenger.of(context).showSnackBar(buildErrorSnackbar(
theme: theme,
text: localization.connectionIssue,
log: state.message,
log: getLogMessage(state.message),
color: theme.colorScheme.error));
} else if (state.transactionStatus == TransactionStatus.exception) {
ScaffoldMessenger.of(context).clearSnackBars();
Expand Down Expand Up @@ -141,15 +147,23 @@ class LayoutState extends State<Layout> with TickerProviderStateMixin {
},
));
}
print(
'CLEAR SNACKBARS?? ${currentState.status == ExplorerStatus.dataloaded && previousState.status != ExplorerStatus.error}');
if (currentState.status == ExplorerStatus.dataloaded &&
previousState.status != ExplorerStatus.error) {
ScaffoldMessenger.of(context).clearSnackBars();
}
return true;
},
listener: (context, state) {
print('state:: ${state}');
if (state.status == ExplorerStatus.error) {
ScaffoldMessenger.of(context).clearSnackBars();
print('*********** show snakcbar error*************');
ScaffoldMessenger.of(context).showSnackBar(buildErrorSnackbar(
theme: theme,
text: localization.connectionIssue,
log: state.errorMessage,
log: getLogMessage(state.errorMessage),
color: theme.colorScheme.error));
}
},
Expand Down

0 comments on commit 007cbfb

Please sign in to comment.