Skip to content

Commit

Permalink
Merge pull request #31 from Nuxify/feature/reown-migration
Browse files Browse the repository at this point in the history
Feature/reown migration
  • Loading branch information
JosesGabriel authored Feb 4, 2025
2 parents 28d4256 + 1d46c7f commit 46f5ccc
Show file tree
Hide file tree
Showing 18 changed files with 772 additions and 640 deletions.
2 changes: 1 addition & 1 deletion .fvm/fvm_config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"flutterSdkVersion": "3.19.6"
"flutterSdkVersion": "3.27.0"
}
2 changes: 1 addition & 1 deletion .fvmrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"flutter": "3.19.6"
"flutter": "3.27.0"
}
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"dart.flutterSdkPath": ".fvm/versions/3.19.6"
"dart.flutterSdkPath": ".fvm/versions/3.27.0"
}
3 changes: 2 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
buildscript {
ext.kotlin_version = '1.7.10'
ext.kotlin_version = '2.0.21'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:8.7.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
9 changes: 8 additions & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ PODS:
- CoinbaseWalletSDK/Client (1.0.4)
- CoinbaseWalletSDK/CrossPlatform (1.0.4):
- CoinbaseWalletSDK/Client
- connectivity_plus (0.0.1):
- Flutter
- FlutterMacOS
- Flutter (1.0.0)
- flutter_native_splash (0.0.1):
- Flutter
Expand Down Expand Up @@ -84,6 +87,7 @@ PODS:
DEPENDENCIES:
- appcheck (from `.symlinks/plugins/appcheck/ios`)
- coinbase_wallet_sdk (from `.symlinks/plugins/coinbase_wallet_sdk/ios`)
- connectivity_plus (from `.symlinks/plugins/connectivity_plus/darwin`)
- Flutter (from `Flutter`)
- flutter_native_splash (from `.symlinks/plugins/flutter_native_splash/ios`)
- flutter_secure_storage (from `.symlinks/plugins/flutter_secure_storage/ios`)
Expand Down Expand Up @@ -116,6 +120,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/appcheck/ios"
coinbase_wallet_sdk:
:path: ".symlinks/plugins/coinbase_wallet_sdk/ios"
connectivity_plus:
:path: ".symlinks/plugins/connectivity_plus/darwin"
Flutter:
:path: Flutter
flutter_native_splash:
Expand All @@ -141,6 +147,7 @@ SPEC CHECKSUMS:
appcheck: e1ab9d4e03736f03e0401554a134d1ed502d7629
coinbase_wallet_sdk: 7ccd4e1a7940deba6ba9bd81beece999a2268c15
CoinbaseWalletSDK: ea1f37512bbc69ebe07416e3b29bf840f5cc3152
connectivity_plus: 18382e7311ba19efcaee94442b23b32507b20695
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_native_splash: edf599c81f74d093a4daf8e17bd7a018854bc778
flutter_secure_storage: d33dac7ae2ea08509be337e775f6b59f1ff45f12
Expand All @@ -166,4 +173,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 1959d098c91d8a792531a723c4a9d7e9f6a01e38

COCOAPODS: 1.14.3
COCOAPODS: 1.15.0
9 changes: 6 additions & 3 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = BNA4KC4Q9J;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
Expand All @@ -494,6 +494,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 2.3.0;
PRODUCT_BUNDLE_IDENTIFIER = com.nuxify.sophon;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand Down Expand Up @@ -665,7 +666,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = BNA4KC4Q9J;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
Expand All @@ -674,6 +675,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 2.3.0;
PRODUCT_BUNDLE_IDENTIFIER = com.nuxify.sophon;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand All @@ -689,7 +691,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = BNA4KC4Q9J;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
Expand All @@ -698,6 +700,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 2.3.0;
PRODUCT_BUNDLE_IDENTIFIER = com.nuxify.sophon;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand Down
8 changes: 4 additions & 4 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
<string>2.3.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<string>1</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>metamask</string>
Expand All @@ -36,6 +36,8 @@
</array>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSCameraUsageDescription</key>
<string>Camera access is needed to scan QR codes.</string>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>UILaunchStoryboardName</key>
Expand All @@ -57,7 +59,5 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSCameraUsageDescription</key>
<string>Camera access is needed to scan QR codes.</string>
</dict>
</plist>
4 changes: 2 additions & 2 deletions lib/configs/themes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ ThemeData _buildDefaultTheme() {
);
}

Color shimmerBase = kPink.withOpacity(0.2);
Color shimmerGlow = kPink.withOpacity(0.5);
Color shimmerBase = kPink.withValues(alpha: 0.2);
Color shimmerGlow = kPink.withValues(alpha: 0.5);
3 changes: 2 additions & 1 deletion lib/configs/web3_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import 'package:web3dart/web3dart.dart';

