Skip to content

Commit

Permalink
chore: 🐛 Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
redDwarf03 authored and Chralu committed Feb 11, 2025
1 parent 1382412 commit 6a1b65c
Show file tree
Hide file tree
Showing 14 changed files with 318 additions and 16 deletions.
41 changes: 41 additions & 0 deletions lib/application/airdrop/airdrop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,44 @@ Future<({double personalLP, double personalLPFlexible})> airdropPersonalLP(

return (personalLP: personalLP, personalLPFlexible: personalLPFlexible);
}

@riverpod
Future<bool> airdropEmailConfirmedCheck(
Ref ref,
) async {
try {
final session = ref.watch(sessionNotifierProvider).loggedIn;
final keychainKeypair = archethic.deriveKeyPair(
archethic.uint8ListToHex(
Uint8List.fromList(session!.wallet.keychainSecuredInfos.seed),
),
0,
);

final payload = {
'pubkey': archethic.uint8ListToHex(keychainKeypair.publicKey!),
};

final response = await http.post(
Uri.parse(
'https://airdrop-backend.archethic.net/check-confirmation-email'),
headers: {
'Content-Type': 'application/json',
},
body: jsonEncode(payload),
);

if (response.statusCode == 200) {
final json = jsonDecode(response.body);

final airdropNotifier = ref.read(airdropNotifierProvider.notifier);
await airdropNotifier.updateMailConfirmed(json['confirmed']);
return json['confirmed'];
}
} catch (e) {
_logger.severe('airdropCheck error : $e');
}
final airdropNotifier = ref.read(airdropNotifierProvider.notifier);
await airdropNotifier.updateMailConfirmed(false);
return false;
}
19 changes: 19 additions & 0 deletions lib/application/airdrop/airdrop.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions lib/application/airdrop/airdrop_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,19 @@ class AirdropNotifier extends _$AirdropNotifier {
);
}
}

Future<void> updateMailConfirmed(bool isMailConfirmed) async {
final currentAirdrop = state.valueOrNull;
if (currentAirdrop != null) {
final updatedAirdrop =
currentAirdrop.copyWith(isMailConfirmed: isMailConfirmed);
await setAirdrop(updatedAirdrop);
} else {
await setAirdrop(
Airdrop(
isMailConfirmed: isMailConfirmed,
),
);
}
}
}
2 changes: 1 addition & 1 deletion lib/application/airdrop/airdrop_notifier.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@
"airdropParticipateStepWaitlistDesc1": "You'll receive updates on our progress in delivering the biometric cold wallet before anyone else",
"airdropParticipateStepWaitlistDesc2": "Only one airdrop registration is allowed per person. If multiple registrations are detected, all associated airdrops will be canceled.",
"airdropParticipateStepWaitlistInputField": "Email Address",
"airdropParticipateStepWaitlistBtn": "Join the waitlist",
"airdropParticipateStepWaitlistBtn": "Next",
"airdropParticipateStepConfirmEmailTitle": "Your registration is almost complete!",
"airdropParticipateStepConfirmEmailDesc1": "To finalize your participation, please check your inbox and click the confirmation link we just sent at:",
"airdropParticipateStepConfirmEmailDesc2": "Didn’t receive the email? Check your spam folder or ",
Expand Down Expand Up @@ -759,6 +759,10 @@
"airdropBackendAlreadySubscribe": "Sorry but there is already a subscription for this wallet and this e-mail address.",
"airdropBackendMissingParameters": "Please complete all required fields to proceed.",
"airdropBackendInvalidEmail": "Please enter a valid email address.",
"airdropBackendEmailSent": "Confirmation email sent.",
"airdropBackendEmailNotFound": "Email not found.",
"airdropBackendEmailAlreadyConfirmed": "This email has been already confirmed.",
"airdropBackendEmailNotConfirmed": "Your email has not been confirmed. Please confirm it before continuing.",
"airdropBackendInvalidPubKey": "The wallet you are using is not valid. Please check and try again.",
"airdropBackendInvalidSignature": "The signature is invalid. Please verify and try again.",
"airdropBackendUnknownError": "An unknown error occurred. Please try again or contact support if the issue persists.",
Expand Down
76 changes: 76 additions & 0 deletions lib/ui/views/airdrop/bloc/provider.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:convert';
import 'dart:typed_data';

import 'package:aewallet/application/airdrop/airdrop.dart';
import 'package:aewallet/application/airdrop/airdrop_notifier.dart';
import 'package:aewallet/application/session/session.dart';
import 'package:aewallet/domain/models/core/failures.dart';
Expand Down Expand Up @@ -60,6 +61,78 @@ class AirdropFormNotifier extends _$AirdropFormNotifier {
state.copyWith(mailAddress: mailAddress.toLowerCase(), failure: null);
}

