|
| 1 | +// SPDX-License-Identifier: ice License 1.0 |
| 2 | + |
| 3 | +import 'package:flutter/material.dart'; |
| 4 | +import 'package:flutter_hooks/flutter_hooks.dart'; |
| 5 | +import 'package:go_router/go_router.dart'; |
| 6 | +import 'package:hooks_riverpod/hooks_riverpod.dart'; |
| 7 | +import 'package:ion/app/components/avatar/avatar.dart'; |
| 8 | +import 'package:ion/app/components/button/button.dart'; |
| 9 | +import 'package:ion/app/components/gradient_border_painter/gradient_border_painter.dart'; |
| 10 | +import 'package:ion/app/components/progress_bar/ion_loading_indicator.dart'; |
| 11 | +import 'package:ion/app/components/screen_offset/screen_bottom_offset.dart'; |
| 12 | +import 'package:ion/app/components/screen_offset/screen_side_offset.dart'; |
| 13 | +import 'package:ion/app/extensions/extensions.dart'; |
| 14 | +import 'package:ion/app/features/auth/providers/auth_provider.m.dart'; |
| 15 | +import 'package:ion/app/features/feed/views/pages/feed_page/components/stories/mock.dart'; |
| 16 | +import 'package:ion/app/features/ion_connect/model/event_reference.f.dart'; |
| 17 | +import 'package:ion/app/features/tokenized_communities/providers/token_market_info_provider.r.dart'; |
| 18 | +import 'package:ion/app/features/user/model/profile_mode.dart'; |
| 19 | +import 'package:ion/app/features/user/pages/profile_page/components/profile_background.dart'; |
| 20 | +import 'package:ion/app/features/user/pages/profile_page/components/profile_details/user_name_tile/user_name_tile.dart'; |
| 21 | +import 'package:ion/app/features/user/providers/user_metadata_provider.r.dart'; |
| 22 | +import 'package:ion/app/hooks/use_avatar_colors.dart'; |
| 23 | +import 'package:ion/app/router/app_routes.gr.dart'; |
| 24 | +import 'package:ion/app/router/components/navigation_app_bar/navigation_close_button.dart'; |
| 25 | +import 'package:ion/app/router/utils/show_simple_bottom_sheet.dart'; |
| 26 | +import 'package:ion/app/services/logger/logger.dart'; |
| 27 | +import 'package:ion/app/services/ui_event_queue/ui_event_queue_notifier.r.dart'; |
| 28 | +import 'package:ion/generated/assets.gen.dart'; |
| 29 | + |
| 30 | +class CreatorTokenIsLiveDialogEvent extends UiEvent { |
| 31 | + CreatorTokenIsLiveDialogEvent(this.tokenDefinitionEventReference); |
| 32 | + |
| 33 | + static bool shown = false; |
| 34 | + final ReplaceableEventReference tokenDefinitionEventReference; |
| 35 | + |
| 36 | + @override |
| 37 | + void performAction(BuildContext context) { |
| 38 | + if (!shown) { |
| 39 | + shown = true; |
| 40 | + showSimpleBottomSheet<void>( |
| 41 | + context: context, |
| 42 | + backgroundColor: context.theme.appColors.forest, |
| 43 | + child: |
| 44 | + CreatorTokenIsLiveDialog(tokenDefinitionEventReference: tokenDefinitionEventReference), |
| 45 | + ).whenComplete(() => shown = false); |
| 46 | + } |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +class CreatorTokenIsLiveDialog extends HookConsumerWidget { |
| 51 | + const CreatorTokenIsLiveDialog({required this.tokenDefinitionEventReference, super.key}); |
| 52 | + |
| 53 | + final ReplaceableEventReference tokenDefinitionEventReference; |
| 54 | + |
| 55 | + @override |
| 56 | + Widget build(BuildContext context, WidgetRef ref) { |
| 57 | + final avatarUrl = ref.watch(currentUserMetadataProvider).value?.data.avatarUrl; |
| 58 | + final imageColors = useImageColors(avatarUrl); |
| 59 | + |
| 60 | + return ProfileGradientBackground( |
| 61 | + colors: imageColors ?? useAvatarFallbackColors, |
| 62 | + disableDarkGradient: false, |
| 63 | + child: _ContentState(tokenDefinitionEventReference), |
| 64 | + ); |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +class _ContentState extends HookConsumerWidget { |
| 69 | + const _ContentState(this.tokenDefinitionEventReference); |
| 70 | + |
| 71 | + final ReplaceableEventReference tokenDefinitionEventReference; |
| 72 | + |
| 73 | + @override |
| 74 | + Widget build(BuildContext context, WidgetRef ref) { |
| 75 | + final isLoading = useState(false); |
| 76 | + final currentUserMasterPubkey = ref.watch(currentPubkeySelectorProvider) ?? ''; |
| 77 | + final userMetadata = ref.watch(currentUserMetadataProvider).valueOrNull; |
| 78 | + final avatarUrl = userMetadata?.data.avatarUrl ?? ''; |
| 79 | + |
| 80 | + final eventReferenceString = userMetadata?.toEventReference().toString(); |
| 81 | + |
| 82 | + final token = eventReferenceString != null |
| 83 | + ? ref.watch(tokenMarketInfoProvider(eventReferenceString)).valueOrNull |
| 84 | + : null; |
| 85 | + |
| 86 | + return Stack( |
| 87 | + children: [ |
| 88 | + PositionedDirectional( |
| 89 | + bottom: 0, |
| 90 | + start: 0, |
| 91 | + end: 0, |
| 92 | + child: Assets.images.tokenizedCommunities.creatorMonetizationLiveRays |
| 93 | + .iconWithDimensions(width: 461.s, height: 461.s), |
| 94 | + ), |
| 95 | + PositionedDirectional( |
| 96 | + end: 8, |
| 97 | + child: NavigationCloseButton(color: context.theme.appColors.onPrimaryAccent), |
| 98 | + ), |
| 99 | + ScreenSideOffset.medium( |
| 100 | + child: Column( |
| 101 | + children: [ |
| 102 | + SizedBox(height: 30.0.s), |
| 103 | + CustomPaint( |
| 104 | + painter: GradientBorderPainter( |
| 105 | + strokeWidth: 2.0.s, |
| 106 | + cornerRadius: 26.0.s, |
| 107 | + gradient: storyBorderGradients[3], |
| 108 | + backgroundColor: context.theme.appColors.forest.withAlpha(125), |
| 109 | + ), |
| 110 | + child: Padding( |
| 111 | + padding: EdgeInsets.all(18.0.s), |
| 112 | + child: Avatar( |
| 113 | + size: 64.0.s, |
| 114 | + fit: BoxFit.cover, |
| 115 | + imageUrl: avatarUrl, |
| 116 | + borderRadius: BorderRadius.all(Radius.circular(16.0.s)), |
| 117 | + ), |
| 118 | + ), |
| 119 | + ), |
| 120 | + SizedBox(height: 8.0.s), |
| 121 | + UserNameTile( |
| 122 | + showProfileTokenPrice: true, |
| 123 | + profileMode: ProfileMode.dark, |
| 124 | + pubkey: currentUserMasterPubkey, |
| 125 | + priceUsd: token?.marketData.priceUSD, |
| 126 | + ), |
| 127 | + SizedBox(height: 18.0.s), |
| 128 | + Text( |
| 129 | + context.i18n.tokenized_community_creator_token_live_title, |
| 130 | + textAlign: TextAlign.center, |
| 131 | + style: context.theme.appTextThemes.title |
| 132 | + .copyWith(color: context.theme.appColors.onPrimaryAccent), |
| 133 | + ), |
| 134 | + SizedBox(height: 8.0.s), |
| 135 | + Text( |
| 136 | + context.i18n.tokenized_community_creator_token_live_subtitle, |
| 137 | + textAlign: TextAlign.center, |
| 138 | + style: context.theme.appTextThemes.body2 |
| 139 | + .copyWith(color: context.theme.appColors.secondaryBackground), |
| 140 | + ), |
| 141 | + SizedBox(height: 24.0.s), |
| 142 | + Button( |
| 143 | + disabled: isLoading.value, |
| 144 | + label: Text(context.i18n.button_share), |
| 145 | + minimumSize: Size(double.infinity, 56.0.s), |
| 146 | + trailingIcon: |
| 147 | + isLoading.value ? const IONLoadingIndicator() : const SizedBox.shrink(), |
| 148 | + onPressed: token != null |
| 149 | + ? () async { |
| 150 | + isLoading.value = true; |
| 151 | + try { |
| 152 | + if (context.mounted) { |
| 153 | + context.pop(); |
| 154 | + |
| 155 | + await ShareViaMessageModalRoute( |
| 156 | + eventReference: tokenDefinitionEventReference.encode(), |
| 157 | + ).push<void>(context); |
| 158 | + } |
| 159 | + } catch (e, st) { |
| 160 | + Logger.error(e, stackTrace: st); |
| 161 | + } finally { |
| 162 | + isLoading.value = false; |
| 163 | + } |
| 164 | + } |
| 165 | + : null, |
| 166 | + ), |
| 167 | + ScreenBottomOffset(), |
| 168 | + ], |
| 169 | + ), |
| 170 | + ), |
| 171 | + ], |
| 172 | + ); |
| 173 | + } |
| 174 | +} |
0 commit comments