Skip to content

Commit

Permalink
added flavor to android, changed and cloned qr reader, added flavors …
Browse files Browse the repository at this point in the history
…to schemes
  • Loading branch information
quetool committed Jul 22, 2024
1 parent cc31ccc commit 4f1a2e3
Show file tree
Hide file tree
Showing 18 changed files with 100 additions and 113 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@ app.*.map.json
# Run scripts
*.sh
*.env.secret

example/wallet/packages/
14 changes: 14 additions & 0 deletions example/dapp/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,27 @@ android {
versionName flutterVersionName
}

// Specifies one flavor dimension.
flavorDimensions = ["version"]

productFlavors {
internal {
dimension "version"
applicationIdSuffix ".internal"
}
production {
dimension "version"
}
}

buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}

namespace 'com.walletconnect.flutterdapp'
}

Expand Down
8 changes: 7 additions & 1 deletion example/dapp/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="wcflutterdapp" />
<data android:scheme="wcflutterdapp-internal" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="wcflutterdapp-production" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
Expand Down
4 changes: 2 additions & 2 deletions example/dapp/ios/Runner/Info-internal.plist
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleURLSchemes</key>
<array>
<string>wcflutterdappinternal</string>
<string>wcflutterdapp-internal</string>
</array>
</dict>
</array>
Expand All @@ -41,7 +41,7 @@
<string></string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>wcflutterwalletinternal</string>
<string>wcflutterwallet-internal</string>
<string>walletapp</string>
</array>
<key>ITSAppUsesNonExemptEncryption</key>
Expand Down
4 changes: 2 additions & 2 deletions example/dapp/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleURLSchemes</key>
<array>
<string>wcflutterdapp</string>
<string>wcflutterdapp-production</string>
</array>
</dict>
</array>
Expand All @@ -43,7 +43,7 @@
<string></string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>wcflutterwallet</string>
<string>wcflutterwallet-production</string>
<string>walletapp</string>
</array>
<key>LSRequiresIPhoneOS</key>
Expand Down
3 changes: 2 additions & 1 deletion example/dapp/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class _MyHomePageState extends State<MyHomePage> {
}