Future<void> resendConfirmationMail(AppLocalizations localizations) async {
state = state.copyWith(resendConfirmationEmailInfo: null, failure: null);
try {
final payload = {
'email': state.mailAddress,
};
final response = await http.post(
Uri.parse(
'https://airdrop-backend.archethic.net/resend-confirmation-email',
),
headers: {
'Content-Type': 'application/json',
},
body: jsonEncode(payload),
);

//
if (response.statusCode == 200) {
state = state.copyWith(
resendConfirmationEmailInfo: localizations.airdropBackendEmailSent,
);
} else if (response.statusCode == 400) {
final responseBody = jsonDecode(response.body);
var errorMessage = responseBody['error'] ?? 'Unknown error';
switch (errorMessage) {
case 'Email parameter is missing':
errorMessage = localizations.airdropBackendMissingParameters;
break;
case 'Email not found':
errorMessage = localizations.airdropBackendEmailNotFound;
break;
case 'Email already confirmed':
errorMessage = localizations.airdropBackendEmailAlreadyConfirmed;
break;
default:
errorMessage = localizations.airdropBackendUnknownError;
}

state = state.copyWith(
failure: Failure.other(
message: errorMessage,
),
resendConfirmationEmailInfo: errorMessage,
);
} else {
if (response.statusCode == 500) {
final responseBody = jsonDecode(response.body);
final errorMessage =
(responseBody['error'] ?? '') + ' - ' + responseBody['details'] ??
'Unknown error';
state = state.copyWith(
failure: Failure.other(
message: 'Error 500 - $errorMessage',
),
resendConfirmationEmailInfo: errorMessage,
);
}
}
} catch (e) {
state = state.copyWith(
failure: Failure.network(
message: 'Network error: $e',
),
resendConfirmationEmailInfo: 'Network error: $e',
);
}
}

Future<bool> checkConfirmation() async {
return await ref.read(airdropEmailConfirmedCheckProvider.future);
}

Future<void> joinWaitlist(AppLocalizations localizations) async {
try {
state = state.copyWith(joinWaitlistInProgress: true);
Expand Down Expand Up @@ -175,5 +248,8 @@ class AirdropFormNotifier extends _$AirdropFormNotifier {
}

state = state.copyWith(joinWaitlistInProgress: false);
if (state.failure == null) {
setAirdropProcessStep(AirdropProcessStep.confirmEmail);
}
}
}
2 changes: 1 addition & 1 deletion lib/ui/views/airdrop/bloc/provider.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/ui/views/airdrop/bloc/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class AirdropFormState with _$AirdropFormState {
@Default(false) bool confirmPrivacyPolicy,
@Default(false) bool joinWaitlistInProgress,
@Default(0.0) double personalLP,
String? resendConfirmationEmailInfo,
Failure? failure,
}) = _AirdropFormState;
const AirdropFormState._();
Expand Down
26 changes: 25 additions & 1 deletion lib/ui/views/airdrop/bloc/state.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ mixin _$AirdropFormState {
bool get confirmPrivacyPolicy => throw _privateConstructorUsedError;
bool get joinWaitlistInProgress => throw _privateConstructorUsedError;
double get personalLP => throw _privateConstructorUsedError;
String? get resendConfirmationEmailInfo => throw _privateConstructorUsedError;
Failure? get failure => throw _privateConstructorUsedError;

/// Create a copy of AirdropFormState
Expand All @@ -48,6 +49,7 @@ abstract class $AirdropFormStateCopyWith<$Res> {
bool confirmPrivacyPolicy,
bool joinWaitlistInProgress,
double personalLP,
String? resendConfirmationEmailInfo,
Failure? failure});