/// Get deployed greeter contract
Future<DeployedContract> get deployedGreeterContract async {
const String abiDirectory = 'lib/contracts/staging/greeter.abi.json';
const String abiDirectory =
'lib/core/infrastructures/contracts/staging/greeter.abi.json';
final String contractAddress = dotenv.get('GREETER_CONTRACT_ADDRESS');
final String contractABI = await rootBundle.loadString(abiDirectory);

Expand Down
74 changes: 39 additions & 35 deletions lib/core/application/service/cubit/web3_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,42 +1,37 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:reown_appkit/reown_appkit.dart';
import 'package:sophon/configs/web3_config.dart';
import 'package:sophon/internal/enums.dart';
import 'package:sophon/internal/web3_contract.dart';
import 'package:web3modal_flutter/web3modal_flutter.dart';

part 'web3_state.dart';

enum HomeScreenActionButton {
upgradeWallet,
writeToContract,
connectWallet,
}

class Web3Cubit extends Cubit<Web3State> {
Web3Cubit() : super(const Web3State());

late W3MService w3mService;
late ReownAppKitModal w3mService;

bool get isLoggedInViaEmail =>
w3mService.session?.connectedWalletName == 'Email Wallet';

Future<String> get blockchainExplorer async {
final String blockExplorer =
w3mService.selectedChain?.blockExplorer?.url ?? '';
final String blockExplorer = w3mService.selectedChain?.explorerUrl ?? '';
final String address = (await deployedGreeterContract).address.toString();

return '$blockExplorer/address/$address';
}

Future<void> fetchGreeting() async {
try {
await w3mService.selectChain(W3MChainPresets.chains['11155111']);

final List<dynamic> contractData = await w3mService.requestReadContract(
topic: null,
chainId: w3mService.selectedChain!.chainId,
deployedContract: await deployedGreeterContract,
functionName: greetFunction,
);

emit(FetchGreetingSuccess(message: contractData[0].toString()));
} catch (e) {
emit(
Expand All @@ -48,23 +43,23 @@ class Web3Cubit extends Cubit<Web3State> {
}
}

void _addExtraChains() {
for (final MapEntry<String, W3MChainInfo> entry
in W3MChainPresets.extraChains.entries) {
W3MChainPresets.chains.putIfAbsent(entry.key, () => entry.value);
}
for (final MapEntry<String, W3MChainInfo> entry
in W3MChainPresets.testChains.entries) {
W3MChainPresets.chains.putIfAbsent(entry.key, () => entry.value);
}
}

Future<void> instantiate() async {
// void _addExtraChains() {
// for (final MapEntry<String, ReownAppKitModalNetworkInfo> entry
// in ReownAppKitModalNetworks.) {
// ReownAppKitModalNetworks.chains.putIfAbsent(entry.key, () => entry.value);
// }
// for (final MapEntry<String, ReownAppKitModalNetworkInfo> entry
// in ReownAppKitModalNetworks.testChains.entries) {
// ReownAppKitModalNetworks.chains.putIfAbsent(entry.key, () => entry.value);
// }
// }

Future<void> instantiate(BuildContext context) async {
try {
const String url = 'https://github.com/Nuxify/Sophon';
w3mService = W3MService(
enableEmail: true,
projectId: '2684f2b98f5ae4051dce454b5862b9ff',
w3mService = ReownAppKitModal(
context: context,
projectId: 'ca39991258c8cb8f99a5ff8eae88b6c5',
metadata: const PairingMetadata(
name: 'Sophon',
description:
Expand All @@ -73,11 +68,12 @@ class Web3Cubit extends Cubit<Web3State> {
icons: <String>[
'https://files-nuximart.sgp1.cdn.digitaloceanspaces.com/nuxify-website/blog/images/Nuxify-logo.png',
],
redirect: Redirect(
universal: url,
native: url,
),
redirect: Redirect(universal: url, native: url),
),
excludedWalletIds: <String>{
'fd20dc426fb37566d803205b19bbc1d4096b248ac04548e3cfb6b3a38bd033aa',
'a797aa35c0fadbfc1a53e7f675162ed5226968b44a19ee3d24385c64d1d3c393',
},
includedWalletIds: <String>{
'c57ca95b47569778a828d19178114f4db188b89b763c899ba0be274e97267d96', // metamask
'4622a2b2d6af1c9844944291e5e7351a6aa24cd7b23099efac1b2fd875da31a0', // trust
Expand All @@ -88,8 +84,17 @@ class Web3Cubit extends Cubit<Web3State> {
'84b43e8ddfcd18e5fcb5d21e7277733f9cccef76f7d92c836d0e481db0c70c04', // blockchain.com
},
);
_addExtraChains();
await w3mService.init();
await w3mService.selectChain(
ReownAppKitModalNetworkInfo(
chainId: '11155111',
name: 'Sepolia',
currency: 'ETH',
rpcUrl: 'https://1rpc.io/sepolia',
explorerUrl: 'https://sepolia.etherscan.io/',
),
);

fetchHomeScreenActionButton();
if (!w3mService.isConnected) {
listenToWalletConnection();
Expand Down Expand Up @@ -128,12 +133,11 @@ class Web3Cubit extends Cubit<Web3State> {
w3mService.launchConnectedWallet();

await w3mService.requestWriteContract(
chainId: 'eip155:${dotenv.get('ETHEREUM_CHAIN_ID')}',
chainId: w3mService.selectedChain!.chainId,
topic: w3mService.session?.topic ?? '',
deployedContract: await deployedGreeterContract,
functionName: setGreetingFunction,
parameters: <String>[text],
method: setGreetingFunction,
transaction: Transaction(
from: EthereumAddress.fromHex(sender),
),
Expand Down
6 changes: 4 additions & 2 deletions lib/core/application/service/cubit/web3_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class UpdateGreetingFailed extends Web3State {
class InitializeWeb3MSuccess extends Web3State {
const InitializeWeb3MSuccess({required this.service});

final W3MService service;
final ReownAppKitModal service;
}

class InitializeWeb3MFailed extends Web3State {}
Expand All @@ -64,7 +64,9 @@ class WalletConnectionFailed extends Web3State {
}

class FetchHomeScreenActionButtonSuccess extends Web3State {
const FetchHomeScreenActionButtonSuccess({required this.action});
const FetchHomeScreenActionButtonSuccess({
required this.action,
});

final HomeScreenActionButton action;
}
File renamed without changes.
Loading

0 comments on commit 46f5ccc

Please sign in to comment.