Skip to content

Commit d9580f1

Browse files
authored
fix: Starport Template pre-release fixes (#94)
1 parent ce7ca3f commit d9580f1

16 files changed

+415
-220
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class ImportWalletFormData {
2+
final String mnemonic;
3+
final String name;
4+
final String password;
5+
6+
const ImportWalletFormData({
7+
required this.mnemonic,
8+
required this.name,
9+
required this.password,
10+
});
11+
}

starport_template/lib/main.dart

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@ void _buildDependencies() {
2727
serializers: [AlanCredentialsSerializer()],
2828
),
2929
);
30-
StarportApp.baseEnv = BaseEnv()
31-
..setEnv(
32-
lcdUrl: lcdUrl,
33-
grpcUrl: grpcUrl,
34-
lcdPort: lcdPort,
35-
grpcPort: grpcPort,
36-
ethUrl: ethUrl,
37-
);
30+
StarportApp.baseEnv = BaseEnv();
3831
StarportApp.walletsStore = WalletsStore(StarportApp.signingGateway, StarportApp.baseEnv);
3932
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import 'package:cosmos_ui_components/components/template/cosmos_password_field.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:starport_template/entities/import_wallet_form_data.dart';
4+
5+
class AddWalletBottomSheet extends StatefulWidget {
6+
final void Function(ImportWalletFormData) importClicked;
7+
8+
const AddWalletBottomSheet({
9+
Key? key,
10+
required this.importClicked,
11+
}) : super(key: key);
12+
13+
@override
14+
_AddWalletBottomSheetState createState() => _AddWalletBottomSheetState();
15+
}
16+
17+
class _AddWalletBottomSheetState extends State<AddWalletBottomSheet> {
18+
String _mnemonic = "";
19+
String _alias = "";
20+
String _password = "";
21+
22+
@override
23+
Widget build(BuildContext context) {
24+
return SafeArea(
25+
child: Column(
26+
mainAxisSize: MainAxisSize.min,
27+
children: [
28+
ListTile(
29+
title: TextFormField(
30+
decoration: const InputDecoration(
31+
labelText: "Enter mnemonic",
32+
border: OutlineInputBorder(),
33+
),
34+
onChanged: (value) => _mnemonic = value,
35+
),
36+
),
37+
ListTile(
38+
title: TextFormField(
39+
decoration: const InputDecoration(
40+
labelText: "Enter alias",
41+
border: OutlineInputBorder(),
42+
),
43+
onChanged: (value) => _alias = value,
44+
),
45+
),
46+
ListTile(
47+
title: CosmosPasswordField(
48+
onPasswordUpdated: (value) => _password = value,
49+
),
50+
),
51+
ElevatedButton(
52+
onPressed: () => _importClicked(context),
53+
style: ElevatedButton.styleFrom(
54+
shape: const StadiumBorder(),
55+
),
56+
child: const Text("Import wallet"),
57+
),
58+
],
59+
),
60+
);
61+
}
62+
63+
void _importClicked(BuildContext context) {
64+
Navigator.of(context).pop();
65+
widget.importClicked(
66+
ImportWalletFormData(
67+
mnemonic: _mnemonic,
68+
name: _alias,
69+
password: _password,
70+
),
71+
);
72+
}
73+
}

starport_template/lib/pages/add_wallet_page.dart

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 83 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
import 'package:cosmos_ui_components/cosmos_ui_components.dart';
22
import 'package:cosmos_utils/cosmos_utils.dart';
33
import 'package:flutter/material.dart';
4+
import 'package:flutter_mobx/flutter_mobx.dart';
5+
import 'package:starport_template/entities/import_wallet_form_data.dart';
6+
import 'package:starport_template/pages/add_wallet_bottom_sheet.dart';
47
import 'package:starport_template/pages/wallets_list_page.dart';
58
import 'package:starport_template/starport_app.dart';
69
import 'package:starport_template/widgets/password_setup_sheet.dart';
710

