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

fix: Starport Template pre-release fixes #94

Merged
merged 3 commits into from
Aug 20, 2021
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
11 changes: 11 additions & 0 deletions starport_template/lib/entities/import_wallet_form_data.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class ImportWalletFormData {
final String mnemonic;
final String name;
final String password;

const ImportWalletFormData({
required this.mnemonic,
required this.name,
required this.password,
});
}
9 changes: 1 addition & 8 deletions starport_template/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ void _buildDependencies() {
serializers: [AlanCredentialsSerializer()],
),
);
StarportApp.baseEnv = BaseEnv()
..setEnv(
lcdUrl: lcdUrl,
grpcUrl: grpcUrl,
lcdPort: lcdPort,
grpcPort: grpcPort,
ethUrl: ethUrl,
);
StarportApp.baseEnv = BaseEnv();
StarportApp.walletsStore = WalletsStore(StarportApp.signingGateway, StarportApp.baseEnv);
}
73 changes: 73 additions & 0 deletions starport_template/lib/pages/add_wallet_bottom_sheet.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import 'package:cosmos_ui_components/components/template/cosmos_password_field.dart';
import 'package:flutter/material.dart';
import 'package:starport_template/entities/import_wallet_form_data.dart';

class AddWalletBottomSheet extends StatefulWidget {
final void Function(ImportWalletFormData) importClicked;

const AddWalletBottomSheet({
Key? key,
required this.importClicked,
}) : super(key: key);

@override
_AddWalletBottomSheetState createState() => _AddWalletBottomSheetState();
}

class _AddWalletBottomSheetState extends State<AddWalletBottomSheet> {
String _mnemonic = "";
String _alias = "";
String _password = "";

@override
Widget build(BuildContext context) {
return SafeArea(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
title: TextFormField(
decoration: const InputDecoration(
labelText: "Enter mnemonic",
border: OutlineInputBorder(),
),
onChanged: (value) => _mnemonic = value,
),
),
ListTile(
title: TextFormField(
decoration: const InputDecoration(
labelText: "Enter alias",
border: OutlineInputBorder(),
),
onChanged: (value) => _alias = value,
),
),
ListTile(
title: CosmosPasswordField(
onPasswordUpdated: (value) => _password = value,
),
),
ElevatedButton(
onPressed: () => _importClicked(context),
style: ElevatedButton.styleFrom(
shape: const StadiumBorder(),
),
child: const Text("Import wallet"),
),
],
),
);
}

void _importClicked(BuildContext context) {
Navigator.of(context).pop();
widget.importClicked(
ImportWalletFormData(
mnemonic: _mnemonic,
name: _alias,
password: _password,
),
);
}
}
15 changes: 0 additions & 15 deletions starport_template/lib/pages/add_wallet_page.dart

This file was deleted.

115 changes: 83 additions & 32 deletions starport_template/lib/pages/mnemonic_onboarding_page.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import 'package:cosmos_ui_components/cosmos_ui_components.dart';
import 'package:cosmos_utils/cosmos_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:starport_template/entities/import_wallet_form_data.dart';
import 'package:starport_template/pages/add_wallet_bottom_sheet.dart';
import 'package:starport_template/pages/wallets_list_page.dart';
import 'package:starport_template/starport_app.dart';
import 'package:starport_template/widgets/password_setup_sheet.dart';

