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

2023 11 11 more eth #39

Merged
merged 8 commits into from
Nov 13, 2023
7 changes: 6 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ services:
- 8551:8551 # Authenticated RPC
command:
- --http # enable HTTP RPC
- --http.addr=0.0.0.0 # TODO: add auth config? --authrpc.jwtsecret, --authrpc.addr=0.0.0.0, --authrpc.vhosts=*
# 'personal' API is needed for replicating the old ETH tutorial
# made by Paul. Think it's some sort of wallet functionality? Not sure,
# tbh. Went looking for a list of available APIs, without finding
# anything.
- --http.api=eth,web3,personal,admin,jeth,miner,net,txpool
- --http.addr=0.0.0.0
- --main.host=mainchain
- --main.password=password
- --main.user=user
Expand Down
10 changes: 3 additions & 7 deletions lib/pages/tabs/dashboard_tab_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import 'package:get_it/get_it.dart';
import 'package:intl/intl.dart';
import 'package:logger/logger.dart';
import 'package:sail_ui/sail_ui.dart';
import 'package:sail_ui/theme/theme.dart';
import 'package:sail_ui/widgets/core/sail_text.dart';
import 'package:sidesail/config/sidechains.dart';
import 'package:sidesail/providers/transactions_provider.dart';
import 'package:sidesail/routing/router.dart';
import 'package:sidesail/rpc/models/core_transaction.dart';
import 'package:sidesail/rpc/rpc_sidechain.dart';
import 'package:sidesail/widgets/containers/tabs/dashboard_tab_widgets.dart';
import 'package:sidesail/widgets/dialog.dart';
import 'package:stacked/stacked.dart';

@RoutePage()
Expand Down Expand Up @@ -199,21 +199,17 @@ class DashboardTabViewModel extends BaseViewModel {
}

void send(BuildContext context) async {
final theme = SailTheme.of(context);
await showDialog(
await showThemedDialog(
context: context,
barrierColor: theme.colors.background.withOpacity(0.4),
builder: (BuildContext context) {
return const SendOnSidechainAction();
},
);
}

void receive(BuildContext context) async {
final theme = SailTheme.of(context);
await showDialog(
await showThemedDialog(
context: context,
barrierColor: theme.colors.background.withOpacity(0.4),
builder: (BuildContext context) {
return const ReceiveOnSidechainAction();
},
Expand Down
101 changes: 89 additions & 12 deletions lib/pages/tabs/ethereum/ethereum_rpc_tab_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,106 @@ 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:sail_ui/widgets/core/sail_text.dart';
import 'package:sidesail/routing/router.dart';
import 'package:sidesail/rpc/rpc_ethereum.dart';
import 'package:sidesail/widgets/containers/tabs/console.dart';
import 'package:stacked/stacked.dart';
import 'package:web3dart/web3dart.dart';

@RoutePage()
class EthereumRPCTabPage extends StatelessWidget {
AppRouter get router => GetIt.I.get<AppRouter>();
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(),
],
),
),
return ViewModelBuilder.reactive(
viewModelBuilder: () => EthereumRPCTabPageViewModel(),
builder: ((context, viewModel, child) {
return SailPage(
scrollable: true,
title: 'Ethereum RPC',
subtitle: 'Call RPCs directly to the Ethereum sidechain. Try typing in "eth_blockNumber" in the input below.',
widgetTitle: SailRow(
spacing: SailStyleValues.padding08,
children: [
if (viewModel.account == null)
SailButton.primary(
'Create account',
onPressed: () async {
try {
await viewModel.createAccount();
} catch (err) {
if (!context.mounted) {
return;
}

await showDialog(
context: context,
builder: (context) => AlertDialog(
title: SailText.primary20('Could not create account'),
content: SailText.secondary13(err.toString()),
actions: [
TextButton(
onPressed: () => _router.popUntilRoot(),
child: SailText.primary13('OK'),
),
],
),
);
}
},
loading: viewModel.isBusy,
size: ButtonSize.small,
),
if (viewModel.account == null)
SailText.secondary12('You need an account to deposit and withdraw sidechain-coins'),
if (viewModel.account != null) SailText.secondary13('Your ETH-address: ${viewModel.account!.toString()}'),
Expanded(child: Container()),
],
),
body: const Padding(
padding: EdgeInsets.only(bottom: SailStyleValues.padding30),
child: Column(
children: [
RPCWidget(),
],
),
),
);
}),
);
}
}

