Skip to content

Commit

Permalink
Merge pull request #61 from WalletConnect/feature/bug_fixes_namespaces
Browse files Browse the repository at this point in the history
v3.0.0 Prod
  • Loading branch information
quetool authored Nov 16, 2023
2 parents 80d846c + 1e1a0cd commit 95aefdb
Show file tree
Hide file tree
Showing 25 changed files with 263 additions and 518 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 3.0.0

- Production version!
- Minor fixes on session proposal and wallet redirection after connection
- Minor bug fixes

## 3.0.0-beta19

- Chain switching enhancements
Expand Down
37 changes: 17 additions & 20 deletions example/lib/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ import 'package:walletconnect_flutter_dapp/utils/dart_defines.dart';
import 'package:walletconnect_flutter_dapp/utils/string_constants.dart';

class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.swapTheme});
final void Function() swapTheme;
const MyHomePage({
super.key,
required this.swapTheme,
required this.changeTheme,
});
final VoidCallback swapTheme;
final VoidCallback changeTheme;

@override
State<MyHomePage> createState() => _MyHomePageState();
Expand All @@ -32,21 +37,15 @@ class _MyHomePageState extends State<MyHomePage> {
projectId: DartDefines.projectId,
logLevel: LogLevel.error,
metadata: const PairingMetadata(
name: 'Web3Modal Flutter Example',
description: 'Web3Modal Flutter Example',
name: StringConstants.w3mPageTitleV3,
description: StringConstants.w3mPageTitleV3,
url: 'https://www.walletconnect.com/',
icons: ['https://web3modal.com/images/rpc-illustration.png'],
redirect: Redirect(
native: 'flutterdapp://',
universal: 'https://www.walletconnect.com',
),
),
optionalNamespaces: {
'eip155': const W3MNamespace(
methods: EthConstants.allMethods,
events: EthConstants.allEvents,
),
},
);
await _w3mService.init();

Expand Down Expand Up @@ -87,6 +86,7 @@ class _MyHomePageState extends State<MyHomePage> {

@override
Widget build(BuildContext context) {
final isSquare = Web3ModalTheme.radiusesOf(context).isSquare();
return Scaffold(
backgroundColor: Web3ModalTheme.colorsOf(context).background300,
appBar: AppBar(
Expand All @@ -95,6 +95,12 @@ class _MyHomePageState extends State<MyHomePage> {
backgroundColor: Web3ModalTheme.colorsOf(context).background100,
foregroundColor: Web3ModalTheme.colorsOf(context).foreground100,
actions: [
IconButton(
icon: isSquare
? const Icon(Icons.yard_outlined)
: const Icon(Icons.yard),
onPressed: widget.changeTheme,
),
IconButton(
icon: Web3ModalTheme.maybeOf(context)?.isDarkMode ?? false
? const Icon(Icons.light_mode)
Expand Down Expand Up @@ -161,9 +167,7 @@ class _ConnectedView extends StatelessWidget {
const SizedBox.square(dimension: 12.0),
W3MAccountButton(service: w3mService),
SessionWidget(
session: w3mService.web3App!.sessions.getAll().first,
web3App: w3mService.web3App!,
selectedChain: w3mService.selectedChain!,
w3mService: w3mService,
launchRedirect: () {
w3mService.launchConnectedWallet();
},
Expand All @@ -179,13 +183,6 @@ final _exampleCustomChain = W3MChainInfo(
namespace: 'eip155:42220',
chainId: '42220',
tokenName: 'CELO',
optionalNamespaces: {
'eip155': const RequiredNamespace(
methods: EthConstants.allMethods,
chains: ['eip155:42220'],
events: EthConstants.allEvents,
),
},
rpcUrl: 'https://forno.celo.org/',
blockExplorer: W3MBlockExplorer(
name: 'Celo Explorer',
Expand Down
42 changes: 26 additions & 16 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:walletconnect_flutter_dapp/home_page.dart';
import 'package:walletconnect_flutter_dapp/utils/string_constants.dart';
import 'package:web3modal_flutter/web3modal_flutter.dart';

void main() {
Expand All @@ -15,18 +16,7 @@ class MyApp extends StatefulWidget {

class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
bool _isDarkMode = false;
// ignore: unused_field
final _themeData = Web3ModalThemeData(
lightColors: Web3ModalColors.lightMode.copyWith(
accent100: Colors.red,
background125: Colors.yellow.shade300,
),
darkColors: Web3ModalColors.darkMode.copyWith(
accent100: Colors.green,
background125: Colors.brown,
),
radiuses: Web3ModalRadiuses.square,
);
Web3ModalThemeData? _themeData;

@override
void initState() {
Expand Down Expand Up @@ -64,12 +54,14 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
Widget build(BuildContext context) {
return Web3ModalTheme(
isDarkMode: _isDarkMode,
// Uncomment to see how modal theme is changed
// themeData: _themeData,
themeData: _themeData,
child: MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
home: MyHomePage(swapTheme: () => _swapTheme()),
title: StringConstants.w3mPageTitleV3,
home: MyHomePage(
swapTheme: () => _swapTheme(),
changeTheme: () => _changeTheme(),
),
),
);
}
Expand All @@ -79,4 +71,22 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
_isDarkMode = !_isDarkMode;
});
}

void _changeTheme() {
setState(() {
_themeData = (_themeData == null)
? Web3ModalThemeData(
lightColors: Web3ModalColors.lightMode.copyWith(
accent100: Colors.red,
background125: Colors.yellow.shade300,
),
darkColors: Web3ModalColors.darkMode.copyWith(
accent100: Colors.green,
background125: Colors.brown,
),
radiuses: Web3ModalRadiuses.square,
)
: null;
});
}
}
Loading

0 comments on commit 95aefdb

Please sign in to comment.