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

[Feature] Embedded Wallet Features #34

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions packages/reown_appkit/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
- Reconnection and resubscription mechanism, specially for Android 15 that implemented a strict doze mode.

## 1.2.0
## 1.3.0-alpha01

- Wallet Features for Email and Social Login

## 1.2.0-beta01

- Non-EVM Chains support
- Social Logins
Expand Down
13 changes: 11 additions & 2 deletions packages/reown_appkit/example/base/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
isDarkMode: _isDarkMode,
child: MaterialApp(
title: StringConstants.appTitle,
theme: ThemeData(
colorScheme: _isDarkMode
? ColorScheme.dark(
primary: ReownAppKitModalThemeData().darkColors.accent100,
)
: ColorScheme.light(
primary: ReownAppKitModalThemeData().lightColors.accent100,
),
),
home: const MyHomePage(),
),
);
Expand Down Expand Up @@ -421,13 +430,13 @@ class _MyHomePageState extends State<MyHomePage> {
debugPrint('[SampleDapp] _onSessionAuthResponse $response');
}

void _setState(_) => setState(() {});

void _relayClientError(ErrorEvent? event) {
debugPrint('[SampleDapp] _relayClientError ${event?.error}');
_setState('');
}

void _setState(_) => setState(() {});

@override
void dispose() {
// Unregister event handlers
Expand Down
16 changes: 5 additions & 11 deletions packages/reown_appkit/example/base/lib/pages/connect_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,12 @@ class ConnectPageState extends State<ConnectPage> {
final enabled = snapshot.data != null;
return ElevatedButton(
style: ButtonStyle(
elevation: WidgetStateProperty.all(0.0),
backgroundColor: WidgetStateProperty.all<Color>(
enabled
? ReownAppKitModalTheme.colorsOf(context).accent080
backgroundColor: WidgetStateProperty.resolveWith<Color>(
(states) => states.contains(WidgetState.disabled)
? ReownAppKitModalTheme.colorsOf(context)
.grayGlass005
: ReownAppKitModalTheme.colorsOf(context)
.accenGlass010,
),
foregroundColor: WidgetStateProperty.all<Color>(
enabled
? Colors.white
: ReownAppKitModalTheme.colorsOf(context)
.foreground200,
.background125,
),
),
onPressed: enabled
Expand Down
4 changes: 0 additions & 4 deletions packages/reown_appkit/example/base/lib/utils/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,18 @@ class StyleConstants {

// Text styles
static const TextStyle titleText = TextStyle(
color: Colors.black,
fontSize: magic40,
fontWeight: FontWeight.w600,
);
static const TextStyle subtitleText = TextStyle(
color: Colors.black,
fontSize: linear24,
fontWeight: FontWeight.w600,
);
static const TextStyle paragraph = TextStyle(
color: Colors.black,
fontSize: linear16,
fontWeight: FontWeight.w600,
);
static const TextStyle buttonText = TextStyle(
color: Colors.black,
fontSize: magic14,
fontWeight: FontWeight.w600,
);
Expand Down
2 changes: 1 addition & 1 deletion packages/reown_appkit/example/modal/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies:
flutter:
sdk: flutter
http: ^1.2.2
intl: ^0.19.0
intl: ^0.20.1
reown_appkit:
path: ../..
shared_preferences: ^2.3.4
Expand Down
45 changes: 29 additions & 16 deletions packages/reown_appkit/lib/modal/appkit_modal_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get_it/get_it.dart';
import 'package:reown_appkit/modal/pages/smart_account_page.dart';
import 'package:reown_appkit/modal/services/analytics_service/i_analytics_service.dart';
import 'package:reown_appkit/modal/services/blockchain_service/models/blockchain_identity.dart';
import 'package:reown_appkit/modal/services/explorer_service/i_explorer_service.dart';
import 'package:reown_appkit/modal/services/network_service/i_network_service.dart';
import 'package:reown_appkit/modal/services/siwe_service/i_siwe_service.dart';
Expand Down Expand Up @@ -94,15 +96,15 @@ class ReownAppKitModal
@override
IReownAppKit? get appKit => _appKit;

String? _avatarUrl;
BlockchainIdentity? _blockchainIdentity;
@override
String? get avatarUrl => _avatarUrl;
BlockchainIdentity? get blockchainIdentity => _blockchainIdentity;

double? _chainBalance;
@Deprecated('Use balanceNotifier')
@override
String get chainBalance => CoreUtils.formatChainBalance(_chainBalance);

double? _chainBalance;
@override
final balanceNotifier = ValueNotifier<String>('-.--');

Expand Down Expand Up @@ -490,8 +492,9 @@ class ReownAppKitModal
return;
}

_chainBalance = null;

try {
_chainBalance = null;
final formattedBalance = CoreUtils.formatChainBalance(_chainBalance);
balanceNotifier.value = '$formattedBalance ${chainInfo.currency}';

Expand Down Expand Up @@ -635,14 +638,17 @@ class ReownAppKitModal
@override
Future<void> openModalView([Widget? startWidget]) {
final keyString = startWidget?.key?.toString() ?? '';
final isMagic = _currentSession?.sessionService.isMagic == true;
if (_isConnected) {
final connectedKeys =
_allowedScreensWhenConnected.map((e) => e.toString()).toList();
if (startWidget == null) {
startWidget = const AccountPage();
startWidget =
isMagic ? const SmartAccountPage() : const EOAccountPage();
} else {
if (!connectedKeys.contains(keyString)) {
startWidget = const AccountPage();
startWidget =
isMagic ? const SmartAccountPage() : const EOAccountPage();
}
}
} else {
Expand All @@ -659,7 +665,8 @@ class ReownAppKitModal
KeyConstants.approveTransactionPage,
KeyConstants.confirmEmailPage,
KeyConstants.selectNetworkPage,
KeyConstants.accountPage,
KeyConstants.eoAccountPage,
KeyConstants.smartAccountPage,
KeyConstants.socialLoginPage,
];

Expand Down Expand Up @@ -706,7 +713,8 @@ class ReownAppKitModal

Widget? showWidget = startWidget;
if (_isConnected && showWidget == null) {
showWidget = const AccountPage();
final isMagic = _currentSession?.sessionService.isMagic == true;
startWidget = isMagic ? const SmartAccountPage() : const EOAccountPage();
}

final childWidget = theme == null
Expand Down Expand Up @@ -877,8 +885,6 @@ class ReownAppKitModal
@override
Future<void> buildConnectionUri() async {
if (!_isConnected) {
/// TODO Qs: How do I handle SIWE if non-EVM chains are included?
/// TODO Qs: How do I handle switch to Solana from EVM chain?
try {
if (_siweService.enabled) {
final walletRedirect = _explorerService.getWalletRedirect(
Expand Down Expand Up @@ -1463,7 +1469,7 @@ class ReownAppKitModal
);

try {
_chainBalance = await _blockchainService.getBalance(
_chainBalance = await _blockchainService.getTokenBalance(
address: _currentSession!.getAddress(namespace)!,
namespace: namespace,
chainId: _currentSelectedChainId!,
Expand All @@ -1482,10 +1488,13 @@ class ReownAppKitModal
if (namespace == NetworkUtils.eip155) {
// Get the avatar, each chainId is just a number in string form.
try {
final address = _currentSession!.getAddress(namespace)!;
final blockchainId = await _blockchainService.getIdentity(
_currentSession!.getAddress(namespace)!,
address: address,
);
_blockchainIdentity = BlockchainIdentity.fromJson(
blockchainId.toJson(),
);
_avatarUrl = blockchainId.avatar;
} catch (_) {}
}
_notify();
Expand Down Expand Up @@ -1649,6 +1658,7 @@ class ReownAppKitModal
_lastChainEmitted = null;
_supportsOneClickAuth = false;
_status = ReownAppKitModalStatus.initialized;
_blockchainService.dispose();
_notify();
}

Expand Down Expand Up @@ -1858,12 +1868,15 @@ extension _EmailConnectorExtension on ReownAppKitModal {
}
}

Future<void> _onMagicErrorEvent(MagicErrorEvent? args) async {
_appKit.core.logger.d('[$runtimeType] _onMagicErrorEvent: $args');
final errorMessage = args?.error ?? 'Something went wrong';
Future<void> _onMagicErrorEvent(MagicErrorEvent? event) async {
_appKit.core.logger.d('[$runtimeType] _onMagicErrorEvent: ${event?.error}');
final errorMessage = event?.error ?? 'Something went wrong';
if (!errorMessage.toLowerCase().contains('user denied')) {
onModalError.broadcast(ModalError(errorMessage));
}
if (event is IsConnectedErrorEvent && _currentSession != null) {
await _cleanSession();
}
_notify();
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions packages/reown_appkit/lib/modal/assets/icons/arrow_down.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions packages/reown_appkit/lib/modal/assets/icons/chevron_down.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions packages/reown_appkit/lib/modal/assets/icons/paperplane.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions packages/reown_appkit/lib/modal/assets/icons/receive.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions packages/reown_appkit/lib/modal/assets/icons/regular/send.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions packages/reown_appkit/lib/modal/assets/icons/regular/swap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions packages/reown_appkit/lib/modal/assets/icons/send.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading