Skip to content

Commit

Permalink
bug fix for Trust wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
quetool committed Jul 5, 2024
1 parent 8553939 commit 2d5149d
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 190 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 3.3.0-beta03
## 3.3.0-beta04

- One-Click Auth + SIWE implementation
- Coinbase Wallet dependency update
Expand Down
2 changes: 1 addition & 1 deletion example/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
versionName=3.3.0
versionCode=64
versionCode=65
12 changes: 6 additions & 6 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 64;
CURRENT_PROJECT_VERSION = 65;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = W5R8AG9K22;
ENABLE_BITCODE = NO;
Expand All @@ -496,7 +496,7 @@
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 64;
CURRENT_PROJECT_VERSION = 65;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.web3modal.flutterExample.RunnerTests;
Expand All @@ -514,7 +514,7 @@
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 64;
CURRENT_PROJECT_VERSION = 65;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.web3modal.flutterExample.RunnerTests;
Expand All @@ -530,7 +530,7 @@
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 64;
CURRENT_PROJECT_VERSION = 65;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.web3modal.flutterExample.RunnerTests;
Expand Down Expand Up @@ -655,7 +655,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 64;
CURRENT_PROJECT_VERSION = 65;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = W5R8AG9K22;
ENABLE_BITCODE = NO;
Expand Down Expand Up @@ -686,7 +686,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 64;
CURRENT_PROJECT_VERSION = 65;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = W5R8AG9K22;
ENABLE_BITCODE = NO;
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>64</string>
<string>65</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSApplicationQueriesSchemes</key>
Expand Down
170 changes: 38 additions & 132 deletions example/lib/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:fl_toast/fl_toast.dart';
import 'package:flutter/material.dart';
import 'package:walletconnect_flutter_dapp/widgets/debug_drawer.dart';

import 'package:web3modal_flutter/web3modal_flutter.dart';

