Skip to content

Commit 4b56667

Browse files
Merge pull request #101 from Web3Auth/feat/PD-4388-manageMFA
manageMFA function added.
2 parents 9e2c62c + c79102a commit 4b56667

File tree

12 files changed

+144
-12
lines changed

12 files changed

+144
-12
lines changed

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ android {
5151
dependencies {
5252
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
5353
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3'
54-
implementation 'com.github.web3auth:web3auth-android-sdk:9.0.4'
54+
implementation 'com.github.Web3Auth:web3auth-android-sdk:9.1.2'
5555
implementation 'com.google.code.gson:gson:2.10.1'
5656
}

android/src/main/kotlin/com/web3auth/flutter/web3auth_flutter/Web3AuthFlutterPlugin.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,23 @@ class Web3AuthFlutterPlugin : FlutterPlugin, ActivityAware, MethodCallHandler,
259259
throw Error(e)
260260
}
261261
}
262+
263+
"manageMFA" -> {
264+
try {
265+
val loginArgs = call.arguments<String>() ?: return null
266+
val loginParams = gson.fromJson(loginArgs, LoginParams::class.java)
267+
val obj = JSONObject(loginArgs)
268+
if (obj.has("redirectUrl")) loginParams.redirectUrl =
269+
Uri.parse(obj.get("redirectUrl") as String?)
270+
val setupMfaCF = web3auth.manageMFA(loginParams)
271+
Log.d("${Web3AuthFlutterPlugin::class.qualifiedName}", "#enableMFA")
272+
return setupMfaCF.get()
273+
} catch (e: NotImplementedError) {
274+
throw Error(e)
275+
} catch (e: Throwable) {
276+
throw Error(e)
277+
}
278+
}
262279
}
263280
throw NotImplementedError()
264281
}

example/.metadata

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,42 @@
44
# This file should be version controlled and should not be manually edited.
55

66
version:
7-
revision: 77d935af4db863f6abd0b9c31c7e6df2a13de57b
8-
channel: stable
7+
revision: "2663184aa79047d0a33a14a3b607954f8fdd8730"
8+
channel: "stable"
99

1010
project_type: app
11+
12+
# Tracks metadata for the flutter migrate command
13+
migration:
14+
platforms:
15+
- platform: root
16+
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
17+
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
18+
- platform: android
19+
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
20+
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
21+
- platform: ios
22+
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
23+
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
24+
- platform: linux
25+
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
26+
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
27+
- platform: macos
28+
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
29+
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
30+
- platform: web
31+
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
32+
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
33+
- platform: windows
34+
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
35+
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
36+
37+
# User provided section
38+
39+
# List of Local paths (relative to this file) that should be
40+
# ignored by the migrate tool.
41+
#
42+
# Files that are not part of the templates will be ignored by default.
43+
unmanaged_files:
44+
- 'lib/main.dart'
45+
- 'ios/Runner.xcodeproj/project.pbxproj'

example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
ignoresPersistentStateOnLaunch = "NO"
4949
debugDocumentVersioning = "YES"
5050
debugServiceExtension = "internal"
51+
enableGPUValidationMode = "1"
5152
allowLocationSimulation = "YES">
5253
<BuildableProductRunnable
5354
runnableDebuggingMode = "0">

example/ios/Runner/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import UIKit
21
import Flutter
2+
import UIKit
33

44
@main
55
@objc class AppDelegate: FlutterAppDelegate {
-269 Bytes
Loading
-877 Bytes
Loading

example/lib/main.dart

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
7777
//sdkUrl: 'https://auth.mocaverse.xyz',
7878
//walletSdkUrl: 'https://lrc-mocaverse.web3auth.io',
7979
network: Network.sapphire_devnet,
80-
buildEnv: BuildEnv.testing,
80+
buildEnv: BuildEnv.production,
8181
redirectUrl: redirectUrl,
8282
whiteLabel: WhiteLabelData(
8383
mode: ThemeModes.dark,
@@ -216,6 +216,10 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
216216
onPressed: _setupMFA(),
217217
child: const Text('Setup MFA'),
218218
),
219+
ElevatedButton(
220+
onPressed: _manageMFA(),
221+
child: const Text('Manage MFA'),
222+
),
219223
ElevatedButton(
220224
onPressed: _signMesssage(context),
221225
child: const Text('Sign Message'),
@@ -365,6 +369,23 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
365369
};
366370
}
367371

372+
VoidCallback _manageMFA() {
373+
return () async {
374+
try {
375+
bool result = await Web3AuthFlutter.manageMFA();
376+
if (result) {
377+
log("MFA manage successfully done.");
378+
} else {
379+
log("Some error occured.");
380+
}
381+
} on UserCancelledException {
382+
log("User cancelled.");
383+
} on UnKnownException {
384+
log("Unknown exception occurred");
385+
}
386+
};
387+
}
388+
368389
VoidCallback _signMesssage(BuildContext context) {
369390
return () async {
370391
try {

ios/Classes/SwiftWeb3AuthFlutterPlugin.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,25 @@ public class SwiftWeb3AuthFlutterPlugin: NSObject, FlutterPlugin {
164164
details: error.localizedDescription))
165165
return
166166
}
167+
case "manageMFA":
168+
do {
169+
let loginParams = try? decoder.decode(W3ALoginParams.self, from: data)
170+
171+
if let params = loginParams {
172+
let manageMFAResult = try await web3auth?.manageMFA(params)
173+
result(manageMFAResult)
174+
} else {
175+
let manageMFAResult = try await web3auth?.manageMFA()
176+
result(manageMFAResult)
177+
}
178+
return
179+
} catch {
180+
result(FlutterError(
181+
code: "manageMFAFailedException",
182+
message: "Web3Auth manageMFA failed",
183+
details: error.localizedDescription))
184+
return
185+
}
167186
case "request":
168187
let reqParams: RequestJson
169188
do {

ios/web3auth_flutter.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Flutter SDK for Torus Web3Auth (OpenLogin)
1515
s.source = { :path => '.' }
1616
s.source_files = 'Classes/**/*'
1717
s.dependency 'Flutter'
18-
s.dependency 'Web3Auth', '~> 11.0.5'
18+
s.dependency 'Web3Auth', '~> 11.1.0'
1919
s.platform = :ios, '14.0'
2020

2121
# Flutter.framework does not contain a i386 slice.

0 commit comments

Comments
 (0)