class MnemonicOnboardingPage extends StatefulWidget {
const MnemonicOnboardingPage({Key? key}) : super(key: key);
final bool openWalletsListOnDone;

const MnemonicOnboardingPage({
Key? key,
this.openWalletsListOnDone = true,
}) : super(key: key);

@override
_MnemonicOnboardingPageState createState() => _MnemonicOnboardingPageState();
Expand All @@ -17,6 +25,8 @@ class _MnemonicOnboardingPageState extends State<MnemonicOnboardingPage> {

List<String> get mnemonicWords => mnemonic.trim().split(' ');

bool get isLoading => StarportApp.walletsStore.isWalletImporting;

@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -26,34 +36,59 @@ class _MnemonicOnboardingPageState extends State<MnemonicOnboardingPage> {
body: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: CosmosAppTheme.spacingM),
child: ContentStateSwitcher(
isEmpty: mnemonic.isEmpty,
emptyChild: Center(
child: CosmosElevatedButton(
onTap: _generateMnemonicClicked,
text: "Create new Wallet",
child: Observer(
builder: (context) => ContentStateSwitcher(
isEmpty: mnemonic.isEmpty,
isLoading: isLoading,
emptyChild: SizedBox.expand(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CosmosElevatedButton(
onTap: _generateMnemonicClicked,
text: "Create new Wallet",
),
CosmosElevatedButton(
onTap: _importExistingWalletClicked,
text: "Import existing Wallet",
),
],
),
),
),
contentChild: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
CosmosMnemonicWordsGrid(mnemonicWords: mnemonicWords),
const SizedBox(height: CosmosAppTheme.spacingM),
const Expanded(
child: Text(
'Be sure to write your mnemonic pass phrase in a safe place. '
'This phrase is the only way to recover your account if you forget your password. ',
textAlign: TextAlign.center,
contentChild: Center(
child: Column(
children: [
Expanded(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(height: CosmosAppTheme.spacingM),
const Text(
'Be sure to write your mnemonic pass phrase in a safe place. '
'This phrase is the only way to recover your account if you forget your password. ',
textAlign: TextAlign.center,
),
const SizedBox(height: CosmosAppTheme.spacingM),
Flexible(
child: CosmosMnemonicWordsGrid(
mnemonicWords: mnemonicWords,
physics: const NeverScrollableScrollPhysics(),
),
),
const SizedBox(height: CosmosAppTheme.spacingM),
],
),
),
),
CosmosElevatedButton(
onTap: _proceedClicked,
text: "Proceed",
suffixIcon: const Icon(Icons.arrow_forward),
),
),
CosmosElevatedButton(
onTap: _proceedClicked,
text: "Proceed",
suffixIcon: const Icon(Icons.arrow_forward),
)
],
],
),
),
),
),
Expand All @@ -64,20 +99,36 @@ class _MnemonicOnboardingPageState extends State<MnemonicOnboardingPage> {

void _generateMnemonicClicked() => setState(() => mnemonic = generateMnemonic());

void _importExistingWalletClicked() => showModalBottomSheet(
context: context,
builder: (context) => AddWalletBottomSheet(importClicked: _importWallet),
);

void _proceedClicked() => showModalBottomSheet(
context: context,
builder: (context) => PasswordSetupSheet(
submitClicked: submitPasswordClicked,
),
);

Future submitPasswordClicked(String password) async {
final store = StarportApp.walletsStore;
StarportApp.password = password;
await store.importAlanWallet(mnemonic, password);
Future submitPasswordClicked(String password, String name) async => _importWallet(ImportWalletFormData(
mnemonic: mnemonic.trim(),
name: name,
password: password,
));

Future<void> _importWallet(ImportWalletFormData data) async {
await StarportApp.walletsStore.importAlanWallet(data);
_openWalletsList();
}

void _openWalletsList() {
if (!mounted) {
return;
}
Navigator.of(context).push(MaterialPageRoute(builder: (_) => const WalletsListPage()));
Navigator.of(context)..pop();
if (widget.openWalletsListOnDone) {
Navigator.of(context).push(MaterialPageRoute(builder: (_) => const WalletsListPage()));
}
}
}
3 changes: 2 additions & 1 deletion starport_template/lib/pages/routing_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class _RoutingPageState extends State<RoutingPage> {
if (!mounted) {
return;
}
if (store.wallets.value.isEmpty) {
Navigator.of(context).pop();
if (store.wallets.isEmpty) {
Navigator.of(context).push(MaterialPageRoute(builder: (_) => const MnemonicOnboardingPage()));
} else {
Navigator.of(context).push(MaterialPageRoute(builder: (_) => const WalletsListPage()));
Expand Down
36 changes: 19 additions & 17 deletions starport_template/lib/pages/wallet_details_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ class WalletDetailsPage extends StatefulWidget {
}

class _WalletDetailsPageState extends State<WalletDetailsPage> {
Observable<List<Balance>>? get balancesList => StarportApp.walletsStore.balancesList;
ObservableList<Balance> get balancesList => StarportApp.walletsStore.balancesList;

bool get isBalancesLoading => StarportApp.walletsStore.isBalancesLoading;

bool get isSendMoneyLoading => StarportApp.walletsStore.isSendMoneyLoading;

bool get isError => StarportApp.walletsStore.isError;
bool get isError => StarportApp.walletsStore.isBalancesLoadingError;

@override
void initState() {
Expand All @@ -50,21 +50,20 @@ class _WalletDetailsPageState extends State<WalletDetailsPage> {
const Divider(),
const Padding(padding: EdgeInsets.only(top: 16)),
BalanceHeading(),
if (balancesList != null)
Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: balancesList!.value
.map(
(balance) => BalanceCard(
denomText: balance.denom.text,
amountDisplayText: balance.amount.value.toString(),
onTransferPressed: () => _transferPressed(balance),
),
)
.toList(),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: balancesList
.map(
(balance) => BalanceCard(
denomText: balance.denom.text,
amountDisplayText: balance.amount.value.toString(),
onTransferPressed: () => _transferPressed(balance),
),
)
.toList(),
),
),
if (isSendMoneyLoading)
const Padding(
padding: EdgeInsets.only(top: 8.0),
Expand Down Expand Up @@ -99,7 +98,7 @@ class _WalletDetailsPageState extends State<WalletDetailsPage> {
}

Future<void> _openSendMoneySheet(Denom denom) async {
showModalBottomSheet(
final result = await showModalBottomSheet(
context: context,
builder: (context) => SafeArea(
child: SendMoneySheet(
Expand All @@ -108,5 +107,8 @@ class _WalletDetailsPageState extends State<WalletDetailsPage> {
),
),
);
if (result == true) {
StarportApp.walletsStore.getBalances(widget.walletInfo.address);
}
}
}
Loading