Skip to content

Commit

Permalink
Merge pull request #116 from WalletConnect/chores/refactor
Browse files Browse the repository at this point in the history
Refactor and bug fixes
  • Loading branch information
quetool authored Apr 23, 2024
2 parents b13ee54 + 59a7e33 commit 23679ee
Show file tree
Hide file tree
Showing 25 changed files with 420 additions and 383 deletions.
7 changes: 2 additions & 5 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -684,11 +684,9 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 53;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = W5R8AG9K22;
DEVELOPMENT_TEAM = W5R8AG9K22;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
Expand All @@ -699,7 +697,6 @@
PRODUCT_BUNDLE_IDENTIFIER = com.web3modal.flutterExample;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = FlutterAppStoreProfileWithPush;
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
VERSIONING_SYSTEM = "apple-generic";
Expand Down
81 changes: 36 additions & 45 deletions example/lib/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class _MyHomePageState extends State<MyHomePage> {

void _initializeService() async {
// See https://docs.walletconnect.com/web3modal/flutter/custom-chains
W3MChainPresets.chains.putIfAbsent(_sepolia.chainId, () => _sepolia);
W3MChainPresets.chains.addAll(W3MChainPresets.testChains);

_w3mService = W3MService(
projectId: DartDefines.projectId,
Expand Down Expand Up @@ -69,7 +69,11 @@ class _MyHomePageState extends State<MyHomePage> {
// 'c57ca95b47569778a828d19178114f4db188b89b763c899ba0be274e97267d96', // Metamask
// '1ae92b26df02f0abca6304df07debccd18262fdf5fe82daa81593582dac9a369', // Rainbow
// 'fd20dc426fb37566d803205b19bbc1d4096b248ac04548e3cfb6b3a38bd033aa', // Coinbase Wallet
// 'be49f0a78d6ea1beed3804c3a6b62ea71f568d58d9df8097f3d61c7c9baf273d', // Uniswap
// 'c03dfee351b6fcc421b4494ea33b9d4b92a984f87aa76d1663bb28705e95034a', // Uniswap
// '18450873727504ae9315a084fa7624b5297d2fe5880f0982979c17345a138277', // Kraken Wallet
// '38f5d18bd8522c244bdd70cb4a68e0e718865155811c043f052fb9f1c51de662', // Bitget
// '19177a98252e07ddfc9af2083ba8e07ef627cb6103467ffebb3f8f4205fd7927', // Ledger Live
// '4457c130df49fb3cb1f8b99574b97b35208bd3d0d13b8d25d2b5884ed2cad13a', // Shapeshift
// },
// featuredWalletIds: {
// '18450873727504ae9315a084fa7624b5297d2fe5880f0982979c17345a138277', // Kraken Wallet
Expand Down Expand Up @@ -129,38 +133,37 @@ class _MyHomePageState extends State<MyHomePage> {
}
final polygon = W3MChainPresets.chains['137']!;
final approvedChains = _w3mService.getApprovedChains() ?? [];
if (approvedChains.contains(polygon.namespace)) {
return;
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.requestSwitchToChain(polygon);
_w3mService.launchConnectedWallet();
Navigator.of(context).pop();
},
child: const Text('Switch'),
),
],
);
},
);
},
);
}
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.requestSwitchToChain(polygon);
_w3mService.launchConnectedWallet();
Navigator.of(context).pop();
},
child: const Text('Switch'),
),
],
);
},
);
},
);
}

void _onModalNetworkChange(ModalNetworkChange? event) {
Expand Down Expand Up @@ -340,18 +343,6 @@ class _ConnectedView extends StatelessWidget {
}
}

final _sepolia = W3MChainInfo(
chainName: 'Sepolia Testnet',
chainId: '11155111',
namespace: 'eip155:11155111',
tokenName: 'SEP',
rpcUrl: 'https://ethereum-sepolia.publicnode.com',
blockExplorer: W3MBlockExplorer(
name: 'Sepolia Etherscan',
url: 'https://sepolia.etherscan.io/',
),
);