$FailureCopyWith<$Res>? get failure;
Expand Down Expand Up @@ -75,6 +77,7 @@ class _$AirdropFormStateCopyWithImpl<$Res, $Val extends AirdropFormState>
Object? confirmPrivacyPolicy = null,
Object? joinWaitlistInProgress = null,
Object? personalLP = null,
Object? resendConfirmationEmailInfo = freezed,
Object? failure = freezed,
}) {
return _then(_value.copyWith(
Expand Down Expand Up @@ -106,6 +109,10 @@ class _$AirdropFormStateCopyWithImpl<$Res, $Val extends AirdropFormState>
? _value.personalLP
: personalLP // ignore: cast_nullable_to_non_nullable
as double,
resendConfirmationEmailInfo: freezed == resendConfirmationEmailInfo
? _value.resendConfirmationEmailInfo
: resendConfirmationEmailInfo // ignore: cast_nullable_to_non_nullable
as String?,
failure: freezed == failure
? _value.failure
: failure // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -144,6 +151,7 @@ abstract class _$$AirdropFormStateImplCopyWith<$Res>
bool confirmPrivacyPolicy,
bool joinWaitlistInProgress,
double personalLP,
String? resendConfirmationEmailInfo,
Failure? failure});

@override
Expand All @@ -170,6 +178,7 @@ class __$$AirdropFormStateImplCopyWithImpl<$Res>
Object? confirmPrivacyPolicy = null,
Object? joinWaitlistInProgress = null,
Object? personalLP = null,
Object? resendConfirmationEmailInfo = freezed,
Object? failure = freezed,
}) {
return _then(_$AirdropFormStateImpl(
Expand Down Expand Up @@ -201,6 +210,10 @@ class __$$AirdropFormStateImplCopyWithImpl<$Res>
? _value.personalLP
: personalLP // ignore: cast_nullable_to_non_nullable
as double,
resendConfirmationEmailInfo: freezed == resendConfirmationEmailInfo
? _value.resendConfirmationEmailInfo
: resendConfirmationEmailInfo // ignore: cast_nullable_to_non_nullable
as String?,
failure: freezed == failure
? _value.failure
: failure // ignore: cast_nullable_to_non_nullable
Expand All @@ -220,6 +233,7 @@ class _$AirdropFormStateImpl extends _AirdropFormState {
this.confirmPrivacyPolicy = false,
this.joinWaitlistInProgress = false,
this.personalLP = 0.0,
this.resendConfirmationEmailInfo,
this.failure})
: super._();

Expand All @@ -244,11 +258,13 @@ class _$AirdropFormStateImpl extends _AirdropFormState {
@JsonKey()
final double personalLP;
@override
final String? resendConfirmationEmailInfo;
@override
final Failure? failure;

@override
String toString() {
return 'AirdropFormState(airdropProcessStep: $airdropProcessStep, mailAddress: $mailAddress, confirmOnlyOneAirdrop: $confirmOnlyOneAirdrop, confirmNotMultipleRegistrations: $confirmNotMultipleRegistrations, confirmPrivacyPolicy: $confirmPrivacyPolicy, joinWaitlistInProgress: $joinWaitlistInProgress, personalLP: $personalLP, failure: $failure)';
return 'AirdropFormState(airdropProcessStep: $airdropProcessStep, mailAddress: $mailAddress, confirmOnlyOneAirdrop: $confirmOnlyOneAirdrop, confirmNotMultipleRegistrations: $confirmNotMultipleRegistrations, confirmPrivacyPolicy: $confirmPrivacyPolicy, joinWaitlistInProgress: $joinWaitlistInProgress, personalLP: $personalLP, resendConfirmationEmailInfo: $resendConfirmationEmailInfo, failure: $failure)';
}

@override
Expand All @@ -272,6 +288,10 @@ class _$AirdropFormStateImpl extends _AirdropFormState {
other.joinWaitlistInProgress == joinWaitlistInProgress) &&
(identical(other.personalLP, personalLP) ||
other.personalLP == personalLP) &&
(identical(other.resendConfirmationEmailInfo,
resendConfirmationEmailInfo) ||
other.resendConfirmationEmailInfo ==
resendConfirmationEmailInfo) &&
(identical(other.failure, failure) || other.failure == failure));
}

Expand All @@ -285,6 +305,7 @@ class _$AirdropFormStateImpl extends _AirdropFormState {
confirmPrivacyPolicy,
joinWaitlistInProgress,
personalLP,
resendConfirmationEmailInfo,
failure);

/// Create a copy of AirdropFormState
Expand All @@ -306,6 +327,7 @@ abstract class _AirdropFormState extends AirdropFormState {
final bool confirmPrivacyPolicy,
final bool joinWaitlistInProgress,
final double personalLP,
final String? resendConfirmationEmailInfo,
final Failure? failure}) = _$AirdropFormStateImpl;
const _AirdropFormState._() : super._();

Expand All @@ -324,6 +346,8 @@ abstract class _AirdropFormState extends AirdropFormState {
@override
double get personalLP;
@override
String? get resendConfirmationEmailInfo;
@override
Failure? get failure;

/// Create a copy of AirdropFormState
Expand Down
Loading

0 comments on commit 6a1b65c

Please sign in to comment.