Skip to content

Commit

Permalink
improvements and layout change in sample wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
quetool committed Jan 19, 2024
1 parent 4e0243e commit 911f613
Show file tree
Hide file tree
Showing 37 changed files with 452 additions and 618 deletions.
2 changes: 1 addition & 1 deletion example/dapp/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>myflutterwallet</string>
<string>wcflutterwallet</string>
</array>
</dict>
</plist>
20 changes: 11 additions & 9 deletions example/dapp/lib/pages/connect_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import 'package:fl_toast/fl_toast.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:qr_flutter/qr_flutter.dart';
// ignore: unused_import
import 'package:url_launcher/url_launcher_string.dart';
import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart';
import 'package:walletconnect_flutter_v2_dapp/models/chain_metadata.dart';
import 'package:walletconnect_flutter_v2_dapp/utils/constants.dart';
Expand Down Expand Up @@ -156,24 +158,24 @@ class ConnectPageState extends State<ConnectPage> {
// It is currently safer to send chains approvals on optionalNamespaces
// but depending on Wallet implementation you may need to send some (for innstance eip155:1) as required
final ConnectResponse res = await widget.web3App.connect(
requiredNamespaces: {
'eip155': const RequiredNamespace(
chains: [],
methods: MethodsConstants.requiredMethods,
events: EventsConstants.requiredEvents,
),
},
optionalNamespaces: {
'eip155': RequiredNamespace(
chains: _selectedChains.map((c) => c.chainId).toList(),
methods: MethodsConstants.optionalMethods,
events: EventsConstants.optionalEvents,
methods: MethodsConstants.allMethods,
events: EventsConstants.allEvents,
),
},
);

_showQrCode(res);

// // Uncomment to use a wallet
// final String encodedUri = Uri.encodeComponent(res.uri.toString());
// await launchUrlString(
// 'wcflutterwallet://wc?uri=$encodedUri',
// mode: LaunchMode.externalApplication,
// );

try {
debugPrint('Awaiting session proposal settlement');
final _ = await res.session.future;
Expand Down
19 changes: 9 additions & 10 deletions example/dapp/lib/widgets/session_widget.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher_string.dart';
import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart';
import 'package:walletconnect_flutter_v2_dapp/models/chain_metadata.dart';
import 'package:walletconnect_flutter_v2_dapp/utils/constants.dart';
Expand Down Expand Up @@ -183,22 +184,20 @@ class SessionWidgetState extends State<SessionWidget> {
),
child: ElevatedButton(
onPressed: () async {
final walletUrl = widget.session.peer.metadata.redirect?.native;
if ((walletUrl ?? '').isNotEmpty) {
launchUrlString(
walletUrl!,
mode: LaunchMode.externalApplication,
);
}
Future<dynamic> future = callChainMethod(
chainMetadata.type,
method,
chainMetadata,
address,
);
// print('got here');
// print(await future);
// if (chainMetadata.type == ChainType.eip155) {
// future =
// }
MethodDialog.show(
context,
method,
future,
);
MethodDialog.show(context, method, future);
},
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(
Expand Down
75 changes: 4 additions & 71 deletions example/dapp/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,47 +1,24 @@
name: walletconnect_flutter_v2_dapp
description: An example dApp for WalletConnect v2 built with Flutter.

# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
publish_to: "none"

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.0.0+1

environment:
sdk: '>=2.18.6 <3.0.0'
sdk: ">=2.18.6 <3.0.0"

# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
# consider running `flutter pub upgrade --major-versions`. Alternatively,
# dependencies can be manually updated by changing the version numbers below to
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
flutter:
sdk: flutter

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
qr_flutter: ^4.0.0
json_annotation: ^4.8.1
walletconnect_flutter_v2:
path: ../..
fl_toast: ^3.1.0
# kadena_dart_sdk: ^2.0.0
url_launcher: ^6.2.2
walletconnect_flutter_v2:
path: ../..

dev_dependencies:
flutter_test:
Expand All @@ -50,51 +27,7 @@ dev_dependencies:
json_serializable: ^6.5.3
dependency_validator: ^3.2.2

# The "flutter_lints" package below contains a set of recommended lints to
# encourage good coding practices. The lint set provided by the package is
# activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints: ^2.0.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter packages.
flutter:

# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true

# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg

# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware

# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages

# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
4 changes: 2 additions & 2 deletions example/wallet/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:label="wallet"
android:label="Web3Wallet"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
Expand All @@ -27,7 +27,7 @@
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myflutterwallet" />
<data android:scheme="wcflutterwallet" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
Expand Down
6 changes: 6 additions & 0 deletions example/wallet/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,15 @@ PODS:
- shared_preferences_foundation (0.0.1):
- Flutter
- FlutterMacOS
- url_launcher_ios (0.0.1):
- Flutter

DEPENDENCIES:
- Flutter (from `Flutter`)
- mobile_scanner (from `.symlinks/plugins/mobile_scanner/ios`)
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)

SPEC REPOS:
trunk:
Expand All @@ -93,6 +96,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/package_info_plus/ios"
shared_preferences_foundation:
:path: ".symlinks/plugins/shared_preferences_foundation/darwin"
url_launcher_ios:
:path: ".symlinks/plugins/url_launcher_ios/ios"

SPEC CHECKSUMS:
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
Expand All @@ -111,6 +116,7 @@ SPEC CHECKSUMS:
package_info_plus: 115f4ad11e0698c8c1c5d8a689390df880f47e85
PromisesObjC: 09985d6d70fbe7878040aa746d78236e6946d2ef
shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126
url_launcher_ios: bbd758c6e7f9fd7b5b1d4cde34d2b95fcce5e812

PODFILE CHECKSUM: ef19549a9bc3046e7bb7d2fab4d021637c0c58a3

Expand Down
53 changes: 46 additions & 7 deletions example/wallet/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,50 @@ import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}

private var deepLinkChannel: FlutterEventChannel?
private static let CHANNEL = "com.walletconnect.flutterwallet/events"
var initialLink: String?

private let linkStreamHandler = LinkStreamHandler()

override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
GeneratedPluginRegistrant.register(with: self)

let controller = window.rootViewController as! FlutterViewController
deepLinkChannel = FlutterEventChannel(name: AppDelegate.CHANNEL, binaryMessenger: controller.binaryMessenger)
deepLinkChannel?.setStreamHandler(linkStreamHandler)

return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}

override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
return linkStreamHandler.handleLink(url.absoluteString)
}
}