811
class MnemonicOnboardingPage extends StatefulWidget {
9-
const MnemonicOnboardingPage({Key? key}) : super(key: key);
12+
final bool openWalletsListOnDone;
13+
14+
const MnemonicOnboardingPage({
15+
Key? key,
16+
this.openWalletsListOnDone = true,
17+
}) : super(key: key);
1018

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

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

28+
bool get isLoading => StarportApp.walletsStore.isWalletImporting;
29+
2030
@override
2131
Widget build(BuildContext context) {
2232
return Scaffold(
@@ -26,34 +36,59 @@ class _MnemonicOnboardingPageState extends State<MnemonicOnboardingPage> {
2636
body: SafeArea(
2737
child: Padding(
2838
padding: const EdgeInsets.symmetric(horizontal: CosmosAppTheme.spacingM),
29-
child: ContentStateSwitcher(
30-
isEmpty: mnemonic.isEmpty,
31-
emptyChild: Center(
32-
child: CosmosElevatedButton(
33-
onTap: _generateMnemonicClicked,
34-
text: "Create new Wallet",
39+
child: Observer(
40+
builder: (context) => ContentStateSwitcher(
41+
isEmpty: mnemonic.isEmpty,
42+
isLoading: isLoading,
43+
emptyChild: SizedBox.expand(
44+
child: Column(
45+
mainAxisAlignment: MainAxisAlignment.center,
46+
children: [
47+
CosmosElevatedButton(
48+
onTap: _generateMnemonicClicked,
49+
text: "Create new Wallet",
50+
),
51+
CosmosElevatedButton(
52+
onTap: _importExistingWalletClicked,
53+
text: "Import existing Wallet",
54+
),
55+
],
56+
),
3557
),
36-
),
37-
contentChild: Center(
38-
child: Column(
39-
mainAxisAlignment: MainAxisAlignment.center,
40-
mainAxisSize: MainAxisSize.min,
41-
children: [
42-
CosmosMnemonicWordsGrid(mnemonicWords: mnemonicWords),
43-
const SizedBox(height: CosmosAppTheme.spacingM),
44-
const Expanded(
45-
child: Text(
46-
'Be sure to write your mnemonic pass phrase in a safe place. '
47-
'This phrase is the only way to recover your account if you forget your password. ',
48-
textAlign: TextAlign.center,
58+
contentChild: Center(
59+
child: Column(
60+
children: [
61+
Expanded(
62+
child: SingleChildScrollView(
63+
child: Column(
64+
mainAxisAlignment: MainAxisAlignment.center,
65+
mainAxisSize: MainAxisSize.min,
66+
children: [
67+
const SizedBox(height: CosmosAppTheme.spacingM),
68+
const Text(
69+
'Be sure to write your mnemonic pass phrase in a safe place. '
70+
'This phrase is the only way to recover your account if you forget your password. ',
71+
textAlign: TextAlign.center,
72+
),
73+
const SizedBox(height: CosmosAppTheme.spacingM),
74+
Flexible(
75+
child: CosmosMnemonicWordsGrid(
76+
mnemonicWords: mnemonicWords,
77+
physics: const NeverScrollableScrollPhysics(),
78+
),
79+
),
80+
const SizedBox(height: CosmosAppTheme.spacingM),
81+
],
82+
),
83+
),
84+
),
85+
CosmosElevatedButton(
86+
onTap: _proceedClicked,
87+
text: "Proceed",
88+
suffixIcon: const Icon(Icons.arrow_forward),
4989
),
50-
),
51-
CosmosElevatedButton(
52-
onTap: _proceedClicked,
53-
text: "Proceed",
54-
suffixIcon: const Icon(Icons.arrow_forward),
55-
)
56-
],
90+
],
91+
),
5792
),
5893
),
5994
),
@@ -64,20 +99,36 @@ class _MnemonicOnboardingPageState extends State<MnemonicOnboardingPage> {
6499

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

102+
void _importExistingWalletClicked() => showModalBottomSheet(
103+
context: context,
104+
builder: (context) => AddWalletBottomSheet(importClicked: _importWallet),
105+
);
106+
67107
void _proceedClicked() => showModalBottomSheet(
68108
context: context,
69109
builder: (context) => PasswordSetupSheet(
70110
submitClicked: submitPasswordClicked,
71111
),
72112
);
73113

74-
Future submitPasswordClicked(String password) async {
75-
final store = StarportApp.walletsStore;
76-
StarportApp.password = password;
77-
await store.importAlanWallet(mnemonic, password);
114+
Future submitPasswordClicked(String password, String name) async => _importWallet(ImportWalletFormData(
115+
mnemonic: mnemonic.trim(),
116+
name: name,
117+
password: password,
118+
));
119+
120+
Future<void> _importWallet(ImportWalletFormData data) async {
121+
await StarportApp.walletsStore.importAlanWallet(data);
122+
_openWalletsList();
123+
}
124+
125+
void _openWalletsList() {
78126
if (!mounted) {
79127
return;
80128
}
81-
Navigator.of(context).push(MaterialPageRoute(builder: (_) => const WalletsListPage()));
129+
Navigator.of(context)..pop();
130+
if (widget.openWalletsListOnDone) {
131+
Navigator.of(context).push(MaterialPageRoute(builder: (_) => const WalletsListPage()));
132+
}
82133
}
83134
}

starport_template/lib/pages/routing_page.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class _RoutingPageState extends State<RoutingPage> {
2525
if (!mounted) {
2626
return;
2727
}
28-
if (store.wallets.value.isEmpty) {
28+
Navigator.of(context).pop();
29+
if (store.wallets.isEmpty) {
2930
Navigator.of(context).push(MaterialPageRoute(builder: (_) => const MnemonicOnboardingPage()));
3031
} else {
3132
Navigator.of(context).push(MaterialPageRoute(builder: (_) => const WalletsListPage()));

starport_template/lib/pages/wallet_details_page.dart

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ class WalletDetailsPage extends StatefulWidget {
2020
}
2121

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

2525
bool get isBalancesLoading => StarportApp.walletsStore.isBalancesLoading;
2626

2727
bool get isSendMoneyLoading => StarportApp.walletsStore.isSendMoneyLoading;
2828

29-
bool get isError => StarportApp.walletsStore.isError;
29+
bool get isError => StarportApp.walletsStore.isBalancesLoadingError;
3030

3131
@override
3232
void initState() {
@@ -50,21 +50,20 @@ class _WalletDetailsPageState extends State<WalletDetailsPage> {
5050
const Divider(),
5151
const Padding(padding: EdgeInsets.only(top: 16)),
5252
BalanceHeading(),
53-
if (balancesList != null)
54-
Padding(
55-
padding: const EdgeInsets.all(8.0),
56-
child: Column(
57-
children: balancesList!.value
58-
.map(
59-
(balance) => BalanceCard(
60-
denomText: balance.denom.text,
61-
amountDisplayText: balance.amount.value.toString(),
62-
onTransferPressed: () => _transferPressed(balance),
63-
),
64-
)
65-
.toList(),
66-
),
53+
Padding(
54+
padding: const EdgeInsets.all(8.0),
55+
child: Column(
56+
children: balancesList
57+
.map(
58+
(balance) => BalanceCard(
59+
denomText: balance.denom.text,
60+
amountDisplayText: balance.amount.value.toString(),
61+
onTransferPressed: () => _transferPressed(balance),
62+
),
63+
)
64+
.toList(),
6765
),
66+
),
6867
if (isSendMoneyLoading)
6968
const Padding(
7069
padding: EdgeInsets.only(top: 8.0),
@@ -99,7 +98,7 @@ class _WalletDetailsPageState extends State<WalletDetailsPage> {
9998
}
10099

101100
Future<void> _openSendMoneySheet(Denom denom) async {
102-
showModalBottomSheet(
101+
final result = await showModalBottomSheet(
103102
context: context,
104103
builder: (context) => SafeArea(
105104
child: SendMoneySheet(
@@ -108,5 +107,8 @@ class _WalletDetailsPageState extends State<WalletDetailsPage> {
108107
),
109108
),
110109
);
110+
if (result == true) {
111+
StarportApp.walletsStore.getBalances(widget.walletInfo.address);
112+
}
111113
}
112114
}

0 commit comments

Comments
 (0)