class EthereumRPCTabPageViewModel extends BaseViewModel {
EthereumRPC get _rpc => GetIt.I.get<EthereumRPC>();

EthereumAddress? get account => _rpc.account;

EthereumRPCTabPageViewModel() {
_rpc.addListener(notifyListeners);
}

bool running = false;

Future<void> createAccount() async {
setBusy(true);
if (account != null) {
throw Exception('you can only make one account using the GUI');
}

await _rpc.newAccount();
setBusy(false);
notifyListeners();
}

@override
void dispose() {
super.dispose();
_rpc.removeListener(notifyListeners);
}
}
19 changes: 16 additions & 3 deletions lib/pages/tabs/sidechain_explorer_tab_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ 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/app.dart';
import 'package:sidesail/config/sidechains.dart';
import 'package:sidesail/providers/balance_provider.dart';
import 'package:sidesail/rpc/rpc_ethereum.dart';
import 'package:sidesail/rpc/rpc_sidechain.dart';
import 'package:sidesail/rpc/rpc_testchain.dart';
import 'package:sidesail/storage/client_settings.dart';
import 'package:sidesail/storage/sail_settings/theme_settings.dart';
import 'package:sidesail/widgets/containers/chain_overview_card.dart';
import 'package:sidesail/widgets/containers/tabs/dashboard_tab_widgets.dart';
import 'package:stacked/stacked.dart';
Expand All @@ -20,6 +23,8 @@ class SidechainExplorerTabPage extends StatelessWidget {

@override
Widget build(BuildContext context) {
final app = SailApp.of(context);

return ViewModelBuilder.reactive(
viewModelBuilder: () => SidechainExplorerTabViewModel(),
builder: ((context, viewModel, child) {
Expand All @@ -41,15 +46,15 @@ class SidechainExplorerTabPage extends StatelessWidget {
unconfirmedBalance: viewModel.pendingBalance,
highlighted: false,
currentChain: viewModel.chain.type == SidechainType.testChain,
onPressed: () => viewModel.setSidechainRPC(test),
onPressed: () => viewModel.setSidechainRPC(test, app),
),
ChainOverviewCard(
chain: EthereumSidechain(),
confirmedBalance: viewModel.balance,
unconfirmedBalance: viewModel.pendingBalance,
highlighted: false,
currentChain: viewModel.chain.type == SidechainType.ethereum,
onPressed: () => viewModel.setSidechainRPC(eth),
onPressed: () => viewModel.setSidechainRPC(eth, app),
),
],
),
Expand All @@ -67,6 +72,8 @@ class SidechainExplorerTabPage extends StatelessWidget {
class SidechainExplorerTabViewModel extends BaseViewModel {
BalanceProvider get _balanceProvider => GetIt.I.get<BalanceProvider>();
SidechainRPC get _sideRPC => GetIt.I.get<SidechainRPC>();
ClientSettings get _clientSettings => GetIt.I.get<ClientSettings>();
SailThemeValues theme = SailThemeValues.light;

double get balance => _balanceProvider.balance;
double get pendingBalance => _balanceProvider.pendingBalance;
Expand All @@ -80,11 +87,17 @@ class SidechainExplorerTabViewModel extends BaseViewModel {
// pass notifyListeners of this view model directly
_balanceProvider.addListener(notifyListeners);
_sideRPC.addListener(notifyListeners);
_init();
}

Future<void> _init() async {
theme = (await _clientSettings.getValue(ThemeSetting())).value;
}

void setSidechainRPC(SidechainSubRPC sideSubRPC) {
void setSidechainRPC(SidechainSubRPC sideSubRPC, SailAppState sailApp) {
_sideRPC.setSubRPC(sideSubRPC);
notifyListeners();
sailApp.loadTheme(theme);
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:logger/logger.dart';
import 'package:sail_ui/sail_ui.dart';
import 'package:sail_ui/theme/theme.dart';
import 'package:sail_ui/widgets/core/sail_text.dart';
import 'package:sidesail/pages/tabs/dashboard_tab_page.dart';
import 'package:sidesail/providers/transactions_provider.dart';
import 'package:sidesail/routing/router.dart';
import 'package:sidesail/rpc/models/core_transaction.dart';
import 'package:sidesail/widgets/containers/tabs/dashboard_tab_widgets.dart';
import 'package:sidesail/widgets/containers/tabs/transfer_mainchain_tab_widgets.dart';
import 'package:sidesail/widgets/dialog.dart';
import 'package:stacked/stacked.dart';

@RoutePage()
Expand Down Expand Up @@ -95,22 +95,17 @@ class TransferMainchainTabViewModel extends BaseViewModel {
}

void pegOut(BuildContext context) async {
final theme = SailTheme.of(context);

await showDialog(
await showThemedDialog(
context: context,
barrierColor: theme.colors.background.withOpacity(0.4),
builder: (BuildContext context) {
return const PegOutAction();
},
);
}

void pegIn(BuildContext context) async {
final theme = SailTheme.of(context);
await showDialog(
await showThemedDialog(
context: context,
barrierColor: theme.colors.background.withOpacity(0.4),
builder: (BuildContext context) {
return const PegInAction();
},
Expand Down
Loading