Skip to content

Commit

Permalink
Merge pull request #51 from zenon-network/feature/plasma-sync
Browse files Browse the repository at this point in the history
Separate plasma from sync
  • Loading branch information
alienc0der authored Mar 6, 2024
2 parents 9e0a73b + e60ef9d commit 02ff179
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 53 deletions.
1 change: 1 addition & 0 deletions assets/lottie/ic_anim_plasma_generation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"v":"5.7.1","fr":30,"ip":0,"op":80,"w":500,"h":500,"nm":"Plasma generation","ddd":0,"assets":[],"layers":[{"ddd":0,"ind":1,"ty":4,"nm":"thunder Outlines 2","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[250,250,0],"ix":2},"a":{"a":0,"k":[250,250,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[95.758,-41.79],[21.469,-41.79],[22.96,-175.92],[-95.757,41.789],[-21.469,41.789],[-22.96,175.92]],"c":true},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"rd","nm":"Round Corners 1","r":{"a":0,"k":10,"ix":1},"ix":2,"mn":"ADBE Vector Filter - RC","hd":false},{"ty":"tm","s":{"a":1,"k":[{"i":{"x":[0.667],"y":[1]},"o":{"x":[0.333],"y":[0]},"t":0,"s":[100]},{"t":43,"s":[0]}],"ix":1},"e":{"a":0,"k":100,"ix":2},"o":{"a":0,"k":0,"ix":3},"m":1,"ix":3,"nm":"Trim Paths 1","mn":"ADBE Vector Filter - Trim","hd":false},{"ty":"st","c":{"a":0,"k":[0.31,0.82,0.4],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":10,"ix":5},"lc":2,"lj":2,"bm":0,"nm":"Stroke 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"tr","p":{"a":0,"k":[250,250],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Group 1","np":4,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":300,"st":0,"bm":0},{"ddd":0,"ind":2,"ty":4,"nm":"thunder Outlines","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[250,250,0],"ix":2},"a":{"a":0,"k":[250,250,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[95.758,-41.79],[21.469,-41.79],[22.96,-175.92],[-95.757,41.789],[-21.469,41.789],[-22.96,175.92]],"c":true},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"rd","nm":"Round Corners 1","r":{"a":0,"k":10,"ix":1},"ix":2,"mn":"ADBE Vector Filter - RC","hd":false},{"ty":"st","c":{"a":0,"k":[0.702,0.702,0.702],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":4,"ix":5},"lc":2,"lj":1,"ml":10,"bm":0,"nm":"Stroke 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"tr","p":{"a":0,"k":[250,250],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Group 1","np":3,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":300,"st":0,"bm":0},{"ddd":0,"ind":3,"ty":4,"nm":"thunder_2 Outlines","sr":1,"ks":{"o":{"a":1,"k":[{"i":{"x":[0.667],"y":[1]},"o":{"x":[0.167],"y":[0]},"t":34,"s":[0]},{"i":{"x":[0.833],"y":[1]},"o":{"x":[0.167],"y":[0]},"t":41,"s":[60]},{"t":49,"s":[100]}],"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[250,250,0],"ix":2},"a":{"a":0,"k":[250,250,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"o":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"v":[[95.758,-41.79],[21.469,-41.79],[22.96,-175.92],[-95.757,41.789],[-21.469,41.789],[-22.96,175.92]],"c":true},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"fl","c":{"a":0,"k":[0.31,0.82,0.4],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"bm":0,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[250,250],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Group 1","np":2,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false},{"ty":"rd","nm":"Round Corners 1","r":{"a":0,"k":10,"ix":1},"ix":2,"mn":"ADBE Vector Filter - RC","hd":false}],"ip":32,"op":322,"st":22,"bm":0}],"markers":[]}
7 changes: 5 additions & 2 deletions lib/screens/node_management_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,11 @@ class _NodeManagementScreenState extends State<NodeManagementScreen> {
),
kVerticalSpacing,
Text(
'By default Syrius connects to its own built-in full node, which is called the Embedded Node. If you want to connect to a different node, you can add one below. Otherwise just connect and continue.',
style: Theme.of(context).textTheme.headlineMedium,
'By default Syrius connects to its own built-in full node, which is called the Embedded Node. '
'It may take up to 24 hours to fully sync the network via the embedded node. '
'During this time, you cannot send or receive transactions.\n\n'
'It you want to get started right away, please connect to a community node.',
style: Theme.of(context).textTheme.headlineSmall,
textAlign: TextAlign.center,
),
SizedBox(
Expand Down
6 changes: 4 additions & 2 deletions lib/utils/global.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ final List<Tabs> kTabsWithIconTitles = [
Tabs.help,
Tabs.notifications,
Tabs.settings,
Tabs.resyncWallet,
Tabs.generation,
Tabs.sync,
Tabs.lock,
];

final List<Tabs> kDisabledTabs = [
Tabs.resyncWallet,
Tabs.generation,
Tabs.sync,
];

List<String> kDefaultNodes = [
Expand Down
167 changes: 124 additions & 43 deletions lib/widgets/main_app_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_svg/svg.dart';
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
import 'package:logging/logging.dart';
import 'package:lottie/lottie.dart';
import 'package:provider/provider.dart';
import 'package:wallet_connect_uri_validator/wallet_connect_uri_validator.dart';
import 'package:window_manager/window_manager.dart';
Expand Down Expand Up @@ -43,7 +44,8 @@ enum Tabs {
plasma,
tokens,
p2pSwap,
resyncWallet,
generation,
sync,
accelerator,
walletConnect,
}
Expand All @@ -66,29 +68,22 @@ class _MainAppContainerState extends State<MainAppContainer>
with TickerProviderStateMixin, ClipboardListener, WindowListener {
late AnimationController _animationController;
late Animation _animation;

final NodeSyncStatusBloc _netSyncStatusBloc = NodeSyncStatusBloc();

late StreamSubscription _lockBlockStreamSubscription;
late StreamSubscription _incomingLinkSubscription;

Timer? _navigateToLockTimer;

late LockBloc _lockBloc;

Timer? _navigateToLockTimer;
TabController? _tabController;

TransferTabChild? _transferTabChild;
bool _initialUriIsHandled = false;

final NodeSyncStatusBloc _netSyncStatusBloc = NodeSyncStatusBloc();
final _appLinks = AppLinks();
final FocusNode _focusNode = FocusNode(
skipTraversal: true,
canRequestFocus: false,
);

bool _initialUriIsHandled = false;

final _appLinks = AppLinks();

@override
void initState() {
sl<WalletConnectService>().context = context;
Expand All @@ -112,6 +107,7 @@ class _MainAppContainerState extends State<MainAppContainer>
_initLockBlock();
_handleIncomingLinks();
_handleInitialUri();

super.initState();
}

Expand Down Expand Up @@ -344,7 +340,10 @@ class _MainAppContainerState extends State<MainAppContainer>
),
),
Tab(
child: _getPowGeneratingStatus(),
child: _getGenerationStatus(),
),
Tab(
child: _getSyncStatus(),
),
Tab(
child: _isTabSelected(Tabs.lock)
Expand All @@ -364,7 +363,7 @@ class _MainAppContainerState extends State<MainAppContainer>
];
}

