Catch exception when disconnected

This commit is contained in:
Hanh 2022-09-24 20:05:45 +08:00
parent cf524d9bd5
commit 02358365bb
8 changed files with 57 additions and 36 deletions

View File

@ -124,6 +124,7 @@ flatpak-builder --user --install --force-clean build-dir me.hanh.zwallet.Ywallet
flatpak build-export ~/repo build-dir
flatpak build-bundle ~/repo ywallet.flatpak me.hanh.zwallet.Ywallet
rm -rf build-dir
rm -rf ~/repo
docker rm zwallet_linux
```

View File

@ -14,7 +14,7 @@ RUN apt-get install -yq curl gnupg2
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- -y
RUN apt-get update
RUN apt-get install -yq unzip xz-utils clang cmake git ninja-build pkg-config libgtk-3-dev liblzma-dev libgstreamer-plugins-base1.0-dev
RUN curl -o flutter.tar.xz https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_3.3.1-stable.tar.xz
RUN curl -o flutter.tar.xz https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_3.3.2-stable.tar.xz
RUN tar xvf flutter.tar.xz
RUN rm -f flutter.tar.xz

View File

@ -277,7 +277,10 @@ abstract class _ActiveAccount with Store {
@action
void updateTBalance() {
tbalance = WarpApi.getTBalance();
try {
tbalance = WarpApi.getTBalance();
}
on String {}
}
@action

View File

@ -95,7 +95,7 @@ class ContactsState extends State<ContactsTab> {
S.of(context).ok);
if (approve) {
final tx = await WarpApi.commitUnsavedContacts(settings.anchorOffset);
showSnackBar("${S.of(context).txId}: $tx");
showSnackBar(S.of(context).txId(tx));
contacts.markContactsSaved(active.coin, true);
}
}

View File

@ -8,40 +8,49 @@ import 'main.dart';
final rescanKey = GlobalKey<RescanFormState>();
Future<int?> rescanDialog(BuildContext context) async {
final approved = await showDialog<bool>(
context: context,
barrierDismissible: false,
builder: (context) => AlertDialog(
title: Text(S.of(context).rescanFrom),
content: RescanForm(key: rescanKey),
actions: confirmButtons(
context, () => Navigator.of(context).pop(true),
cancelValue: false))) ??
false;
if (approved) {
final date = rescanKey.currentState!.startDate;
final heightText = rescanKey.currentState!.heightController.text;
final approved = await confirmWifi(context);
try {
DateTime minDate = WarpApi.getActivationDate();
final approved = await showDialog<bool>(
context: context,
barrierDismissible: false,
builder: (context) =>
AlertDialog(
title: Text(S
.of(context)
.rescanFrom),
content: RescanForm(minDate, key: rescanKey),
actions: confirmButtons(
context, () => Navigator.of(context).pop(true),
cancelValue: false))) ??
false;
if (approved) {
showSnackBar(S.of(context).rescanning, autoClose: true);
final height = int.tryParse(heightText);
if (height != null) return height;
final height2 = await WarpApi.getBlockHeightByTime(date);
return height2;
final date = rescanKey.currentState!.startDate;
final heightText = rescanKey.currentState!.heightController.text;
final approved = await confirmWifi(context);
if (approved) {
showSnackBar(S
.of(context)
.rescanning, autoClose: true);
final height = int.tryParse(heightText);
if (height != null) return height;
final height2 = await WarpApi.getBlockHeightByTime(date);
return height2;
}
}
}
on String {}
return null;
}
class RescanForm extends StatefulWidget {
RescanForm({Key? key}) : super(key: key);
final minDate;
RescanForm(this.minDate, {Key? key}) : super(key: key);
@override
RescanFormState createState() => RescanFormState();
}
class RescanFormState extends State<RescanForm> {
DateTime minDate = WarpApi.getActivationDate();
DateTime maxDate = DateTime.now();
late DateTime startDate;
var heightController = TextEditingController();
@ -49,7 +58,7 @@ class RescanFormState extends State<RescanForm> {
@override
void initState() {
super.initState();
startDate = minDate;
startDate = widget.minDate;
}
@override
@ -68,7 +77,7 @@ class RescanFormState extends State<RescanForm> {
}
_showDatePicker() async {
final date = await showDatePicker(context: context, firstDate: minDate, initialDate: startDate, lastDate: maxDate);
final date = await showDatePicker(context: context, firstDate: widget.minDate, initialDate: startDate, lastDate: maxDate);
if (date != null) {
setState(() {
startDate = date;

View File

@ -607,14 +607,19 @@ abstract class _PriceStore with Store {
}
Future<void> updateChart() async {
final _lastChartUpdateTime = lastChartUpdateTime;
final now = DateTime.now().millisecondsSinceEpoch ~/ 1000;
if (_lastChartUpdateTime == null || now > _lastChartUpdateTime + 5 * 60) {
await fetchCoinPrice(active.coin);
await WarpApi.syncHistoricalPrices(settings.currency);
await active.fetchChartData();
lastChartUpdateTime = _lastChartUpdateTime;
try {
final _lastChartUpdateTime = lastChartUpdateTime;
final now = DateTime
.now()
.millisecondsSinceEpoch ~/ 1000;
if (_lastChartUpdateTime == null || now > _lastChartUpdateTime + 5 * 60) {
await fetchCoinPrice(active.coin);
await WarpApi.syncHistoricalPrices(settings.currency);
await active.fetchChartData();
lastChartUpdateTime = _lastChartUpdateTime;
}
}
on String {}
}
}
@ -702,7 +707,10 @@ abstract class _SyncStatus with Store {
if (server != null && server.isNotEmpty)
WarpApi.updateLWD(active.coin, server);
}
latestHeight = await WarpApi.getLatestHeight();
try {
latestHeight = await WarpApi.getLatestHeight();
}
on String {}
final _syncedInfo = await getDbSyncedHeight();
// if syncedHeight = 0, we just started sync therefore don't set it back to null
if (syncedHeight != 0 && _syncedInfo != null) setSyncHeight(_syncedInfo.height, _syncedInfo.timestamp);

@ -1 +1 @@
Subproject commit 3d5becd20e2a8e7167ffe909ee939ee25f0fc1c2
Subproject commit 2451d6b29f64ce2253a6188d434da168293030aa

View File

@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.2.14+285
version: 1.2.14+286
environment:
sdk: ">=2.12.0 <3.0.0"