Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic ETH RPC #33

Merged
merged 8 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 23 additions & 29 deletions lib/config/dependencies.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:get_it/get_it.dart';
import 'package:sidesail/app.dart';
import 'package:sidesail/config/sidechains.dart';
import 'package:sidesail/providers/balance_provider.dart';
import 'package:sidesail/providers/transactions_provider.dart';
Expand All @@ -13,9 +12,9 @@ import 'package:sidesail/storage/secure_store.dart';

// register all global dependencies, for use in views, or in view models
// each dependency can only be registered once
Future<void> initGetitDependencies(Sidechain chain) async {
Future<void> initGetitDependencies(Sidechain initialChain) async {
final mainFuture = MainchainRPCLive.create();
await setSidechainRPC(chain);
await _initSidechainRPC(initialChain);
final mainRPC = await mainFuture;

GetIt.I.registerLazySingleton<MainchainRPC>(
Expand All @@ -40,40 +39,35 @@ Future<void> initGetitDependencies(Sidechain chain) async {
);
}

// register all global dependencies, for use in views, or in view models
// each dependency can only be registered once
Future<void> setSidechainRPC(Sidechain chain) async {
SidechainRPC sidechainRPC;
// register all rpc connections. We attempt to create all
// rpcs in parallell, so they're ready instantly when swapping
// we can also query the balance
Future<void> _initSidechainRPC(Sidechain chain) async {
final ethFuture = EthereumRPCLive.create();
final testFuture = TestchainRPCLive.create();

final ethRPC = await ethFuture;
final testRPC = await testFuture;

GetIt.I.registerLazySingleton<TestchainRPC>(
() => testRPC,
);
GetIt.I.registerLazySingleton<EthereumRPC>(
() => ethRPC,
);

SidechainSubRPC sidechainSubRPC;
switch (chain.type) {
case SidechainType.testChain:
final testchainRPC = await TestchainRPCLive.create();
if (GetIt.I.isRegistered<TestchainRPC>()) {
GetIt.I.unregister<TestchainRPC>();
}
GetIt.I.registerLazySingleton<TestchainRPC>(
() => testchainRPC,
);
sidechainRPC = testchainRPC;
sidechainSubRPC = testRPC;
break;

case SidechainType.ethereum:
final testchainRPC = await EthereumRPCLive.create();
if (GetIt.I.isRegistered<EthereumRPC>()) {
GetIt.I.unregister<EthereumRPC>();
}
GetIt.I.registerLazySingleton<EthereumRPC>(
() => testchainRPC,
);
sidechainRPC = testchainRPC;
sidechainSubRPC = ethRPC;
break;
}

if (GetIt.I.isRegistered<SidechainRPC>()) {
GetIt.I.unregister<SidechainRPC>();
}
GetIt.I.registerLazySingleton<SidechainRPC>(
() => sidechainRPC,
() => SidechainRPC(subRPC: sidechainSubRPC),
);

SailApp.sailAppKey.currentState?.rebuildUI();
}
118 changes: 0 additions & 118 deletions lib/console.dart

This file was deleted.

30 changes: 30 additions & 0 deletions lib/pages/tabs/ethereum/ethereum_rpc_tab_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:sail_ui/sail_ui.dart';
import 'package:sidesail/routing/router.dart';
import 'package:sidesail/widgets/containers/tabs/console.dart';

@RoutePage()
class EthereumRPCTabPage extends StatelessWidget {
AppRouter get router => GetIt.I.get<AppRouter>();

const EthereumRPCTabPage({super.key});

@override
Widget build(BuildContext context) {
return const SailPage(
scrollable: true,
title: 'Ethereum RPC',
subtitle: 'Call RPCs directly to the Ethereum sidechain. Try typing in "eth_blockNumber" in the input below.',
body: Padding(
padding: EdgeInsets.only(bottom: SailStyleValues.padding30),
child: Column(
children: [
RPCWidget(),
],
),
),
);
}
}
63 changes: 22 additions & 41 deletions lib/pages/tabs/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:auto_route/auto_route.dart' as auto_router;
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:logger/logger.dart';
Expand All @@ -13,65 +14,45 @@ import 'package:sidesail/rpc/rpc_sidechain.dart';
import 'package:sidesail/widgets/containers/chain_overview_card.dart';
import 'package:stacked/stacked.dart';

@auto_router.RoutePage()
@RoutePage()
class HomePage extends StatelessWidget {
SidechainRPC get _sideRPC => GetIt.I.get<SidechainRPC>();

const HomePage({super.key});

@override
Widget build(BuildContext context) {
final routes = routesForChain(_sideRPC.chain);
final theme = SailTheme.of(context);
const routes = [
// common routes
SidechainExplorerTabRoute(),
// testchain routes
DashboardTabRoute(),
TransferMainchainTabRoute(),
WithdrawalBundleTabRoute(),
BlindMergedMiningTabRoute(),

// ethereum routes
EthereumRPCTabRoute(),

// trailing common routes
NodeSettingsTabRoute(),
ThemeSettingsTabRoute(),
];

return auto_router.AutoTabsRouter.builder(
homeIndex: 1,
routes: routes,
builder: (context, children, _) {
final tabsRouter = auto_router.AutoTabsRouter.of(context);
builder: (context, children, tabsRouter) {
return Scaffold(
backgroundColor: theme.colors.background,
body: SideNav(
child: children[tabsRouter.activeIndex],
// assume settings tab is final tab!
navigateToSettings: () => tabsRouter.setActiveIndex(routes.length - 1),
navigateToSettings: () => tabsRouter.setActiveIndex(routes.length - 2),
),
);
},
);
}

List<auto_router.PageRouteInfo<dynamic>> routesForChain(Sidechain chain) {
final preRoutes = [
const SidechainExplorerTabRoute(),
];
final postRoutes = [
const NodeSettingsTabRoute(),
const ThemeSettingsTabRoute(),
];

List<auto_router.PageRouteInfo<dynamic>> chainRoutes = [];
switch (chain.type) {
case SidechainType.testChain:
chainRoutes = [
const DashboardTabRoute(),
const TransferMainchainTabRoute(),
const WithdrawalBundleTabRoute(),
const BlindMergedMiningTabRoute(),
];

case SidechainType.ethereum:
chainRoutes = [
const DashboardTabRoute(),
];
}

return [
...preRoutes,
...chainRoutes,
...postRoutes,
];
}
}

class SideNav extends StatefulWidget {
Expand Down Expand Up @@ -219,9 +200,9 @@ class _SideNavState extends State<SideNav> {
NavEntry(
title: '${viewModel.chain.name} Dashboard',
icon: SailSVGAsset.iconDashboardTab,
selected: tabsRouter.activeIndex == 1,
selected: tabsRouter.activeIndex == 5,
onPressed: () {
tabsRouter.setActiveIndex(1);
tabsRouter.setActiveIndex(5);
},
),
];
Expand Down
9 changes: 3 additions & 6 deletions lib/pages/tabs/settings/node_settings_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,9 @@ class NodeConnectionSettings extends ViewModelWidget<NodeConnectionViewModel> {
label: 'Config path',
controller: settings.configPathController,
hintText: '/the/path/to/your/somethingchain.conf',
suffixWidget: Padding(
padding: const EdgeInsets.only(left: SailStyleValues.padding08),
child: SailTextButton(
label: 'Read file',
onPressed: settings.readAndSetValuesFromFile,
),
suffixWidget: SailTextButton(
label: 'Read file',
onPressed: settings.readAndSetValuesFromFile,
),
),
SailTextField(
Expand Down
Loading