Skip to content

Commit

Permalink
feat: dynamic link sharing of event from non nft creation
Browse files Browse the repository at this point in the history
  • Loading branch information
AhsanRns committed May 27, 2024
1 parent 219115f commit 3f91175
Show file tree
Hide file tree
Showing 8 changed files with 230 additions and 132 deletions.
3 changes: 2 additions & 1 deletion wallet/lib/ipc/handler/handlers/create_recipe_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:pylons_wallet/pages/home/home_provider.dart';
import 'package:pylons_wallet/providers/collections_tab_provider.dart';
import 'package:pylons_wallet/pylons_app.dart';
import 'package:pylons_wallet/stores/wallet_store.dart';
import 'package:pylons_wallet/utils/constants.dart';
import 'package:pylons_wallet/utils/route_util.dart';
import 'package:pylons_wallet/modules/Pylonstech.pylons.pylons/module/export.dart' as pylons;

Expand Down Expand Up @@ -38,7 +39,7 @@ class CreateRecipeHandler implements BaseHandler {
if (shouldShowNFTPreview()) {
final msgObj = pylons.MsgCreateRecipe.create()..mergeFromProto3Json(jsonMap);

if (msgObj.cookbookId.contains('Evently')) {
if (msgObj.cookbookId.contains(kEvently)) {
final events = await Events.eventFromRecipeId(msgObj.cookbookId, msgObj.id);
if (events != null) {
await navigatorKey.currentState!.pushNamed(Routes.eventView.name, arguments: events);
Expand Down
12 changes: 4 additions & 8 deletions wallet/lib/pages/detailed_asset_view/owner_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ class _CollapsedBottomMenuState extends State<_CollapsedBottomMenu> {
final ibcEnumCoins = viewModel.nft.ibcCoins;

/// This change will reflect only for upylon ibcCoins
final coinWithDenom =ibcEnumCoins.getAbbrev() == constants.kPYLN_ABBREVATION
final coinWithDenom = ibcEnumCoins.getAbbrev() == constants.kPYLN_ABBREVATION
? "\$${ibcEnumCoins.pylnToCredit(viewModel.nft.ibcCoins.getCoinWithProperDenomination(viewModel.nft.price))} ${viewModel.nft.ibcCoins.getAbbrev()}"
: "${ibcEnumCoins.getCoinWithProperDenomination(viewModel.nft.price)} ${ibcEnumCoins.getAbbrev()}";

Expand Down Expand Up @@ -334,9 +334,7 @@ class _CollapsedBottomMenuState extends State<_CollapsedBottomMenu> {
children: [
if (viewModel.nft.type != NftType.TYPE_ITEM)
Text(
viewModel.nft.price == "0"
? LocaleKeys.free.tr()
: coinWithDenom,
viewModel.nft.price == "0" ? LocaleKeys.free.tr() : coinWithDenom,
style: TextStyle(color: Colors.white, fontSize: 15.sp, fontWeight: FontWeight.bold),
)
],
Expand Down Expand Up @@ -402,7 +400,7 @@ class __ExpandedBottomMenuState extends State<_ExpandedBottomMenu> {
final ibcEnumCoins = viewModel.nft.ibcCoins;

// This change will reflect only for upylon ibcCoins
final coinWithDenom = ibcEnumCoins.getAbbrev() == constants.kPYLN_ABBREVATION
final coinWithDenom = ibcEnumCoins.getAbbrev() == constants.kPYLN_ABBREVATION
? "\$${ibcEnumCoins.pylnToCredit(viewModel.nft.ibcCoins.getCoinWithProperDenomination(viewModel.nft.price))} ${viewModel.nft.ibcCoins.getAbbrev()}"
: "${ibcEnumCoins.getCoinWithProperDenomination(viewModel.nft.price)} ${ibcEnumCoins.getAbbrev()}";

Expand Down Expand Up @@ -664,9 +662,7 @@ class __ExpandedBottomMenuState extends State<_ExpandedBottomMenu> {
children: [
if (viewModel.nft.type != NftType.TYPE_ITEM) ...[
Text(
viewModel.nft.price == "0"
? LocaleKeys.free.tr()
: coinWithDenom,
viewModel.nft.price == "0" ? LocaleKeys.free.tr() : coinWithDenom,
style: TextStyle(color: Colors.white, fontSize: 15.sp, fontWeight: FontWeight.bold),
)
]
Expand Down
17 changes: 17 additions & 0 deletions wallet/lib/pages/detailed_asset_view/owner_view_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:flutter/foundation.dart';
import 'package:just_audio/just_audio.dart';
import 'package:pylons_wallet/components/loading.dart';
import 'package:pylons_wallet/model/common.dart';
import 'package:pylons_wallet/model/event.dart';
import 'package:pylons_wallet/model/nft.dart';
import 'package:pylons_wallet/model/nft_ownership_history.dart';
import 'package:pylons_wallet/pages/detailed_asset_view/widgets/create_trade_bottom_sheet.dart';
Expand All @@ -32,6 +33,9 @@ class OwnerViewViewModel extends ChangeNotifier {
final VideoPlayerHelper videoPlayerHelper;
final ShareHelper shareHelper;

///* for events
late Events events;

OwnerViewViewModel({
required this.repository,
required this.walletsStore,
Expand Down Expand Up @@ -473,6 +477,19 @@ class OwnerViewViewModel extends ChangeNotifier {
});
}

Future<void> shareEventsLink({required Size size}) async {
final address = accountPublicInfo.publicAddress;

final link = await repository.createDynamicLinkForRecipeEventShare(address: address, events: events);
return link.fold((l) {
LocaleKeys.something_wrong.tr().show();
return null;
}, (r) {
shareHelper.shareText(text: r, size: size);
return null;
});
}

Future<void> changeNFTEnabledDisableStatus({required bool enabled}) async {
final response = await repository.enableDisableRecipe(
cookBookId: CookbookId(nft.cookbookID),
Expand Down
54 changes: 42 additions & 12 deletions wallet/lib/pages/events/events_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:get_it/get_it.dart';
import 'package:provider/provider.dart';
import 'package:pylons_wallet/components/space_widgets.dart';
import 'package:pylons_wallet/model/event.dart';
import 'package:pylons_wallet/pages/detailed_asset_view/owner_view_view_model.dart';
import 'package:pylons_wallet/utils/constants.dart';
import 'package:shimmer_animation/shimmer_animation.dart';

import '../../model/event.dart';

class EventPassViewScreen extends StatefulWidget {
const EventPassViewScreen({super.key, required this.events});
Expand All @@ -18,8 +19,31 @@ class EventPassViewScreen extends StatefulWidget {
}

class _EventPassViewScreenState extends State<EventPassViewScreen> {
OwnerViewViewModel ownerViewViewModel = GetIt.I.get();

@override
void initState() {
super.initState();
ownerViewViewModel.events = widget.events;
}

@override
Widget build(BuildContext context) {
return ChangeNotifierProvider.value(
value: ownerViewViewModel,
builder: (_, __) => const EventPassViewContent(),
);
}
}

class EventPassViewContent extends StatelessWidget {
const EventPassViewContent({
super.key,
});

@override
Widget build(BuildContext context) {
final viewModel = context.watch<OwnerViewViewModel>();
return ColoredBox(
color: AppColors.kBlack87,
child: SafeArea(
Expand All @@ -44,7 +68,13 @@ class _EventPassViewScreenState extends State<EventPassViewScreen> {
color: AppColors.kWhite,
),
),
SvgPicture.asset(shareIcon),
GestureDetector(
onTap: () {
final Size size = MediaQuery.of(context).size;
viewModel.shareEventsLink(size: size);
},
child: SvgPicture.asset(shareIcon),
),
],
),
),
Expand All @@ -59,7 +89,7 @@ class _EventPassViewScreenState extends State<EventPassViewScreen> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.events.eventName,
viewModel.events.eventName,
style: Theme.of(context).textTheme.displayLarge?.copyWith(fontSize: 25.sp, fontWeight: FontWeight.w700, color: AppColors.kWhite),
),
VerticalSpace(20.h),
Expand All @@ -74,7 +104,7 @@ class _EventPassViewScreenState extends State<EventPassViewScreen> {
style: Theme.of(context).textTheme.displayLarge?.copyWith(fontSize: 11.sp, fontWeight: FontWeight.w400, color: AppColors.kWhite),
),
Text(
widget.events.startDate,
viewModel.events.startDate,
style: Theme.of(context).textTheme.labelSmall?.copyWith(fontSize: 15.sp, fontWeight: FontWeight.w700, color: AppColors.kWhite),
),
],
Expand All @@ -87,7 +117,7 @@ class _EventPassViewScreenState extends State<EventPassViewScreen> {
style: Theme.of(context).textTheme.displayLarge?.copyWith(fontSize: 11.sp, fontWeight: FontWeight.w400, color: AppColors.kWhite),
),
Text(
widget.events.startDate,
viewModel.events.startTime,
style: Theme.of(context).textTheme.labelSmall?.copyWith(fontSize: 15.sp, fontWeight: FontWeight.w700, color: AppColors.kWhite),
),
],
Expand All @@ -106,7 +136,7 @@ class _EventPassViewScreenState extends State<EventPassViewScreen> {
style: Theme.of(context).textTheme.displayLarge?.copyWith(fontSize: 11.sp, fontWeight: FontWeight.w400, color: AppColors.kWhite),
),
Text(
widget.events.location,
viewModel.events.location,
style: Theme.of(context).textTheme.labelSmall?.copyWith(fontSize: 15.sp, fontWeight: FontWeight.w700, color: AppColors.kWhite),
),
],
Expand All @@ -115,11 +145,11 @@ class _EventPassViewScreenState extends State<EventPassViewScreen> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'SEAT',
'PRICE',
style: Theme.of(context).textTheme.displayLarge?.copyWith(fontSize: 11.sp, fontWeight: FontWeight.w400, color: AppColors.kWhite),
),
Text(
"no seat",
viewModel.events.price == "0" ? "Free" : viewModel.events.price,
style: Theme.of(context).textTheme.labelSmall?.copyWith(fontSize: 15.sp, fontWeight: FontWeight.w700, color: AppColors.kWhite),
),
],
Expand All @@ -143,7 +173,7 @@ class _EventPassViewScreenState extends State<EventPassViewScreen> {
SvgPicture.asset(kDiamondIcon),
SizedBox(width: 5.w),
Text(
'x ${widget.events.listOfPerks?.length}',
'x ${viewModel.events.listOfPerks?.length}',
style: TextStyle(fontSize: 15.sp, color: AppColors.kWhite, fontWeight: FontWeight.bold),
),
SizedBox(width: 5.w),
Expand All @@ -164,7 +194,7 @@ class _EventPassViewScreenState extends State<EventPassViewScreen> {
margin: EdgeInsets.symmetric(horizontal: 20.w),
child: CachedNetworkImage(
fit: BoxFit.fill,
imageUrl: widget.events.thumbnail,
imageUrl: viewModel.events.thumbnail,
errorWidget: (a, b, c) => const Center(
child: Icon(
Icons.error_outline,
Expand Down
13 changes: 11 additions & 2 deletions wallet/lib/pages/home/collection_screen/collection_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ import 'package:flutter_svg/flutter_svg.dart';
import 'package:provider/provider.dart';
import 'package:pylons_wallet/components/loading.dart';
import 'package:pylons_wallet/gen/assets.gen.dart';
import 'package:pylons_wallet/model/event.dart';
import 'package:pylons_wallet/model/nft.dart';
import 'package:pylons_wallet/pages/home/collection_screen/collection_view_model.dart';
import 'package:pylons_wallet/pages/home/collection_screen/widgets/creation_collection_sheet.dart';
import 'package:pylons_wallet/pages/home/collection_screen/widgets/show_recipe_json.dart';
import 'package:pylons_wallet/providers/items_provider.dart';
import 'package:pylons_wallet/providers/recipes_provider.dart';
import 'package:pylons_wallet/pylons_app.dart';
import 'package:pylons_wallet/utils/constants.dart';
import 'package:pylons_wallet/utils/enums.dart';
import 'package:pylons_wallet/utils/route_util.dart';

import '../../../providers/collections_tab_provider.dart';
import 'widgets/purchase_collection_sheet.dart';
import 'widgets/trades_collection_sheet.dart';
Expand Down Expand Up @@ -181,9 +182,17 @@ class NONNftCreations extends StatelessWidget {
padding: EdgeInsets.symmetric(horizontal: 16.w),
itemBuilder: (context, index) => InkWell(
onTap: () {
final recipe = viewModel.nonNFTRecipes[index];

if (recipe.cookbookId.contains(kEvently)) {
final events = Events.fromRecipe(recipe);
navigatorKey.currentState!.pushNamed(Routes.eventView.name, arguments: events);
return;
}

final showRecipeJsonDialog = ShowRecipeJsonDialog(
context: context,
recipe: viewModel.nonNFTRecipes[index],
recipe: recipe,
);
showRecipeJsonDialog.show();
},
Expand Down
Loading

0 comments on commit 3f91175

Please sign in to comment.