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

v2.1.9 #216

Merged
merged 5 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.1.9

- Added support for Verify API

## 2.1.8

- Minor changes.
Expand Down
8 changes: 5 additions & 3 deletions example/dapp/lib/pages/connect_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,10 @@ class ConnectPageState extends State<ConnectPage> {
);
}

Future<void> _onConnect(List<ChainMetadata> chains,
{Function(String message)? showToast}) async {
Future<void> _onConnect(
List<ChainMetadata> chains, {
Function(String message)? showToast,
}) async {
// Use the chain metadata to build the required namespaces:
// Get the methods, get the events
final Map<String, RequiredNamespace> requiredNamespaces = {};
Expand All @@ -184,7 +186,7 @@ class ConnectPageState extends State<ConnectPage> {
// Send off a connect
debugPrint('Creating connection and session');
final ConnectResponse res = await widget.web3App.connect(
requiredNamespaces: requiredNamespaces,
optionalNamespaces: requiredNamespaces,
);
// debugPrint('Connection created, connection response: ${res.uri}');

Expand Down
4 changes: 2 additions & 2 deletions example/wallet/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ android {

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.walletconnect.flutter_wallet"
applicationId "com.walletconnect.flutterwallet"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion 21
Expand All @@ -60,7 +60,7 @@ android {
signingConfig signingConfigs.debug
}
}
namespace 'com.example.wallet'
namespace 'com.walletconnect.flutterwallet'
}

flutter {
Expand Down
2 changes: 1 addition & 1 deletion example/wallet/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
android:name="com.walletconnect.flutter_wallet.MainActivity"
android:name="com.walletconnect.flutterwallet.MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.walletconnect.flutter_wallet
package com.walletconnect.flutterwallet

import io.flutter.embedding.android.FlutterActivity

Expand Down
6 changes: 3 additions & 3 deletions example/wallet/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.example.wallet;
PRODUCT_BUNDLE_IDENTIFIER = com.walletconnect.flutterwallet;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
Expand Down Expand Up @@ -494,7 +494,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.example.wallet;
PRODUCT_BUNDLE_IDENTIFIER = com.walletconnect.flutterwallet;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -517,7 +517,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.example.wallet;
PRODUCT_BUNDLE_IDENTIFIER = com.walletconnect.flutterwallet;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
Expand Down
12 changes: 6 additions & 6 deletions example/wallet/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
Expand All @@ -24,6 +26,10 @@
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSCameraUsageDescription</key>
<string>This app needs camera access to scan QR codes</string>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
Expand All @@ -43,11 +49,5 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>NSCameraUsageDescription</key>
<string>This app needs camera access to scan QR codes</string>
</dict>
</plist>
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 @@ -36,7 +36,7 @@ class Web3WalletService extends IWeb3WalletService {

@override
void create() {
// Create the web3wallet
// Create the web3wallet
_web3Wallet = Web3Wallet(
core: Core(
projectId: DartDefines.projectId,
Expand Down Expand Up @@ -137,6 +137,7 @@ class Web3WalletService extends IWeb3WalletService {
wallet: _web3Wallet!,
sessionProposal: WCSessionRequestModel(
request: args.params,
verifyContext: args.verifyContext,
),
),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:walletconnect_flutter_v2/apis/core/verify/models/verify_context.dart';
import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart';
import 'package:walletconnect_flutter_v2_wallet/utils/constants.dart';
import 'package:walletconnect_flutter_v2_wallet/utils/namespace_model_builder.dart';
Expand Down Expand Up @@ -49,10 +50,8 @@ class WCConnectionRequestWidget extends StatelessWidget {
textAlign: TextAlign.center,
),
const SizedBox(height: StyleConstants.linear8),
Text(
metadata.metadata.url,
style: StyleConstants.bodyText,
textAlign: TextAlign.center,
VerifyContextWidget(
verifyContext: sessionProposal?.verifyContext,
),
const SizedBox(height: StyleConstants.linear8),
authRequest != null
Expand Down Expand Up @@ -109,3 +108,130 @@ class WCConnectionRequestWidget extends StatelessWidget {
// );
}
}

class VerifyContextWidget extends StatelessWidget {
const VerifyContextWidget({
super.key,
required this.verifyContext,
});
final VerifyContext? verifyContext;

@override
Widget build(BuildContext context) {
if (verifyContext == null) {
return const SizedBox.shrink();
}

if (verifyContext!.validation.scam) {
return VerifyBanner(
color: StyleConstants.errorColor,
origin: verifyContext!.origin,
title: 'Security risk',
text: 'This domain is flagged as unsafe by multiple security providers.'
' Leave immediately to protect your assets.',
);
}
if (verifyContext!.validation.invalid) {
return VerifyBanner(
color: StyleConstants.errorColor,
origin: verifyContext!.origin,
title: 'Domain mismatch',
text:
'This website has a domain that does not match the sender of this request.'
' Approving may lead to loss of funds.',
);
}
if (verifyContext!.validation.valid) {
return VerifyHeader(
iconColor: StyleConstants.successColor,
title: verifyContext!.origin,
);
}
return VerifyBanner(
color: Colors.orange,
origin: verifyContext!.origin,
title: 'Cannot verify',
text: 'This domain cannot be verified. '
'Check the request carefully before approving.',
);
}
}

class VerifyHeader extends StatelessWidget {
const VerifyHeader({
super.key,
required this.iconColor,
required this.title,
});
final Color iconColor;
final String title;

@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.shield_outlined,
color: iconColor,
),
const SizedBox(width: StyleConstants.linear8),
Text(
title,
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
],
);
}
}

class VerifyBanner extends StatelessWidget {
const VerifyBanner({
super.key,
required this.origin,
required this.title,
required this.text,
required this.color,
});
final String origin, title, text;
final Color color;

@override
Widget build(BuildContext context) {
return Column(
children: [
Text(
origin,
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
const SizedBox.square(dimension: 8.0),
Container(
padding: const EdgeInsets.all(8.0),
decoration: BoxDecoration(
color: color,
borderRadius: const BorderRadius.all(Radius.circular(12.0)),
),
child: Column(
children: [
VerifyHeader(
iconColor: Colors.white,
title: title,
),
const SizedBox(height: 4.0),
Text(
text,
style: const TextStyle(color: Colors.white),
),
],
),
),
],
);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import 'package:walletconnect_flutter_v2/apis/core/verify/models/verify_context.dart';
import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart';

class WCSessionRequestModel {
// final List<String> accounts;
final ProposalData request;
final VerifyContext? verifyContext;

WCSessionRequestModel({
// required this.accounts,
required this.request,
this.verifyContext,
});
}
18 changes: 14 additions & 4 deletions lib/apis/core/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import 'package:walletconnect_flutter_v2/apis/core/store/i_store.dart';
import 'package:walletconnect_flutter_v2/apis/core/relay_client/i_relay_client.dart';
import 'package:walletconnect_flutter_v2/apis/core/pairing/i_pairing.dart';
import 'package:walletconnect_flutter_v2/apis/core/store/shared_prefs_store.dart';
import 'package:walletconnect_flutter_v2/apis/core/verify/i_verify.dart';
import 'package:walletconnect_flutter_v2/apis/core/verify/verify.dart';
import 'package:walletconnect_flutter_v2/apis/utils/constants.dart';
import 'package:walletconnect_flutter_v2/apis/utils/log_level.dart';
import 'package:walletconnect_flutter_v2/apis/utils/walletconnect_utils.dart';
Expand All @@ -34,13 +36,13 @@ class Core implements ICore {
String get version => '2';

@override
String relayUrl = WalletConnectConstants.DEFAULT_RELAY_URL;
final String projectId;

@override
final String projectId;
String relayUrl = WalletConnectConstants.DEFAULT_RELAY_URL;

@override
final String pushUrl;
String pushUrl = WalletConnectConstants.DEFAULT_PUSH_URL;

@override
late ICrypto crypto;
Expand All @@ -60,6 +62,9 @@ class Core implements ICore {
@override
late IHeartBeat heartbeat;

@override
late IVerify verify;

Logger _logger = Logger(
level: Level.off,
printer: PrettyPrinter(),
Expand All @@ -71,8 +76,8 @@ class Core implements ICore {
late IStore<Map<String, dynamic>> storage;

Core({
this.relayUrl = WalletConnectConstants.DEFAULT_RELAY_URL,
required this.projectId,
this.relayUrl = WalletConnectConstants.DEFAULT_RELAY_URL,
this.pushUrl = WalletConnectConstants.DEFAULT_PUSH_URL,
bool memoryStore = false,
LogLevel logLevel = LogLevel.nothing,
Expand Down Expand Up @@ -150,6 +155,11 @@ class Core implements ICore {
httpClient: httpClient,
),
);
verify = Verify(
core: this,
projectId: projectId,
httpClient: httpClient,
);
}

@override
Expand Down
2 changes: 2 additions & 0 deletions lib/apis/core/i_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:walletconnect_flutter_v2/apis/core/pairing/i_expirer.dart';
import 'package:walletconnect_flutter_v2/apis/core/pairing/i_pairing.dart';
import 'package:walletconnect_flutter_v2/apis/core/relay_client/i_relay_client.dart';
import 'package:walletconnect_flutter_v2/apis/core/store/i_store.dart';
import 'package:walletconnect_flutter_v2/apis/core/verify/i_verify.dart';

abstract class ICore {
final String protocol = 'wc';
Expand All @@ -24,6 +25,7 @@ abstract class ICore {
abstract IPairing pairing;
abstract IEcho echo;
abstract final Logger logger;
abstract IVerify verify;

Future<void> start();
}
1 change: 1 addition & 0 deletions lib/apis/core/pairing/utils/pairing_models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class PairingMetadata with _$PairingMetadata {
required String description,
required String url,
required List<String> icons,
String? verifyUrl,
Redirect? redirect,
}) = _PairingMetadata;

Expand Down
Loading