class LinkStreamHandler: NSObject, FlutterStreamHandler {
var eventSink: FlutterEventSink?
var queuedLinks = [String]()

func onListen(withArguments arguments: Any?, eventSink events: @escaping FlutterEventSink) -> FlutterError? {
self.eventSink = events
queuedLinks.forEach({ events($0) })
queuedLinks.removeAll()
return nil
}

func onCancel(withArguments arguments: Any?) -> FlutterError? {
self.eventSink = nil
return nil
}

func handleLink(_ link: String) -> Bool {
guard let eventSink = eventSink else {
queuedLinks.append(link)
return false
}
eventSink(link)
return true
}
}
13 changes: 8 additions & 5 deletions example/wallet/ios/Runner/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina6_12" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22504"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Flutter View Controller-->
Expand All @@ -14,13 +16,14 @@
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="132" y="-34"/>
</scene>
</scenes>
</document>
8 changes: 5 additions & 3 deletions example/wallet/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>Wallet</string>
<string>Web3Wallet</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>wallet</string>
<string>Web3Wallet</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
Expand Down Expand Up @@ -58,9 +58,11 @@
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleURLSchemes</key>
<array>
<string>myflutterwallet</string>
<string>wcflutterwallet</string>
</array>
</dict>
</array>
<key>FlutterDeepLinkingEnabled</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class BottomSheetListenerState extends State<BottomSheetListener> {
builder: (context) {
return Container(
decoration: const BoxDecoration(
color: StyleConstants.layerColor1,
color: StyleConstants.lightGray,
borderRadius: BorderRadius.all(
Radius.circular(
StyleConstants.linear16,
Expand Down
Loading

0 comments on commit 911f613

Please sign in to comment.