ButtonStyle buttonStyle(BuildContext context) {
final themeColors = Web3ModalTheme.colorsOf(context);
return ButtonStyle(
Expand Down
20 changes: 6 additions & 14 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -612,18 +612,18 @@ packages:
dependency: transitive
description:
name: package_info_plus
sha256: cb44f49b6e690fa766f023d5b22cac6b9affe741dd792b6ac7ad4fabe0d7b097
sha256: "2c582551839386fa7ddbc7770658be7c0f87f388a4bff72066478f597c34d17f"
url: "https://pub.dev"
source: hosted
version: "6.0.0"
version: "7.0.0"
package_info_plus_platform_interface:
dependency: transitive
description:
name: package_info_plus_platform_interface
sha256: "9bc8ba46813a4cc42c66ab781470711781940780fd8beddd0c3da62506d3a6c6"
sha256: f49918f3433a3146047372f9d4f1f847511f2acd5cd030e1f44fe5a50036b70e
url: "https://pub.dev"
source: hosted
version: "2.0.1"
version: "3.0.0"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -981,14 +981,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.2"
universal_io:
dependency: transitive
description:
name: universal_io
sha256: "1722b2dcc462b4b2f3ee7d188dad008b6eb4c40bbd03a3de451d82c78bba9aad"
url: "https://pub.dev"
source: hosted
version: "2.2.2"
url_launcher:
dependency: transitive
description:
Expand Down Expand Up @@ -1113,10 +1105,10 @@ packages:
dependency: transitive
description:
name: walletconnect_flutter_v2
sha256: "8502a7adc59475cad5e968e4f57e6ee5d6a538cce63ca93c7ac1abf5573d5ea5"
sha256: cc6fa6a537910a66258ee64bb510edbfc0dee01485ea1138651431087c94671b
url: "https://pub.dev"
source: hosted
version: "2.2.2"
version: "2.2.3"
watcher:
dependency: transitive
description:
Expand Down
130 changes: 130 additions & 0 deletions lib/models/listing.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import 'dart:convert';

class Listing {
final String id;
final String name;
final String homepage;
final String imageId;
final int order;
final String? mobileLink;
final String? desktopLink;
final String? webappLink;
final String? appStore;
final String? playStore;
final String? rdns;
final List<Injected>? injected;

Listing({
required this.id,
required this.name,
required this.homepage,
required this.imageId,
required this.order,
this.mobileLink,
this.desktopLink,
this.webappLink,
this.appStore,
this.playStore,
this.rdns,
this.injected,
});

Listing copyWith({
String? id,
String? name,
String? homepage,
String? imageId,
int? order,
String? mobileLink,
String? desktopLink,
String? webappLink,
String? appStore,
String? playStore,
String? rdns,
List<Injected>? injected,
}) =>
Listing(
id: id ?? this.id,
name: name ?? this.name,
homepage: homepage ?? this.homepage,
imageId: imageId ?? this.imageId,
order: order ?? this.order,
mobileLink: mobileLink ?? this.mobileLink,
desktopLink: desktopLink ?? this.desktopLink,
webappLink: webappLink ?? this.webappLink,
appStore: appStore ?? this.appStore,
playStore: playStore ?? this.playStore,
rdns: rdns ?? this.rdns,
injected: injected ?? this.injected,
);

factory Listing.fromRawJson(String str) => Listing.fromJson(json.decode(str));

String toRawJson() => json.encode(toJson());

factory Listing.fromJson(Object? json) {
final j = json as Map<String, dynamic>? ?? {};
return Listing(
id: j['id'],
name: j['name'],
homepage: j['homepage'],
imageId: j['image_id'],
order: j['order'],
mobileLink: j['mobile_link'],
desktopLink: j['desktop_link'],
webappLink: j['webapp_link'],
appStore: j['app_store'],
playStore: j['play_store'],
rdns: j['rdns'],
injected: j['injected'] == null
? []
: List<Injected>.from(
j['injected']!.map((x) => Injected.fromJson(x)),
),
);
}

Map<String, dynamic> toJson() => {
'id': id,
'name': name,
'homepage': homepage,
'image_id': imageId,
'order': order,
'mobile_link': mobileLink,
'desktop_link': desktopLink,
'webapp_link': webappLink,
'app_store': appStore,
'play_store': playStore,
'rdns': rdns,
'injected': injected == null
? []
: List<dynamic>.from(injected!.map((x) => x.toJson())),
};
}

class Injected {
final String namespace;
final String injectedId;

Injected({required this.namespace, required this.injectedId});

Injected copyWith({String? namespace, String? injectedId}) => Injected(
namespace: namespace ?? this.namespace,
injectedId: injectedId ?? this.injectedId,
);

factory Injected.fromRawJson(String str) =>
Injected.fromJson(json.decode(str));

String toRawJson() => json.encode(toJson());

factory Injected.fromJson(Map<String, dynamic> json) => Injected(
namespace: json['namespace'],
injectedId: json['injected_id'],
);

Map<String, dynamic> toJson() => {
'namespace': namespace,
'injected_id': injectedId,
};
}
2 changes: 1 addition & 1 deletion lib/models/w3m_wallet_info.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:web3modal_flutter/services/explorer_service/models/api_response.dart';
import 'package:web3modal_flutter/models/listing.dart';

part 'w3m_wallet_info.freezed.dart';
part 'w3m_wallet_info.g.dart';
Expand Down
1 change: 1 addition & 0 deletions lib/pages/get_wallet_page.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:io';
import 'dart:math';

import 'package:flutter/material.dart';
Expand Down
7 changes: 4 additions & 3 deletions lib/pages/wallets_list_long_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ class _WalletsListLongPageState extends State<WalletsListLongPage> {
final service = Web3ModalProvider.of(context).service;
final totalListings = explorerService.instance.totalListings.value;
final rows = (totalListings / 4.0).ceil();
final isSearchAvailable = totalListings >= kShortWalletListCount;
final maxHeight = (rows * kGridItemHeight) +
(kPadding16 * 2.0) +
(kPadding16 * 4.0) +
(isSearchAvailable ? kSearchFieldHeight : 0.0) +
ResponsiveData.paddingBottomOf(context);
final isSearchAvailable = totalListings >= 20;
return Web3ModalNavbar(
title: 'All wallets',
onTapTitle: () => _controller.animateTo(
Expand All @@ -76,7 +77,7 @@ class _WalletsListLongPageState extends State<WalletsListLongPage> {
constraints: BoxConstraints(
maxHeight: !isSearchAvailable
? maxHeight
: ResponsiveData.maxHeightOf(context),
: min(maxHeight, ResponsiveData.maxHeightOf(context)),
),
child: Column(
children: [
Expand Down
Loading

0 comments on commit 23679ee

Please sign in to comment.