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

feat: created config base env file #244

Merged
merged 14 commits into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from 11 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
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ install-cosmos-ui-components:
install-cosmos-utils:
$(info Running flutter pub upgrade on `cosmos_utils`)
cd packages/cosmos_utils && fvm install && fvm flutter pub upgrade

install-cosmos-auth:
$(info Running flutter pub upgrade on `cosmos_auth`)
cd packages/cosmos_auth && fvm install && fvm flutter pub upgrade

install-transaction-signing-gateway:
$(info Running flutter pub upgrade on `transaction_signing_gateway`)
Expand All @@ -17,6 +21,7 @@ install-starport-template:

# Ensures proper flutter channel is in use, runs pub upgrade.
install:
$(MAKE) install-cosmos-auth
$(MAKE) install-cosmos-ui-components
$(MAKE) install-cosmos-utils
$(MAKE) install-transaction-signing-gateway
Expand Down
14 changes: 7 additions & 7 deletions packages/cosmos_auth/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ packages:
description:
path: "packages/cosmos_utils"
ref: main
resolved-ref: "79f8b8ebb452ffbe4e3fa092e43824f0d2a79282"
resolved-ref: "6d6a66c11aec98326728f99eab2672a88a9de8a3"
url: "https://github.com/tendermint/flutter.git"
source: git
version: "0.0.1"
Expand Down Expand Up @@ -215,7 +215,7 @@ packages:
name: js
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.3"
version: "0.6.4"
lint:
dependency: "direct dev"
description:
Expand All @@ -229,7 +229,7 @@ packages:
name: local_auth
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.10"
version: "1.1.11"
logging:
dependency: transitive
description:
Expand Down Expand Up @@ -313,7 +313,7 @@ packages:
name: pointycastle
url: "https://pub.dartlang.org"
source: hosted
version: "3.5.1"
version: "3.5.2"
pool:
dependency: transitive
description:
Expand All @@ -327,14 +327,14 @@ packages:
name: pub_semver
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.1.1"
shelf:
dependency: transitive
description:
name: shelf
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.0"
shelf_packages_handler:
dependency: transitive
description:
Expand Down Expand Up @@ -481,5 +481,5 @@ packages:
source: hosted
version: "3.1.0"
sdks:
dart: ">=2.15.0-7.0.dev <3.0.0"
dart: ">=2.16.0 <3.0.0"
flutter: ">=2.5.0"
6 changes: 6 additions & 0 deletions packages/cosmos_auth/test/mocks/mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import 'package:mocktail/mocktail.dart';
class StubSecureDataStore implements SecureDataStore {
Map<String, String> map = {};

@override
Future<Either<CredentialsStorageFailure, bool>> clearAllData() async {
map.clear();
return right(true);
}

@override
Future<Either<CredentialsStorageFailure, String?>> readSecureText({
required String key,
Expand Down
2 changes: 1 addition & 1 deletion packages/cosmos_ui_components/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ packages:
description:
path: "packages/cosmos_utils"
ref: main
resolved-ref: "99035c7be78a9959591220c8efb3e1e122274c03"
resolved-ref: "6d6a66c11aec98326728f99eab2672a88a9de8a3"
url: "https://github.com/tendermint/flutter.git"
source: git
version: "0.0.1"
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 @@ -28,7 +28,7 @@ packages:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "3.2.2"
version: "3.3.0"
args:
dependency: transitive
description:
Expand Down Expand Up @@ -167,7 +167,7 @@ packages:
description:
path: "packages/cosmos_utils"
ref: main
resolved-ref: "99035c7be78a9959591220c8efb3e1e122274c03"
resolved-ref: "6d6a66c11aec98326728f99eab2672a88a9de8a3"
url: "https://github.com/tendermint/flutter.git"
source: git
version: "0.0.1"
Expand Down Expand Up @@ -673,7 +673,7 @@ packages:
name: win32
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.4"
version: "2.5.1"
xdg_directories:
dependency: transitive
description:
Expand Down
24 changes: 19 additions & 5 deletions starport_template/README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,46 @@
## Setup and run Flutter app

- [Setup Flutter based on your operating system](https://flutter.dev/docs/get-started/install)

- Make sure you follow all the steps above and have an all-green output of `flutter doctor` command.

- [Install and run Anroid Studio once](https://developer.android.com/studio/install)

- (For iOS) Install XCode from AppStore

- You can use Android Studio, [IntelliJ Idea](https://www.jetbrains.com/idea/download),
or [VSCode](https://code.visualstudio.com/download) for Flutter development

- Install Flutter plugin in your chosen IDE

- Clone this repository using `git clone https://github.com/tendermint/flutter.git`

- To run it on your `localhost` environment, you will just have to run `main.dart` file in your project. That can be
done directly by clicking on the play button in your IDE, or by running `flutter run` from the root of your project.
This will run the app on any device or simulator connected to your system

- If you're running the app on real device instead of emulator/simulator or want to taget a specific blockchain run on a
remote machine, make sure to specify proper urls and ports when running the app. Here is an example for running the
app on cosmos hub testnet:
remote machine, make sure to specify proper urls and ports when running the app.

- Edit and update your environment variables in the [`app_config.dart`](https://github.com/tendermint/flutter/blob/main/starport_template/app_config.dart)

- Run the `starport_template` app using `fvm flutter run` or `make run-dev` commands:

```
flutter run --dart-define=LCD_URL=https://api.testnet.cosmos.network --dart-define=LCD_PORT=443 --dart-define=GRPC_URL=https://grpc.testnet.cosmos.network --dart-define=GRPC_PORT=443
```

## Using template from Starport's scaffolded chain

- Clone the [Starport](https://github.com/tendermint/starport) repository from `develop` branch

- Make sure to install [GoLang](https://go.dev/dl/) for your platform

- Run `make install` in Starport's root directory

- Run `starport scaffold chain github.com/cosmonaut/mars` to create a new chain

- Run `cd mars`

- Run `starport scaffold flutter` to create a new Flutter app (this clones the `starport_template` repository - the
current repo) and puts in under `flutter` subdirectory

- Run `starport generate dart` to generate dart files from proto files to be used by the template to interact with the
blockchain
61 changes: 61 additions & 0 deletions starport_template/lib/app_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import 'package:alan/alan.dart';
import 'package:grpc/grpc.dart';

class AppConfig {
AppConfig({
this.lcdUrl = 'http://10.0.2.2',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 10.0.2.2 - localhost for android emulators
  • lhttp://localhost - ios simulator

you'll have to stick with only 1 version, I suggest going with http://localhost for both LCD and grpc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

this.grpcUrl = 'http://localhost',
this.lcdPort = '1317',
this.grpcPort = '9090',
this.prefixAddress = 'cosmos',
});

/// Configure the LCD Url
final String lcdUrl;

/// Configure the GRPC Url
final String grpcUrl;

/// Configure the LCD Port
final String lcdPort;

/// Configure the GRPC Port
final String grpcPort;

/// Configure the address prefix
final String prefixAddress;

/// Configure the base api url
String get baseApiUrl => '$lcdUrl:$lcdPort';

/// Network information of the Cosmos-based network.
NetworkInfo get networkInfo => NetworkInfo(
bech32Hrp: prefixAddress,
lcdInfo: LCDInfo(
host: lcdUrl,
port: int.parse(lcdPort),
),
grpcInfo: GRPCInfo(
host: grpcUrl,
port: int.parse(grpcPort),
credentials:
int.parse(grpcPort) == 443 ? const ChannelCredentials.secure() : const ChannelCredentials.insecure(),
),
);

AppConfig copyWith({
String? lcdUrl,
String? grpcUrl,
String? lcdPort,
String? grpcPort,
String? prefixAddress,
}) {
return AppConfig(
lcdUrl: lcdUrl ?? this.lcdUrl,
grpcUrl: grpcUrl ?? this.grpcUrl,
lcdPort: lcdPort ?? this.lcdPort,
grpcPort: grpcPort ?? this.grpcPort,
prefixAddress: prefixAddress ?? this.prefixAddress,
);
}
}
12 changes: 6 additions & 6 deletions starport_template/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import 'package:alan/alan.dart';
import 'package:cosmos_auth/cosmos_auth.dart';
import 'package:cosmos_utils/cosmos_utils.dart';
import 'package:flutter/material.dart';
import 'package:starport_template/app_config.dart';
import 'package:starport_template/starport_app.dart';
import 'package:starport_template/stores/accounts_store.dart';
import 'package:starport_template/stores/settings_store.dart';
import 'package:starport_template/stores/transactions_store.dart';
import 'package:starport_template/utils/base_env.dart';
import 'package:transaction_signing_gateway/mobile/no_op_transaction_summary_ui.dart';
import 'package:transaction_signing_gateway/transaction_signing_gateway.dart';

Expand All @@ -16,8 +16,8 @@ void main() {
}

void _buildDependencies() {
StarportApp.baseEnv = BaseEnv();
StarportApp.networkInfo = StarportApp.baseEnv.networkInfo;
StarportApp.appConfig = AppConfig();
StarportApp.networkInfo = StarportApp.appConfig.networkInfo;
_logBackendInfo(StarportApp.networkInfo);
StarportApp.secureDataStore = FlutterSecureStorageDataStore();

Expand All @@ -37,9 +37,9 @@ void _buildDependencies() {
);

StarportApp.cosmosAuth = CosmosAuth();
StarportApp.accountsStore = AccountsStore(StarportApp.signingGateway, StarportApp.baseEnv);
StarportApp.settingsStore = SettingsStore(StarportApp.cosmosAuth, StarportApp.secureDataStore, StarportApp.baseEnv);
StarportApp.transactionsStore = TransactionsStore(StarportApp.baseEnv);
StarportApp.accountsStore = AccountsStore(StarportApp.signingGateway, StarportApp.appConfig);
StarportApp.settingsStore = SettingsStore(StarportApp.cosmosAuth, StarportApp.secureDataStore, StarportApp.appConfig);
StarportApp.transactionsStore = TransactionsStore(StarportApp.appConfig);
}

void _logBackendInfo(NetworkInfo networkInfo) => debugLog(
Expand Down
4 changes: 2 additions & 2 deletions starport_template/lib/starport_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import 'package:cosmos_auth/auth/cosmos_auth.dart';
import 'package:cosmos_ui_components/cosmos_theme.dart';
import 'package:cosmos_utils/cosmos_utils.dart';
import 'package:flutter/material.dart';
import 'package:starport_template/app_config.dart';
import 'package:starport_template/pages/routing_page.dart';
import 'package:starport_template/stores/accounts_store.dart';
import 'package:starport_template/stores/settings_store.dart';
import 'package:starport_template/stores/transactions_store.dart';
import 'package:starport_template/utils/base_env.dart';
import 'package:transaction_signing_gateway/gateway/transaction_signing_gateway.dart';

class StarportApp extends StatelessWidget {
Expand All @@ -18,7 +18,7 @@ class StarportApp extends StatelessWidget {
static late TransactionSigningGateway signingGateway;
static late AccountsStore accountsStore;
static late TransactionsStore transactionsStore;
static late BaseEnv baseEnv;
static late AppConfig appConfig;
static late NetworkInfo networkInfo;
static late SecureDataStore secureDataStore;
static late SettingsStore settingsStore;
Expand Down
10 changes: 5 additions & 5 deletions starport_template/lib/stores/accounts_store.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:cosmos_utils/cosmos_utils.dart';
import 'package:flutter/foundation.dart';
import 'package:mobx/mobx.dart';
import 'package:starport_template/app_config.dart';
import 'package:starport_template/entities/account_additional_data.dart';
import 'package:starport_template/entities/balance.dart';
import 'package:starport_template/entities/import_account_form_data.dart';
import 'package:starport_template/utils/base_env.dart';
import 'package:starport_template/utils/cosmos_balances.dart';
import 'package:starport_template/utils/token_sender.dart';
import 'package:transaction_signing_gateway/alan/alan_account_derivation_info.dart';
Expand All @@ -13,13 +13,13 @@ import 'package:transaction_signing_gateway/transaction_signing_gateway.dart';
class AccountsStore {
AccountsStore(
this._transactionSigningGateway,
this.baseEnv,
this.appConfig,
);

static const chainId = 'my_starport_chain';
final TransactionSigningGateway _transactionSigningGateway;

final BaseEnv baseEnv;
final AppConfig appConfig;

final Observable<bool> _areAccountsLoading = Observable(false);
final Observable<bool> _isSendMoneyLoading = Observable(false);
Expand Down Expand Up @@ -149,7 +149,7 @@ class AccountsStore {
isBalancesLoadingError = false;
isBalancesLoading = true;
try {
final newBalances = await CosmosBalances(baseEnv).getBalances(accountAddress);
final newBalances = await CosmosBalances(appConfig).getBalances(accountAddress);
balancesList
..clear()
..addAll(newBalances);
Expand All @@ -170,7 +170,7 @@ class AccountsStore {
.deriveAccount(
accountDerivationInfo: AlanAccountDerivationInfo(
accountAlias: data.name,
networkInfo: baseEnv.networkInfo,
networkInfo: appConfig.networkInfo,
mnemonic: data.mnemonic,
chainId: chainId,
),
Expand Down
4 changes: 2 additions & 2 deletions starport_template/lib/stores/settings_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import 'package:cosmos_auth/auth/cosmos_auth.dart';
import 'package:cosmos_utils/cosmos_utils.dart';
import 'package:mobx/mobx.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:starport_template/app_config.dart';
import 'package:starport_template/pages/passcode_prompt_page.dart';
import 'package:starport_template/utils/base_env.dart';
import 'package:starport_template/utils/node_info_loader.dart';

class SettingsStore {
Expand All @@ -18,7 +18,7 @@ class SettingsStore {
static const _nodeNetworkKey = 'node_network';

final CosmosAuth _cosmosAuth;
final BaseEnv _baseEnv;
final AppConfig _baseEnv;
final SecureDataStore _secureDataStore;
final Observable<bool> _appLockEnabled = Observable(false);
final Observable<bool> _biometricsEnabled = Observable(false);
Expand Down
8 changes: 4 additions & 4 deletions starport_template/lib/stores/transactions_store.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import 'package:cosmos_utils/cosmos_utils.dart';
import 'package:mobx/mobx.dart';
import 'package:starport_template/app_config.dart';
import 'package:starport_template/entities/transaction_history_item.dart';
import 'package:starport_template/utils/base_env.dart';
import 'package:starport_template/utils/cosmos_transaction_history_loader.dart';

class TransactionsStore {
TransactionsStore(this.baseEnv);
TransactionsStore(this.appConfig);

final BaseEnv baseEnv;
final AppConfig appConfig;
final Observable<bool> _isTransactionHistoryLoading = Observable(false);
final Observable<bool> _isTransactionHistoryError = Observable(false);

Expand All @@ -24,7 +24,7 @@ class TransactionsStore {
Future<void> getTransactionHistory(String accountAddress) async {
isTransactionHistoryLoading = true;
try {
final list = await CosmosTransactionHistoryLoader(baseEnv).getTransactionHistory(accountAddress);
final list = await CosmosTransactionHistoryLoader(appConfig).getTransactionHistory(accountAddress);
transactionsList
..clear()
..addAll(list);
Expand Down
Loading