Future<void> initialize() async {
const flavor = String.fromEnvironment('FLUTTER_APP_FLAVOR');
_web3App = Web3App(
core: Core(
projectId: DartDefines.projectId,
Expand All @@ -70,7 +71,7 @@ class _MyHomePageState extends State<MyHomePage> {
'https://images.prismic.io/wallet-connect/65785a56531ac2845a260732_WalletConnect-App-Logo-1024X1024.png'
],
redirect: Redirect(
native: 'wcflutterdapp://',
native: 'wcflutterdapp-$flavor://',
universal: 'https://walletconnect.com',
),
),
Expand Down
11 changes: 7 additions & 4 deletions example/dapp/lib/pages/connect_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ class ConnectPageState extends State<ConnectPage> {
);

final encodedUri = Uri.encodeComponent(connectResponse.uri.toString());
final uri = 'wcflutterwallet://wc?uri=$encodedUri';
const flavor = String.fromEnvironment('FLUTTER_APP_FLAVOR');
final uri = 'wcflutterwallet-$flavor://wc?uri=$encodedUri';
// final uri = 'metamask://wc?uri=$encodedUri';
if (await canLaunchUrlString(uri)) {
final openApp = await showDialog(
Expand Down Expand Up @@ -422,8 +423,9 @@ class ConnectPageState extends State<ConnectPage> {
);

final scheme = event?.session.peer.metadata.redirect?.native;
const flavor = String.fromEnvironment('FLUTTER_APP_FLAVOR');
launchUrlString(
scheme ?? 'wcflutterwallet://',
scheme ?? 'wcflutterwallet-$flavor://',
mode: LaunchMode.externalApplication,
);

Expand All @@ -446,10 +448,11 @@ class ConnectPageState extends State<ConnectPage> {
Function(String message)? showToast,
}) async {
final methods = optionalNamespaces['eip155']?.methods ?? [];
const flavor = String.fromEnvironment('FLUTTER_APP_FLAVOR');
final authResponse = await widget.web3App.authenticate(
params: SessionAuthRequestParams(
chains: _selectedChains.map((e) => e.chainId).toList(),
domain: 'wcflutterdapp://',
domain: 'wcflutterdapp-$flavor://',
nonce: AuthUtils.generateNonce(),
uri: Constants.aud,
statement: 'Welcome to example flutter app',
Expand All @@ -458,7 +461,7 @@ class ConnectPageState extends State<ConnectPage> {
);

final encodedUri = Uri.encodeComponent(authResponse.uri.toString());
final uri = 'wcflutterwallet://wc?uri=$encodedUri';
final uri = 'wcflutterwallet-$flavor://wc?uri=$encodedUri';

if (await canLaunchUrlString(uri)) {
final openApp = await showDialog(
Expand Down
4 changes: 3 additions & 1 deletion example/wallet/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ app.*.map.json
/android/app/release

# Run scripts
*.sh
*.sh

packages/
14 changes: 14 additions & 0 deletions example/wallet/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
namespace "com.walletconnect.flutterwallet"
compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion

Expand Down Expand Up @@ -53,6 +54,19 @@ android {
versionName flutterVersionName
}

// Specifies one flavor dimension.
flavorDimensions = ["version"]

productFlavors {
internal {
dimension "version"
applicationIdSuffix ".internal"
}
production {
dimension "version"
}
}

buildTypes {
release {
// TODO: Add your own signing config for the release build.
Expand Down
8 changes: 7 additions & 1 deletion example/wallet/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="wcflutterwallet" />
<data android:scheme="wcflutterwallet-production" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="wcflutterwallet-internal" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
Expand Down
19 changes: 19 additions & 0 deletions example/wallet/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
PODS:
- Flutter (1.0.0)
- MTBBarcodeScanner (5.0.11)
- package_info_plus (0.4.5):
- Flutter
- qr_bar_code_scanner_dialog (0.0.1):
- Flutter
- qr_code_scanner (0.2.0):
- Flutter
- MTBBarcodeScanner
- shared_preferences_foundation (0.0.1):
- Flutter
- FlutterMacOS
Expand All @@ -11,22 +17,35 @@ PODS:
DEPENDENCIES:
- Flutter (from `Flutter`)
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
- qr_bar_code_scanner_dialog (from `.symlinks/plugins/qr_bar_code_scanner_dialog/ios`)
- qr_code_scanner (from `.symlinks/plugins/qr_code_scanner/ios`)
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)

SPEC REPOS:
trunk:
- MTBBarcodeScanner

EXTERNAL SOURCES:
Flutter:
:path: Flutter
package_info_plus:
:path: ".symlinks/plugins/package_info_plus/ios"
qr_bar_code_scanner_dialog:
:path: ".symlinks/plugins/qr_bar_code_scanner_dialog/ios"
qr_code_scanner:
:path: ".symlinks/plugins/qr_code_scanner/ios"
shared_preferences_foundation:
:path: ".symlinks/plugins/shared_preferences_foundation/darwin"
url_launcher_ios:
:path: ".symlinks/plugins/url_launcher_ios/ios"

SPEC CHECKSUMS:
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
MTBBarcodeScanner: f453b33c4b7dfe545d8c6484ed744d55671788cb
package_info_plus: 58f0028419748fad15bf008b270aaa8e54380b1c
qr_bar_code_scanner_dialog: d59c27f37c96ef8649711e6eee8033a69191f907
qr_code_scanner: bb67d64904c3b9658ada8c402e8b4d406d5d796e
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78
url_launcher_ios: 5334b05cef931de560670eeae103fd3e431ac3fe

Expand Down
2 changes: 1 addition & 1 deletion example/wallet/ios/Runner/Info-internal.plist
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleURLSchemes</key>
<array>
<string>wcflutterwalletinternal</string>
<string>wcflutterwallet-internal</string>
</array>
</dict>
</array>
Expand Down
2 changes: 1 addition & 1 deletion example/wallet/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleURLSchemes</key>
<array>
<string>wcflutterwallet</string>
<string>wcflutterwallet-production</string>
</array>
</dict>
</array>
Expand Down
3 changes: 2 additions & 1 deletion example/wallet/lib/dependencies/web3wallet_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Web3WalletService extends IWeb3WalletService {
@override
Future<void> create() async {
// Create the web3wallet
const flavor = String.fromEnvironment('FLUTTER_APP_FLAVOR');
_web3Wallet = Web3Wallet(
core: Core(
projectId: DartDefines.projectId,
Expand All @@ -39,7 +40,7 @@ class Web3WalletService extends IWeb3WalletService {
'https://docs.walletconnect.com/assets/images/web3walletLogo-54d3b546146931ceaf47a3500868a73a.png'
],
redirect: Redirect(
native: 'wcflutterwallet://',
native: 'wcflutterwallet-$flavor://',
universal: 'https://walletconnect.com',
),
),
Expand Down
23 changes: 12 additions & 11 deletions example/wallet/lib/pages/apps_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:fl_toast/fl_toast.dart';
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:get_it_mixin/get_it_mixin.dart';
import 'package:qr_bar_code_scanner_dialog/qr_bar_code_scanner_dialog.dart';
import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart';
import 'package:walletconnect_flutter_v2_wallet/dependencies/bottom_sheet/i_bottom_sheet_service.dart';
import 'package:walletconnect_flutter_v2_wallet/dependencies/deep_link_handler.dart';
Expand All @@ -11,7 +12,6 @@ import 'package:walletconnect_flutter_v2_wallet/utils/constants.dart';
import 'package:walletconnect_flutter_v2_wallet/utils/eth_utils.dart';
import 'package:walletconnect_flutter_v2_wallet/utils/string_constants.dart';
import 'package:walletconnect_flutter_v2_wallet/widgets/pairing_item.dart';
import 'package:walletconnect_flutter_v2_wallet/widgets/qr_scan_sheet.dart';
import 'package:walletconnect_flutter_v2_wallet/widgets/uri_input_popup.dart';

class AppsPage extends StatefulWidget with GetItStatefulWidgetMixin {
Expand Down Expand Up @@ -196,16 +196,17 @@ class AppsPageState extends State<AppsPage> with GetItStateMixin {
}

Future _onScanQrCode() async {
final scannedValue = await showModalBottomSheet<String>(
context: context,
builder: (BuildContext modalContext) {
return QRScanSheet(
title: StringConstants.scanPairing,
);
},
);

_onFoundUri(scannedValue);
try {
QrBarCodeScannerDialog().getScannedQrBarCode(
context: context,
onCode: (value) {
if (!mounted) return;
_onFoundUri(value);
},
);
} catch (e) {
debugPrint(e.toString());
}
}

Future<void> _onFoundUri(String? uri) async {
Expand Down
3 changes: 3 additions & 0 deletions example/wallet/lib/pages/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ class _SettingsPageState extends State<SettingsPage> {
@override
void initState() {
super.initState();
// TODO
// PackageInfo.fromPlatform().then((info) {
// setState(() {
// version =
// '${info.version} (${info.buildNumber}) - SDK v$packageVersion';
// });
// });

version = const String.fromEnvironment('FLUTTER_APP_FLAVOR');
}

@override
Expand Down
Loading

0 comments on commit 4f1a2e3

Please sign in to comment.