Expand Down Expand Up @@ -31,11 +32,13 @@ class _MyHomePageState extends State<MyHomePage> {
@override
void initState() {
super.initState();
_siweTestService = SIWESampleWebService();
WidgetsBinding.instance.addPostFrameCallback((_) {
_toggleOverlay();
SharedPreferences.getInstance().then((instance) {
_initializeService(instance);
});
});
_siweTestService = SIWESampleWebService();
_initializeService();
}

void _toggleOverlay() {
Expand All @@ -55,7 +58,7 @@ class _MyHomePageState extends State<MyHomePage> {
),
);

SIWEConfig get _siweConfig => SIWEConfig(
SIWEConfig _siweConfig(bool enabled) => SIWEConfig(
getNonce: () async {
// this has to be called at the very moment of creating the pairing uri
try {
Expand Down Expand Up @@ -152,15 +155,19 @@ class _MyHomePageState extends State<MyHomePage> {
// Called when disconnecting WalletConnect session was successfull
debugPrint('[SIWEConfig] onSignOut()');
},
// enabled: true,
enabled: enabled,
// signOutOnDisconnect: true,
// signOutOnAccountChange: true,
// signOutOnNetworkChange: true,
// nonceRefetchIntervalMs: 300000,
// sessionRefetchIntervalMs: 300000,
);

void _initializeService() async {
void _initializeService(SharedPreferences prefs) async {
final analyticsValue = prefs.getBool('app_w3m_analytics') ?? true;
final emailWalletValue = prefs.getBool('app_w3m_email_wallet') ?? true;
final siweAuthValue = prefs.getBool('app_w3m_siwe_auth') ?? true;

// See https://docs.walletconnect.com/appkit/flutter/core/custom-chains
W3MChainPresets.chains.addAll(W3MChainPresets.extraChains);
W3MChainPresets.chains.addAll(W3MChainPresets.testChains);
Expand All @@ -171,9 +178,9 @@ class _MyHomePageState extends State<MyHomePage> {
projectId: DartDefines.projectId,
logLevel: LogLevel.error,
metadata: _pairingMetadata,
siweConfig: _siweConfig,
enableAnalytics: true, // OPTIONAL - null by default
enableEmail: true, // OPTIONAL - false by default
siweConfig: _siweConfig(siweAuthValue),
enableAnalytics: analyticsValue, // OPTIONAL - null by default
enableEmail: emailWalletValue, // OPTIONAL - false by default
// requiredNamespaces: {},
// optionalNamespaces: {},
// includedWalletIds: {},
Expand Down Expand Up @@ -248,62 +255,13 @@ class _MyHomePageState extends State<MyHomePage> {

void _onModalConnect(ModalConnect? event) {
debugPrint('[ExampleApp] _onModalConnect ${event?.toString()}');
debugPrint(
'[ExampleApp] _onModalConnect selectedChain ${_w3mService.selectedChain?.chainId}',
);
debugPrint(
'[ExampleApp] _onModalConnect address ${_w3mService.session!.address}',
);
setState(() {});
final walletName = _w3mService.session?.peer?.metadata.name ?? '';
if (walletName.toLowerCase().contains('metamask')) {
_switchToPolygonIfNeeded();
}
}

void _onModalUpdate(ModalConnect? event) {
setState(() {});
}

void _switchToPolygonIfNeeded() {
final polygon = W3MChainPresets.chains['137']!;
// final approvedChains = _w3mService.getApprovedChains() ?? [];
// if (!approvedChains.contains(polygon.namespace)) {
Future.delayed(
const Duration(milliseconds: 500),
() {
showDialog(
context: context,
builder: (_) {
return AlertDialog(
content: const Text('Switch to Polygon?'),
actions: [
ElevatedButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('Cancel'),
),
ElevatedButton(
onPressed: () async {
_w3mService.launchConnectedWallet();
try {
await _w3mService.requestSwitchToChain(polygon);
} catch (e) {
debugPrint('[ExampleApp] requestSwitchToChain $e');
}
// ignore: use_build_context_synchronously
Navigator.of(context).pop();
},
child: const Text('Switch'),
),
],
);
},
);
},
);
// }
}

void _onModalNetworkChange(ModalNetworkChange? event) {
debugPrint('[ExampleApp] _onModalNetworkChange ${event?.toString()}');
setState(() {});
Expand Down Expand Up @@ -360,32 +318,13 @@ class _MyHomePageState extends State<MyHomePage> {

@override
Widget build(BuildContext context) {
final isCustom = Web3ModalTheme.isCustomTheme(context);
return Scaffold(
backgroundColor: Web3ModalTheme.colorsOf(context).background125,
appBar: AppBar(
elevation: 0.0,
title: const Text(StringConstants.w3mPageTitleV3),
backgroundColor: Web3ModalTheme.colorsOf(context).background175,
foregroundColor: Web3ModalTheme.colorsOf(context).foreground100,
actions: [
IconButton(
icon: const Icon(Icons.logo_dev_rounded),
onPressed: _toggleOverlay,
),
IconButton(
icon: isCustom
? const Icon(Icons.yard)
: const Icon(Icons.yard_outlined),
onPressed: widget.toggleTheme,
),
IconButton(
icon: Web3ModalTheme.maybeOf(context)?.isDarkMode ?? false
? const Icon(Icons.light_mode_outlined)
: const Icon(Icons.dark_mode_outlined),
onPressed: widget.toggleBrightness,
),
],
),
body: !_initialized
? const SizedBox.shrink()
Expand All @@ -396,19 +335,35 @@ class _MyHomePageState extends State<MyHomePage> {
mainAxisAlignment: MainAxisAlignment.start,
children: [
const SizedBox.square(dimension: 4.0),
Text(
'v$packageVersion',
style: TextStyle(
color: Web3ModalTheme.colorsOf(context).foreground100,
),
),
_ButtonsView(w3mService: _w3mService),
const Divider(height: 0.0, color: Colors.transparent),
_ConnectedView(w3mService: _w3mService)
_ConnectedView(w3mService: _w3mService),
],
),
),
),
endDrawer: Drawer(
backgroundColor: Web3ModalTheme.colorsOf(context).background125,
child: DebugDrawer(
toggleOverlay: _toggleOverlay,
toggleBrightness: widget.toggleBrightness,
toggleTheme: widget.toggleTheme,
),
),
onEndDrawerChanged: (isOpen) {
// write your callback implementation here
if (isOpen) return;
showDialog(
context: context,
builder: (BuildContext context) {
return const AlertDialog(
content: Text(
'If you made changes you\'ll need to restart the app',
),
);
},
);
},
);
}

Expand Down Expand Up @@ -499,52 +454,3 @@ class _ConnectedView extends StatelessWidget {
);
}
}

ButtonStyle buttonStyle(BuildContext context) {
final themeColors = Web3ModalTheme.colorsOf(context);
return ButtonStyle(
backgroundColor: MaterialStateProperty.resolveWith<Color>(
(states) {
if (states.contains(MaterialState.disabled)) {
return Web3ModalTheme.colorsOf(context).background225;
}
return Web3ModalTheme.colorsOf(context).accent100;
},
),
shape: MaterialStateProperty.resolveWith<RoundedRectangleBorder>(
(states) {
return RoundedRectangleBorder(
side: states.contains(MaterialState.disabled)
? BorderSide(color: themeColors.grayGlass005, width: 1.0)
: BorderSide(color: themeColors.grayGlass010, width: 1.0),
borderRadius: borderRadius(context),
);
},
),
textStyle: MaterialStateProperty.resolveWith<TextStyle>(
(states) {
return Web3ModalTheme.getDataOf(context).textStyles.small600.copyWith(
color: (states.contains(MaterialState.disabled))
? Web3ModalTheme.colorsOf(context).foreground300
: Web3ModalTheme.colorsOf(context).inverse100,
);
},
),
foregroundColor: MaterialStateProperty.resolveWith<Color>(
(states) {
return (states.contains(MaterialState.disabled))
? Web3ModalTheme.colorsOf(context).foreground300
: Web3ModalTheme.colorsOf(context).inverse100;
},
),
);
}

BorderRadiusGeometry borderRadius(BuildContext context) {
final radiuses = Web3ModalTheme.radiusesOf(context);
return radiuses.isSquare()
? const BorderRadius.all(Radius.zero)
: radiuses.isCircular()
? BorderRadius.circular(1000.0)
: BorderRadius.circular(8.0);
}
11 changes: 11 additions & 0 deletions example/lib/utils/crypto/eip155_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,17 @@ class EIP155 {
contract: deployedContract,
);
case 'write':
// return await w3mService.requestWriteContract(
// topic: w3mService.session?.topic ?? '',
// chainId: 'eip155:11155111',
// deployedContract: deployedContract,
// functionName: 'subscribe',
// parameters: [],
// transaction: Transaction(
// from: EthereumAddress.fromHex(w3mService.session!.address!),
// value: EtherAmount.fromInt(EtherUnit.finney, 1),
// ),
// );
// we first call `decimals` function, which is a read function,
// to check how much decimal we need to use to parse the amount value
final decimals = await w3mService.requestReadContract(
Expand Down
4 changes: 2 additions & 2 deletions example/lib/utils/crypto/siwe_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SIWESampleWebService {

Future<void> _checkHeaders() async {
final instance = await SharedPreferences.getInstance();
final headers = instance.getString('w3m_siwe_headers');
final headers = instance.getString('app_w3m_siwe_headers');
if (headers != null) {
_headers = {
...(jsonDecode(headers) as Map<String, dynamic>),
Expand All @@ -32,7 +32,7 @@ class SIWESampleWebService {

Future<void> _persistHeaders() async {
final instance = await SharedPreferences.getInstance();
await instance.setString('w3m_siwe_headers', jsonEncode(_headers));
await instance.setString('app_w3m_siwe_headers', jsonEncode(_headers));
}

Future<Map<String, dynamic>> getNonce() async {
Expand Down
15 changes: 0 additions & 15 deletions example/lib/widgets/logger_widget.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:web3modal_flutter/services/analytics_service/analytics_service_singleton.dart';
import 'package:web3modal_flutter/version.dart';

class DraggableCard extends StatefulWidget {
final OverlayController overlayController;
Expand Down Expand Up @@ -54,20 +53,6 @@ class _DraggableCardState extends State<DraggableCard> {
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
color: Colors.black,
width: MediaQuery.of(context).size.width,
height: 20.0,
alignment: Alignment.center,
child: const Text(
packageVersion,
style: TextStyle(
color: Colors.white,
fontSize: 12.0,
fontWeight: FontWeight.bold,
),
),
),
SizedBox(
width: MediaQuery.of(context).size.width,
height: 200.0,
Expand Down
Loading

0 comments on commit 2d5149d

Please sign in to comment.