Skip to content

Commit

Permalink
button logic change, sync wallets and publish
Browse files Browse the repository at this point in the history
  • Loading branch information
d-reader-luka committed Apr 3, 2024
1 parent ebd4d41 commit e15967a
Show file tree
Hide file tree
Showing 14 changed files with 179 additions and 798 deletions.
1 change: 1 addition & 0 deletions android/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ GeneratedPluginRegistrant.java
key.properties
**/*.keystore
**/*.jks
**/*.jks.*
212 changes: 100 additions & 112 deletions lib/features/comic_issue/presentation/screens/comic_issue_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -458,119 +458,107 @@ class BottomNavigation extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final bool canRead =
issue.myStats?.canRead != null && issue.myStats!.canRead;
final bool showReadButtonOnly = issue.isFreeToRead &&
canRead &&
issue.activeCandyMachineAddress == null &&
!issue.isSecondarySaleActive;
return showReadButtonOnly
? ReadButton(issue: issue)
: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: ReadButton(
issue: issue,
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: ReadButton(
issue: issue,
),
),
issue.activeCandyMachineAddress != null
? Expanded(
child: TransactionButton(
isLoading: ref.watch(globalNotifierProvider).isLoading,
onPressed: ref.watch(isOpeningSessionProvider)
? null
: () async {
await ref
.read(comicIssueControllerProvider.notifier)
.handleMint(
displaySnackbar: ({
required String text,
bool isError = false,
}) {
showSnackBar(
context: context,
text: text,
backgroundColor: isError
? ColorPalette.dReaderRed
: ColorPalette.greyscale300,
);
},
triggerVerificationDialog: () {
return triggerVerificationDialog(context, ref);
},
onSuccessMint: () {
nextScreenPush(
context: context,
path: RoutePath.mintLoadingAnimation,
);
},
onException: (exception) {
if (exception is NoWalletFoundException) {
return _showWalkthroughDialog(
context: context, ref: ref);
} else if (exception is LowPowerModeException) {
return triggerLowPowerModeDialog(context);
}
showSnackBar(
context: context,
text: exception is BadRequestException
? exception.cause
: exception.toString(),
backgroundColor: ColorPalette.dReaderRed,
);
},
);
},
text: 'Mint',
price: ref.watch(activeCandyMachineGroup)?.mintPrice ?? 0,
),
),
ref.watch(activeCandyMachineGroup) != null
? Expanded(
child: TransactionButton(
isLoading: ref.watch(globalNotifierProvider).isLoading,
onPressed: ref.watch(isOpeningSessionProvider)
? null
: () async {
await ref
.read(comicIssueControllerProvider.notifier)
.handleMint(
displaySnackbar: ({
required String text,
bool isError = false,
}) {
showSnackBar(
context: context,
text: text,
backgroundColor: isError
? ColorPalette.dReaderRed
: ColorPalette.greyscale300,
);
},
triggerVerificationDialog: () {
return triggerVerificationDialog(
context, ref);
},
onSuccessMint: () {
nextScreenPush(
context: context,
path: RoutePath.mintLoadingAnimation,
);
},
onException: (exception) {
if (exception is NoWalletFoundException) {
return _showWalkthroughDialog(
context: context, ref: ref);
} else if (exception
is LowPowerModeException) {
return triggerLowPowerModeDialog(context);
}
showSnackBar(
context: context,
text: exception is BadRequestException
? exception.cause
: exception.toString(),
backgroundColor: ColorPalette.dReaderRed,
);
},
);
},
text: 'Mint',
price:
ref.watch(activeCandyMachineGroup)?.mintPrice ?? 0,
),
)
: issue.isSecondarySaleActive
? Expanded(
child: TransactionButton(
isLoading:
ref.watch(globalNotifierProvider).isLoading,
onPressed:
ref.read(selectedListingsProvider).isNotEmpty &&
!ref.watch(isOpeningSessionProvider)
? () async {
await ref
.read(comicIssueControllerProvider
.notifier)
.handleBuy(
displaySnackBar: ({
required String text,
required bool isSuccess,
}) {
showSnackBar(
context: context,
text: text,
backgroundColor: isSuccess
? ColorPalette.dReaderGreen
: ColorPalette.dReaderRed,
);
},
onException: (exception) {
triggerLowPowerOrNoWallet(
context,
exception,
);
},
);
}
: null,
text: 'Buy',
price: ref.watch(selectedListingsPrice),
isListing: true,
),
)
: const SizedBox(),
],
);
)
: issue.isSecondarySaleActive
? Expanded(
child: TransactionButton(
isLoading: ref.watch(globalNotifierProvider).isLoading,
onPressed: ref
.read(selectedListingsProvider)
.isNotEmpty &&
!ref.watch(isOpeningSessionProvider)
? () async {
await ref
.read(comicIssueControllerProvider.notifier)
.handleBuy(
displaySnackBar: ({
required String text,
required bool isSuccess,
}) {
showSnackBar(
context: context,
text: text,
backgroundColor: isSuccess
? ColorPalette.dReaderGreen
: ColorPalette.dReaderRed,
);
},
onException: (exception) {
triggerLowPowerOrNoWallet(
context,
exception,
);
},
);
}
: null,
text: 'Buy',
price: ref.watch(selectedListingsPrice),
isListing: true,
),
)
: const SizedBox(),
],
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import 'package:d_reader_flutter/constants/constants.dart';
import 'package:d_reader_flutter/constants/enums.dart';
import 'package:d_reader_flutter/constants/routes.dart';
import 'package:d_reader_flutter/features/library/presentation/providers/owned/owned_providers.dart';
import 'package:d_reader_flutter/features/user/domain/providers/user_provider.dart';
import 'package:d_reader_flutter/features/user/presentation/providers/user_providers.dart';
import 'package:d_reader_flutter/features/wallet/presentation/providers/wallet_notifier.dart';
import 'package:d_reader_flutter/features/wallet/presentation/providers/wallet_providers.dart';
import 'package:d_reader_flutter/shared/domain/providers/environment/environment_notifier.dart';
import 'package:d_reader_flutter/shared/domain/providers/solana/solana_providers.dart';
import 'package:d_reader_flutter/shared/presentations/providers/global/global_notifier.dart';
import 'package:d_reader_flutter/shared/theme/app_colors.dart';
Expand Down Expand Up @@ -98,6 +100,9 @@ class MyWalletsScreen extends ConsumerWidget {
)
: RefreshIndicator(
onRefresh: () async {
await ref
.read(userRepositoryProvider)
.syncWallets(ref.watch(environmentProvider).user!.id);
ref.invalidate(userWalletsProvider);
},
backgroundColor: ColorPalette.dReaderYellow100,
Expand Down
29 changes: 0 additions & 29 deletions lib/features/settings/presentation/screens/wallet/wallet_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,35 +119,6 @@ class _WalletInfoScreenState extends ConsumerState<WalletInfoScreen> {
const Divider(
color: ColorPalette.greyscale400,
),
SettingsCommonListTile(
title: 'Sync wallet',
leadingPath: '${Config.settingsAssetsPath}/light/wallet.svg',
overrideColor: Colors.green,
overrideLeading: ref.watch(privateLoadingProvider)
? const SizedBox(
height: 24,
width: 24,
child: CircularProgressIndicator(
color: ColorPalette.dReaderGreen,
),
)
: null,
overrideTrailing: const SizedBox(),
onTap: ref.watch(globalNotifierProvider).isLoading
? null
: () {
ref.read(walletControllerProvider.notifier).syncWallet(
address: widget.address,
callback: () {
showSnackBar(
context: context,
text: 'Wallet synced successfully',
backgroundColor: ColorPalette.dReaderGreen,
);
},
);
},
),
if (ref.read(environmentProvider).solanaCluster ==
SolanaCluster.devnet.value) ...[
SettingsCommonListTile(
Expand Down
100 changes: 68 additions & 32 deletions lib/features/user/domain/models/user.dart
Original file line number Diff line number Diff line change
@@ -1,38 +1,59 @@
import 'dart:io' show File;

import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:flutter/foundation.dart';

part 'user.freezed.dart';
part 'user.g.dart';

@freezed
class UserModel with _$UserModel {
const factory UserModel({
required int id,
required int referralsRemaining,
required String email,
required String avatar,
required String name,
required String role,
required bool isEmailVerified,
required bool hasBetaAccess,
required List<String> deviceTokens,
}) = _UserModel;

factory UserModel.fromJson(Map<String, Object?> json) =>
_$UserModelFromJson(json);
}
class UserModel {
final int id, referralsRemaining;
final String email, avatar, name, role;
final bool isEmailVerified, hasBetaAccess;
final List<String> deviceTokens;

UserModel({
required this.id,
required this.email,
required this.name,
required this.avatar,
required this.role,
required this.isEmailVerified,
required this.hasBetaAccess,
required this.referralsRemaining,
required this.deviceTokens,
});

factory UserModel.fromJson(dynamic json) {
return UserModel(
id: json['id'],
email: json['email'],
avatar: json['avatar'],
name: json['name'],
role: json['role'],
isEmailVerified: json['isEmailVerified'],
hasBetaAccess: json['hasBetaAccess'] ?? false,
referralsRemaining: json['referralsRemaining'] ?? 0,
deviceTokens: json['deviceTokens'] != null
? List<String>.from(json['deviceTokens'])
: [],
);
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['id'] = id;
data['email'] = email;
data['name'] = name;
data['avatar'] = avatar;
data['role'] = role;
data['isEmailVerified'] = isEmailVerified;
data['hasBetaAccess'] = hasBetaAccess;
data['referralsRemaining'] = referralsRemaining;
data['deviceTokens'] = deviceTokens;
return data;
}

@override
bool operator ==(Object other) =>
other is UserModel && other.runtimeType == runtimeType && other.id == id;

@freezed
class UpdateUserPayload with _$UpdateUserPayload {
const factory UpdateUserPayload({
required int id,
String? email,
String? name,
String? referrer,
File? avatar,
}) = _UpdateUserPayload;
@override
int get hashCode => Object.hash(runtimeType, id, email);
}

enum UserRole {
Expand All @@ -52,3 +73,18 @@ extension UserRoleValue on UserRole {

String get name => userRoles[this] ?? 'User';
}

class UpdateUserPayload {
final int id;

final File? avatar;
final String? email, name, referrer;

UpdateUserPayload({
required this.id,
this.email,
this.name,
this.avatar,
this.referrer,
});
}
Loading

0 comments on commit e15967a

Please sign in to comment.