Widget _getWebsocketConnectionStatusStreamBuilder() {
Widget _getSyncStatus() {
return StreamBuilder<SyncInfo>(
stream: _netSyncStatusBloc.stream,
builder: (_, snapshot) {
Expand All @@ -379,8 +378,34 @@ class _MainAppContainerState extends State<MainAppContainer>
);
}

Widget _getGenerationStatus() {
return StreamBuilder<PowStatus>(
stream: sl.get<PowGeneratingStatusBloc>().stream,
builder: (_, snapshot) {
if (snapshot.hasData && snapshot.data == PowStatus.generating) {
return Tooltip(
message: 'Generating Plasma',
child: Lottie.asset(
'assets/lottie/ic_anim_plasma_generation.json',
fit: BoxFit.contain,
width: 30.0,
repeat: true,
),
);
}
return Tooltip(
message: 'Plasma generation idle',
child: Icon(
MaterialCommunityIcons.lightning_bolt,
color: Theme.of(context).iconTheme.color,
),
);
},
);
}

Widget _getSyncingStatusIcon(SyncState syncState, [SyncInfo? syncInfo]) {
var message = 'Connected and synced';
String message = 'Connected and synced';

if (syncState != SyncState.notEnoughPeers &&
syncState != SyncState.syncDone &&
Expand All @@ -391,19 +416,58 @@ class _MainAppContainerState extends State<MainAppContainer>

if (syncState == SyncState.unknown) {
message = 'Not ready';
return Tooltip(
message: message,
child: Icon(
Icons.sync_disabled,
size: 24.0,
color: _getSyncIconColor(syncState),
));
} else if (syncState == SyncState.syncing) {
if (syncInfo != null) {
if (syncInfo.targetHeight > 0 &&
syncInfo.currentHeight > 0 &&
(syncInfo.targetHeight - syncInfo.currentHeight) < 3) {
message = 'Connected and synced';
syncState = SyncState.syncDone;
return Tooltip(
message: message,
child: Icon(
Icons.radio_button_unchecked,
size: 24.0,
color: _getSyncIconColor(syncState),
));
} else if (syncInfo.targetHeight == 0 || syncInfo.currentHeight == 0) {
message = 'Started syncing with the network, please wait';
syncState = SyncState.syncing;
return Tooltip(
message: message,
child: Icon(Icons.sync,
size: 24.0, color: _getSyncIconColor(syncState)));
} else {
message =
'Sync progress: momentum ${syncInfo.currentHeight} of ${syncInfo.targetHeight}';
return Tooltip(
message: message,
child: SizedBox(
height: 18.0,
width: 18.0,
child: Center(
child: CircularProgressIndicator(
backgroundColor: Theme.of(context).iconTheme.color,
color: _getSyncIconColor(syncState),
value: syncInfo.currentHeight / syncInfo.targetHeight,
strokeWidth: 3.0,
)),
),
);
}
} else {
message = 'Syncing momentums';
return Tooltip(
message: message,
child: Icon(Icons.sync,
size: 24.0, color: _getSyncIconColor(syncState)));
}
} else if (syncState == SyncState.notEnoughPeers) {
if (syncInfo != null) {
Expand All @@ -412,17 +476,49 @@ class _MainAppContainerState extends State<MainAppContainer>
(syncInfo.targetHeight - syncInfo.currentHeight) < 20) {
message = 'Connecting to peers';
syncState = SyncState.syncing;
return Tooltip(
message: message,
child: SizedBox(
height: 18.0,
width: 18.0,
child: Center(
child: CircularProgressIndicator(
backgroundColor: Theme.of(context).iconTheme.color,
color: _getSyncIconColor(syncState),
value: syncInfo.currentHeight / syncInfo.targetHeight,
strokeWidth: 3.0,
))));
} else if (syncInfo.targetHeight == 0 || syncInfo.currentHeight == 0) {
message = 'Connecting to peers';
message = 'Connecting to peers, please wait';
syncState = SyncState.syncing;
return Tooltip(
message: message,
child: Icon(Icons.sync,
size: 24.0, color: _getSyncIconColor(syncState)));
} else {
message =
'Sync progress: momentum ${syncInfo.currentHeight} of ${syncInfo.targetHeight}';
syncState = SyncState.syncing;
return Tooltip(
message: message,
child: SizedBox(
height: 18.0,
width: 18.0,
child: Center(
child: CircularProgressIndicator(
backgroundColor: Theme.of(context).iconTheme.color,
color: _getSyncIconColor(syncState),
value: syncInfo.currentHeight / syncInfo.targetHeight,
strokeWidth: 3.0,
))));
}
} else {
message = 'Connecting to peers';
syncState = SyncState.syncing;
return Tooltip(
message: message,
child: Icon(Icons.sync_problem,
size: 24.0, color: _getSyncIconColor(syncState)));
}
} else {
message = 'Connected and synced';
Expand All @@ -431,10 +527,16 @@ class _MainAppContainerState extends State<MainAppContainer>

return Tooltip(
message: message,
child: Icon(
Icons.radio_button_unchecked,
size: 24.0,
color: _getSyncIconColor(syncState),
child: SizedBox(
height: 18.0,
width: 18.0,
child: Center(
child: CircularProgressIndicator(
backgroundColor: Theme.of(context).iconTheme.color,
color: _getSyncIconColor(syncState),
value: 1,
strokeWidth: 2.0,
)),
),
);
}
Expand Down Expand Up @@ -473,7 +575,6 @@ class _MainAppContainerState extends State<MainAppContainer>
const NotificationsTabChild(),
SettingsTabChild(
_onChangeAutoLockTime,
_onResyncWalletPressed,
onStepperNotificationSeeMorePressed: () => _navigateTo(
Tabs.notifications,
),
Expand All @@ -482,6 +583,7 @@ class _MainAppContainerState extends State<MainAppContainer>
),
),
const SizedBox(),
const SizedBox(),
LockTabChild(_mainLockCallback, _afterAppInitCallback),
],
);
Expand Down Expand Up @@ -530,6 +632,7 @@ class _MainAppContainerState extends State<MainAppContainer>
} else {
_lockBloc.addEvent(LockEvent.navigateToDashboard);
}

