Skip to content

Commit

Permalink
feat: Template - routing page (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejchm authored Aug 3, 2021
1 parent b5def25 commit 3efa695
Show file tree
Hide file tree
Showing 12 changed files with 193 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ import 'package:flutter/material.dart';
class ContentStateSwitcher extends StatelessWidget {
final bool isLoading;
final bool isEmpty;
final bool isError;
final Widget loadingChild;
final Widget emptyChild;
final Widget contentChild;
final Widget errorChild;

const ContentStateSwitcher({
Key? key,
this.isLoading = false,
this.isEmpty = false,
this.isError = false,
this.loadingChild = const ContentLoadingIndicator(),
this.emptyChild = const SizedBox.shrink(),
this.errorChild = const SizedBox.shrink(),
required this.contentChild,
}) : super(key: key);

Expand All @@ -23,9 +27,11 @@ class ContentStateSwitcher extends StatelessWidget {
duration: const MediumDuration(),
child: isLoading
? loadingChild
: isEmpty
? emptyChild
: contentChild,
: isError
? errorChild
: isEmpty
? emptyChild
: contentChild,
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:cosmos_ui_components/cosmos_ui_components.dart';
import 'package:flutter/material.dart';

class CosmosErrorView extends StatelessWidget {
const CosmosErrorView({
Key? key,
required this.title,
required this.message,
}) : super(key: key);

final String title;
final String message;

@override
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Icons.error,
color: Theme.of(context).colorScheme.error,
),
const SizedBox(height: CosmosAppTheme.spacingM),
Text(title),
const SizedBox(height: CosmosAppTheme.spacingM),
Text(message),
],
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export 'components/content_loading_indicator.dart';
export 'components/content_state_switcher.dart';
export 'components/cosmos_app_bar.dart';
export 'components/cosmos_elevated_button.dart';
export 'components/cosmos_error_view.dart';
export 'components/mnemonic_choice_chip.dart';
export 'components/mnemonic_words_grid.dart';
export 'cosmos_app_theme.dart';
Expand Down
1 change: 0 additions & 1 deletion packages/cosmos_ui_components/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ dependencies:
path: packages/cosmos_utils
ref: main


dev_dependencies:
flutter_test:
sdk: flutter
Expand Down
6 changes: 3 additions & 3 deletions packages/transaction_signing_gateway/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.6.1"
version: "2.5.0"
bech32:
dependency: transitive
description:
Expand Down Expand Up @@ -409,7 +409,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.8.0"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -444,7 +444,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.0"
version: "0.2.19"
typed_data:
dependency: transitive
description:
Expand Down
24 changes: 24 additions & 0 deletions starport_template/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
import 'package:flutter/material.dart';
import 'package:starport_template/starport_app.dart';
import 'package:starport_template/stores/wallets_store.dart';
import 'package:transaction_signing_gateway/alan/alan_credentials_serializer.dart';
import 'package:transaction_signing_gateway/alan/alan_transaction_broadcaster.dart';
import 'package:transaction_signing_gateway/alan/alan_transaction_signer.dart';
import 'package:transaction_signing_gateway/gateway/transaction_signing_gateway.dart';
import 'package:transaction_signing_gateway/mobile/mobile_key_info_storage.dart';
import 'package:transaction_signing_gateway/mobile/no_op_transaction_summary_ui.dart';

void main() {
_buildDependencies();
runApp(StarportApp());
}

void _buildDependencies() {
StarportApp.signingGateway = TransactionSigningGateway(
transactionSummaryUI: NoOpTransactionSummaryUI(),
signers: [
AlanTransactionSigner(),
],
broadcasters: [
AlanTransactionBroadcaster(),
],
infoStorage: MobileKeyInfoStorage(
serializers: [AlanCredentialsSerializer()],
),
);
StarportApp.walletsStore = WalletsStore(StarportApp.signingGateway);
}
47 changes: 47 additions & 0 deletions starport_template/lib/pages/routing_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'package:cosmos_ui_components/cosmos_ui_components.dart';
import 'package:flutter/material.dart';
import 'package:starport_template/pages/mnemonic_onboarding_page.dart';
import 'package:starport_template/pages/wallets_list_page.dart';
import 'package:starport_template/starport_app.dart';

class RoutingPage extends StatefulWidget {
const RoutingPage({Key? key}) : super(key: key);

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

class _RoutingPageState extends State<RoutingPage> {
@override
void initState() {
super.initState();
_loadWallets();
}

Future<void> _loadWallets() async {
final store = StarportApp.walletsStore;
await store.loadWallets();
if (store.loadWalletsFailure.value == null) {
if (store.wallets.value.isEmpty) {
Navigator.of(context).push(MaterialPageRoute(builder: (_) => const MnemonicOnboardingPage()));
} else {
Navigator.of(context).push(MaterialPageRoute(builder: (_) => const WalletsListPage()));
}
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
body: ContentStateSwitcher(
isLoading: StarportApp.walletsStore.areWalletsLoading.value,
isError: StarportApp.walletsStore.loadWalletsFailure.value != null,
errorChild: const CosmosErrorView(
title: "Something went wrong",
message: "We had problems retrieving wallets from secure storage.",
),
contentChild: const SizedBox(),
),
);
}
}
14 changes: 14 additions & 0 deletions starport_template/lib/pages/wallets_list_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'package:flutter/material.dart';

class WalletsListPage extends StatelessWidget {
const WalletsListPage({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return const Scaffold(
body: Center(
child: Text("Wallets List Page"),
),
);
}
}
9 changes: 7 additions & 2 deletions starport_template/lib/starport_app.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import 'package:cosmos_ui_components/cosmos_ui_components.dart';
import 'package:flutter/material.dart';
import 'package:starport_template/pages/mnemonic_onboarding_page.dart';
import 'package:starport_template/pages/routing_page.dart';
import 'package:starport_template/stores/wallets_store.dart';
import 'package:transaction_signing_gateway/gateway/transaction_signing_gateway.dart';

class StarportApp extends StatelessWidget {
static late TransactionSigningGateway signingGateway;
static late WalletsStore walletsStore;

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Starport template',
theme: CosmosAppTheme.buildAppTheme(),
home: const MnemonicOnboardingPage(),
home: const RoutingPage(),
);
}
}
25 changes: 25 additions & 0 deletions starport_template/lib/stores/wallets_store.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:mobx/mobx.dart';
import 'package:transaction_signing_gateway/gateway/transaction_signing_gateway.dart';
import 'package:transaction_signing_gateway/model/credentials_storage_failure.dart';
import 'package:transaction_signing_gateway/model/wallet_public_info.dart';

class WalletsStore {
final TransactionSigningGateway _transactionSigningGateway;

WalletsStore(this._transactionSigningGateway);

final Observable<bool> areWalletsLoading = Observable(false);

final Observable<CredentialsStorageFailure?> loadWalletsFailure = Observable(null);

Observable<List<WalletPublicInfo>> wallets = Observable([]);

Future<void> loadWallets() async {
areWalletsLoading.value = true;
(await _transactionSigningGateway.getWalletsList()).fold(
(fail) => loadWalletsFailure.value = fail,
(newWallets) => wallets.value = newWallets,
);
areWalletsLoading.value = false;
}
}
28 changes: 22 additions & 6 deletions starport_template/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ packages:
dependency: "direct main"
description:
path: "packages/cosmos_ui_components"
ref: main
resolved-ref: "2094d62b6ca111c0a7586609a65b15b24df76f7c"
ref: "feature/template-routing-page"
resolved-ref: "8d806c743aff52a079cbb101b176be10b3c36eef"
url: "https://github.com/tendermint/flutter.git"
source: git
version: "0.0.1"
Expand All @@ -148,7 +148,7 @@ packages:
description:
path: "packages/cosmos_utils"
ref: main
resolved-ref: "2094d62b6ca111c0a7586609a65b15b24df76f7c"
resolved-ref: b5def25829007bef4b10498514805f79f30b111e
url: "https://github.com/tendermint/flutter.git"
source: git
version: "0.0.1"
Expand Down Expand Up @@ -220,6 +220,13 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_mobx:
dependency: "direct main"
description:
name: flutter_mobx
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
flutter_secure_storage:
dependency: transitive
description:
Expand Down Expand Up @@ -330,6 +337,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
mobx:
dependency: "direct main"
description:
name: mobx
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3"
package_config:
dependency: transitive
description:
Expand Down Expand Up @@ -436,9 +450,11 @@ packages:
transaction_signing_gateway:
dependency: "direct main"
description:
path: "../packages/transaction_signing_gateway"
relative: true
source: path
path: "packages/transaction_signing_gateway"
ref: main
resolved-ref: b5def25829007bef4b10498514805f79f30b111e
url: "https://github.com/tendermint/flutter.git"
source: git
version: "0.0.1"
typed_data:
dependency: transitive
Expand Down
12 changes: 9 additions & 3 deletions starport_template/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,27 @@ environment:
dependencies:
flutter:
sdk: flutter
transaction_signing_gateway:
path: ../packages/transaction_signing_gateway

mobx: ^2.0.3
flutter_mobx: ^2.0.1
cosmos_ui_components:
git:
url: https://github.com/tendermint/flutter.git
path: packages/cosmos_ui_components
ref: main
ref: feature/template-routing-page

cosmos_utils:
git:
url: https://github.com/tendermint/flutter.git
path: packages/cosmos_utils
ref: main

transaction_signing_gateway:
git:
url: https://github.com/tendermint/flutter.git
path: packages/transaction_signing_gateway
ref: main

cupertino_icons: ^1.0.3

dev_dependencies:
Expand Down

0 comments on commit 3efa695

Please sign in to comment.