Created
November 8, 2024 04:06
-
-
Save JaveedIshaq/8297faddaf08752853fead3580e7856e to your computer and use it in GitHub Desktop.
wepin-widget-code.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// String? googleAccessToken; | |
// String? socialTokenIsAppleOrGoogle; | |
// String? appleIdToken; | |
// final SecureStorage _secureStorage = getIt<SecureStorage>(); | |
// final Map<String, String> currency = { | |
// 'ko': 'KRW', | |
// 'en': 'USD', | |
// 'ja': 'JPY', | |
// }; | |
// WepinWidgetSDK? wepinSDK; | |
// String? selectedValue = sdkConfigs[0]['name']; | |
// WepinLifeCycle wepinStatus = WepinLifeCycle.notInitialized; | |
// String userEmail = ''; | |
// List<WepinAccount> selectedAccounts = []; | |
List<WepinAccount> accountsList = []; | |
// List<WepinAccountBalanceInfo> balanceList = []; | |
// List<WepinNFT> nftList = []; | |
// bool isLoading = false; | |
// //String? privateKey; | |
// List<LoginProvider> loginProviders = sdkConfigs[0]['loginProviders']; | |
// List<LoginProvider> selectedSocialLogins = sdkConfigs[0]['loginProviders']; | |
@override | |
void initState() { | |
super.initState(); | |
} | |
// initSocialLoginValues() async { | |
// socialTokenIsAppleOrGoogle = | |
// await getIt<AuthLocalDataSource>().getSocialTokenIsAppleOrGoogle() ?? | |
// ''; | |
// if (socialTokenIsAppleOrGoogle == SocialLoginType.APPLE.name) { | |
// appleIdToken = | |
// await _secureStorage.read(StorageValues.appleIdToken) ?? ''; | |
// } | |
// if (socialTokenIsAppleOrGoogle == SocialLoginType.GOOGLE.name) { | |
// googleAccessToken = | |
// await getIt<AuthCubit>().refreshGoogleAccessToken() ?? ''; | |
// } | |
// setState(() {}); | |
// } | |
// void initializeWepin() async { | |
// "initializeWepin is called =========".log(); | |
// getIt<WepinCubit>().startCountdown(); | |
// initSocialLoginValues(); | |
// await Future.delayed(const Duration(milliseconds: 100)); | |
// final selectedConfig = | |
// sdkConfigs.firstWhere((config) => config['name'] == selectedValue); | |
// if (Platform.isAndroid) { | |
// initWepinSDK(selectedConfig['appId']!, selectedConfig['appKeyAndroid']!, | |
// selectedConfig['privateKey']!); | |
// } | |
// if (Platform.isIOS && | |
// socialTokenIsAppleOrGoogle == SocialLoginType.GOOGLE.name) { | |
// initWepinSDK(selectedConfig['appId']!, selectedConfig['appKeyApple']!, | |
// selectedConfig['privateKey']!); | |
// } | |
// if (Platform.isIOS && | |
// socialTokenIsAppleOrGoogle == SocialLoginType.APPLE.name) { | |
// initWepinSDK(selectedConfig['appId']!, selectedConfig['appKeyApple']!, | |
// selectedConfig['privateKey']!); | |
// } | |
// } | |
/// Initializes the Wepin SDK. | |
/// | |
/// This function will finalize any existing Wepin SDK instance and then | |
/// initialize a new Wepin SDK instance with the provided appId, appKey, and | |
/// privateKey. | |
/// | |
/// If the SDK initialization is successful, it will then call the | |
/// [loginSocialAuthProvider] function to attempt to login with the | |
/// user's social login token. | |
/// | |
/// If the SDK initialization fails, it will log an error message and | |
/// throw an exception. | |
/// | |
/// Returns a [Future] that completes when the SDK initialization is | |
/// complete. | |
// Future<void> initWepinSDK( | |
// String appId, | |
// String appKey, | |
// String privateKey, | |
// ) async { | |
// await wepinSDK?.finalize(); | |
// await Future.delayed(const Duration(milliseconds: 500)); | |
// try { | |
// "Initializing WepinSDK AppKey: $appKey".log(); | |
// wepinSDK = WepinWidgetSDK(wepinAppKey: appKey, wepinAppId: appId); | |
// await wepinSDK!.init( | |
// attributes: WidgetAttributes( | |
// defaultLanguage: context.locale.languageCode, | |
// defaultCurrency: currency[context.locale.languageCode]!), | |
// ); | |
// } on Exception catch (e) { | |
// getIt<WepinCubit>().dismissLoader(); | |
// "Error Initializing WepinSDK: $e".log(); | |
// throw Exception(e); | |
// } | |
// wepinStatus = await wepinSDK!.getStatus(); | |
// // Save to Cubit | |
// getIt<WepinCubit>().updateWepinStatus(wepinStatus); | |
// // | |
// userEmail = wepinStatus == WepinLifeCycle.login | |
// ? (await wepinSDK!.login.getCurrentWepinUser())?.userInfo?.email ?? '' | |
// : ''; | |
// if (wepinStatus == WepinLifeCycle.notInitialized) { | |
// showError('WepinSDK is not initialized.'); | |
// } | |
// getStatus(); | |
// //setState(() {}); | |
// // call Login with AccessToken | |
// if (wepinSDK != null) { | |
// "calling loginSocialAuthProvider".log(); | |
// await loginSocialAuthProvider(); | |
// } | |
// } | |
// void showError(String message) { | |
// getIt<WepinCubit>().dismissLoader(); | |
// "Error occurred: $message".log(); | |
// // | |
// if (!message.contains('User Cancel')) { | |
// context.showErrorSnackBar(LocaleKeys.somethingError.tr()); | |
// } | |
// showDialog( | |
// context: context, | |
// builder: (ctx) => CustomDialog(message: message, isError: true), | |
// ); | |
// } | |
// void showSuccess(String title, String message) { | |
// context.showSnackBar(message); | |
// // showDialog( | |
// // context: context, | |
// // builder: (ctx) => CustomDialog(title: title, message: message), | |
// // ); | |
// } | |
// Future<void> performActionWithLoading(Function action) async { | |
// //setState(() => isLoading = true); | |
// try { | |
// await action(); | |
// } catch (e) { | |
// showError(e.toString()); | |
// //"Error occurred: $e".log(); | |
// } finally { | |
// //setState(() => isLoading = false); | |
// } | |
// } | |
// Future<void> loginSocialAuthProvider() async { | |
// await performActionWithLoading(() async { | |
// try { | |
// LoginResult? fbToken; | |
// // if Login Type is Google | |
// if (socialTokenIsAppleOrGoogle == SocialLoginType.GOOGLE.name) { | |
// fbToken = await wepinSDK!.login.loginWithAccessToken( | |
// provider: 'google', accessToken: googleAccessToken ?? ''); | |
// } | |
// // if Login Type is Apple | |
// if (socialTokenIsAppleOrGoogle == SocialLoginType.APPLE.name) { | |
// fbToken = await wepinSDK!.login | |
// .loginWithIdToken(idToken: appleIdToken ?? ''); | |
// } | |
// if (fbToken != null) { | |
// final wepinUser = await wepinSDK?.login.loginWepin(fbToken); | |
// if (wepinUser != null && wepinUser.userInfo != null) { | |
// userEmail = wepinUser.userInfo!.email; // Update user's email | |
// wepinStatus = await wepinSDK!.getStatus(); // Get wepin status | |
// getIt<WepinCubit>().updateWepinStatus(wepinStatus); | |
// } else { | |
// ('Login Failed. No user info found.').log(); | |
// showErrorAlertAndPerformLogout( | |
// errorMessage: LocaleKeys.somethingError.tr()); | |
// } | |
// } else { | |
// ('Login Failed. Invalid token.').log(); | |
// showErrorAlertAndPerformLogout( | |
// errorMessage: LocaleKeys.somethingError.tr()); | |
// } | |
// } catch (e) { | |
// if (!e.toString().contains('UserCancelled')) { | |
// ('Login Failed. (error code - $e)').log(); | |
// } | |
// // | |
// showErrorAlertAndPerformLogout( | |
// errorMessage: LocaleKeys.somethingError.tr()); | |
// } | |
// }); | |
// } | |
// void getStatus() async { | |
// await performActionWithLoading(() async { | |
// if (wepinSDK != null) { | |
// wepinStatus = await wepinSDK!.getStatus(); | |
// getIt<WepinCubit>().updateWepinStatus(wepinStatus); | |
// } | |
// }); | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment