Skip to content

Commit

Permalink
Final changes
Browse files Browse the repository at this point in the history
  • Loading branch information
quetool committed Oct 14, 2024
1 parent 2d576f5 commit a9b2c00
Show file tree
Hide file tree
Showing 22 changed files with 84 additions and 48 deletions.
2 changes: 1 addition & 1 deletion packages/reown_appkit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 1.1.0
## 1.1.0-beta01

- Social Logins

Expand Down
1 change: 1 addition & 0 deletions packages/reown_appkit/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ linter:
sort_pub_dependencies: true
avoid_unnecessary_containers: true
cancel_subscriptions: true
public_member_api_docs: false

analyzer:
exclude:
Expand Down
4 changes: 2 additions & 2 deletions packages/reown_appkit/example/base/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ class _MyHomePageState extends State<MyHomePage> {
context: context,
appKit: _appKit,
siweConfig: _siweConfig(),
enableAnalytics: true,
featuresConfig: FeaturesConfig(
enableAnalytics: true,
enableEmail: true,
email: true,
socials: [
AppKitSocialOption.Farcaster,
AppKitSocialOption.X,
Expand Down
6 changes: 3 additions & 3 deletions packages/reown_appkit/example/modal/lib/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,16 @@ class _MyHomePageState extends State<MyHomePage> {
logLevel: LogLevel.error,
metadata: _pairingMetadata(),
siweConfig: _siweConfig(siweAuthValue),
enableAnalytics: analyticsValue, // OPTIONAL - null by default
featuresConfig: FeaturesConfig(
enableAnalytics: analyticsValue, // OPTIONAL - null by default
enableEmail: emailWalletValue, // OPTIONAL - false by default
email: emailWalletValue,
socials: [
AppKitSocialOption.Farcaster,
AppKitSocialOption.X,
AppKitSocialOption.Apple,
AppKitSocialOption.Discord,
],
showMainWallets: false, // OPTIONAL - true by default
showMainWallets: true, // OPTIONAL - true by default
),
// requiredNamespaces: {},
// optionalNamespaces: {},
Expand Down
12 changes: 6 additions & 6 deletions packages/reown_appkit/lib/appkit_modal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
// platforms in the `pubspec.yaml` at
// https://flutter.dev/docs/development/packages-and-plugins/developing-packages#plugin-platforms.

/// Models
// Models
export 'modal/models/public/appkit_modal_models.dart';

/// Theme
// Theme
export 'modal/theme/public/appkit_modal_theme.dart';

/// Utils
// Utils
export 'modal/utils/public/appkit_modal_utils.dart';

/// Widgets
// Widgets
export 'modal/widgets/public/appkit_modal_widgets.dart';

/// Pages
// Pages
export 'modal/pages/public/appkit_modal_pages.dart';

/// Services
// Services
export 'modal/appkit_modal_impl.dart';
4 changes: 4 additions & 0 deletions packages/reown_appkit/lib/base/appkit_base_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import 'package:reown_core/relay_client/websocket/http_client.dart';
import 'package:reown_core/store/generic_store.dart';
import 'package:reown_core/store/i_generic_store.dart';

/// Base class that containes Core and SIgn used dapps developers to create UI-less interaction with WalletConnect protocol
class ReownAppKit implements IReownAppKit {
///
static const List<List<String>> DEFAULT_METHODS = [
[
MethodConstants.WC_SESSION_PROPOSE,
Expand All @@ -17,6 +19,7 @@ class ReownAppKit implements IReownAppKit {

bool _initialized = false;

/// Creates a instance of ReownAppKit to be used alone or to pass to ReownAppKitModal
static Future<ReownAppKit> createInstance({
required String projectId,
String relayUrl = ReownConstants.DEFAULT_RELAY_URL,
Expand Down Expand Up @@ -54,6 +57,7 @@ class ReownAppKit implements IReownAppKit {
@override
final PairingMetadata metadata;

///
ReownAppKit({
required this.core,
required this.metadata,
Expand Down
5 changes: 5 additions & 0 deletions packages/reown_appkit/lib/base/i_appkit_base_impl.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import 'package:reown_sign/i_sign_dapp.dart';
import 'package:reown_sign/reown_sign.dart';

///
abstract class IReownAppKit implements IReownSignDapp {
///
final String protocol = 'wc';

///
final int version = 2;

///
abstract final IReownSign reOwnSign;
}
10 changes: 5 additions & 5 deletions packages/reown_appkit/lib/modal/appkit_modal_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ class ReownAppKitModal with ChangeNotifier implements IReownAppKitModal {
@override
ReownAppKitModalSession? get session => _currentSession;

// Logger get _appKit.core.logger => _appKit.core.logger;

IStore<Map<String, dynamic>> get _storage => _appKit.core.storage;

bool _disconnectOnClose = false;
Expand All @@ -130,18 +128,20 @@ class ReownAppKitModal with ChangeNotifier implements IReownAppKitModal {
@override
late final FeaturesConfig featuresConfig;

///
ReownAppKitModal({
required BuildContext context,
IReownAppKit? appKit,
String? projectId,
PairingMetadata? metadata,
bool? enableAnalytics,
SIWEConfig? siweConfig,
FeaturesConfig? featuresConfig,
Map<String, RequiredNamespace>? requiredNamespaces,
Map<String, RequiredNamespace>? optionalNamespaces,
Set<String>? featuredWalletIds,
Set<String>? includedWalletIds,
Set<String>? excludedWalletIds,
FeaturesConfig? featuresConfig,
LogLevel logLevel = LogLevel.nothing,
}) {
if (appKit == null) {
Expand All @@ -157,7 +157,7 @@ class ReownAppKitModal with ChangeNotifier implements IReownAppKitModal {
}
}

this.featuresConfig = featuresConfig ?? FeaturesConfig();
this.featuresConfig = featuresConfig ?? FeaturesConfig(email: false);

_context = context;

Expand All @@ -177,7 +177,7 @@ class ReownAppKitModal with ChangeNotifier implements IReownAppKitModal {

analyticsService.instance = AnalyticsService(
core: _appKit.core,
enableAnalytics: this.featuresConfig.enableAnalytics,
enableAnalytics: enableAnalytics,
)..init().then((_) {
analyticsService.instance.sendEvent(ModalLoadedEvent());
});
Expand Down
2 changes: 2 additions & 0 deletions packages/reown_appkit/lib/modal/constants/key_constants.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: public_member_api_docs

import 'package:flutter/material.dart';

class KeyConstants {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: public_member_api_docs

import 'package:reown_appkit/reown_appkit.dart';
import 'package:reown_sign/version.dart' as reown_sign;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: public_member_api_docs

const kListItemHeight = 56.0;

const kGridItemWidth = 76.0;
Expand Down
2 changes: 2 additions & 0 deletions packages/reown_appkit/lib/modal/i_appkit_modal_impl.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: public_member_api_docs

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:reown_appkit/reown_appkit.dart';
Expand Down
2 changes: 2 additions & 0 deletions packages/reown_appkit/lib/modal/models/grid_item.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: public_member_api_docs

class GridItem<T> {
final String image;
final String id;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:reown_appkit/reown_appkit.dart';

/// Event fired when connection is done
class ModalConnect extends EventArgs {
final ReownAppKitModalSession session;
ModalConnect(this.session);
Expand All @@ -10,6 +11,7 @@ class ModalConnect extends EventArgs {
}
}

/// Event fired when network is changed through the modal
class ModalNetworkChange extends EventArgs {
final String chainId;
ModalNetworkChange({required this.chainId});
Expand All @@ -20,6 +22,7 @@ class ModalNetworkChange extends EventArgs {
}
}

/// Event fired when disconnect happens, either from the wallet of the modal
class ModalDisconnect extends EventArgs {
final String? topic;
final int? id;
Expand All @@ -31,6 +34,7 @@ class ModalDisconnect extends EventArgs {
}
}

/// Event fired every time an error occurs
class ModalError extends EventArgs {
final String message;
ModalError(this.message);
Expand All @@ -41,14 +45,17 @@ class ModalError extends EventArgs {
}
}

/// Event fired when trying to opening a wallet that is not installed
class WalletNotInstalled extends ModalError {
WalletNotInstalled() : super('Wallet app not installed');
}

/// Error opening wallet
class ErrorOpeningWallet extends ModalError {
ErrorOpeningWallet() : super('Unable to open Wallet app');
}

/// Event fired when user rejects connection in the wallet
class UserRejectedConnection extends ModalError {
UserRejectedConnection() : super('User rejected connection');
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import 'package:reown_appkit/modal/models/public/appkit_social_options.dart';

/// Object to pass to [featuresConfig:] parameter of ReownAppKitModal to enable or disable these extra features
class FeaturesConfig {
final bool? enableAnalytics;
final bool enableEmail;
final bool email;
final List<AppKitSocialOption> socials;
final bool showMainWallets;

FeaturesConfig({
this.enableAnalytics,
this.enableEmail = false,
this.email = true,
this.socials = const [],
this.showMainWallets = true,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ enum ReownAppKitModalConnector {
bool get noSession => this == ReownAppKitModalConnector.none;
}

/// Session object of the modal when connected
class ReownAppKitModalSession {
SessionData? _sessionData;
CoinbaseData? _coinbaseData;
Expand Down Expand Up @@ -69,6 +70,7 @@ class ReownAppKitModalSession {
);
}

/// Indicates the connected service
ReownAppKitModalConnector get sessionService {
if (_sessionData != null) {
return ReownAppKitModalConnector.wc;
Expand All @@ -77,6 +79,7 @@ class ReownAppKitModalSession {
return ReownAppKitModalConnector.coinbase;
}
if (_magicData != null) {
// TODO rename to ReownAppKitModalConnector.socials
return ReownAppKitModalConnector.magic;
}

Expand All @@ -101,6 +104,7 @@ class ReownAppKitModalSession {
return supportsAddChain;
}

/// Get the approved methods by the connected peer
List<String>? getApprovedMethods() {
if (sessionService.noSession) {
return null;
Expand All @@ -118,6 +122,7 @@ class ReownAppKitModalSession {
return methodsList ?? [];
}

/// Get the approved events by the connected peer
List<String>? getApprovedEvents() {
if (sessionService.noSession) {
return null;
Expand All @@ -135,6 +140,7 @@ class ReownAppKitModalSession {
return eventsList ?? [];
}

/// Get the approved chains by the connected peer
List<String>? getApprovedChains() {
if (sessionService.noSession) {
return null;
Expand All @@ -149,6 +155,7 @@ class ReownAppKitModalSession {
return approvedChains;
}

/// Get the approved accounts by the connected peer
List<String>? getAccounts() {
if (sessionService.noSession) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:reown_appkit/reown_appkit.dart';
part 'appkit_siwe_config.g.dart';
part 'appkit_siwe_config.freezed.dart';

/// Object to pass to [siweConfig:] parameter of ReownAppKitModal to enable or disable One-Click Auth + SIWE
class SIWEConfig {
final Future<String> Function() getNonce;
final Future<SIWEMessageArgs> Function() getMessageParams;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ class _AppKitModalMainWalletsPageState
);
}
final emailEnabled = _magicService.isEmailEnabled.value;
if (!modalInstance.featuresConfig.showMainWallets && emailEnabled) {
final socials = _magicService.socials;
if (!modalInstance.featuresConfig.showMainWallets &&
(emailEnabled || socials.isNotEmpty)) {
items.clear();
}
final itemsCount = min(kShortWalletListCount, items.length);
Expand All @@ -103,7 +105,7 @@ class _AppKitModalMainWalletsPageState
}
final socialEnabled = _magicService.isSocialEnabled.value;
if (socialEnabled) {
final length = _magicService.socials.length;
final length = socials.length;
if (length <= 4) {
maxHeight += (kListItemHeight * 2);
} else {
Expand Down Expand Up @@ -143,9 +145,27 @@ class _AppKitModalMainWalletsPageState
bottomItems: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 4.0),
child: modalInstance.featuresConfig.showMainWallets ||
!emailEnabled
child: (!modalInstance.featuresConfig.showMainWallets &&
(emailEnabled || socials.isNotEmpty))
? AllWalletsItem(
title: 'Connect wallet',
titleAlign: TextAlign.center,
leading: RoundedIcon(
padding: 10.0,
assetPath:
'lib/modal/assets/icons/regular/wallet.svg',
assetColor: themeColors.foreground100,
circleColor: Colors.transparent,
borderColor: Colors.transparent,
),
onTap: () {
widgetStack.instance.push(
const ReownAppKitModalAllWalletsPage(),
event: ClickAllWalletsEvent(),
);
},
)
: AllWalletsItem(
trailing: (items.length <= kShortWalletListCount)
? null
: ValueListenableBuilder<int>(
Expand Down Expand Up @@ -173,24 +193,6 @@ class _AppKitModalMainWalletsPageState
);
}
},
)
: AllWalletsItem(
title: 'Connect wallet',
titleAlign: TextAlign.center,
leading: RoundedIcon(
padding: 10.0,
assetPath:
'lib/modal/assets/icons/regular/wallet.svg',
assetColor: themeColors.foreground100,
circleColor: Colors.transparent,
borderColor: Colors.transparent,
),
onTap: () {
widgetStack.instance.push(
const ReownAppKitModalAllWalletsPage(),
event: ClickAllWalletsEvent(),
);
},
),
),
],
Expand Down
Loading

0 comments on commit a9b2c00

Please sign in to comment.