_listenToAutoReceiveTxWorkerNotifications();
}

Expand All @@ -539,28 +642,6 @@ class _MainAppContainerState extends State<MainAppContainer>
});
}

void _onResyncWalletPressed() {
_navigateTo(Tabs.resyncWallet);
}

Widget _getPowGeneratingStatus() {
return StreamBuilder<PowStatus>(
stream: sl.get<PowGeneratingStatusBloc>().stream,
builder: (_, snapshot) {
if (snapshot.hasData && snapshot.data == PowStatus.generating) {
return const Tooltip(
message: 'Generating Plasma',
child: SyriusLoadingWidget(
size: 20.0,
strokeWidth: 2.5,
),
);
}
return _getWebsocketConnectionStatusStreamBuilder();
},
);
}

bool _isTabSelected(Tabs page) =>
_tabController!.index == kTabs.indexOf(page);

Expand Down
4 changes: 1 addition & 3 deletions lib/widgets/tab_children_widgets/settings_tab_child.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import 'package:zenon_syrius_wallet_flutter/widgets/widgets.dart';

class SettingsTabChild extends StatefulWidget {
final VoidCallback _onChangeAutoLockTime;
final VoidCallback _onResyncWalletPressed;
final VoidCallback onStepperNotificationSeeMorePressed;
final VoidCallback onNodeChangedCallback;

const SettingsTabChild(
this._onChangeAutoLockTime,
this._onResyncWalletPressed, {
this._onChangeAutoLockTime, {
required this.onStepperNotificationSeeMorePressed,
required this.onNodeChangedCallback,
Key? key,
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -751,10 +751,10 @@ packages:
dependency: "direct main"
description:
name: lottie
sha256: "0793a5866062e5cc8a8b24892fa94c3095953ea914a7fdf790f550dd7537fe60"
sha256: b8bdd54b488c54068c57d41ae85d02808da09e2bee8b8dd1f59f441e7efa60cd
url: "https://pub.dev"
source: hosted
version: "2.5.0"
version: "2.6.0"
marquee_widget:
dependency: "direct main"
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:

fl_chart: ^0.63.0
overlay_support: ^2.1.0
lottie: ^2.1.0
lottie: ^2.6.0
dotted_border: ^2.0.0+2
flutter_svg: ^2.0.0+1
flutter_vector_icons: ^2.0.0
Expand Down

0 comments on commit 02ff179

Please sign in to comment.